在 TWS API 中请求 nextOrderID 不起作用

2024-04-25

我正在尝试使用 python 通过 TWS API 下订单。我的问题是获取下一个有效的订单 ID。

这是我正在使用的:

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.common import TickerId
from ibapi import contract, order, common
from threading import Thread

class ib_class(EWrapper, EClient):

    def __init__(self, addr, port, client_id):
        EClient.__init__(self, self)
        self.connect(addr, port, client_id) # Connect to TWS
        thread = Thread(target=self.run, daemon=True)  # Launch the client thread
        thread.start()

    def error(self, reqId:TickerId, errorCode:int, errorString:str):
        if reqId > -1:
            print("Error. Id: " , reqId, " Code: " , errorCode , " Msg: " , errorString)

    def nextValidId(self, orderId: int):
        self.nextValidId = orderId

ib_api = ib_class("127.0.0.1", 7496, 1)

orderID = ib_api.nextValidId(0)

这给了我:

TypeError: 'int' object is not callable

The nextValidId方法是一个包装方法。从客户端,您需要调用reqIds获取订单 ID。

ib_api.reqIds(-1)

参数为reqIds没关系。此外,它没有返回值。反而,reqIds向 IB 发送一条消息,当收到响应时,包装器的nextValidId方法将被调用。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 TWS API 中请求 nextOrderID 不起作用 的相关文章

随机推荐