Getting Started Using ib_insync / ib_async Python Libraries
How much easier are they to use than the ibapi library?
So far I’ve been building my trading models with the ibapi python library, but I’m at the point where I’m reminiscing about the IBrokers library in R that was so much easier to use for me.
One of the key benefits of the ib_insync / ib_async libraries is that they abstract away the threading complexity that we have in the ibapi so there is no manual threading management needed.
I had the dog-ate-my-homework incident recently, where I literally can’t find the code I finished a few days ago with the ibapi library. Since that code was such a headache to put together, I figured why not just pop over the fence and check out what I can do with these other libraries since they’re supposedly easier to use.
Also, while I say ib_insync / ib_async, technically ib_async is supposed to be the most current version. Ib_insync was the original library created by Ewald de Wit who passed away in 2024. Ib_async is a fork of the original library.
One of the core reasons why these libraries are easier to use is because they replace ibapi’s manual threading model with Python’s asyncio event loop.
For example:
Even just writing code to place a market order is exponentially easier.
You only need a few lines of code to do this:
from ib_async import *
util.startLoop()
ib = IB()
ib.connect(‘127.0.0.1’, 7497, clientId=1)
contract = Stock(‘TSLA’, ‘SMART’, ‘USD’)
ib.qualifyContracts(contract)
order = MarketOrder(‘BUY’, 1)
trade = ib.placeOrder(contract, order)
print(f"Order Status: {trade.orderStatus.status}”)
ib.disconnect()
By the way, since I’m using Jupyter Notebooks for this at the moment, I included the util.startLoop() function here.
I probably had triple the amount of code here just defining methods for the IBApi class using the ibapi library.
What’s next?
I’m expecting that I’ll probably need to revert back to using the ibapi library eventually, but for now I’m going to see how far I can get with ib_async.
The next step for me is to revise my code so that I can place limit orders. It’s really simple to do this when you hard-code the limit price:
limit_price = 460.00
order = LimitOrder(‘BUY’, 1, limit_price)
However, I’m writing a trading algorithm, so I need to connect to my market data API to figure out what price I should use.
Stay tuned for more!



