Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cannot modify order error message

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

    Cannot modify order error message

    Hello,

    I'm working with IB using unmanaged strategies. When trying to modify or cancel an order usin ChangeOrder or CancelOrder methods I receive messages like "Cannot cancel the filled order (201) affected Order" or "Cannot modify the filled order (201) affected Order". As an unmanaged strategy this error doesn't affect the behaviour but it's very annoying.

    I asked IB and they say that they cannot avoid sending this error message and it cannot be disabled from TWS.

    Do you have any idea on how to correct this error?

    #2
    guillembm, the only idea I would have then is debug why the event is thrown and optimize your code in the manner to ensure you're not attempting to cancel / modify an already filled order.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      I already thought that this could be the problem. Each time I use CancelOrder or ChangeOrder I set a conditional requesting that to change or cancel the MarketPosition has to be Flat. I think that the problem is that if the CancelOrder or ChangeOrder methods are executed on the same bar that has filled the order is when the problem comes. Actually I believe that this is the case of an overfill.

      the only instrucions I think I can use to control that CancelOrder or ChangeOrder are not executed if an order doesn't exist are:

      if (Position.MarketPosition != MarketPosition.Flat)
      or
      if (MyOrder != null)

      Do you know another way?

      Comment


        #4
        Do you run on CalculateOnBarClose = false here? Otherwise the issue is if you rely on the position update it would take up to an OnBarUpdate() to cycle to show up.

        Generally your thinking is correct, you should not try to change / cancel order when the order reports filled - this would be earliest seen in the OnExecution().
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I make all calculation on the close of the bar. To report if an order is filled or cancelled I use OnOrderUpdate() and OnExecution(), following this order. I use both. Perhaps putting OnExecution() before OnOrderUpdate() on the code could be the solution?

          Comment


            #6
            This should not make any difference for you, the code relational order would not determine their event call sequence seen. For the monitoring of the fill please move to the OnExecution() only.

            To further debug I would suggest printing the order-states and their sequence seen, so you could pinpoint where you need to change the code to circumvent the erroneous call triggering the IB error.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              So you mean getting rid of order.OrderState == OrderState.Filled on OnOrderUpdate and leaving it only in OnExecution()

              Comment


                #8
                Originally posted by guillembm View Post
                So you mean getting rid of order.OrderState == OrderState.Filled on OnOrderUpdate and leaving it only in OnExecution()
                That would be a potential first step to try, yes - it's next to impossible for me to really comment as I would not know which exact code you're dealing with and what event sequence would be seen. I would therefore suggest you add the prints as mentioned to see in detail what changes need to be made.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  It's possible that when the order has been filled on the broker NT hasn't still set this order to filled?

                  If this is the problem I wonder if there is a solution.

                  Comment


                    #10
                    Could be the case guillembm, to be sure NT has seen the fill check from the OnExecution() event.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      I think this is the problem. Do you think there is a solution?

                      Comment


                        #12
                        guillembm, the solution would debugging the script and event sequence seen, especially you would need to understand which call you're issueing is the erroneous one that would trigger the IB error message you're trying to avoid. If you're depending on seeing a particular fill state, work on OnExecution() and not OnOrderUpdate() as this will ensure internal strategy logic used is propertly updated as needed.
                        BertrandNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by GussJ, 03-04-2020, 03:11 PM
                        11 responses
                        3,227 views
                        0 likes
                        Last Post xiinteractive  
                        Started by andrewtrades, Today, 04:57 PM
                        1 response
                        13 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by chbruno, Today, 04:10 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post chbruno
                        by chbruno
                         
                        Started by josh18955, 03-25-2023, 11:16 AM
                        6 responses
                        440 views
                        0 likes
                        Last Post Delerium  
                        Started by FAQtrader, Today, 03:35 PM
                        0 responses
                        11 views
                        0 likes
                        Last Post FAQtrader  
                        Working...
                        X