Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Race Condition Issue and Order Reject

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

    Race Condition Issue and Order Reject

    Hi,

    I have attached a screenshot of a live trade gone wrong because of a race condition.

    When the 'order reject' was received by NinjaTrader, it tried to close the position but failed to do so and exited (stopped the strategy) with the trade still running.

    Here's a summary of what happened:
    1) Strategy tried to change a pending limit order.
    2) In exactly the second it submitted the change request, the initial order got filled by the exchange.
    3) The change order was then 'Rejected' because the initial order has been filled.
    4) Ninja thinks everything went nuclear, because of the order reject and tries to close the position while turning off the strategy.
    5) Ninja cannot close the position ... *Possibly* because the 'Filled' event didn't arrive yet ?!?!

    So there are 2 issues here:
    - Race Condition (how to fix this?)
    - Ninja terminating a strategy without closing the position, deadly!

    Thank you very much for any help,
    dax3k
    Attached Files

    #2
    Hello dax3k,

    Once an order submitted by an automated strategy is rejected, the strategy will be terminated. This is as expected and as far as I know cannot be changed.

    Unfortunately this is one of the risks upon trading electronically. As you mentioned, before the order receives confirmation of its modification, it executes.
    JasonNinjaTrader Customer Service

    Comment


      #3
      Jason,

      If you set the following in Initialize(), won't that obviate the strategy termination?

      Code:
      RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
      mrlogik
      NinjaTrader Ecosystem Vendor - Purelogik Trading

      Comment


        #4
        Correct mrlogik, but then you need to take manually care in case orders get rejected...
        BertrandNinjaTrader Customer Service

        Comment


          #5
          That's fine. As long as there is a way to detect such an event, and take any actions you feel necessary to preclude a major catastrophe.

          which, there is :-)
          mrlogik
          NinjaTrader Ecosystem Vendor - Purelogik Trading

          Comment


            #6
            dax3k,

            Which brokerage are you with? IB? Are you on NT6.5.1000.9? Please send in your trace & log files to support [at] ninjatrader ]dot[ com Attn: Josh and mention this thread. We would like to investigate those files to see if we can find any clues. Thank you.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Hi Josh,

              Thank you for your help.

              Submitted my logs last week and got a reply; although I'm not yet convinced that an upgrade will solve this race condition issue.

              Now, if I were turn on the following command:
              RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;

              How would I handle Order Rejects manually? Could you give me an example in terms of code? For instance, if an order was rejected, will Ninja try to resubmit the order again? What if the order was rejected (an order to change the limit price) because the original order had already been filled .. will Ninja wait for a confirmation from IB or will it try to resubmit a 'change limit order' once again?

              In essence, on an 'Order Reject', how does Ninja determine the net position within the strategy?

              Appreciate your help on this matter,

              dax3k

              Comment


                #8
                dax3k,

                Do you have a ticket number for the email case?

                If you turned off error handling you will have to do all of that yourself. You can see order reject events in the OnOrderUpdate() method. You will receive an OrderState of Rejected. Please see the reference sample here for an idea of using OnOrderUpdate(): http://www.ninjatrader-support2.com/...ead.php?t=7499

                When you turn off error handling NinjaTrader will not do anything by default. You will need to program it to do whatever you want. If you want to resubmit you have to tell it to resubmit, etc. etc. NinjaTrader knows its position because an order reject doesn't change anything on its strategy position.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by funk10101, Today, 08:14 AM
                2 responses
                3 views
                0 likes
                Last Post funk10101  
                Started by samish18, Yesterday, 08:57 AM
                11 responses
                28 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by yertle, Today, 08:38 AM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by love2code2trade, Yesterday, 01:45 PM
                3 responses
                22 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by trilliantrader, Today, 08:16 AM
                2 responses
                7 views
                0 likes
                Last Post trilliantrader  
                Working...
                X