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

Possible bugs with OnFundamentalData

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

    Possible bugs with OnFundamentalData

    Hi,


    I found while developing an AddOn using as basis your sample AddOn from the NT documentation that a thread gets stuck in fundamentalData.Update -= OnFundamentalData; while it progresses without problems the other event subscriptions

    Hangs in my code
    marketData.Update -= OnMarketData;
    barsRequest.Update -= OnBarUpdate;
    fundamentalData.Update -= OnFundamentalData; <== Hangs here.

    Also found that if you subscribe to fundamentalData.Update += OnFundamentalData; we stop receiving MarketData.DailyVolume in OnMarketData if you are also not subscribed to OnBarsUpdate.

    Do you have any suggestions for the thread stuck issue? Have you seen this before?



    #2
    Hello jmneto,

    Thanks for your post.

    The AddOnFramework example unsubscribes from these sequentially in the Instrument's setter, and in the AddOn window's CleanUp method. There are not any threading errors seen here. You may find some further direction by reducing the AddOnFramework script into what functionality you are looking for.

    I have included a demonstration showing Market Data update subscriptions and prints where unsubscriptions take place.

    Demo - https://drive.google.com/file/d/1cR6...w?usp=drivesdk

    As far as Daily Volume is concerned, OnBarUpdate events should not effect this. I have attached the script I have used to test in the video. I commented out subscriptions to OnBarUpdate, and I am still able to see valid output for DailyVolume.

    Please let me know if you have any questions.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi, I am well past samples, I have written a complex multithreaded app that uses these events. Interesting enough is that I create the events subscriptions all together, and unsubscribe all together like you see in the code extract I provided. The thread only hangs when unsubscribing the fundamenta data. I found other odd behaviors with Fundamenta Data also. Anyways, I just wanted to report this to your developers to take a second peek around this.

      Comment


        #4
        Hello jmneto,

        If you would like to share a reduced AddOn that demonstrates the issue without taking any other action, with some steps to reproduce, we could open up a ticket with the development team. Without such a case, we are left to guess at how you are hitting an issue.

        I'll be happy to file a report with you if you can provide such a case.
        JimNinjaTrader Customer Service

        Comment


          #5
          In your sample, all the subscription to these events is started (+=) or removed (-=) from the UI thread or Dispatcher.InvokeAsync. In my code, to add the event subscriptions to MarketData, BarsRequest and Fundamenta Data I use a thread started via Task.Run. Do you have any history about issues with this setup?

          Comment


            #6
            I think I found the problem: Appears that if you call
            fundamentalData.Update += OnFundamentalData in one thread, and then later you attempt to call fundamentalData.Update -= OnFundamentalData on another diferrent thread to unsubscribe the event for the same object, the later thread hangs. It does not happen when subscribing/unsubscribing to the other data subscription events, onmarketdata or onbarupdate.

            In other words, you have to subscribe to fundamental data and unsubscribe to fundamental data from the same thread. (again other market data subscriptions are not affected by this).

            Please let me know your developers thoughts on this. For now I found a workaround, but this is something you might want to investigate.

            Comment


              #7
              Hello jmneto,

              I don't see anything internally regarding threading issues with OnFundamentalData, but we do document some precautions for cross thread exceptions. Due to the multi-threaded nature of NinjaTrader 8 it would be expected to run into such issues with separate threads. Subscribing and Unsubscribing on separate threads would qualify here.

              Our cross thread exception advisories can be referenced in the Multi-threading considerations page of the help guide.

              Cross Thread Exceptions

              When accessing objects included on the UI, you may receive the following error if you attempt to access a certain property/method from the wrong thread:

              "Error on calling 'OnBarUpdate' method on bar 0: You are accessing an object which resides on another thread. I.E. creating your own Brush without calling .Freeze(), or trying to access a UI control from the wrong thread without using a Dispatcher"

              This error can be avoided by invoking the Dispatcher used on the appropriate UI thread.
              I have asked that this particular case gets noted in this advisory page, however we cannot document every particular case that could be encountered with cross thread exceptions. More general notes are typically preferred in the documentation, so I could not say if the specific note will be added.

              If you disagree that this is explained (in general) in the Multi Threading Considerations page, please send us a test script so we can forward your inquiry to Development. (We are capable of creating test scripts on the NinjaScript team for review, but we also have other priorities that we need to take first. It is best if we can receive a test script from you that explains the matter in clear terms so we can avoid any guess work, get the issue reported as you see it, and so we can continue assisting others in a timely manner.)

              I look forward to being of any further assistance.
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by yertle, Today, 08:38 AM
              3 responses
              9 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
              80 responses
              19,667 views
              5 likes
              Last Post NinjaTrader_ChelseaB  
              Started by adeelshahzad, Today, 03:54 AM
              2 responses
              16 views
              0 likes
              Last Post adeelshahzad  
              Started by dappa, Today, 09:18 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by bill2023, Yesterday, 08:51 AM
              5 responses
              25 views
              0 likes
              Last Post bltdavid  
              Working...
              X