Skip to content
All library documents

Paginating Binance Futures Kline History and Updating Bars

Article Strategy library · Author: 发明者量化-小小梦

Summary

This JavaScript template shows how to retrieve a requested length of historical candles from Binance futures when one exchange request cannot supply them all. It maps supported second-based intervals to Binance interval names, selects the USD-margined or coin-margined endpoint based on the quote currency, and requests data in bounded batches. Results are converted into timestamped OHLCV bars and prepended until the requested history is collected or the exchange returns no more data. The example also checks for duplicate timestamps and gaps between bars.

A separate update function merges newly fetched candles into the existing series, replacing the latest bar when it changes and appending newer bars. The demonstration requests minute candles and periodically refreshes them. This is a data-acquisition example rather than a trading strategy, and its exchange and interval support is limited. It provides no performance evidence; users should account for API behavior, missing history, and the possibility that the latest candle is still forming.

Key ideas

  • The retrieval function batches candle requests up to the exchange limit and requested history length.
  • Supported intervals and endpoints are selected from the contract and quote currency.
  • Historical results are ordered into a series of OHLCV bars, with basic continuity checks in the demonstration.
  • The update function replaces a changed latest bar and appends bars with newer timestamps.
  • The template is limited to Binance futures and does not establish trading performance.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.