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.1.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.1.1.0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hftbt-0.1.1.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.1.1.0.tar.gz
Algorithm Hash digest
SHA256 03635d0b7a95658593c224c02439a4ecaa934d36b50d6ba47bcd90e8c7fddca4
MD5 d27184e135848334be5ca7f738f028db
BLAKE2b-256 475d1944d4724e9d9632d44f26db232fdc6df843f0e371c4eb70992c8cb8dc0e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hftbt-0.1.1.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.1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 203a8fb98ed18c9d9b668995c8e91e33f9937604ace56d87fa6ba8eaa3022dba
MD5 3c102be707ea6035a4fcfdb067ebc561
BLAKE2b-256 d61f6f2892e4cf00cc234217a0cd5de4c27b1bbad9f1afbf2eb19cb5eb8a7e5c

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