Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

DuplicateOrderID due to NT8 Multitreading?

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

    DuplicateOrderID due to NT8 Multitreading?

    This morning, I had a strategy to go long on the NQ at the open. The strategy placed a market order at the open and a stop loss and profit target. This was all done on NT 8 Beta 11.

    The trade never triggered due to NT creating duplicated order? Below is the error

    2016-06-02 06:29:58:437 (IB TWS) Cbi.Account.CreateOrder: orderId='ae7ad48a171448f4bcbe4446bdbb2e7d' account='U122122' name='StrategyA' orderState=Initialized instrument='NQ 06-16' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=2502 gtd='2099-12-01'
    2016-06-02 06:29:58:439 (IB TWS) Cbi.Account.Submit0: orderId='ae7ad48a171448f4bcbe4446bdbb2e7d' account='U122122' name='StrategyA' orderState=Initialized instrument='NQ 06-16' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=2502 gtd='2099-12-01' currentOrderState=Initialized
    2016-06-02 06:29:58:440 (IB TWS) Cbi.Account.Submit1: orderId='ae7ad48a171448f4bcbe4446bdbb2e7d' account='U122122' name='StrategyA' orderState=Initialized instrument='NQ 06-16' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=2502 gtd='2099-12-01' currentOrderState=Initialized
    2016-06-02 06:29:58:440 (IB TWS) IB.Adapter.Submit0: count=1
    2016-06-02 06:29:58:440 (IB TWS) IB.Adapter.Submit: orderId='ae7ad48a171448f4bcbe4446bdbb2e7d' account='U122122' name='StrategyA' orderState=Initialized instrument='NQ 06-16' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=2502 gtd='2099-12-01'
    2016-06-02 06:29:58:442 (IB TWS) IB.Adapter.OnError: id=12601 errorCode='DuplicateOrderID' errorMessage='Duplicate order id'
    2016-06-02 06:29:58:446 ERROR: Failed to submit orders: System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(Exceptio nResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKe y key, TValue value, Boolean add) at NinjaTrader.IB.Adapter.Submit(Order[] orders) at NinjaTrader.Cbi.Account.<>c__DisplayClass254_3.<Su bmit>b__4()



    I am thinking the duplicate order might be related to the mutitreading of NT 8 in where the entry order, exit order and target order happened on different threads, thsus causing the issue? If indeed this is the case,, is there other conditions I need to incorporate in the code below such that this does not happen again?

    Below is the sample code used for this strategy.

    protected override void OnBarUpdate()
    {
    if (State == State.Historical)
    return;

    if (entryOrder == null && ToTime(Time[0]) >= startTime)
    {
    if (GetCurrentBid() > longMaxEntry
    && GetCurrentBid() < longMinEntry
    && longEnabled == true)
    // Go Long
    entryOrder = EnterLong (1,Name);
    else
    if (GetCurrentAsk() < ShortMaxEntry
    && GetCurrentAsk() > ShortMinEntry
    && shortEnabled == true)
    // Go Short
    entryOrder = EnterShort (1,Name);
    else
    {
    SetState(State.Terminated);
    Print("Condition not met. Disabling " + Name + " Strategy" + " " + State + " " + ToTime(Time[0]));
    }

    }


    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    if (entryOrder != null
    && entryOrder == execution.Order
    && (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled))
    {

    entryOrder = execution.Order;

    if (execution.Order.IsLong)
    {
    Print ("Strategy " + Name + " is Long. Entry Price @" + entryOrder.AverageFillPrice + " " + ToTime(Time[0]));
    if (stopOrder == null)
    {
    stopOrder = ExitLongStopMarket(0, true, 1, entryOrder.AverageFillPrice - (stopLossTicks*Bars.Instrument.MasterInstrument.Ti ckSize), "MyStop", Name);
    //stopOrder = ExitLongStopMarket(0, true, 1, entryOrder.AverageFillPrice - .05, "MyStop", Name);
    Print ("Strategy " + Name + " Stop Order Price @" + stopOrder.StopPrice + " " + ToTime(Time[0]));
    }
    if(targetOrder == null)
    {
    targetOrder = ExitLongLimit(0, true, execution.Order.Filled, profitTargetPrice, "MyTarget", Name);
    //targetOrder = ExitLongLimit(0, true, execution.Order.Filled, entryOrder.AverageFillPrice +.01, "MyTarget", Name);
    Print ("Strategy " + Name + " Profit Target Price @" + targetOrder.LimitPrice + " " + ToTime(Time[0]));
    }

    }

    #2
    Hello hotsalami, and thank you for your question.

    Order IDs and other thread synchronization concerns are handled "under the hood", and there is nothing extra you need to do at the strategy override level.

    Please send me your log and trace files so that I may look into what occurred.
    You can do this by going to the Control Center-> Help-> Email Support.
    Please reference the following ticket number in the body of the email: 1524278
    Please also tick all the boxes in the "Other Files" section.

    Thank you for your report, and for helping NT8 be the best product it can be.
    Last edited by NinjaTrader_JessicaP; 06-02-2016, 01:56 PM.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Hi Jessica

      I think you left out the ticket # part. Please provide that and I can send you the log file. I have also pasted the relevant areas of the trace and log file below:

      Trace file:
      2016-06-02 06:29:15:734 (IB TWS) Cbi.Account.AccountItemCallback: account='U122122' accountItem=NetLiquidationByCurrency currency=UsDollar value=*****
      2016-06-02 06:29:58:437 (IB TWS) Cbi.Account.CreateOrder: orderId='ae7ad48a171448f4bcbe4446bdbb2e7d' account='U122122' name='StrategyA' orderState=Initialized instrument='NQ 06-16' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=2502 gtd='2099-12-01'
      2016-06-02 06:29:58:439 (IB TWS) Cbi.Account.Submit0: orderId='ae7ad48a171448f4bcbe4446bdbb2e7d' account='U122122' name='StrategyA' orderState=Initialized instrument='NQ 06-16' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=2502 gtd='2099-12-01' currentOrderState=Initialized
      2016-06-02 06:29:58:440 (IB TWS) Cbi.Account.Submit1: orderId='ae7ad48a171448f4bcbe4446bdbb2e7d' account='U122122' name='StrategyA' orderState=Initialized instrument='NQ 06-16' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=2502 gtd='2099-12-01' currentOrderState=Initialized
      2016-06-02 06:29:58:440 (IB TWS) IB.Adapter.Submit0: count=1
      2016-06-02 06:29:58:440 (IB TWS) IB.Adapter.Submit: orderId='ae7ad48a171448f4bcbe4446bdbb2e7d' account='U122122' name='StrategyA' orderState=Initialized instrument='NQ 06-16' orderAction=Buy orderType='Market' limitPrice=0 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=2502 gtd='2099-12-01'
      2016-06-02 06:29:58:442 (IB TWS) IB.Adapter.OnError: id=12601 errorCode='DuplicateOrderID' errorMessage='Duplicate order id'
      2016-06-02 06:29:58:446 ERROR: Failed to submit orders: System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(Exceptio nResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKe y key, TValue value, Boolean add) at NinjaTrader.IB.Adapter.Submit(Order[] orders) at NinjaTrader.Cbi.Account.<>c__DisplayClass254_3.<Su bmit>b__4()


      Log File:

      2016-06-02 06:29:58:439|1|4|NinjaScript strategy 'StrategyA/66399720' submitting order
      2016-06-02 06:29:58:442|3|32|Failed to submit orders: System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(Exceptio nResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKe y key, TValue value, Boolean add) at NinjaTrader.IB.Adapter.Submit(Order[] orders) at NinjaTrader.Cbi.Account.<>c__DisplayClass254_3.<Su bmit>b__4()
      Last edited by hotsalami; 06-02-2016, 01:53 PM.

      Comment


        #4
        Sorry about that, and thanks. I have edited this number into the post :

        1524278
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          I followed your instructions, however, I am getting the following errors

          This message was created automatically by mail delivery software.

          A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed:

          [email protected]
          host mx1.emailsrvr.com [98.129.185.131]
          SMTP error from remote mail server after RCPT TO:<[email protected]>:
          550 5.7.1 <[email protected]>: Relay access denied.

          Reporting-MTA: dns; host1.ninjatrader-support2.com

          Action: failed
          Final-Recipient: rfc822;[email protected]
          Status: 5.0.0
          Remote-MTA: dns; mx1.emailsrvr.com
          Diagnostic-Code: smtp; 550 5.7.1 <[email protected]>: Relay access denied.

          Any suggestions on how to correct this?

          Comment


            #6
            I suspect, from both the duplicate keys message in the database and the platform's failure to send out an e-mail, that you may have a corrupt installation. Would it be possible for me to start a remote support session with you, so that I can retrieve the files I need directly? If so, I would like to ask you to send me a PM with the following information :
            • A phone number where you can be reached
            • A time window where I can call you (please include a time zone) our regular support hours are 8:30am to 6pm US Eastern, Monday through Friday.
            • Shortly before our call, please launch our remote support application (TeamViewer). There are 2 ways you can do this.


            If this is not possible, the following instructions utilizing the publicly available website sendspace.com should give me everything I need to reproduce and help from my end


            • Close NT8
            • Browse to your (My) Documents folder
            • Right-click your NinjaTrader 8 folder and select "Send To" -> "Compressed (Zip) Folder"
            • Call the resulting file NinjaTrader 8.zip
            • Visit the publicly available website https://www.sendspace.com/
            • Browse to your (My) Documents\NinjaTrader 8.zip file
            • Set the recipient to platformsupport[at]ninjatrader[dot]com , replacing [at] and [dot] appropriately
            • Set the sender to [email protected]
            • Press Upload

            I look forward to assisting further
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Hi Jessica

              The strategy traded again this morning and in this case, it created 2 market orders where it was suppose to only created 1 market order. This appears to be a NT 8 multithreading issues where the broker is Interatcive brokers. I am on release TWS Build 954.2r, Jan 4, 2016 11:00:09 AM, which i believe is the supported version for NT 8.

              Do let me know if you are able to meet to day to go over this issue.

              Thanks

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by XXtrader, Yesterday, 11:30 PM
              2 responses
              11 views
              0 likes
              Last Post XXtrader  
              Started by Waxavi, Today, 02:10 AM
              0 responses
              6 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by TradeForge, Today, 02:09 AM
              0 responses
              11 views
              0 likes
              Last Post TradeForge  
              Started by Waxavi, Today, 02:00 AM
              0 responses
              2 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by elirion, Today, 01:36 AM
              0 responses
              7 views
              0 likes
              Last Post elirion
              by elirion
               
              Working...
              X