V
V
Vitaly Vozhov2021-01-26 19:07:56
JavaScript
Vitaly Vozhov, 2021-01-26 19:07:56

Displaying data on a chart via API?

To display data (date and price) on the stock price chart received through the Moscow Exchange API, I use this code:

(async () => {  // асинхронная функция

    for (start = 0;; start += 500) {   

  let url = 'https://iss.moex.com/iss/engines/stock/markets/shares/boards/TQBR/securities/SBER/candles.json?interval=24&start=' + start;
  let response = await fetch(url); 
  let data = await response.json();

  let formattedData = data.candles.data.map(item => ({  // благодаря объекту map вывожу на график каждый элемент массива
    time: item[7].split(" ")[0],
    value: item[1],
  }));
  let Itemlength = data['candles']['data'].length
  
if (Itemlength < 500) break; // пока не достигнут последний блок данных (их меньше 500), параметр start в url увеличивается на 500
areaSeries.setData(formattedData) // функция графика
}
})();


However, only 500 values ​​are returned for this url, and to get the full amount of data, you need to increase the start parameter in the url by 500 with each iteration. This code gives me only the last block of data.
How can I change the loop to display all the data on the graph?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question