Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

cant cancel IB orders when get order rejected error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    cant cancel IB orders when get order rejected error

    some live orders in IB are not being canceled.

    I am working with StopLimit orders having a limit below the stop (negative)
    the order is accepted by the IB.
    in some cases when the stop is triggered but the limit is not yet reached , I sometimes want to replace the order with a new one.
    this is when the IB rejects the updated order.
    I then trap the error in OnOrderUpdate and have this code :
    Code:
    if (entryOrder != null && entryOrder == order && order.OrderState == OrderState.Rejected)
      {
        // Rejection handling    
        iPrint("REJECTED - Previous order was already triggered so we cancel and resubmit ");
        foreach (Order openorder in Orders)
         {
           Print(openorder.Name + " " + openorder.OrderState);
           CancelOrder(openorder);
         }
    
           EnterLongStopLimit(0 , true , OffsetTradeSize , LimitLevelforLONG , StopLevelforLONG   , "FCMoveLong");
    
    }
    ​
    the old order is not being canceled. What am I doing wrong ?

    #2
    Hello dadarara,

    If IB is rejecting the order change you would need to review the reason in the log. If you are trying to change an order that is in the process of filling that may be preventing you from doing a change. If the order has already filled or is in process the cancel order would not work.

    I also see that you are working with the Orders collection which is not a documented part of strategies. That exists but is not documented for any type of use cases. I would suggest to try and instead store the order to a variable in OnOrderUpdate and then use that variable to cancel it to see if that works better. It looks like your doing that for entryOrder already so it would be the same general concept to store a variable for any other order you use.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X