IBKR API修改Bracket Order报错:被修改订单与原订单不匹配
Fix for "Order being modified does not match original order" when modifying IBKR Bracket Order
Root Cause
Your code resubmits the entire bracket order (parent, take-profit, stop-loss) during modification, which violates IBKR's order rules:
- The original parent order was already activated (transmitted) by the stop-loss order's
Transmit=trueflag in the initial submission. - Resending the parent order with
Transmit=falsecreates a mismatch between the existing order's state and the modification request, triggering the error. - Resubmitting unchanged orders (parent and stop-loss) is unnecessary and causes conflicts with the active order book.
Corrected Modification Code
Instead of recreating the entire bracket, only send the modified take-profit order (the only component you want to change):
// Original bracket creation (unchanged) int ParentOrderId = EWI.NextOrderId; List<Order> bracket = BracketOrder(ParentOrderId, "BUY", 100, 30, 40, 20); foreach (Order o in bracket) client.placeOrder(o.OrderId, Contract, o); // Modify ONLY the take-profit order Order modifiedTakeProfit = new Order(); modifiedTakeProfit.OrderId = ParentOrderId + 1; // Match original take-profit order ID modifiedTakeProfit.Action = "SELL"; // Opposite of parent's BUY action modifiedTakeProfit.OrderType = "LMT"; // Same as original take-profit order type modifiedTakeProfit.TotalQuantity = 100; // Same quantity as original modifiedTakeProfit.LmtPrice = 50; // New take-profit price modifiedTakeProfit.ParentId = ParentOrderId; // Link to parent order ID modifiedTakeProfit.Transmit = true; // Critical: send this standalone order to activate modification client.placeOrder(modifiedTakeProfit.OrderId, Contract, modifiedTakeProfit);
Key Rules for Modifying IBKR Bracket Orders
- Only modify changed orders: Don't resubmit the parent or unchanged child orders.
- Match original order attributes: Keep
OrderId,ParentId,Action,OrderType, andTotalQuantityidentical to the original order (only update the specific field you want to change, e.g.,LmtPrice). - Set
Transmit=truefor modifications: Since you're sending a standalone request, not part of a bracket submission chain. - Avoid conflicting flags: Never resend a parent order with
Transmit=falseafter it's already been activated by the initial bracket submission.
内容的提问来源于stack exchange,提问作者nitinsy
相关产品推荐
相关产品推荐

