首页 > 解决方案 > 运行简单 API 示例时出现属性错误

问题描述

我正在运行一个非常简单的 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(最近一次调用最后):文件“C:\Users\Gebruiker\Desktop\Python projects\IB TWS\test_app.py”,第 9 行,在 app.connect('127.0.0.1', 7497, 123) 文件中“ C:\Users\Gebruiker\Desktop\Python projects\IB TWS\ibapi\client.py",第 151 行,连接 self.decoder = decoder.Decoder(self.wrapper, self.serverVersion()) AttributeError: 'IBapi'对象没有属性“包装器”

如果我检查源文件中的代码,我会看到这一点(我删除了一些不相关的代码):

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 个参数 ( EWrapperand EClient),那么对象 app 怎么可能是IBapi没有参数的类的实例?

只是为了澄清我从互联网上拿了这个例子。谢谢。

标签: pythonapiattributes

解决方案


推荐阅读