Actively developed

HftBacktest guide

Ordinary bar backtests cannot judge a market-making strategy; HftBacktest exists to model exactly what they miss.

Last reviewed

Quick answer

HftBacktest is an open-source framework for backtesting high-frequency and market-making strategies on full order-book and trade data. It models your order’s queue position and both feed and order latencies, so limit-order fills are realistic. The core is Rust with Python bindings (Numba-compatible), and it includes live connectors for Binance Futures and Bybit.

HftBacktest at a glance

Category
HFT & market making
Language
Rust, Python
License
MIT
Does
Backtesting, Live trading, Market making
Markets
Crypto, Futures
Best for
Market making and other limit-order strategies where queue position and latency decide profitability.
In AlgoGP
Use the exported strategy object from your own code

Pick it if

Market making and other limit-order strategies where queue position and latency decide profitability.

Watch out for

Requires large tick datasets.

HftBacktest strengths and limitations

Strengths

  • Queue-position and latency modelling.
  • Level-2/3 and tick data replay.
  • Rust speed with a Python API.

Limitations

  • Requires large tick datasets.
  • Specialist tool with a steep learning curve.

HftBacktest example

pip install hftbacktest
Install
from hftbacktest import BacktestAsset, HashMapMarketDepthBacktest
asset = (BacktestAsset().data(["btcusdt_20240101.npz"]).linear_asset(1.0)
         .constant_latency(10_000_000, 10_000_000).risk_adverse_queue_model()
         .tick_size(0.1).lot_size(0.001))
hbt = HashMapMarketDepthBacktest([asset])
Abridged: create an asset with latency and queue models.

Use HftBacktest with AlgoGP

AlgoGP does not add HftBacktest to projects automatically yet, but nothing stops you using them together. Every AlgoGP project exports plain Python with a framework-neutral strategy object, so you can call it from HftBacktest yourself.

  1. 1

    Design and backtest in AlgoGP

    Describe the idea to the copilot and backtest it on AlgoGP’s normalized history.

  2. 2

    Add any bridge to get the adapter core

    Adding a bridged framework (for example Backtrader) writes frameworks/algogp_bridge.py, whose StrategyBridge.on_bar() returns the orders the strategy wants.

  3. 3

    Call it from HftBacktest

    Feed HftBacktest’s bars to StrategyBridge, place the returned orders with HftBacktest, and report fills back with sync().

HftBacktest connects to Binance, Bybit, Databento. Each guide shows how to create the API key, which you can store in the project’s Keys & secrets.

HftBacktest: frequently asked questions

Where do I get data for HftBacktest?

Record exchange WebSocket feeds or buy tick data (e.g. Tardis, Databento) and convert it to its format.

HftBacktest alternatives

Independent guide. AlgoGP is not affiliated with HftBacktest. Features, licenses and maintenance change; check the official documentation. Nothing here is investment advice.

Build a strategy