Custom Quote Feed with refresh and pagination support

This fiddle demonstrates how to implement a custom QuoteFeed with refresh and pagination support.

by sonylnagale

HTML

<link rel="stylesheet" href="https://jsfiddle.chartiq.com/chart/css/stx-chart.css">
<div class="chartContainer" style="width:100%;height:400px;position:relative;"></div>

<!--[if IE 8]><script>alert("This template is not compatible with IE8");</script><![endif]-->

<script src="https://jsfiddle.chartiq.com/chart/js/chartiq.js"></script>

JavaScript

// Create your QuoteFeed object.
var myQuoteFeed = {};

myQuoteFeed.url = "https://jsfiddle.chartiq.com/sample_json.js";


// This is where the action is. params will tell you what the chart needs (symbol, interval, date ranges)
// Use that data to construct your query. Use our ajax, or jquery, or any other method to fetch the data
// Make sure it's in the right format and return it in the callback like below.  
// Always use cb() to return data from fetch methods!  Even errors. 

// This method is called by the chart to fetch initial data
myQuoteFeed.fetchInitialData = function(symbol, startDate, endDate, params, cb) {
  // this alert and console log are here to help you see what the fetch calls are doing.
  //alert('Open the console to see what is happening....');
  console.log("Asking for initial data...");

  var query = this.url +
    "?symbol=" + symbol +
    "&interval=" + params.interval +
    "&startDate=" + CIQ.yyyymmddhhmm(startDate) +
    "&endDate=" + CIQ.yyyymmddhhmm(endDate);

  CIQ.postAjax(query, null, function(status, response) {
    if (status == 200) {
      cb({
        quotes: JSON.parse(response),
        moreAvailable: true
      });
    } else {
      cb({
        error: (response ? response : status)
      });
    }
  });

  // This sample assumes the response returns only the data and in the right format.
  // Put your code here to format the response according to the specs 
  // and return it in the callback.
  // Example code to iterate trough the responses and load them one at a time:
  //	var quotes=formatQuotes(response);  // your function to creates a properly formatted array.
  //	var newQuotes=[];
  //	for(var i=0;i<quotes.length;i++){
  //		newQuotes[i]={};
  //		newQuotes[i].Date=quotes[i][0]; // Or set newQuotes[i].DT if you have a JS Date
  //		newQuotes[i].Open=quotes[i][1];
  //		newQuotes[i].High=quotes[i][2];
  //		newQuotes[i].Low=quotes[i][3];
  //		newQuotes[i].Close=quotes[i][4];
 ...