HftBacktest is an open-source framework for developing and testing high-frequency trading (HFT) and market-making strategies. It replays historical market data tick by tick, helping developers evaluate algorithmic trading systems under simulated market conditions before risking capital in live environments.
Unlike basic backtesting tools, HftBacktest models important execution factors such as market-data feed latency, order submission delays, and order queue positions. These details can significantly affect whether a trading strategy would realistically receive a fill, particularly in fast-moving markets.
HftBacktest processes historical trades and order book updates at granular time intervals. Developers can configure simulation timing around market events or feed and order receipt times. This helps reveal how a strategy responds to rapid price changes and changing liquidity.
The framework supports Level 2 (L2) Market-By-Price and Level 3 (L3) Market-By-Order data. L2 feeds represent aggregated quantities at each price level, while L3 feeds provide individual order-level information when available. This market depth data helps simulate trading decisions using more than historical closing prices.
Network and exchange delays can change the outcome of an HFT strategy. HftBacktest supports built-in and custom latency models to represent delays in receiving market data, submitting orders, and receiving responses.
It also models order queue positions to estimate when limit orders might execute. Developers can compare queue models and exchange simulation settings to understand how different assumptions affect fill rates, profitability, and execution quality.
HftBacktest supports strategies involving multiple assets and exchanges. Its Python implementation uses Numba just-in-time compilation to accelerate strategy code, while its Rust implementation provides additional capabilities for performance-focused workflows.
The Rust implementation also supports live trading bot development with the same algorithmic approach, currently targeting Binance Futures and Bybit. This live-trading functionality is Rust-only, so check the official documentation for supported features and exchange requirements.
HftBacktest supports Python 3.10 and later in its current documentation. Install the Python package with pip:
python -m pip install hftbacktest
For the Rust implementation, add the crate to an existing Cargo project:
cargo add hftbacktest
Developers who want to test the latest source changes can also clone the project’s official GitHub repository. Follow the relevant installation and data-preparation instructions for the implementation you plan to use. For help with command-line workflows, see our guide to the Linux shell.
The framework is useful for investigating a range of algorithmic trading approaches, including:
Market replay cannot fully reproduce live trading. A simulated order generally does not change the historical order book, so the framework cannot accurately model every form of market impact. Large orders may therefore produce unrealistic fill assumptions, particularly when consuming available liquidity.
Results also depend on the quality of historical data, timestamp accuracy, latency assumptions, fee calculations, and queue models. Validate these inputs carefully, account for transaction costs, and use paper trading or controlled live tests before deploying a strategy with real capital.
Start with the official HftBacktest documentation for tutorials covering data preparation, market depth, latency modeling, queue-based execution, and multi-market strategies. The GitHub project provides the source code and implementation details for developers who want to inspect or extend the framework.