Interactive Broker Python API shows error: IB AttributeError: 'IBapi' object has no attribute 'connState'

最后都变了- 提交于 2020-05-14 09:07:19

问题


I tried to make a simple Python program, that connects via the IB native API to my Demo Account. But when I run the program it comes an error: IB AttributeError: 'IBapi' object has no attribute 'connState'

The program looks like this:

from ibapi.wrapper import EWrapper  

class IBapi(EWrapper, EClient):
     def init(self):
         EClient.init(self, self) 

app = IBapi()
app.connect('127.0.0.1', 7497, 123)
app.run()

I used the tutorial from this website: https://algotrading101.com/learn/interactive-brokers-python-api-native-guide/

Thanks for helping!


回答1:


The python initialization method that is automatically called after an object instance has been created is named __init__, not init.

https://docs.python.org/3/reference/datamodel.html#object.init

In your code the init method will never be called. It should be:

from ibapi.client import EClient 
from ibapi.wrapper import EWrapper


class IBapi(EWrapper, EClient):
    def __init__(self):         
        EClient.__init__(self, self)

...

You might be interested in the Python API course in the Traders' Academy on the IBKR website.



来源:https://stackoverflow.com/questions/61029782/interactive-broker-python-api-shows-error-ib-attributeerror-ibapi-object-has

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