Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hftbt-0.1.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hftbt-0.1.0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file hftbt-0.1.0.tar.gz.

File metadata

  • Download URL: hftbt-0.1.0.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

Hashes for hftbt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0fb2dc339a8a1389d3de93412abbe4816169432962d124083657f06979db03d5
MD5 d2011177cfd9ac4d378593d320caec61
BLAKE2b-256 e22167197bc466c04bf6bc9fc1ac1475449cc3b723284af3ace16fc7ba5bcf3c

See more details on using hashes here.

File details

Details for the file hftbt-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hftbt-0.1.0-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

Hashes for hftbt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b766cec74d0b5635c6abdbcb67b73c76e561be0c8db02bfdfef9620c7c457aca
MD5 37f798a20a404e4e89c93c0ef04ae648
BLAKE2b-256 5f65f79e77804e0b3d85e0116df54c70991d01be35d202e7159d282a26d3258c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page