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

Coincidentally, creates a duplicated client order id #146

Closed StephenLee2016 closed 2 months ago

StephenLee2016 commented 2 months ago

Hi, @nkaz001 I encountered “Coincidentally, creates a duplicated client order id.” warning during the live trading process, and I am still getting familiar with this framework. I would like to know under what circumstances this issue might occur? Thx

nkaz001 commented 2 months ago

In the Bot interface, the order ID is handled as an integer, but when it's sent to the exchange, a random string is generated as the order ID. The error occurs when the generated random ID already exists. Have you encountered this error frequently? The probability of a collision is quite low.

StephenLee2016 commented 2 months ago

Hi, @nkaz001 . I noticed that the order_id is generated via // order price in tick is used as order id. new_ask_orders.insert(ask_price_tick, ask_price); , and then I see similar issues here https://dev.binance.vision/t/futures-api-duplicating-orders-issue/11684/1 https://dev.binance.vision/t/how-is-exclude-duplicate-order-execution-by-api/1585.

I usually encounter this problem after running for a while. Have you come across this issue before?

nkaz001 commented 2 months ago

Please see https://github.com/nkaz001/hftbacktest/blob/master/hftbacktest/src/connector/binancefutures/ordermanager.rs#L277-L282

The actual order ID is generated with a random string which gives the error you encountered. The integer order ID gives the different error when it already exists.

StephenLee2016 commented 2 months ago

Please see https://github.com/nkaz001/hftbacktest/blob/master/hftbacktest/src/connector/binancefutures/ordermanager.rs#L277-L282

The actual order ID is generated with a random string which gives the error you encountered. The integer order ID gives the different error when it already exists.

Thank you very much for your reply. I think I understand where the problem lies. I will try generating longer random strings to reduce conflicts. If I have further questions, I will synchronize them here. Thank you again.

nkaz001 commented 1 month ago

I discovered an issue with the mishandling of order IDs, which led to the duplication of order IDs. It’s unclear whether this problem arose during refactoring or if it existed beforehand. The issue is fixed in the new version, but the new version is still unstable.