简体   繁体   中英

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

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM