我试图使用python通过TWSAPI下订单。我的问题是获取下一个有效的订单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
nextValidId
方法是一种包装器方法。从客户端,您需要调用reqIds
来获取订单IDreqIds
的参数无关紧要。而且,它没有返回值。相反,reqIds
向IB发送消息,当收到响应时,将调用包装器的nextValidId
方法Algorithmic Trading with Interactive Brokers
相关问题 更多 >
编程相关推荐