Search code examples
pythonapiinteractive-brokersib-api

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!


Solution

  • 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.