我正在尝试使用 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