开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

AttributeError: 'TestApp' object has no attribute 'nextValidOrderId'


 

from ibapi.client import EClient from ibapi.wrapper import EWrapper, iswrapper from ibapi.contract import Contract from ibapi.order import Order import threading import time ... class TestApp(EWrapper, EClient): def __init__(self): EClient.__init__(self, self) @iswrapper def nextValidId(self, orderId:int): super().nextValidId(orderId) self.nextValidOrderId = orderId def nextOrderId(self): oid = self.nextValidOrderId self.nextValidOrderId += 1 return oid ... def BracketOrder(action, quantity, limitPrice, takeProfitLimitPrice, stopLossPrice): parent = Order() parent.orderId = app.nextValidOrderId parent.action = action parent.orderType = "LMT" parent.totalQuantity = quantity parent.lmtPrice = limitPrice parent.transmit = False takeProfit = Order() takeProfit.orderId = app.nextValidOrderId takeProfit.action = "SELL" takeProfit.orderType = "LMT" takeProfit.totalQuantity = quantity takeProfit.lmtPrice = takeProfitLimitPrice takeProfit.parentId = app.nextValidOrderId takeProfit.transmit = False stopLoss = Order() stopLoss.orderId = app.nextValidOrderId stopLoss.action = "SELL" stopLoss.orderType = "STP" stopLoss.auxPrice = stopLossPrice stopLoss.totalQuantity = quantity stopLoss.parentId = app.nextValidOrderId stopLoss.transmit = True bracketOrder = [parent, takeProfit, stopLoss] return bracketOrder bracket = BracketOrder("BUY", how_much, get_price, win_price, lost_price) for o in bracket: app.placeOrder(app.nextValidOrderId, stonk(whom), o) time.sleep(1) app.nextOrderId()


I got this error:
Traceback (most recent call last):
? File "C:/Users/komp/PycharmProjects/paperbuild0.1/final8.py", line 105, in <module>
? ? bracket = BracketOrder("BUY", how_much, get_price, win_price, lost_price)
? File "C:/Users/komp/PycharmProjects/paperbuild0.1/final8.py", line 77, in BracketOrder
? ? parent.orderId = app.nextValidOrderId
AttributeError: 'TestApp' object has no attribute 'nextValidOrderId'

I admit that I'm completely surprised and exhausted. This code has been working yesterday during live session, today cannot get order Id. Could anybody fix this error and explain why this method (changed a lot of times) is so erratic? Best, G.

Join twsapi@groups.io to automatically receive all group messages.