Lightweight high-frequency backtest engine for CryptoHFTData/hftbacktest-style event arrays.
Project description
HFTBT
Lightweight high-performance HFT backtest engine with a hftbacktest-style
@njit strategy API.
Install
cd /Users/chenchen/Desktop/quant/hftbt
uv sync
Run Demo
uv run python examples/njit_market_making_demo.py \
--events-npz data/demo_events.npz \
--tick-size 0.0001 \
--lot-size 0.1
With a fast equity curve:
uv run python examples/njit_market_making_demo.py \
--events-npz data/demo_events.npz \
--tick-size 0.0001 \
--lot-size 0.1 \
--equity-svg results/equity.svg
Strategy Shape
from numba import njit
from hftbt import GTX, LIMIT, FastConfig, load_hft_events, run_njit_strategy, save_equity_svg
@njit
def market_making_algo(hbt):
asset_no = 0
while hbt.elapse(10_000_000) == 0:
depth = hbt.depth(asset_no)
if depth.best_bid <= 0 or depth.best_ask <= depth.best_bid:
continue
hbt.submit_buy_order(asset_no, depth.best_bid_tick, depth.best_bid, 1.0, GTX, LIMIT, False)
return True
events = load_hft_events("data/demo_events.npz")
result = run_njit_strategy(
events,
market_making_algo,
FastConfig(tick_size=0.0001, lot_size=0.1, record_interval_ns=60_000_000_000),
)
equity = result["stat_equity"]
save_equity_svg(result, "results/equity.svg")
Download CryptoHFTData
# preferred local secret file:
mkdir -p ~/.config/hftbt
chmod 700 ~/.config/hftbt
$EDITOR ~/.config/hftbt/secrets.toml
[cryptohftdata]
api_key = "..."
uv run hftbt download-cryptohftdata
--symbol ARBUSDT
--exchange binance_futures
--start-date 2026-06-01
--end-date 2026-06-01
--out data/ARBUSDT_2026-06-01.npz
## Check
```bash
uv run hftbt check
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hftbt-0.1.2.tar.gz.
File metadata
- Download URL: hftbt-0.1.2.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3975bbe7263df906d64a8c82122c19fce4906dde72a987a7d80aa63166ea9a32
|
|
| MD5 |
9bab916f693fceca73e2216ebc70bfb1
|
|
| BLAKE2b-256 |
67c9e8f68da500dec4cb508094a9e887768a17bc3201359ecd2b7027c022ca70
|
File details
Details for the file hftbt-0.1.2-py3-none-any.whl.
File metadata
- Download URL: hftbt-0.1.2-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0866737501df85277dd49a906bdb51db8579db6c3a3170940ed6d686fba83f2
|
|
| MD5 |
94780e9cc5735268131a95d7526e899d
|
|
| BLAKE2b-256 |
2c09f63f686722b8807bace25541bec1758d6f878cc348b325db31d578c8c6d8
|