Interface: IDatafeedChartApi
Charting Library.IDatafeedChartApi
Methods
getBars
getBars(symbolInfo, resolution, periodParams, onResult, onError): void
This function is called when the chart needs a history fragment defined by dates range.
Parameters
| Name | Type | Description |
|---|---|---|
symbolInfo | LibrarySymbolInfo | A SymbolInfo object |
resolution | ResolutionString | Resolution of the symbol |
periodParams | PeriodParams | An object used to pass specific requirements for getting bars |
onResult | HistoryCallback | Callback function for historical data |
onError | DatafeedErrorCallback | Callback function whose only argument is a text error message. If using special characters, please consider encodeURIComponent. |
getMarks
Optional
getMarks(symbolInfo, from, to, onDataCallback, resolution): void
The library calls this function to get marks for visible bars range.
The library assumes that you will call onDataCallback only once per getMarks call.
A few marks per bar are allowed (for now, the maximum is 10). The time of each mark must match the time of a bar. For example, if the bar times are 2023-01-01, 2023-01-08, and 2023-01-15, then a mark cannot have the time 2023-01-05.
Remark: This function will be called only if you confirmed that your back-end is supporting marks (DatafeedConfiguration.supports_marks).
Parameters
| Name | Type | Description |
|---|---|---|
symbolInfo | LibrarySymbolInfo | A SymbolInfo object |
from | number | Unix timestamp in seconds (leftmost visible bar) |
to | number | Unix timestamp in seconds (rightmost visible bar) |
onDataCallback | GetMarksCallback<Mark> | Callback function containing an array of marks |
resolution | ResolutionString | Resolution of the symbol |
getServerTime
Optional
getServerTime(callback): void
This function is called if the supports_time configuration flag is true when the chart needs to know the server time.
The library expects a callback to be called once.
The time is a Unix timestamp in seconds. Example: 1445324591.
getServerTime is used to display countdown on the price scale.
Note that the countdown can be displayed only for intraday resolutions.
Parameters
| Name | Type |
|---|---|
callback | ServerTimeCallback |
getTimescaleMarks
Optional
getTimescaleMarks(symbolInfo, from, to, onDataCallback, resolution): void
The library calls this function to get timescale marks for visible bars range.
The library assumes that you will call onDataCallback only once per getTimescaleMarks call.
Remark: This function will be called only if you confirmed that your back-end is supporting marks (DatafeedConfiguration.supports_timescale_marks).
Parameters
| Name | Type | Description |
|---|---|---|
symbolInfo | LibrarySymbolInfo | A SymbolInfo object |
from | number | Unix timestamp in seconds (leftmost visible bar) |
to | number | Unix timestamp in seconds (rightmost visible bar) |
onDataCallback | GetMarksCallback<TimescaleMark> | Callback function containing an array of marks |
resolution | ResolutionString | Resolution of the symbol |
getVolumeProfileResolutionForPeriod
Optional
getVolumeProfileResolutionForPeriod(currentResolution, from, to, symbolInfo): ResolutionString
The library calls this function to get a detailed resolution for the Volume Profile Visible Range,
Volume Profile Fixed Range, and Session Volume Profile
indicators. The from and to arguments describe the visible range, the selected fixed range, or the
range that the main series has loaded respectively.
Usually, you might want to implement this method to calculate these indicators more accurately. The implementation depends on how much data you can transfer to the library and the depth of data in your datafeed.
The currentResolution argument is the resolution of the chart the indicator is calculated on. If you
return a different resolution, the library requests an additional series at that resolution. If you
return currentResolution, or do not implement this function at all, Visible Range and Fixed Range
build the profile from the chart's own bars and no additional request is made.
Session Volume Profile selects the resolution differently. On time-based charts, it can choose a finer
resolution advertised by the symbol or datafeed, and a finer resolution returned by this function takes
precedence. On tick charts, it always uses currentResolution because finer tick bars cannot be mapped
completely to a displayed bar by timestamp. Refer to
Detailed data for the full selection order.
Parameters
| Name | Type | Description |
|---|---|---|
currentResolution | ResolutionString | Resolution of the chart the indicator is calculated on |
from | number | Unix timestamp in milliseconds at the start of the calculation range |
to | number | Unix timestamp in milliseconds at the end of the calculation range |
symbolInfo | LibrarySymbolInfo | A Symbol object |
Returns
ResolutionString — A resolution
resolveSymbol
resolveSymbol(symbolName, onResolve, onError, extension?): void
The library will call this function when it needs to get SymbolInfo by symbol name.
Parameters
| Name | Type | Description |
|---|---|---|
symbolName | string | Symbol name or ticker |
onResolve | ResolveCallback | Callback function returning a SymbolInfo (LibrarySymbolInfo) |
onError | DatafeedErrorCallback | Callback function whose only argument is a text error message |
extension? | SymbolResolveExtension | An optional object with additional parameters |
searchSymbols
searchSymbols(userInput, exchange, symbolType, onResult, searchSource?): void
Provides a list of symbols that match the user's search query.
Parameters
| Name | Type | Description |
|---|---|---|
userInput | string | Text entered by user in the symbol search field |
exchange | string | The requested exchange. Empty value means no filter was specified |
symbolType | string | Type of symbol. Empty value means no filter was specified |
onResult | SearchSymbolsCallback | Callback function that returns an array of results (SearchSymbolResultItem) or empty array if no symbols found |
searchSource? | SearchInitiationPoint | The source of the search (SearchInitiationPoint). |
searchSymbolsPaginated
Optional
searchSymbolsPaginated(options, onResult): void
Provides a list of symbols that match the user's search query.
Optional. If defined, the library uses this method instead of the non-paginated searchSymbols.
Use the start property from options to determine which "page" of results to return.
For example, if the first call returns 50 results with 10 remaining, the second call will have start set to 50.
When no more results are available on the server, set the symbolsRemaining parameter of the callback to 0.
Parameters
| Name | Type | Description |
|---|---|---|
options | SymbolSearchPaginatedOptions | Object containing the user input, exchange, symbol type, and search source (SearchInitiationPoint). |
onResult | SearchSymbolsPaginatedCallback | Callback function that returns an array of results (SearchSymbolResultItem) or an empty array if no symbols are found. |
subscribeBars
subscribeBars(symbolInfo, resolution, onTick, listenerGuid, onResetCacheNeededCallback): void
The library calls this function when it wants to receive real-time updates for a symbol.
The library assumes that you will call the callback provided by the onTick parameter every time you want to update the most recent bar or to add a new one.
Parameters
| Name | Type | Description |
|---|---|---|
symbolInfo | LibrarySymbolInfo | A SymbolInfo object |
resolution | ResolutionString | Resolution of the symbol |
onTick | SubscribeBarsCallback | Callback function returning a Bar object |
listenerGuid | string | |
onResetCacheNeededCallback | () => void | Function to be executed when bar data has changed |
subscribeDepth
Optional
subscribeDepth(symbol, callback): string
The library calls this function when it wants to receive real-time symbol data in the Depth of Market (DOM) widget.
Note that you should set the BrokerConfigFlags.supportLevel2Data configuration flag to true.
Parameters
| Name | Type | Description |
|---|---|---|
symbol | string | A SymbolInfo object |
callback | DOMCallback | A function returning an object to update DOM data |
Returns
string — A unique identifier that will be used to unsubscribe from the data
unsubscribeBars
unsubscribeBars(listenerGuid): void
The library calls this function when it doesn't want to receive updates anymore.
Parameters
| Name | Type | Description |
|---|---|---|
listenerGuid | string | id to unsubscribe from |
unsubscribeDepth
Optional
unsubscribeDepth(subscriberUID): void
The library calls this function to stop receiving real-time updates for the Depth of Market listener.
Note that you should set the BrokerConfigFlags.supportLevel2Data configuration flag to true.
Parameters
| Name | Type | Description |
|---|---|---|
subscriberUID | string | A string returned by subscribeDepth |