I'm trying to place an order using the TWS-API and the python package ib_insync. However, I recognize that the order status is not updated by TWS automatically. Please consider the following snippet:
stock = Stock('BMW', 'SMART', 'EUR')
ib.qualifyContracts(stock)
order = MarketOrder("BUY", 10)
trade = ib.placeOrder(stock, order)
A look into the order status of the trade just made (i.e. with trade.log) reveals the order to remain in the submitted state. For that, see the following screenshot:
Highlighted with the red box, you see the log-command printing the order state "submitted". At that point in time, though, the order got already filled when looking into the TWS.
Interestingly, if I now run ib.sleep() (highlighted in green) and look into the order state afterwards, I can see that the order's state has changed to filled (see blue box). This behavior is what I observed several times. Only after typing ib.sleep() the order state seems to be updated in accordance to what is happening in the TWS.
Shouldn't the state of the order automatically be updated by the TWS-API, or do I really need to update the order myself by quering the state from the TWS API?
Any kind of guidance is greatly appreciated. Many thanks in advance!