Add CryptoHFTData.com orderbook/trades support and full workflow notebook - #307
Add CryptoHFTData.com orderbook/trades support and full workflow notebook#307hmate9 wants to merge 4 commits into
Conversation
|
Does book data include snapshots per file (hourly) or per day? |
deltas are most common, but after a disconnect it now also has snapshots: |
|
but even with just deltas, you can effectively create a snapshot by reading in deltas a few hours from before the exact timeframe youre interested in and "warming up" with that data |
|
@nkaz001 any feedback or plans to merge this? |
|
@hmate9
I think it's expected to have one gap per day due to planned exchange engine restarts, but there're more frequent gaps, is it a known issue? Also, is there github/discord? |
|
@AnMakc thanks for flagging this. I rechecked the full range from your screenshot, plus the period since then, against the currently published CryptoHFTData files. Method: for Binance USD-M futures orderbook updates, I collapsed the price-level rows back to event-level depth messages and checked the Binance continuity rule:
Snapshot rows were treated as valid reset anchors.
Results as of 2026-06-20:
So yes, your complaint was valid for the earlier data, especially March. But the situation has improved a lot since then: roughly a 91% lower gap rate, and from 2026-05-28 through the latest available 2026-06-20 hour I found zero real We have invested into making our collectors much more stable and more reliable. We still have rare disconnects from binance websockets but recover quickly. |
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Documentation | 9 minor |
🟢 Metrics 61 complexity · 4 duplication
Metric Results Complexity 61 Duplication 4
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.


Summary
This PR adds CryptoHFTData as a historical order book and trade data provider for the Python data utilities, including conversion, documentation, a command-line example, and an end-to-end notebook.
Disclosure: I created CryptoHFTData.com and provide the historical market data used by this integration. The provider has broad spot and derivatives coverage and supports rate-limited keyless downloads through its free tier.
What’s included
hftbacktest.data.utils.cryptohftdatadownload(...)convert(...)download_and_convert(...)hftbacktest[cryptohftdata]dependency usingcryptohftdata>=0.4.0CRYPTOHFTDATA_API_KEYcredentialsevent_dtypeexamples/cryptohftdata.pyfor command-line downloads and conversionexamples/CryptoHFTData Workflow.ipynbcovering download, conversion, snapshot reconstruction, replay, and statisticsConverter behavior
The converter maps CryptoHFTData’s normalized schema into HftBacktest’s event format:
local_ts = received_timeexch_ts = coalesce(transaction_time, event_time) * 1_000_000local_ts = received_timeexch_ts = coalesce(trade_time, event_time) * 1_000_000is_buyer_maker=TruebecomesSELL_EVENT | TRADE_EVENTBUY_EVENT | TRADE_EVENTDEPTH_EVENTDEPTH_CLEAR_EVENTandDEPTH_SNAPSHOT_EVENTsequencesThe normal latency correction, stable event ordering, and event-order validation are applied before output.
Usage
pip install "hftbacktest[cryptohftdata]" python examples/cryptohftdata.py \ BTCUSDT binance_futures 2026-03-01 2026-03-02 \ data/btcusdt_20260301_20260302.npzAn API key is optional.
CRYPTOHFTDATA_API_KEYcan be set for account access without putting credentials in source code.Validation
python -m pytest py-hftbacktest/tests/test_cryptohftdata.py -q— 9 passedruff checkon the provider, tests, and command-line example — passedHashMapMarketDepthBacktestto a valid 0.0445 / 0.0446 terminal bookThe broader upstream Python test directory currently contains an existing test that expects an untracked
tmp_20240501.npzfixture and a Numba function namedtest_runthat pytest collects as a fixture-based test. Those failures are unrelated to this change; the complete CryptoHFTData test module passes.Notes