Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Retrieve a price volume currenly sitting in the order book

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

    Retrieve a price volume currenly sitting in the order book

    Hi, is there a way to get the current number of contracts already sitting in the orderbook at a certain price? (for simplicity suppose the price of interest is the current BID or ASK). In some situations It will be helpfull to know the queue load before issuing a limit order. Thanks.

    #2
    Hello shil111,

    Thank you for your note.

    You would need to store the values as the update to a collection. Then the collection can be accessed at any valid key.

    Below is a link to the help guide reference sample which demonstrates.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the info

      Comment


        #4
        Hi, I saw in your attached example that "OnMarketDepth" is protected by a lock. I wonder if I should lock also the code in "OnMarketData"? I am not sure if we are dealing here with multithreaded or single thread environment, and using lock - if not "a must", could have overhead in an already tight computation process. What would you suggest? Thanks

        Comment


          #5
          Hello shil111,

          The lock freezes the collection so no elements can be removed or added while the collection is being used.


          It is possible for the collection to be modified while the collection is being used, so either a lock or a copy would be necessary.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thanks for your response.
            Follow-up question (I'll try it to be the last on the subject):
            In an attempt to better understand the way "OnMarketData" works, i printed out which of the event triggered the function (Trade, Bid volume change, Ask volume change). The results seems odd, as they seems not to keep the real order of events. You can see in the output sample below that the trades apear aggregated. (why it is wierd? for instance, you would think that after every call triggered by a "trade" there will be immediatly a call triggered by Bid or Ask "liquidity change",as the trade itself neccesarily changes one of them).
            What may be the explanation for the apperantly "loss of real events order"?
            Is there maybe some aggregation done at the broker server-side? (meaning this is not a real per-event tracking).
            Thanks

            Output:
            ---------
            BID. current liquidity (volume)=30 (current Bid price=6066.75)
            ASK. current liquidity (volume)=60 (current Ask price=6067)
            BID. current liquidity (volume)=33 (current Bid price=6066.75)
            ASK. current liquidity (volume)=47 (current Ask price=6067)
            BID. current liquidity (volume)=46 (current Bid price=6066.75)
            ASK. current liquidity (volume)=46 (current Ask price=6067)
            BID. current liquidity (volume)=47 (current Bid price=6066.75)
            ASK. current liquidity (volume)=49 (current Ask price=6067)
            ASK. current liquidity (volume)=50 (current Ask price=6067)
            BID. current liquidity (volume)=32 (current Bid price=6066.75)
            ASK. current liquidity (volume)=61 (current Ask price=6067)
            ASK. current liquidity (volume)=62 (current Ask price=6067)
            BID. current liquidity (volume)=31 (current Bid price=6066.75)
            ASK. current liquidity (volume)=63 (current Ask price=6067)
            ASK. current liquidity (volume)=70 (current Ask price=6067)
            BID. current liquidity (volume)=23 (current Bid price=6066.75)
            BID. current liquidity (volume)=28 (current Bid price=6066.75)
            ASK. current liquidity (volume)=71 (current Ask price=6067)
            BID. current liquidity (volume)=21 (current Bid price=6066.75)
            BID. current liquidity (volume)=22 (current Bid price=6066.75)
            BID. current liquidity (volume)=21 (current Bid price=6066.75)
            BID. current liquidity (volume)=22 (current Bid price=6066.75)
            ASK. current liquidity (volume)=72 (current Ask price=6067)
            BID. current liquidity (volume)=21 (current Bid price=6066.75)
            BID. current liquidity (volume)=17 (current Bid price=6066.75)
            BID. current liquidity (volume)=14 (current Bid price=6066.75)
            ASK. current liquidity (volume)=75 (current Ask price=6067)
            BID. current liquidity (volume)=29 (current Bid price=6066.75)
            ASK. current liquidity (volume)=72 (current Ask price=6067)
            BID. current liquidity (volume)=14 (current Bid price=6066.75)
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 3 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 2 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            ASK. current liquidity (volume)=17 (current Ask price=6066.75)
            BID. current liquidity (volume)=159 (current Bid price=6066.5)
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 2 (current bid=6066.75, current ask=6067
            ASK. current liquidity (volume)=8 (current Ask price=6066.75)
            BID. current liquidity (volume)=148 (current Bid price=6066.5)
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            ASK. current liquidity (volume)=7 (current Ask price=6066.75)
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067
            TRADE. trade price: 6066.75 , trade volume: 1 (current bid=6066.75, current ask=6067​

            Comment


              #7
              Hello shil111,

              Is 'TRADE' meant to be last data?
              What specific properties are being printed?

              I can provide an example that mimics the Time & Sales window.


              As far as how data is reported from the exchange I don't have too many specifics about, but from my understanding the ask would be the accumulated orders working at the first ask / bid price row on an exchange at any given time.
              How the data is aggregated and filtered is different with each data provider and brokerage. I believe most aggregate and send updates at intervals.

              As trades are exchanged, this would reduce from the from the ask or bid volume, however there could be other orders that have become working or also been filled so the outcome of the next ask update would be unknown.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Hi Chelsea,
                Regarding the output sample attached above: I just made "OnMarketData" report the event that triggered it, and then return without doing anything. each text line represent a single call to the function.
                "TRADE" = marketDataUpdate.MarketDataType == MarketDataType.Last
                "Bid" = marketDataUpdate.MarketDataType == MarketDataType.Bid
                "Ask" = marketDataUpdate.MarketDataType == MarketDataType.Ask

                I agree that the most probable explanation is some data aggregation on the exchange side.
                However, this makes the usage of "OnMarketData" for high-rate "delicate" trading somewhat questionable.
                Thank you for the prompt and helpfull responses.
                Last edited by shil111; 12-10-2024, 10:25 AM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                54 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                130 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                71 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                44 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                49 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X