API Reference
Namespaces
Classes
Events
Global
Externals

Namespace: quotefeed

quotefeed

See tutorial Data Integration: Quotefeeds for a complete overview and step by step source code for implementing a quotefeed.

Interface for classes that implement a quotefeed. You define a quotefeed object and attach it to the chart using CIQ.ChartEngine#attachQuoteFeed. Each member "fetch..." method is optional. The chart will call your member method if it exists, and will skip if it does not.

Also see CIQ.ChartEngine#dontRoll if your feed aggregates weekly and monthly bars and you do not wish the chart to roll them from daily bars.

Note: Prebuilt quotefeeds are available in a dedicated GitHub repo for real-data quotefeeds at https://github.com/chartiq/quotefeeds.

Properties:
Name Type Description
maxTicks number

The maximum number of ticks a quoteFeed should request at a single time. This value will be overridden if the CIQ.ChartEngine.Driver has a behavior.maximumTicks set.

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 the fetch call.

dataCallback object

The data returned to fetch

Example
quotefeed.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{
			CIQ.alert("Error fetching quote:" + dataCallback.error);	// Probably a not found error?
		}
	};

fetchInitialData(symbol, suggestedStartDate, suggestedEndDate, params, cb)

See Data Integration : Quotefeeds

The charting engine calls this quotefeed function whenever the chart is wiped clean and created again with new data. This typically occurs when CIQ.ChartEngine#loadChart is called but can also occur from other methods such as CIQ.ChartEngine#setPeriodicity or CIQ.ChartEngine#importLayout.

Parameters:
Name Type Description
symbol string

The ticker symbol of the data being fetched

suggestedStartDate Date

A suggested starting date for the fetched data (based on how much can be displayed)

suggestedEndDate Date

A suggested starting date for the fetched data (based on how much can be displayed)

params object

Provides additional information on the data requested by the chart.

Properties
Name Type Argument Default Description
series Boolean

If true then the request is for series/comparison data (i.e. not the the main symbol)

stx CIQ.ChartEngine

The chart object requesting data

symbolObject string <optional>

The symbol to fetch in object format; if a symbolObject is initialized ( see CIQ.ChartEngine#loadChart, CIQ.ChartEngine#addSeries, CIQ.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 CIQ.ChartEngine#setPeriodicity, 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 CIQ.ChartEngine#setRange or CIQ.ChartEngine#setSpan)

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 (for example, Kagi, Renko, or linebreak). 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 suggested number of data points to return. This is calculated as twice the number of bars displayed on the chart. This can be used as an alternative to suggestedStartDate.

timeout number <optional>
10000

This may be used to set the timeout in msec of the remote server request.

cb quotefeed~dataCallback

Call this function with the results (or error) of your data request.

Since:
  • 4.1.2 Added timeout parameter.


fetchPaginationData(symbol, suggestedStartDate, endDate, params, cb)

See Data Integration : Quotefeeds

The charting engine calls this quotefeed function whenever the chart requires older data. Usually this is because a user has scrolled or zoomed past the end of the data.

Note: This method may be called during initial load if your fetchInitialData didn't provide enough data to fill the visible chart.*

Parameters:
Name Type Description
symbol string

The ticker symbol of the data being fetched

suggestedStartDate Date

A suggested starting data for the fetched data (based on how much can be displayed)

endDate Date

The date of the last datum point currently available in the chart. You should return data from this point and then backward in time.

params object

Provides additional information on the data requested by the chart.

Properties
Name Type Argument Default Description
stx CIQ.ChartEngine

The chart object requesting data

symbolObject string <optional>

The symbol to fetch in object format; if a symbolObject is initialized ( see CIQ.ChartEngine#loadChart, CIQ.ChartEngine#addSeries, CIQ.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 CIQ.ChartEngine#setPeriodicity, 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 CIQ.ChartEngine#setRange or CIQ.ChartEngine#setSpan)

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 (for example, Kagi, Renko, or linebreak). 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 suggested number of data points to return. This is calculated as twice the number of bars displayed on the chart. This can be used as an alternative to suggestedStartDate.

timeout number <optional>
10000

This may be used to set the timeout in msec of the remote server request.

future Boolean <optional>

If set to true, the chart is scrolling in a 'forward' direction

cb quotefeed~dataCallback

Call this function with the results (or error) of your data request.

Since:
  • 4.1.2 Added params.timeout.
  • 6.0.0 Added params.future.

fetchUpdateData(symbol, startDate, params, cb)

See Data Integration : Quotefeeds

The charting engine calls this quotefeed function periodically (poll) to request updated data. The polling frequency is determined by the refreshInterval that you provided when you called CIQ.ChartEngine#attachQuoteFeed.

Parameters:
Name Type Description
symbol string

The ticker symbol of the data being fetched

startDate Date

The starting date for the fetched data (based on how much can be displayed)

params object

Provides additional information on the data requested by the chart.

Properties
Name Type Argument Default Description
series Boolean

If true then the request is for series/comparison data (i.e. not the main symbol)

stx CIQ.ChartEngine

The chart object requesting data

symbolObject string <optional>

The symbol to fetch in object format; if a symbolObject is initialized ( see CIQ.ChartEngine#loadChart, CIQ.ChartEngine#addSeries, CIQ.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 CIQ.ChartEngine#setPeriodicity, 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 CIQ.ChartEngine#setRange or CIQ.ChartEngine#setSpan)

timeout number <optional>
10000

This may be used to set the timeout in msec of the remote server request.

cb quotefeed~dataCallback

Call this function with the results (or error) of your data request.

Since:
  • 4.1.2 Added timeout parameter.


subscribe(params)

See Data Integration : Advanced

Although not a core quotefeed function, the charting engine calls this optional function each time the chart encounters a new symbol or a particular periodicity for that symbol. This could happen when a user changes periodcity, changes a symbol, adds a comparison symbol, or a new study is added that requires an underlying symbol.

Use this along with unsubscribe() to keep track of symbols on the chart. Use cases include: maintaining legends, lists of securities, or adding/removing subscriptions to streaming connections.

If using a push stream, subscribe and then have the push streamer push updates using CIQ.ChartEngine#updateChartData.

Parameters:
Name Type Description
params object

Provides additional information on the data requested by the chart.

Properties
Name Type Description
stx CIQ.ChartEngine

The chart object requesting data

symbol string

The symbol being added

symbolObject string

The symbol being added in object form

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 CIQ.ChartEngine#setPeriodicity, 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 CIQ.ChartEngine#setRange or CIQ.ChartEngine#setSpan)

Since:
  • 4.0.0 Changes to periodicity (period/interval) will now also cause subscribe calls.


unsubscribe(params)

See Data Integration : Advanced

Although not a core quotefeed function, the charting engine calls this optional function each time the chart no longer requires a symbol or a particular periodicity for that symbol.

Parameters:
Name Type Description
params object

Provides additional information on the data requested by the chart.

Properties
Name Type Description
stx CIQ.ChartEngine

The chart object requesting data

symbol string

The symbol being removed

symbolObject string

The symbol being removed in object form

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 CIQ.ChartEngine#setPeriodicity, 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 CIQ.ChartEngine#setRange or CIQ.ChartEngine#setSpan)

Since:
  • 4.0.0 Changes to periodicity (period/interval) will now also cause unsubscribe calls.

Type Definitions


dataCallback(response)

All of your quote feed "fetch..." methods must call this callback function to return results to the chart, even if no data is returned from your feed.

Parameters:
Name Type Description
response object

Contains the results of the quote feed function that called this callback function.

Properties
Name Type Argument Description
error string <optional>

An error message, if one occurred.

suppressAlert string <optional>

Set this to true to not display errors.

quotes array <optional>

An array of quotes in required JSON format, if no error occurred.

moreAvailable boolean <optional>

Set this to false to stop pagination requests if you know that no older data is available.

upToDate boolean <optional>

Set this to true to stop forward pagination requests if you know that no newer data is available.

attribution object <optional>

This object is assigned to stx.chart.attribution. Your UI can use this to display attribution messages. See example below.

Since:
  • 8.0.0 Added the response.upToDate property.

Examples

Returning quotes in the dataCallback object.

cb({quotes:[--array of quote elements here--]});

Returning an error in the dataCallback object.

cb({error:"Your error message here"});

Setting attribution through the dataCallback object.
Note: Using dataCallback to display a message requires that the attribution web component not be present in your template; otherwise the message will not display. For information on how to override the web component with custom attribution messages, see https://documentation.chartiq.com/WebComponents.Attribution.html#messages.html#messages.

// Set up a callback function to be called whenever fetchInitialData is called.
 stxx.attachQuoteFeed(yourQuoteFeed, {callback: showAttribution});

// After every data call, the attribution function is called,
// and you can then use it to display any message regarding the quote feed.
	function showAttribution(params){
		var message=params.stx.chart.attribution.message;
		// Add your code here to display the message on your screen.
	}

// In your quote feed's fetchInitialData method, set the attribution object.
cb({quotes:[--array of quote elements here--], attribution:{message:"Data is delayed by 15 minutes"}});