Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order objects as keys to Dictionaries

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

    Order objects as keys to Dictionaries

    Hello,

    I've got some metadata associated with order objects. Since there can be multiple orders any given time, I want to keep the data in a dictionary, with the Order objects as keys.
    According to the manual, I mustn't use <IOrder>.OrderId, nor Token, as they will change throughout the order's lifetime.
    • s there another field/property in IOrder can use as key?
    • Can I use the order itself as key? (namely, does it implement the IEqualityComparer() interface such that no two orders will return the same value - see e.g. here )


    Thanks,
    Boaz

    #2
    Hi Boaz, I think you can use the token combined with the orderID and update your references then when the strategy transitions from historical to realtime data.

    Comment


      #3
      Bertrand,
      I'm not sure I understand - I need some property of the Order which never changes, otherwise it is illegal, according to C# reference, to use that as a dictionary key. For one thing, after the OrderId has changed, I won't be able to retrieve it from the dictionary.

      Is there some constant property of the IOrder which can be used as key? Can I use the order object itself?

      Thanks,
      Boaz

      Comment


        #4
        Hi Boaz,

        You can't use the order object itself as you use the same object for multiple orders. With the existing IOrder properties, Bertrand's suggestion to combine token and order id is likely the best way to capture the properties of different IOrder instances

        If you need more control, you could create your own class and supply its own unique ID, using something like this to generate one:


        Unfortunately we would not be able to support these general C# techniques but NinjaScript is flexible enough that it should be possible. .
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Hi Ryan,
          Sorry for persisting on this, but I need to be able to dispatch the correct order on methods such as OnOrderUpate() and OnExecution(), similar to what is done in this sample. In the sample, orders are compared by reference.
          I'm OK with the IOrder object changing states and IDs, but I need to be able to associate them with the command that originated them, a-la:

          Code:
           entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "Enter Long");
          According to the spec, I can directly compare orders. As far as I can see, they are compared by reference. In C# it is legal to use references as keys. Thus, I cannot see any reason not to use Orders as keys.

          Am I correct?

          Thanks,
          Boaz

          Comment


            #6
            Boaz, while I have not personally used this approach I see no issue you doing it this way, as long as you keep in mind the order objects are not static throughout their lifespan.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            647 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 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