The following behavior puzzles me (due to my poor understanding of the underlying asyncio mechanics).?
?
1st, the program requests market data. A callback is attached. The callback will call `disconnect`. There is also a callback for the `disconnectedEvent`.?
?
When the program is executed, the `on_tick` callback is called. `isConnected` returns first True and then False, yet neither the `on_disconnect` function is ever called nor does the program ever continue its execution after the statement ib.run().?
?
How can this be explained, and is there a way I can make the program continue after disconnecting? For example, I have implemented a shutdown timer, and the only way I managed to actually end the program is with os._exit(0)
?
Code:?
?
from ib_async import Ticker, IB, Forex
def on_tick(ticker: Ticker):
print("Disconnecting")
print(f"Is connected={ib.client.isConnected()}")
ib.client.disconnect()
print(f"Is connected={ib.client.isConnected()}")
def on_disconnect():
print("Disconnected")
ib = IB()
ib.connect(host='127.0.0.1', port=4001, clientId=1)
contract = Forex('GBPUSD', 'IDEALPRO')
ib.qualifyContracts(contract)
ticker = ib.reqMktData(contract)
ticker.updateEvent += on_tick
ib.disconnectedEvent += on_disconnect
ib.run()
print("End") # never executed