Encounter error “IB API required” when IB API is installed

守給你的承諾、 提交于 2019-12-23 00:56:12

问题


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;


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/48485442/encounter-error-ib-api-required-when-ib-api-is-installed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!