hftbacktest

repository·master·Indexed 26 days ago

https://github.com/nkaz001/hftbacktest

A Rust framework for high-frequency trading (HFT) and market-making strategies. It features accurate market replay-based backtesting with tick-by-tick simulation, L2/L3 order book reconstruction, and latency accounting. The ecosystem includes a Connector for centralized communication between bots and exchanges (supporting Binance Futures and Bybit), a collector CLI for gathering market data into compressed files, and Python bindings via py-hftbacktest.

Tokens
38.5K
Snippets
54
Records
207
Agent score
88%

What's inside hftbacktest

  1. Overview of HftBacktest features

    master

    HftBacktest is a Rust framework for high-frequency trading (HFT) and market-making strategies. It provides accurate market replay-based backtesting using full order book and trade tick feed data.

    Key capabilities include:

    • Tick-by-tick simulation: Customizable time intervals or based on feed/order receipt.
    • Order Book Reconstruction: Supports L2 Market-By-Price and L3 Market-By-Order feeds.
    • Latency Accounting: Models both feed and order latency.
    • Order Fill Simulation: Accounts for order queue position.
    • Multi-asset/Multi-exchange: Supports complex models across different assets and exchanges.
    • Live Bot Deployment: Run the same algorithm code for live trading (currently supports Binance Futures and Bybit).
  2. Understand Latency Types in HftBacktest

    master

    HftBacktest accounts for three distinct types of latency to ensure realistic HFT strategy backtesting:

    1. Feed latency: The delay between the exchange sending feed events (e.g., order book changes, trades) and the local system receiving them. This is managed using both local timestamp and exchange timestamp.
    2. Order entry latency: The delay between sending an order request and the exchange's matching engine processing it.
    3. Order response latency: The delay between the matching engine processing an order and the local system receiving the response (including order fill responses).
  3. Run the HftBacktest Connector

    master

    Run the Connector using the connector executable. You can run multiple instances for the same exchange by providing unique names and different configuration files.

    Important: Because the Connector communicates with bots via shared memory, both the Connector and the bots must be running on the same machine.

    connector --name bf --connector binancefutures --config binancefutures.toml
  4. Build the Py-HftBacktest shared library

    master
    To build the shared library required for testing the Python bindings, use the maturin develop command. This is typically used during the development process to ensure the Rust-based core is correctly compiled and available to the Python environment.
    maturin develop
  5. Explore HftBacktest examples

    master

    HftBacktest provides various examples to help you understand how to implement strategies and run backtests. You can find general examples in the examples directory and specific Rust-based implementation examples in the hftbacktest/examples directory.

    A notable comprehensive example is the high-frequency gridtrading notebook, which demonstrates the complete process of backtesting Binance Futures using a high-frequency grid trading strategy implemented in Rust.