How to import ib_insync?

Hi,

i´m creating a streamlit app for stock trading.

I tried to import ib_insync, but it doesn`t work.

from ib_insync import *
RuntimeError: There is no current event loop in thread 'ScriptRunner.scriptThread'.
Traceback:
File "/home/xxx/.local/lib/python3.9/site-packages/streamlit/script_runner.py", line 350, in _run_script
    exec(code, module.__dict__)
File "/home/xxx/stocks/streamlit/streamlit.py", line 1, in <module>
    from ib_insync import *
File "/home/xxx/.local/lib/python3.9/site-packages/ib_insync/__init__.py", line 7, in <module>
    from eventkit import Event
File "/home/xxx/.local/lib/python3.9/site-packages/eventkit/__init__.py", line 4, in <module>
    from .event import Event
File "/home/xxx/.local/lib/python3.9/site-packages/eventkit/event.py", line 7, in <module>
    from .util import NO_VALUE, main_event_loop
File "/home/xxx/.local/lib/python3.9/site-packages/eventkit/util.py", line 18, in <module>
    main_event_loop = asyncio.get_event_loop()
File "/usr/lib/python3.9/asyncio/events.py", line 642, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'

Is it possible to get it work?

Thank you

1 Like

Hi @mick76

Is this similar to the issue you’re facing?

Charly

Yes, it seems the same problem.

1 Like

Any idea or is it impossible?

Ok, it seems impossible.

Does anybody use the API from Interactive Brokers with streamlit?