¿ªÔÆÌåÓý

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

Sent multiple bracket orders (open, takeprofit, stoploss, exit at time), but 1 of them only took (open and exit at time)


 

I send multiple orders to ib gateway everyday, for the last week I have been using the following bracket order.

Open -> long or short an equity Take profit -> price above long entry or below short entry stop loss -> price below long entry or above short entry exit before market close -> price at time.

I sent this bracket order for 3-7 stocks everyday for the last week and it ran fine.

Today, for one of the orders, the take profit and stop loss portion of it was missing. I have no idea why, I called the IB trade desk and they say that portion of the order is missing for this order. I'm sure that this order also had all 4 of the legs above. Any ideas on what could have gone wrong???


 

I hope your client properly captures and records error callbacks (there are three different I.callbacks) as well as the update callbacks you receive after placing orders.

You need to go back to those logs and determine:
  • whether any of the missing orders were rejected outright and what the error codes were
  • whether TWS/IBGW acknowledged the missing orders and what states those orders went through

Without that kind of detail, a discussion would be based on guess work. Please provide error/order status detail or, in case you don't record them, improve your client to do so in the future.

In TWS you could also go to Account -> Audit Trail and get a detailed view of you order and trade activity, but I am not sure whether orders that were rejected with an error code appear in the audit report.

´³¨¹°ù²µ±ð²Ô


 

It happened again today but this time, only the MIT part of the order was missing from 2 of the orders. Here is a screenshot.

IB got back to me after I sent them the logs, they told me that,

After reviewing your logs further, we saw that almost all of your orders are using the same set of order IDs, 71, 73, 74, 75. Given Interactive Brokers does not allow order IDs to repeat, it means that either all subsequent orders are having an error for duplicate order IDs, or the more likely reason is because there is some other error rejecting the order initially.

I am not sure how to fix, am I advancing through each bracket / new parent order wrongly here???

def nextValidId(self, orderId: int):
    super().nextValidId(orderId)
    self.nextValidOrderId = orderId
    print('The next valid order id is: ', orderId)

def nextOrderId(self):
    oid = self.nextValidOrderId
    self.nextValidOrderId += 1
    return oid



for ticker, orders in new_portfolio.items():
    bracket = app.BracketOrder(.........)
    for o in bracket:
        app.placeOrder(o.orderId, app.EQ_order_MKT(ticker), o)
        app.nextOrderId() 

app.disconnect()

As such, we noticed the average API connection time was no more than about 150ms before you had disconnected. We would ask that you remain connected for at least 1 second before disconnecting. Please try your standard code, with the extended connection time, and let us know if any messages are returned. The increased connection time should allow for order status and error messages to return.

Do they mean I should put a time.sleep(1) after I finish my loops?