I am building an app to place orders through the Python API an am having an issue with the consistency of order transmission where only one order can be received and executed per app instance.
As an example if I run the below code it will execute and transmit a sample order indefinitely, no matter how many times I run the script.
from ib_insync import *
# connect to Interactive Brokers
ib = IB()
ib.connect('127.0.0.1', 7497, clientId=3) #4002 / 7497
stock = Stock("AAPL", 'SMART', 'USD')
order = MarketOrder('BUY', 10)
trade = ib.placeOrder(stock, order)
print('Done')
However if I define the order part as a function and run it, it will only transmit an order once no matter how many times I call the function. If I restart the script then I can send another order with the same function but again only once.
Is there a way around this as I want to be able to send other orders without having to restart the app.