Additional methods
This article describes the additional methods in the Datafeed API. With methods, you can enable additional features such as marks and a countdown to the bar close.
searchSymbolsPaginated
The library calls the searchSymbolsPaginated method to request symbols in pages (batches) as the user scrolls.
When implemented, this method is used instead of searchSymbols.
The method receives an options object containing the search criteria (such as symbol type and exchange) and pagination details.
Pass the resulting array of symbols as a parameter to the onResult callback.
searchSymbolsPaginated: async (
options,
onResult,
) => {
console.log('[searchSymbolsPaginated]: Method call', options);
// options object contains: userInput, exchange, symbolType, limit, etc.
const symbols = await getMatchingSymbolsFromBackend(options);
onResult(symbols);
}
As a result, the library gets an array of SearchSymbolResultItem objects that have the following format:
[
{
"symbol": "<short symbol name>",
"description": "<symbol description>",
"exchange": "<symbol exchange name>",
"ticker": "<symbol ticker name>",
"type": "stock" // "futures"/"crypto"/"forex"/"index"
},
{
//...
}
]
getMarks
The library calls getMarks to request marks for the visible bar range. The library assumes that you call GetMarksCallback once per getMarks call. Pass an array of Mark objects as a callback parameter.
Only ten marks can be attached to a bar. 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.
This method is called only if your datafeed supports marks.
By default, the mark's pop-up tooltip displays the plain text string from the text property. In Trading Platform, you can render fully custom tooltip content with your own web component by providing the customTooltip property. Refer to the Customize mark tooltips guide for more information.
The code sample below demonstrates the example of getMarks implementation:
getMarks = (symbolInfo, startDate, endDate, onDataCallback, resolution) => {
console.log('getMarks');
onDataCallback(
[
{
id: 1,
time: endDate,
color: 'red',
text: ['This is the mark pop-up text.'],
label: 'M',
labelFontColor: 'blue',
minSize: 25
},
{
id: 2,
time: endDate + 5260000, // 2 months
color: 'red',
text: ['Second marker'],
label: 'S',
labelFontColor: 'green',
minSize: 25
}
]);
};
getTimescaleMarks
The library calls getTimescaleMarks to request timescale marks for the visible bar range. The library assumes that you call GetMarksCallback once per getTimescaleMarks call. Pass an array of TimescaleMark objects as a callback parameter.
These method is called only if your datafeed supports marks.
By default, the mark's pop-up tooltip displays the plain text strings from the tooltip property. In Trading Platform, you can render fully custom tooltip content with your own web component by providing the customTooltip property. Refer to the Customize mark tooltips guide for more information.
The code sample below demonstrates the example of getTimescaleMarks implementation:
getTimescaleMarks = (
symbolInfo,
startDate,
endDate,
onDataCallback,
resolution
) => {
// optional
console.log('getTimescaleMarks');
let marks = [];
if (symbolInfo.name === 'AAPL') {
marks = [
{
id: 1,
time: startDate,
color: 'red',
label: 'Aa',
minSize: 30,
tooltip: [
'Lorem',
'Ipsum',
'Dolor',
'Sit',
]
},
{
id: 2,
time: startDate + 5260000, // 2 months
color: 'blue',
label: 'B',
minSize: 30,
tooltip: [
'Amet',
'Consectetur',
'Adipiscing',
'Elit',
]
}
];
} else {
marks = [
{
id: 'String id',
time: endDate,
color: 'red',
label: 'T',
tooltip: ['Nulla']
}
];
}
onDataCallback(marks);
};
getServerTime
By default, the library gets the time from the user's machine. If the machine time is incorrect, the time used in the library is also incorrect.
To synchronize the library time with a server's time, enable the supports_time property and implement the getServerTime method.
In the implementation, send a request to a time server and return the accurate value to the library using the ServerTimeCallback.
The time value should be a Unix timestamp, for example, 1445324591.
Note that the callback should be called only once.
The library allows you to display the countdown to the bar closing on the price scale.
If you use this feature, consider implementing getServerTime to make sure that the countdown is correct.
To display a countdown, set the mainSeriesProperties.showCountdown property to true.
getVolumeProfileResolutionForPeriod
The library calls getVolumeProfileResolutionForPeriod to request a detailed resolution for the Volume Profile Visible Range, Volume Profile Fixed Range, and Session Volume Profile indicators. Implement this method if you want 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 from and to arguments describe the range that the indicator calculates:
- the visible range for Volume Profile Visible Range
- the selected range for Volume Profile Fixed Range
- the range that the main series has loaded for Session Volume Profile
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 and builds the profile from its bars. If you return currentResolution, or do not implement the method 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 detailed resolution differently: on time-based charts, it can pick a finer resolution advertised by the symbol or datafeed configuration, and your result takes precedence when it is finer than the chart resolution. For more information, refer to the Session Volume Profile article.