I am having some strange behavior while sending orders to interactive brokers.
Consider this code:
from ib_insync import *
import time
ib = IB()
client_id = int(time.time()) # gets second since epoch. No need for the milliseconds, so round to int
ib.connect('127.0.0.1', 7497, clientId=client_id, timeout=10)
ib.placeOrder(contract=Stock('SPY', exchange='SMART', currency='USD'), order=MarketOrder('BUY', 100))
ib.placeOrder(contract=Stock('AAPL', exchange='SMART', currency='USD'), order=MarketOrder('BUY', 100))
ib.placeOrder(contract=Stock('IBM', exchange='SMART', currency='USD'), order=MarketOrder('BUY', 100))
When I run it, only the first order is displayed in TWS:
However, if I then run ib.sleep(0)
the other orders appear in TWS:
Any idea what may be causing this issue? I can put ib.sleep(0) in different spots throughout my code to make sure information is being transmitted, but this is a workaround.
Thank you.