Skip to content
All library documents

Converting Bybit Historical Order Book and Trade Data for HftBacktest

Code Stratmill research code

Summary

This Python utility converts Bybit historical depth and trade files into the event array format used by HftBacktest. It reads order book updates from a zipped JSON stream and trades from a gzip-compressed CSV, creates depth, snapshot, clear, and trade events, and orders them by exchange and local timestamps. Optional arguments allow artificial feed latency and base latency to be applied, and the converted data can be saved in compressed NumPy format.

The main limitation is missing local timestamps in the source data, which means the feed latency needed to represent live delivery is not observed. The documentation warns that this can cause meaningful differences between backtests and live trading, and recommends self-collected or higher-quality vendor data. The script demonstrates data preparation mechanics, not a trading strategy or evidence of strategy performance; results depend on source data quality and latency assumptions.

Key ideas

  • The converter reads Bybit order book data from a ZIP archive and trades from a compressed CSV.
  • It maps snapshots, depth updates, and trades into HftBacktest event records.
  • Artificial feed latency and base latency can be supplied when creating local timestamps.
  • Bybit source files lack local timestamps, so backtest latency may differ substantially from live conditions.

Tags

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