Skip to content
All library documents

Converting Binance Historical Depth and Trade Data for Backtesting

Code Stratmill research code

Summary

This utility converts Binance historical order-book depth, snapshot, and trade files into an event format used by HftBacktest. It reads CSV data, identifies or infers column headers, maps records to depth, snapshot, or trade events, and assigns exchange and local timestamps. For snapshots, bid and ask records are sorted by quantity before being returned or saved. For combined depth and trade data, it applies a base-latency correction, sorts events by exchange and local timestamps, corrects event order, and validates the result.

A central caveat is that Binance’s historical files lack local timestamps, so feed latency is unavailable from the source. The converter can add an artificial latency value, but that assumption may create substantial differences between live trading and backtests. The documentation recommends self-collected or higher-quality vendor data for more realistic timing. This is data preparation guidance rather than a strategy, and it does not provide accuracy comparisons or backtest results.

Key ideas

  • The converter maps Binance snapshot, depth, and trade CSV records into HftBacktest event data.
  • It assigns local timestamps by adding a configurable artificial feed latency to exchange timestamps.
  • Combined depth and trade events receive latency correction, event ordering correction, and validation.
  • Historical files lack local timestamps, limiting the reliability of latency assumptions in backtests.
  • The documentation recommends using self-collected or higher-quality vendor data for realistic timing.

Tags

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