运行简单API示例时获取属性错误

2024-06-12 02:01:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行一个非常简单的API示例:

from ibapi.client import EClient
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()

我得到的错误是:

Traceback (most recent call last): File "C:\Users\Gebruiker\Desktop\Python projects\IB TWS\test_app.py", line 9, in app.connect('127.0.0.1', 7497, 123) File "C:\Users\Gebruiker\Desktop\Python projects\IB TWS\ibapi\client.py", line 151, in connect self.decoder = decoder.Decoder(self.wrapper, self.serverVersion()) AttributeError: 'IBapi' object has no attribute 'wrapper'

如果我检查源文件中的代码,我会看到以下内容(我取出了一些不相关的代码):

class EClient(object):
    def __init__(self, wrapper):
        self.wrapper = wrapper

    def connect(self, host, port, clientId):
        self.decoder = decoder.Decoder(self.wrapper, self.serverVersion())

如果包装器属性在类的__init__函数上,怎么可能找不到它呢?我可能会错过什么

我的另一个问题是,如果类IBapi接受2个参数(EWrapperEClient),那么对象应用程序如何可能是IBapi类的一个没有参数的实例

为了澄清,我从互联网上取了这个例子。谢谢


Tags: fromimportselfclientappinitdefconnect