Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simultanious order part fill and fill

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

    Simultanious order part fill and fill

    I use unmanaged approach to develop strategy. And like it says in documentation use IExecution object, which is passed to onExecution callback to see if order is filled or partfilled.
    My logic is driven only from entire fill, so no actions are taken when order is partfilled.
    Also what matters, I use Position object to get current strategy position.

    Recently I have faced with problem:
    According to Execution table - I have simultaneous (within 1 second) order part fill and then fill.
    But strategy is reported about 2 fills ( IExecution.Order.OrderState = OrderState.Filled)
    So for example I have an order for 4 lots to buy. Strategy receives following:
    • onExecution: (order state = filled; Position.Quantity = 3; Position.MarketPosition= MarketPosition.Long; ) ( where should have been reported as partfilled)

    • onExecution: (order state = filled; Position.Quantity = 4; Position.MarketPosition= MarketPosition.Long)

    And as you understand that is not what one would expect to receive.
    So my question is following: how do I work with it?
    If IExecution object, which is passed to onExecution, is synchronized between threads, is there a Position object that is synchronized as well - so I would get correct strategy direction and position?
    I could ignore second reported fill, but I need to know correct strategy position at the moment of first onExecution callback.

    #2
    Hi Andreano, so this would be one order using one IOrder object only in your code? Would you mind contacting me via Help >> Mail to Support so I would have access to your diagnostic log / trace files to be able to review the event sequence seen here for this trade?

    Comment


      #3
      The thing here is that information I have got - is information received from client, so there are no NT logs on my machine.
      I have 2 cases reported by clients and 2 set data to related cases:
      1)Containing strategy logs ( logs, written by strategy)
      2) Execution table
      I will send you this info and even strategy code, but I don't think you would investigate it in such format.
      So I will just have to take any advice you have based on what I have given you.

      Comment


        #4
        Hello,

        We received your files, but it is hard for to determine what is occurring in your cases without these files. If there is anyway you can get this information from your clients, we'd be happy to investigate this as much as we can.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Matthew,

          What was the resolution to this issue? I am having a similar problem. I use unmanaged orders and track my position and PNL internally.

          In OnExecution, I check the OrderState for Fills or PartFills. When the execution.Order.OrderState == OrderState.Filled, I would want to set my market entry order (a variable named entryOrder) to null.

          The issue is that at every execution, the execution.OrderState returns Filled despite the execution.Quantity being less than the amount of contracts I want to trade. For example, I am trading 8 contracts. The first call to OnExecution results in a fill of 2 contracts (execution.Quantity = 2). Despite the order obviously not being filled, the value of execution.Order.OrderState is OrderState.Filled. I would think it would be OrderState.PartFilled.

          This is critically important for me because I have different code to perform different tasks when the order is PartFilled versus what I need to do when the order is Filled.

          Can you please help explain why this occurs and how I can remedy the issue? Thank you.

          Comment


            #6
            ivb73077, I will check with Matthew later but just ran a simple test script here to try reproducing this issue in unmanaged but I'm not seeing any unexpected results - here you see a test market entry enforcing partial fills on ES, I'm getting two executions until I have the final position. OnOrderUpdate() would be the first to recognize the fully filled state so can definitely set your variable to track from here as well.

            OOU Order='5f55e35e57794f5e98b577a0582030cb/Sim101' Name='LongMkt' State=PendingSubmit Instrument='ES 03-14' Action=Buy Limit price=0 Stop price=0 Quantity=10 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='5f55e35e57794f5e98b577a0582030cb' Gtd='1/1/0001 12:00:00 AM'
            OOU Order='5f55e35e57794f5e98b577a0582030cb/Sim101' Name='LongMkt' State=Accepted Instrument='ES 03-14' Action=Buy Limit price=0 Stop price=0 Quantity=10 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='5f55e35e57794f5e98b577a0582030cb' Gtd='1/1/0001 12:00:00 AM'
            OOU Order='5f55e35e57794f5e98b577a0582030cb/Sim101' Name='LongMkt' State=Working Instrument='ES 03-14' Action=Buy Limit price=0 Stop price=0 Quantity=10 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='5f55e35e57794f5e98b577a0582030cb' Gtd='1/1/0001 12:00:00 AM'
            OOU Order='5f55e35e57794f5e98b577a0582030cb/Sim101' Name='LongMkt' State=PartFilled Instrument='ES 03-14' Action=Buy Limit price=0 Stop price=0 Quantity=10 Type=Market Tif=Gtc OverFill=False Oco='' Filled=2 Fill price=1752.75 Token='5f55e35e57794f5e98b577a0582030cb' Gtd='1/1/0001 12:00:00 AM'
            EXE Execution='4c63ecbcc46d4254b1dc8c0f9b6b8316' Instrument='ES 03-14' Account='Sim101' Name='LongMkt' Exchange=Default Price=1752.75 Quantity=2 Market position=Long Commission=0 Order='5f55e35e57794f5e98b577a0582030cb' Time='2/6/2014 6:09:29 AM'
            OOU Order='5f55e35e57794f5e98b577a0582030cb/Sim101' Name='LongMkt' State=Filled Instrument='ES 03-14' Action=Buy Limit price=0 Stop price=0 Quantity=10 Type=Market Tif=Gtc OverFill=False Oco='' Filled=10 Fill price=1752.75 Token='5f55e35e57794f5e98b577a0582030cb' Gtd='1/1/0001 12:00:00 AM'
            EXE Execution='410ce2f589e240dd814fbc348c73952e' Instrument='ES 03-14' Account='Sim101' Name='LongMkt' Exchange=Default Price=1752.75 Quantity=8 Market position=Long Commission=0 Order='5f55e35e57794f5e98b577a0582030cb' Time='2/6/2014 6:09:29 AM'

            Comment


              #7
              Thank you Bertrand.

              I am just wondering why this might occur.

              I print a simple output that tells me the number of contracts filled on an execution and the order state at that time. I am trying to fill 8 contracts. Here is a sample output:

              Filled: 2
              Filled: 4
              Filled: 3
              Filled: 1

              I don't quite understand why the execution.Order.OrderState returns Filled in each case. I think it should return PartFilled for the first 3 cases and Filled for the last case. I just want to properly understand the behavior before changing code.

              Thank you.

              Comment


                #8
                The OnExecution would be getting called only on the execution events, it would not be concerned with any order state update timings (OnOrderUpdate() will be always called before OnExecution()). So I believe you're seeing a race condition here checking those off from OnExecution(). First point to set your flag would be the order state change fully seen in OnOrderUpdate to .Filled - that's what I would recommend using.

                Comment


                  #9
                  I would not have expected a race condition because the documentation states that OnExecution always fires after OnOrderUpdate.

                  Perhaps I have misunderstood. Could you please confirm?

                  Regardless, I will definitely change to code to test for the OrderState in OnOrderUpdate. Thank you.

                  Comment


                    #10
                    I can understand however a race conditions between those methods could easily occur given the fact NT is a multithreaded event driven environment. The hint you've seen is specific to working on fills where internal logic is called after OnOrderUpdate but before OnExecution. You're working with the IOrder fillstates here and thus OnOrderUpdate() is the event handler to go to.

                    Comment


                      #11
                      ok. thank you.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      646 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      367 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      107 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      569 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      573 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X