Interactive Broker Python API显示错误:IB AttributeError:"IBapi"对象没有属性"connState" [英] Interactive Broker Python API shows error: IB AttributeError: 'IBapi' object has no attribute 'connState'
问题描述
我试图制作一个简单的Python程序,该程序通过IB本机API连接到我的模拟帐户.但是,当我运行程序时,出现错误: IB AttributeError:'IBapi'对象没有属性'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'
程序如下:
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()
我使用了该网站上的教程: https://algotrading101.com/learn/interactive-brokers-python-api-native-guide/
I used the tutorial from this website: https://algotrading101.com/learn/interactive-brokers-python-api-native-guide/
感谢您的帮助!
推荐答案
在创建对象实例后自动调用的python初始化方法名为__init__
,而不是init
.
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)
...
您可能对 IBKR网站上的交易者学院.
这篇关于Interactive Broker Python API显示错误:IB AttributeError:"IBapi"对象没有属性"connState"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!