为了账号安全,请及时绑定邮箱和手机立即绑定

由于日志记录错误,无法连接到 Interactive Brokers Api

由于日志记录错误,无法连接到 Interactive Brokers Api

汪汪一只猫 2023-07-27 16:41:46
所以我正在使用 python 交互式经纪商 api,并且我正在尝试向交互式经纪商下限价单。我的代码是:from ibapi.client import EClientfrom ibapi.wrapper import EWrapperfrom ibapi.contract import Contractfrom ibapi.order import Orderimport threadingimport timeclass TradingApp(EWrapper, EClient, Contract, Order):    def __init__(self):        EClient.__init__(self, self)     def nextValidOrderId(self, orderId):        super().nextValidId(orderId)        self.nextValidOrderId = orderId        print("NextValidId:", orderId)def websocket_con():    app.run()            app = TradingApp()app.connect("127.0.0.1", 7497, clientId=1)con_thread = threading.Thread(target=websocket_con, daemon=True)con_thread.start()time.sleep(1)contract=Contract()contract.symbol = 'AMD'contract.secType = 'STK'contract.currency = 'USD'contract.exchange = 'SMART'order=Order()order.action = 'BUY'order.orderType = 'LMT'order.totalQuantity = 1order.lmtPrice = 10app.placeOrder(app.nextValidOrderId,contract,order)time.sleep(5) 我已确保选中“启用活动和套接字客户端”并且信任 IP 地址为 127.0.0.1 为什么我会收到此日志记录错误?
查看完整描述

1 回答

?
GCT1015

TA贡献1827条经验 获得超4个赞

我想class TradingApp(EWrapper, EClient):这就是你想做的。我认为没有理由扩展 Contract 和 Order 类。

您更改了方法的名称,它必须与超类相同。不要重复使用方法名称作为变量名称。

#def nextValidOrderId(self, orderId):
def nextValidId(self, orderId):
    self.nextValidOrderId = orderId


查看完整回答
反对 回复 2023-07-27
  • 1 回答
  • 0 关注
  • 81 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信