erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.83k stars 767 forks source link

Trade object returns inconsistent values of Trade.order.orderId vis-a-vis Trade.orderStatus.orderId and Trade.fills.orderId #552

Closed pankaj3009 closed 1 year ago

pankaj3009 commented 1 year ago

I came across this issue when placing orders rapidly for the same contract/side. Basically, three orders were placed one after another. The trade object returned by openOrder had expected order_ids (generated by ib_insync) as 263,264 and 265. However, the subsequent trade objects were corrupted. The orderStatus, executions for orderid 263 and 264 displayed order.OrderId as 265. However, orderStatus.orderId was captured correctly. So we had a situation where the trade object displayed a different orderId for order and orderStatus.

The attached log has the relevant extracts with timestamp. The last two lines of the log have the erroneous values.

error.log

erdewit commented 1 year ago

However, the subsequent trade objects were corrupted.

The only time I've seen this happen is if the code is not thread-safe.