Announcement

Collapse
No announcement yet.

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, 11:45 AM.

    #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 hdge4u, Today, 09:09 PM
            0 responses
            15 views
            0 likes
            Last Post hdge4u
            by hdge4u
             
            Started by hdge4u, Today, 09:02 PM
            0 responses
            8 views
            0 likes
            Last Post hdge4u
            by hdge4u
             
            Started by stormcloudseven, Today, 08:41 PM
            1 response
            9 views
            0 likes
            Last Post DavidTrades  
            Started by GussJ, Today, 01:24 PM
            0 responses
            23 views
            0 likes
            Last Post GussJ
            by GussJ
             
            Started by frslvr, Today, 12:40 PM
            0 responses
            16 views
            0 likes
            Last Post frslvr
            by frslvr
             
            Working...
            X