Data Format Requirements
HftBacktest requires normalized data with the following structure:ev: Event type (u64)exch_ts: Exchange timestamp in nanoseconds (i64)local_ts: Local receipt timestamp in nanoseconds (i64)px: Price (f64)qty: Quantity (f64)order_id: Order ID (u64)ival: Integer value field (i64)fval: Float value field (f64)
All timestamps in HftBacktest are in nanoseconds.
Collecting Binance Futures Data
Step 1: Collect Raw Feed Data
You can collect Binance Futures feed data using the Data Collector. Raw feed data format:Step 2: Convert to Normalized Format
Use the built-in conversion utilities to normalize the raw data:- Corrects timestamp latencies
- Reorders events to fix any timestamp inconsistencies
- Produces normalized data ready for backtesting
_ = binancefutures.convert(
'usdm/btcusdt_20240808.gz',
output_filename='usdm/btcusdt_20240808.npz',
combined_stream=True
)
Creating Market Depth Snapshots
Since cryptocurrency exchanges run 24/7, you need initial snapshots to reconstruct complete market depth.Build End-of-Day Snapshot
Save the Snapshot
Snapshot data shows bid levels first, then ask levels, with both sorted from best price to farthest price.
Using Snapshots in Backtests
Load the snapshot as the initial market state:Public Data Sources
You can find some prepared data hosted by supporters:Data Preparation Checklist
Next Steps
- Learn about Working with Market Depth and Trades
- Explore Integrating Custom Data
- See the complete tutorial