new QuoteFeed()
Base class for Quotes infrastructure. Many of the built in UI capabilities such as comparison charts and mult-symbol studies expect to follow this infrastructure. You should define your own classes that follow this pattern in order to adapt your quote feed to make the most use of the built in componentry.
See STXChart#attachQuoteFeed for details on how to attach a QuoteFeed to your chart.
See Data Loading for a complete tutorial on how to load data into your charts.
Note: please review the following tutorial about data accessibility before attempting to request data from the browser : Integrating Third Party Data Feeds
Classes
Methods
-
announceError(params, dataCallback)
-
Whenever an error occurs the params and dataCallback from fetch will be automatically passed to this method by the quote engine. Use this to alert the user if desired. Override this with your own alerting mechanisms.
Parameters:
Name Type Description params
object The params originally passed into fetch()
dataCallback
object The data returned to fetch
Example
STX.MyQuoteFeed.prototype.announceError=function(params, dataCallback){ if(params.startDate){ // Perhaps some sort of "disconnected" message on screen }else if(params.endDate){ // Perhaps something indicating the end of the chart }else{ STX.alert("Error fetching quote:" + dataCallback.error); // Probably a not found error? } };
-
<abstract> fetch(params, cb)
-
The charting engine will call this method whenever it needs data from your feed. Override this with your implementation to fetch data from your server.
See full implementation outline and demo engine example in stx.js and a fully functinal jsfiddle at http://jsfiddle.net/chartiq/qp33kna7.
See Data Loading tutorial for complete usage details and examples.Important: All data returned in the array must be sorted in ascending order. yourData[0] must be the oldest and yourData[length] must be the newest element in the dataset.
Parameters:
Name Type Description params
object Describes the data requested by the chart. You must return exactly what is requested.
Properties
Name Type Argument Description stx
STXChart The chart object requesting data
symbol
string The symbol to fetch.
symbolObject
string <optional>
The symbol to fetch in object format; if a symbolObject is initalized ( see STXChart#newChart, STXChart#addSeries, STX.Comparison.add )
period
number The timeframe each returned object represents. For example, if using interval "minute", a period of 30 means your feed must return ticks (objects) with dates 30 minutes apart; where each tick represents the aggregated activity for that 30 minute period. Note that this will not always be the same as the period set in STXChart#setPeriodicityV2, since it represents the aggregation of the raw data to be returned by the feed server, rather than the final data to be displayed.
interval
string The type of data your feed will need to provide. Allowable values: "millisecond,"second","minute","day","week","month". (This is not how much data you want the chart to show on the screen; for that you can use STXChart#setRange or STXChart#setSpan)
startDate
Date <optional>
The starting datetime. This will be sent when the chart requires an update to add more data at the right side of the chart. Your feed should return any new ticks it has starting from this date. This is also used in combination with endDate when the chart needs a specific date range of data for comparisons. Your feed should return the entire range specified, regardless of ticks. If no start or end dates are sent, your feed should return the number of most current bars requested in
ticks
. If using STXChart#setTimeZone, please be sure to interpret the date appropriately.endDate
Date <optional>
The ending datetime. This will be sent when the chart is executing a "loadMore" pagination operation. Your feed should return the requested number of historical ticks with the most current date not newer than this date. This is also used in combination with startDate when the chart needs a specific date range of data for comparisons. Your feed should return the entire range specified, regardless of ticks. If no start or end dates are sent, your feed should return the number of most current bars requested in
ticks
. If using STXChart#setTimeZone, please be sure to interpret the date appropriately.update
Boolean <optional>
This will be true when the chart requires a refresh. params.startDate will also be set.
fetchMaximumBars
Boolean <optional>
If set to true, the chart requires as much historical data as is available from the feed (params.ticks may also be set to 20,000 to set a safety max), regardless of start date. This is needed for some chart types since they aggregate data (kagi,renko, or linebreak, for example). Developers implementing fetch, should override params.tick and use a smaller number if their feed can't support that much data being sent back. The engine will then make multiple smaller calls to get enough data to fill the screen.
ticks
number The number of ticks required to fill the chart screen. It is suggested to return 3 times this amount to prevent excessive quote feed requests when user paginates. This can be used to determine how much data to fetch when a date range is not requested (initial load) . Less ticks can be returned if your feed can not support the requested amount, and the engine will make additional calls to try to get the rest of the data. If a date range is requested, you must return the entire range regardless of ticks. If an
update
is requested (strtDate only) you can ignore the number ofticks
and return the most current data you have.cb
STX.QuoteFeed~dataCallback Call this function with the results (or error) of your data request, and an indicator back to the engine indicating if there is more historical data available. !!!! This is a mandatory parameter that can not be omitted !!!
- Since:
-
04-2015 -- must take into account the scenario where a date range is sent in the params (params.startDate && params.endDate) to fill in a gap in the masterData array. Usually used for series or studies.
- 2015-11-1 `params.symbolObject` is now available
-
multiFetch(arr, cb)
-
Fetches multiple quotes asynchronously, possibly from various data sources. This method is used to update a chart with multiple symbols such as a comparison chart.
Parameters:
Name Type Description arr
array Array of stock symbols
cb
function Function to callback when quotes are fetched. Will be passed an array of results. Each result is an object {dataCallback, params}.
Type Definitions
-
dataCallback(response)
-
This function MUST be used with the fetch method to return any results back to the chart (errors, or the data used to update the chart) -- this is a requirement. Failure to use this callback will affect the chart's ability to autorefresh and properly render.
Parameters:
Name Type Description response
Properties
Name Type Argument Description error
string Null if no error, otherwise an error message.
quotes
array An array of Quotes in required JSON format if no error.
moreAvailable
boolean <optional>
Set this to
true
to enable pagination when user scrolls off the left of the chart if more data will be available from the quote feed. Set tofalse
if the quote feed has exhausted the historical data for the instrument requested. Not relevant on current quote update requests.attribution
object <optional>
This object will be assigned to
stx.chart.attribution
and can be used by your UI to display market source and mode. See example.Examples
cb({quotes:[--array of quote elements here--], moreAvailable:true, attribution:{source:"delayed", exchange:"NYSE"}});
cb({error:"Your error message here"});
// have your quotefeed callback call the attribution function. var quoteBehavior={ refreshInterval: 1, callback: function(params){ showAttribution(params.stx); } }; // after very data call, the attribution function will be called and you can then use it to display any message regarding the quote feed function showAttribution(stx){ var source=stx.chart.attribution.source; var exchange= stx.chart.attribution.exchange; var message = exchange + " quotes are "+ source; // add your code here to display the message on your screen. }