14 March 2021

A Primer to ib_insync - Interactive Brokers Part 8

Why ib_insync ?

While retrieving stock data for multiple symbols asynchronously from the TWS API provided by IB, I found the going a little steep. And here was ib_insync which made the task so very simple for me.

Pls. note that ib_insync is very different from the TWS API provided by IB. The TWS API is the official API created by IB while  ib_insync is created by a team of individuals headed by Guru Ji Ewald de Wit

Installation of ib_insync

In case you are using anaconda , this is the way to install it:
conda install -c conda-forge ib-insync

But its quite possible that you have not configured your anaconda installation to conda-forge. So do this  as well

conda config --add channels conda-forge

Now lets head straight to the code recipes in the ib_insync documentation and run the code for retrieving multiple stocks from IB. 

Just in case you have run into a runtime error which says 'This event loop is already running',

then it is time to install nest_asyncio.

conda install -c conda-forge nest-asyncio

Further details can be had in the GitHub repo for nest-asyncio

And its important to use it thus in our program: 

import nest_asyncio
nest_asyncio.apply()


A Program to retrieve 5 minute data for multiple stocks




No comments:

Post a Comment