erdewit / ib_insync

Python sync/async framework for Interactive Brokers API
BSD 2-Clause "Simplified" License
2.8k stars 743 forks source link

Events don't trigger except in Jupyter Notebooks #583

Closed szayedoud closed 1 year ago

szayedoud commented 1 year ago

I am requesting historical data using reqHistoricalData, with keepUpToData=True. I've tried adding the on_bar_update method as an event with the following two ways, which work great in a Notebook

self.es_bars.updateEvent += self.on_bar_update self.ib.barUpdateEvent += self.on_bar_update

Both trigger the on_bar_update only in a Notebook and everything works as designed. However, they fail to trigger and the program terminates in Eclipse IDE and the command line. All 3 environments are using the same exact code, with the same version of Python. I've experimented with the util.startLoop() and nest_asyncio.apply() to no avail.

Sorry if this is basic - I am noobie at IB and ib_insync

Thanks in advance for any feedback anyone can offer!

erdewit commented 1 year ago

There should be a ib.run() after setting up all event handlers.

szayedoud commented 1 year ago

That fixed the issue. Thank you!