erdewit / ib_insync

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

qualifyContracts getting error when called in TickerEvent #269

Closed siren0413 closed 4 years ago

siren0413 commented 4 years ago

ib.connect('127.0.0.1', 4001, clientId=1) ib.qualifyContracts(stock_contracts) ib.qualifyContracts(option_contracts)

The above works fine when starting the program. However, if in the tickerEvent func, I'm trying to call the ib.qualifyContracts again for some new symbols, it fails with error:

Traceback (most recent call last): File "/Users/yijunmao/PycharmProjects/inquidtrade/venv/lib/python3.7/site-packages/eventkit/event.py", line 181, in emit func(args) File "/Users/yijunmao/PycharmProjects/inquidtrade/tickers.py", line 13, in onPendingTickers objects.ib.qualifyContracts(tsla) File "/Users/yijunmao/PycharmProjects/inquidtrade/venv/lib/python3.7/site-packages/ib_insync/ib.py", line 551, in qualifyContracts return self._run(self.qualifyContractsAsync(contracts)) File "/Users/yijunmao/PycharmProjects/inquidtrade/venv/lib/python3.7/site-packages/ib_insync/ib.py", line 301, in _run return util.run(*awaitables, timeout=self.RequestTimeout) File "/Users/yijunmao/PycharmProjects/inquidtrade/venv/lib/python3.7/site-packages/ib_insync/util.py", line 312, in run result = loop.run_until_complete(task) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 571, in run_until_complete self.run_forever() File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 526, in run_forever raise RuntimeError('This event loop is already running') RuntimeError: This event loop is already running

siren0413 commented 4 years ago

The problem has been discussed in the groups: https://groups.io/g/insync/topic/28884902#2789