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

MarketData subscription providing data for other instruments.

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

    MarketData subscription providing data for other instruments.

    The MarketData object as described here https://ninjatrader.com/support/help...marketdata.htm . My understanding was that the subscription was for that instrument and its Update event handler would only be called for that instrument.

    I created two different MarketData objects with different handlers in different classes. They each subscribed to different instruments. I ended up with strange bugs because I never bothered to check the instrument being passed. I eventually tested the instrument against what I expected and found that sometimes one of them would be called with market updates for the other instrument.

    Code:
    MarketData dataForA = new MarketData(instrumentA);
    dataForA.Update += UpdateHandlerForA;
    
    // some time passes before this is created by a different object.
    
    MarketData dataForB = new MarketData(instrumentB);
    dataForB.Update += UpdtaeHandlerForB;
    
    void UpdateHandlerForA(...)
    {
         // recieves some of the B events but only after B is created and subscribed
    }
    
    
    void UpdateHandlerForB(...)
    {
       // only seems to receive events for B
    }
    Something doesn't appear to be right either with the documentation or the implementation.

    This only seems to happen on first subscribing to the MarketData event, and only seems to happen for the first MarketData object created between the two. In the above example it only seems to affect dataForA, and not dataForB.
    Last edited by ntbone; 05-22-2019, 12:45 PM.

    #2
    Hello ntbone, thanks for your post.

    I did a quick implementation of this and I get the correct instrument from each market data hook. You can check the instrument name with "e.Instrument" in your event handler method. Can you print this data in the output window to see if the instrument is, in fact, being called on the wrong event method?

    The print statement I used was:

    private void MSFTOnMarketData(object sender, MarketDataEventArgs e)
    {
    NinjaTrader.Code.Output.Process("Instrument: " + e.Instrument.ToString() + " " + e.Last.ToString() ,PrintTo.OutputTab1);
    }

    I look forward to hearing of your results.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks. I had already done this and verified it. I had a strange bug happening when a second object was created using market data for a different instrument. I printed out a message in my event handler whenever it received an event for an instrument it wasn't expecting. There are a few things that are important to note to reproduce this.
      1. You must be subscribing to different instruments for each MarketData instance
      2. There must be time in between each subscription. Instrument A is subscribed and listening, and then Instrument B must be subscribed and listening.
      The messages only show up briefly during the initial subscription to B. If you cannot reproduce this I may try to throw something together in code that will.

      Comment


        #4
        Hi ntbone, thanks for your reply.

        My test does add two different instruments, but I'm not sure about re-creating this time gap you have between adding the event handlers. Does the problem go away if you add them continuously?

        Please post a reduced version of your script here, or you can send it into platformsupport at ninjatrader.com and reference "Attn ChrisL" in the body of the email.

        I look forward to hearing from you.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          I am using the MarketData object as part of a DrawingTool. I create one instance for Instrument A and plot it. Then some time later (has been generally within a minute) I create a second instance on a different chart for Instrument B and plot it. When I first create that second instance on ChartB the handler for A gets B's data. I'll throw together a script and get it to you.

          Comment


            #6
            I attempted to reduce the code to a minimum amount and I was unable to reproduce the bug. I'll post back here if I am able to make any further progress with this. It still happens in the original code.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by XXtrader, Yesterday, 11:30 PM
            2 responses
            10 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
            4 views
            0 likes
            Last Post elirion
            by elirion
             
            Working...
            X