Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Built a coherent Order Book

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

    Built a coherent Order Book

    Hello,

    I am using OnMarketDepth event to build a coherent Order Book. I am using the SampleMarketDepth template.
    My question is related to have coherent data in a particular Time.
    In order to have a coherent OrderBook several instructions need to be processed (for example a change on a price level needs a Remove instruction and an Insert instruction). If in the meantime of these instructions, I perform some calculations they would be wrong because they must be done after the second instruction.
    I know it is because race conditions but I wonder if there is any way to know if in a particular time data is coherent.
    Related to this problem, I want to know, what is the purpose of MarketDepth member of MarketDepthEventArgs class? It seems to have MarketDepthRowCollection items. Is it up to date? Is it valid? Can I use them to have a coherent real time Order Book?

    Thank you in advance

    #2
    Hello jbesada,
    If you look into the SampleMarketDepth code, it uses the lock statement to make sure the collection is not modified until we finish the processing (of our custom calculation). Please refer here to know more about the lock statement http://msdn.microsoft.com/en-us/library/c5kehkcz.aspx

    This is however more of a C# query and beyond what we could support.

    The MarketDepth object further exposes the various objects and collections of the level 2 data.

    Yes, it is realtime and updated on each change in the order book.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thank you for the answer but unfortunately it was not my question.
      I know how to use lock and event conditions.
      Sorry if my explanation is not very clear.
      If for example a change on a price level arises, several OnMarketDepth events need to be processed in an atomic way (lets to say a remove and then an insert for example), but because you don't know how many events are needed, you can have a non coherent Order Book in the meantime of these events (a lock statement doesn't prevent this).
      To summarize, changes in the Order Book could need several events to be processed, is there any way to know how many events will come up to have a 'coherent' order book?

      Regards

      Comment


        #4
        Hello jbesada,
        OnMarketDepth is called and guaranteed to be in the correct sequence for every change in level II. However we have no way to know what data is coming. It is chaotic as it would and orders can get added/updated/deleted at any time.

        To know when it is coherent, one needs to have a reference point and also one needs to define what is "coherent".

        I look forward to assisting you further.
        JoydeepNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

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