I want to place two orders and they are OCA.
I have defined the ocsGroup to bind these two orders, HOWEVER, I found I cannot place two orders just one after another. I need to insert an ib.sleep(2) between the two placeOrder to make them work
Sometimes, the first order will just fire while the second order will wait for 2s to arrive....
?
Can someone help me with this?
?
oca_group = f"OCA_Group_{datetime.now().strftime('%Y%m%d%H%M%S')}"
# Create the Buy Stop order (do not transmit yet)
buy_stop_order = Order(
? ? action='BUY',
? ? totalQuantity=ORDER_QUANTITY,
? ? orderType='STP',
? ? auxPrice=buy_stop_price,
? ? tif='DAY',
? ? ocaGroup=oca_group,
? ? ocaType=1, ?# OCA type
? ? transmit=True
)
# Create the Sell Stop order (this will transmit the group)
sell_stop_order = Order(
? ? action='SELL',
? ? totalQuantity=ORDER_QUANTITY,
? ? orderType='STP',
? ? auxPrice=sell_stop_price,
? ? tif='DAY',
? ? ocaGroup=oca_group,
? ? ocaType=1,
? ? transmit=True ?# Transmit the group
)
# Submit the OCA order group
print(f"Submitting Buy Stop and Sell Stop orders. OCA Group: {oca_group}")
ib.placeOrder(stock, buy_stop_order) ?# Create the Buy Stop order without transmitting
ib.sleep(2) ##### I REALY WANT TO REMOVE THIS 2S AND MAKE SURE THEY ARE PLACED AT THE SAME TIME#############
ib.placeOrder(stock, sell_stop_order) ?# Create and transmit the Sell Stop order (activates the group)
?
?