I am trying to use python to place orders through the TWS API. My problem is getting the next valid order ID.
Here is what I am using:
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)
And this gives me :
TypeError: 'int' object is not callable