Загрузка данных


public getDataSource =
  (indicativeData?: ChartIndicativeData, cb?: (timeframe: Timeframes) => void) =>
  async (timeframe: Timeframes, symbolId: string, until?: Candle) => {
    cb?.(timeframe);

    const symbol = getRequestSymbol(symbolId);

    if (!symbol) {
      return null;
    }

    const interval = moexChartTimeConverter(timeframe);
    const date = until ? until.time - 1 : Math.round(Date.now() / 1000);

    const data = await requestBars({
      currencyPair: symbol.replaceAll(':', '.'),
      interval,
      periodParams: {
        firstDataRequest: !until,
        to: date,
        from: Date.now(),
        countBack: 2000,
      },
      ticker: symbol,
      indicativeData,
    });

    const historyData = until ? data.filter((candle) => candle.time < until.time) : data;

    if (historyData.length === 0) {
      return null;
    }

    const issTimeframe = moexChartToIssTimeframe(timeframe);

    if (issTimeframe === timeframe) {
      this.realtimeShouldBeConvoluted = false;

      return historyData;
    }

    this.realtimeShouldBeConvoluted = true;

    const convolutedData = timeframeConvolution(historyData, timeframe);

    return convolutedData.length > 0 ? convolutedData : null;
  };