nkaz001 / hftbacktest

A high-frequency trading and market-making backtesting tool in Python and Rust, which accounts for limit orders, queue positions, and latencies, utilizing full tick data for trades and order books, with real-world crypto market-making examples for Binance Futures
MIT License
1.78k stars 357 forks source link

Implemented function to create snapshot up to orderbook level L #112

Closed ian-wazowski closed 1 month ago

ian-wazowski commented 1 month ago

Overview

Currently, the MD (MarketDepth) trait only allows retrieval of the best bid/ask tick and quantity.

Improvements

I have written a function to create a snapshot up to Level L in the format Vec<(f64, f64)>.

Example

/// bids depth 
[(500.1, 0.006), (500.0, 0.002)]
nkaz001 commented 1 month ago

Copying and constructing a vector in the backtesting loop is costly. Therefore, I recommend using the type's method that returns the base data structure of the market depth instead of the trait method. For example, ROIVectorMarketDepth provides bid_depth and ask_depth method that returns a slice of the market depth, allowing you to access market depths quickly.

bohblue2 commented 1 month ago

This feature terminates as soon as it is cost effective to use the bid_depth, ask_depth features of ROIVectorMarketDepth.