top of page

ib_insync vs ib_async: Python 3.14 Error and Migration

4 minutes ago
5 min read
ib_insync vs ib_async on Python 3.14: error and migration guide cover

AI Summary: ib_insync vs ib_async on Python 3.14: ib_insync is archived and no longer updated, and in our clean-environment tests on Python 3.14 even importing it fails with “There is no current event loop in thread 'MainThread'”. Setting an event loop before the import is a stopgap. ib_async, the maintained continuation, connects normally on 3.14 and for most code the migration is a package swap, an import rename and a paper-account retest.


If you run Python against Interactive Brokers’ TWS API, you’ve probably used ib_insync. It was the default IBKR Python library for years. It is no longer maintained, and on Python 3.14 the classic script that imports it and calls IB().connect(...) now crashes before it reaches the Gateway. This post covers ib_insync vs ib_async: what breaks, why, a stopgap if you can’t migrate today, and the migration itself. Everything below was tested on real versions, not copied from changelogs.


Running IB Gateway unattended as well? Read our headless IB Gateway in Docker guide next.


Tested on (22 November 2026)

Version

Python

3.14.7 and 3.14.10 (Linux, clean virtual environments)

ib_insync / eventkit

0.9.86 / 1.0.3

ib_async / aeventkit

2.1.0 / 2.1.0


The error: “There is no current event loop in thread 'MainThread'”


This is the minimal script that used to work everywhere:


from ib_insync import IB

ib = IB()
ib.connect("127.0.0.1", 4002, clientId=1)   # paper IB Gateway

On Python 3.14 it fails on the very first line, before it ever reaches the Gateway:


File ".../ib_insync/__init__.py", line 6, in <module>
File ".../eventkit/__init__.py", line 3, in <module>
File ".../eventkit/event.py", line 9, in <module>
File ".../eventkit/util.py", line 24, in <module>
File ".../eventkit/util.py", line 21, in get_event_loop
File ".../asyncio/events.py", line 718, in get_event_loop
RuntimeError: There is no current event loop in thread 'MainThread'.

Two things are worth knowing before you debug it:


  • It fails at import, not at connect. ib_insync imports eventkit, and eventkit 1.0.3 asks asyncio for an event loop the moment it loads. On Python 3.14 there is no loop yet, so from ib_insync import IB raises. On Python 3.13 the same script only prints a DeprecationWarning (“There is no current event loop”) and keeps working, which is why this error often shows up right after a Python upgrade in production.

  • Async code works if the import happens inside the loop. If you move the import inside an async function started with asyncio.run(...) and use await ib.connectAsync(...), it connects normally, because a loop exists by then. Importing at the top of the module, before asyncio.run, still fails.


Why it happens on Python 3.14


ib_insync and eventkit find the event loop through asyncio.get_event_loop_policy().get_event_loop(). Older Python versions quietly created a loop if none existed. Python 3.12 started warning about this (on 3.13 you get a DeprecationWarning: There is no current event loop). Python 3.14 stops creating one and raises RuntimeError instead. Because ib_insync and the original eventkit are archived on GitHub, they won’t be patched.


Heads-up for Python 3.16. Python 3.14 also deprecates the asyncio policy system, including asyncio.get_event_loop_policy(), which is “slated for removal in Python 3.16”. In our tests ib_async 2.1.0 still calls it and prints that DeprecationWarning, even though it works today. Pin your version, watch the ib_async releases, and run your test suite with warnings visible (python -W default) before moving to 3.16.


Stopgap: make ib_insync work on 3.14 today


If you can’t migrate this week, either of these gets you running again. We tested both: each one got past the import and reached the Gateway socket.


# Option 1: create and set a loop BEFORE importing ib_insync
import asyncio
asyncio.set_event_loop(asyncio.new_event_loop())

from ib_insync import IB
ib = IB()
ib.connect("127.0.0.1", 4002, clientId=1)

# Option 2: go async, and import inside the running loop
import asyncio

async def main():
    from ib_insync import IB
    ib = IB()
    await ib.connectAsync("127.0.0.1", 4002, clientId=1)
    ...

asyncio.run(main())

These are stopgaps, not fixes. Both still trigger the 3.16 deprecation warning, and you’re still on an unmaintained library that won’t get new TWS API features or bug fixes.


Is ib_insync still maintained? No. Use ib_async


ib_async is the community-maintained continuation of ib_insync, published by the ib-api-reloaded project (github.com/ib-api-reloaded/ib_async). The original ib_insync repository is archived. Interactive Brokers’ own TWS API documentation says ib_insync is no longer updated and points users who want that structure to ib_async, while noting that IBKR doesn’t provide coding support for either package. The API is almost identical. In our test, the same synchronous script connects normally on Python 3.14 after switching the import.


Migrating from ib_insync to ib_async in three steps


1. Swap the dependency. Pin an exact version you have tested. ib_async 2.1.0 needs Python 3.10 or newer.


# requirements.txt
- ib_insync==0.9.86
+ ib_async==2.1.0          # pin what you tested

2. Rename the imports. For most code this is the whole change.


- from ib_insync import IB, Stock, Option, LimitOrder, util
+ from ib_async import IB, Stock, Option, LimitOrder, util

3. Retest the parts that differ.


  • Event-loop patches. ib_async uses aeventkit instead of eventkit. If you call util.startLoop() or util.patchAsyncio() (common in Jupyter), or use nest_asyncio, retest those paths.

  • Warning vs error codes. The two libraries don’t treat exactly the same IBKR message codes as warnings. In ib_async 2.1.0, codes 105, 321 and 329 are logged as warnings, and 202 (order cancelled) is no longer in the warning list as it was in ib_insync 0.9.86. If your code reacts to any of these, check that it still sees them the way it expects.

  • A full order cycle on paper. Against a paper IB Gateway (port 4002): connect, contract lookup, quote, place order, fill, cancel, reconnect. Only then deploy.


On the trading system we migrated, the code change took minutes. Most of the hour went on re-running integration tests against the paper Gateway.


ib_insync vs ib_async at a glance



ib_insync

ib_async

Maintained

No (repository archived)

Yes (ib-api-reloaded)

Import and sync connect() on Python 3.14

Fails at import: “no current event loop”

Works (tested on 2.1.0)

Async connectAsync() on 3.14

Works only if imported after a loop exists

Works

Event library

eventkit

aeventkit

API surface

Original

Nearly identical; imports renamed

Python 3.16 readiness

Will not be updated

Still calls a deprecated asyncio API in 2.1.0; watch releases


FAQ


Is ib_insync still maintained?

No. ib_insync is no longer updated and its repository is archived. Its maintained continuation is ib_async, published by the ib-api-reloaded project, and Interactive Brokers’ own API documentation points ib_insync users to it. For new code, start with ib_async.

Does ib_insync work on Python 3.14?

Not out of the box. In our tests on Python 3.14.7 and 3.14.10, ib_insync 0.9.86 with eventkit 1.0.3 fails as soon as it is imported, with “RuntimeError: There is no current event loop in thread 'MainThread'”. It only runs if an event loop already exists when you import it.

How do I fix “There is no current event loop” in ib_insync?

Migrate to ib_async, which connects normally on Python 3.14. As a short-term stopgap, create and set an event loop before importing ib_insync, with asyncio.set_event_loop(asyncio.new_event_loop()), or import it inside an async function started with asyncio.run and use connectAsync.

Is ib_async a drop-in replacement for ib_insync?

Almost. For most code you change the package name and the imports. Retest anything that patches the event loop, anything that depends on which IBKR error codes are treated as warnings, and run a full order cycle against a paper account before deploying.


Conclusion


If your IBKR code still imports ib_insync, Python 3.14 is the push to move. The stopgaps work, but ib_async is a near drop-in replacement with active maintenance, and the migration is mostly a rename plus a paper-account test run. Next, make sure the Gateway you connect to stays up: headless IB Gateway in Docker: daily restarts, 2FA and reconnects. For the wider picture of building on IBKR, see our guide to integrating the Interactive Brokers API with a fintech or trading platform.


We build and run production trading systems on Interactive Brokers. If you want a second pair of eyes on your migration, book a call with our team.


imgi_48_Arpan Desai Profile Photo (1).png

About Author 

Arpan Desai

CEO & FinTech Expert

Arpan brings 14+ years of experience in technology consulting and fintech product strategy.
An ex-PwC technology consultant, he works closely with founders, product leaders, and API partners to shape scalable fintech solutions.

 

He is connected with 300+ fintech companies and API providers and is frequently involved in early-stage architectural decision-making.

Rectangle 6067.png

Contact Us

Are you looking to build a robust, scalable & secure Fintech solution?
bottom of page