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

Issue of submitting multiple orders repeatedly in IOC mode #130

Closed 0xdaduck closed 1 month ago

0xdaduck commented 3 months ago

When testing my strategy, I found that there was an error in submitting multiple orders when opening a position. When printing the order details, I found that exch_timestamp was always 0. Is this a bug, or is there a problem with my data? In addition, I want to know whether the time unit in ConstantLatency is nanoseconds or something else? I am using the rust version 0.3.2.

0/Order { qty: 0.36029544226265536, leaves_qty: 0.36029544226265536, price_tick: 277550, tick_size: 0.01, side: Buy, time_in_force: IOC, exch_timestamp: 0, status: None, local_timestamp: 1724490016927000000, req: New, exec_price_tick: 0, exec_qty: 0.0, order_id: 0, maker: false, order_type: Limit }
0/Order { qty: 0.36029544226265536, leaves_qty: 0.36029544226265536, price_tick: 277550, tick_size: 0.01, side: Buy, time_in_force: IOC, exch_timestamp: 0, status: None, local_timestamp: 1724490016927000000, req: New, exec_price_tick: 0, exec_qty: 0.0, order_id: 0, maker: false, order_type: Limit }
1/Order { qty: 0.36029544226265536, leaves_qty: 0.36029544226265536, price_tick: 277550, tick_size: 0.01, side: Buy, time_in_force: IOC, exch_timestamp: 0, status: None, local_timestamp: 1724490017027000000, req: New, exec_price_tick: 0, exec_qty: 0.0, order_id: 1, maker: false, order_type: Limit }
2/Order { qty: 0.7205908845253107, leaves_qty: 0.7205908845253107, price_tick: 278331, tick_size: 0.01, side: Sell, time_in_force: IOC, exch_timestamp: 0, status: None, local_timestamp: 1724490017127000000, req: New, exec_price_tick: 0, exec_qty: 0.0, order_id: 2, maker: false, order_type: Limit }
nkaz001 commented 3 months ago

Please see the document. NoPartialFillExchange and PartialFillExchange The supported order types and time-in-force options vary depending on the exchange model. IOC and FOK are only supported in the PartialFillExchange.

However, liquidity-taking orders may show greater discrepancies, as they have a higher chance of causing market impact, which isn't modeled and is very difficult to simulate accurately in the backtester.

nkaz001 commented 3 months ago

This has been added 126ccee3382a5132a650a9cd3c9e1a76ff86108d

0xdaduck commented 1 month ago

Thanks for your help. Have a nice day