nkaz001 / hftbacktest

A high-frequency trading and market-making backtesting and trading bot 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
2.02k stars 397 forks source link

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

Closed ian-wazowski closed 3 months ago

ian-wazowski commented 3 months 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 3 months 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 3 months ago

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