Skip to main content

Configure resolutions in datafeed

Overview

Resolutions define the time interval of a single bar (for example, 1 minute, 1 day, or 1 month) on a chart. While the Resolution article explains how you can manage resolutions in the UI, this article focuses on the datafeed side.

To ensure that charts display data correctly for each resolution, you need to configure your datafeed. This includes:

  1. Declaring which resolutions are supported globally and per symbol.
  2. Enabling special resolutions such as seconds or ticks.
  3. Implementing the data request logic for each resolution in the getBars method.

The following sections provide step-by-step instructions for configuring resolutions in your datafeed.

1. Specify supported resolutions

To enable any resolution, specify the following properties:

The resolutions should be listed in a specific format. For example, ["1", "15", "240", "D", "6M"] stands for 1 minute, 15 minutes, 4 hours, 1 day, and 6 months. If the certain symbol does not support some chart resolutions, they are disabled for this symbol in the UI.

Supported resolutions

If a user switches to another symbol, that does not support the selected resolution, the library changes the resolution to the first available one for this symbol.

Additional resolutions

The library can combine smaller intervals into larger ones to build new resolutions. For instance, it can build 2-minute bars from 1-minute bars. Therefore, you can enable resolutions that your datafeed does not explicitly provide. To do this, add these resolutions to the supported_resolutions arrays mentioned above.

If you want to disable resolution rebuilding, use the disable_resolution_rebuild featureset.

caution

The library cannot build the following resolutions:

  • daily, weekly, or monthly resolutions using intraday data
  • resolutions higher than seconds using tick data

2. Enable required resolutions

Follow the instructions below to enable the required resolutions.

Resolution in seconds

To enable resolution in seconds, additionally configure the following properties:

Additionally, if your datafeed supports tick data for a symbol, you can tell the library to build seconds bars from ticks. To do this, set build_seconds_from_ticks to true. Note that this feature is available in Trading Platform only.

Resolution in minutes (intraday)

To enable intraday resolution (in minutes), additionally configure the following properties:

Resolution in days

To enable resolution in days, additionally configure the following properties:

Resolution in weeks / months

To enable resolution in weeks or months, additionally configure the following properties:

Resolution in ticks

To enable resolution in ticks, additionally configure the following properties:

Additionally, you can tell the library to build seconds bars from ticks. To do this, set build_seconds_from_ticks to true. Note that this feature is available in Trading Platform only.

3. Implement method in datafeed

The library requests data from the datafeed based on the current resolution selected on the chart. All resolutions that your datafeed explicitly supports should be listed in the *_multipliers properties (seconds_multipliers, daily_multipliers, etc.) and implemented in the getBars method.

Example

Consider the following example. The datafeed has 1-minute and 2-minute bars. Also, you would like to support a 5-minute resolution. In this case, you should configure the LibrarySymbolInfo properties as follows:

//...
"has_intraday": true,
"supported_resolutions": ["1", "2", "5"],
"intraday_multipliers": ["1", "2"], // The library can request 1-minute and 2-minute bars, and will build 5-minute bars from 1-minute data
//...

The example of the getBars implementation is demonstrated below:

getBars(symbolInfo, resolution, periodParams, onHistoryCallback, onErrorCallback) {
if (resolution === '1') {
const bars = getBarsFor1MinuteResolution(periodParams);
onHistoryCallback(bars);

return;
}

if (resolution === '2') {
const bars = getBarsFor2MinuteResolution(periodParams);
onHistoryCallback(bars);

return;
}

//...
}

function getBarsFor1MinuteResolution(periodParams) {
// Your custom logic
}

function getBarsFor2MinuteResolution(periodParams) {
// Your custom logic
}