¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Cannot transmit order (main order and stop loss orders)


 

I am trying to submit two orders, one main order (parent order) and the other is stop loss order. I am following TWS API documentation?
But for some reason my main order does not show in TWS as submitted. It only show us with "Transmit" option. I am expecting both order to be transmitted without any problems. Here is my Python code:

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.ticktype import TickTypeEnum
import time
import datetime
import threading
from ibapi.contract import Contract
from ibapi.order import Order
?
class TestApp(EWrapper, EClient):
? ? def __init__(self):
? ? ? ? EClient.__init__(self, self)
? ? ? ? self.nextValidOrderId = None
? ? ? ??
? ? # this is getting called upon establishing connection? ??
? ? def nextValidId(self, orderId: int):
? ? ? ? super().nextValidId(orderId)
? ? ? ? self.nextValidOrderId = orderId
? ? ? ? print("NextValidId:", orderId)
? ? ? ??
? ? def error(self, reqId, errorCode, errorString, advancedOrderRejectJson):
? ? ? ? print("Error: ", reqId, " ", errorCode, " ", errorString, "", advancedOrderRejectJson)

contract = Contract()
contract.symbol = "SPY"
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"
contract.primaryExchange = "ARCA"
?
order = Order()
order.OrderType = "LMT";
order.action = 'BUY'
order.totalQuantity = 3
order.orderType = 'LMT'
order.lmtPrice = '21'
order.transmit = False
?
stopLossOrder = Order()
stopLossOrder.OrderType = 'STP'
stopLossOrder.action = 'SELL'
stopLossOrder.totalQuantity = 3
stopLossOrder.auxPrice = 18
stopLossOrder.transmit = True

app = TestApp()
app.connect("127.0.0.1", 7497, 1)
?
api_thread = threading.Thread(target=app.run)
api_thread.start()
time.sleep(2)
?
order.orderId = app.nextValidOrderId
stopLossOrder.orderId = app.nextValidOrderId + 1
stopLossOrder.parentId = app.nextValidOrderId
?
app.placeOrder(app.nextValidOrderId, contract, order)
app.placeOrder(app.nextValidOrderId+1, contract, stopLossOrder)
?
?
app.disconnect()

What am I doing wrong?
?
?

Join [email protected] to automatically receive all group messages.