user1315789
user1315789

Reputation: 3649

Encounter error "IB API required" when IB API is installed

I am trying out this new python package ib_insync.

https://github.com/erdewit/ib_insync

I ran the python script below;

from ib_insync import *

ib = IB()
ib.connect('127.0.0.1', 7496, clientId=1)

contract = Forex('EURUSD')
bars = ib.reqHistoricalData(contract, endDateTime='', durationStr='30 D', barSizeSetting='1 hour', whatToShow='MIDPOINT', useRTH=True)

# convert to pandas dataframe:
df = util.df(bars)
print(df[['date', 'open', 'high', 'low', 'close']])

I encountered the error IB API from http://interactivebrokers.github.io is required.

I have already installed IB API ver 9.73.06 under C:\TW_API folder. I am using Windows 10 and anaconda python v3.6 .

Here is a snapshot of my TWS API settings;

enter image description here

Upvotes: 1

Views: 2770

Answers (4)

Farzad Amirjavid
Farzad Amirjavid

Reputation: 705

For windows 10: Maybe as of Feb 2022 none of the above-mentioned options works. Please, try the following:

import sys
sys.path.append("C:\\TWS_API\\source\\pythonclient")
import ibapi

The TWS API is installed in this folder: c:\TWS_API

Upvotes: 1

Josh
Josh

Reputation: 816

This is a general error that occurs when the Python interpreter can't find a module because its not listed in the PYTHONPATH environment variable. One option is to install the ibapi module as a Wheel. Or, if you are using an IDE such as PyCharm you can just right-click on the pythonclient folder in the project directory in the IDE and choose "Mark Directory as Source". This is mentioned in the recorded IBKR Python API webinar.

Since a Python API program is dependent on a specific version of the API, many users also like to use virtual environments (virtualenv) to organize version-specific dependencies of code rather than installing everything globally.

Upvotes: 1

Shing Tse
Shing Tse

Reputation: 31

After installing the TWS API, locate the folder "TWS API". In that folder, find the folder named "source", then the folder named "pythonclient".

Once you're in the folder "pythonclient", copy all the content in there and paste it into your working directory.

You should no longer get the IB API from http://interactivebrokers.github.io is required error again.

Upvotes: 3

user1315789
user1315789

Reputation: 3649

I found the answer to my own question. The problem was that ib-api python module was not installed into the python version that I am using

There is a README.md found in C:\TW_API\source\pythonclient Following the instructions, I ran the following commands;

$ python setup.py bdist_wheel
$ python -m pip install --user --upgrade dist/ibapi-9.73.6-py3-none-any.whl

My python script runs normally without error now.

Upvotes: 5

Related Questions