Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Receiving emails on data feed disconnects

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

    Receiving emails on data feed disconnects

    I have a question regarding the handling of temporary and permanent data connection losses. In my strategy I have enabled ConnectionLossHandling.KeepRunning. The docs suggest that I would receive an email on a temporary disconnect:

    "KeepRunning: Keeps the strategy running and sends a disconnect email alert. When the connection is reestablished the strategy will resume as if no disconnect occurred."

    Here's my setting in the Initialize() method:

    ConnectionLossHandling = ConnectionLossHandling.KeepRunning;

    However in reality my strategies do recover after temporary disconnect of less than 30 seconds, but I don't ever receive an email. The admin email account settings are correct as I'm sending myself other alerts via the strategy. Is there anything special I need to do?

    FYI - I built myself a strategy to be alerted on permanent data disconnects. The method used is here:

    Code:
    protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus)
    		{
    			Print("On Connection Status Called.");
    			if (priceStatus == ConnectionStatus.Disconnected)
    			{
    				Print("Disconnected!");
    				StringBuilder sb = new StringBuilder();
    				sb.Append(HTML_STRONG_TAG_OPEN).Append("DATA FEED IS DOWN!!").Append(HTML_STRONG_TAG_CLOSE).Append(NEWLINE);
    				messageBuffer.Append(sb);
    			}
    			
    //			else if (priceStatus == ConnectionStatus.ConnectionLost)
    //			{
    //				Print("Connection Lost!");
    //				StringBuilder sb = new StringBuilder();
    //				sb.Append(HTML_STRONG_TAG_OPEN).Append("CONNECTION LOST!!").Append(HTML_STRONG_TAG_CLOSE).Append(NEWLINE);
    //				messageBuffer.Append(sb);
    //			}
    			
    			// ######## SENDING MESSAGE ###########
    			if (messageBuffer.Length > 0) {
    				sendMessage(MessageType.ALL);
    			}
    		}
    It's using the same sendMessage method I use in other strategies. However I never receive any emails when the data feed dies for good either.

    What I am looking for is simply a means of being notified. Sometimes disconnects happen on my end and my strategies are down for six hours or more, which is just mindbogglingly scary.

    Any input/help/suggestions are appreciated. Thanks in advance.

    #2
    The documentation is misleading and incorrect. I'll look into having that corrected, so thanks for bringing that up.

    In order for this to work as you are looking for, you would need to Log the disconnect as an alert level. These log level "alerts" can then be emailed to the address you have configured under "mail alert messages to" under Tools-> Options-> Misc tab

    (To be clear, this is NOT the mail setup/smtp options you may have configured and used for other features - specifically you need to fill out the text area that says "Mail alert messages to")

    Once you have that setup, add something similar to your strategy:

    Code:
    		protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus)
    		{
    			
    			if (priceStatus == ConnectionStatus.ConnectionLost)
    			{
    				// if you want to log in NT as well as get an email, make sure to use LogLevel.Alert
    				Log("connection lost at " + DateTime.Now, LogLevel.Alert);
    			}
    		}
    Anything logged as an "Alert" (identified in green text on the log tab of the control center) will be sent to the mail address configured under Tools-> Options-> Misc tab

    This will also work for any other sort of LogLevel.Alerts that NinjaTrader logs natively, such as Order rejections.
    Last edited by NinjaTrader_Matthew; 02-09-2015, 05:29 PM.
    MatthewNinjaTrader Product Management

    Comment


      #3
      That is a very interesting approach - thanks for the response. Alerts however produce pop-ups, correct? Aren't they modal, in that everything is on hold until they are being acknowledged?

      Comment


        #4
        Yes, anything on the alert level will display a pop up, which are modal. If this is undesired behavior, you would need to implement your own send mail routine under the connection lost event.

        Sorry for the confusion with the documentation, we'll have that corrected with the next NT7 release.

        edit: I should mention, only UI interactions are on hold when the modal window is displayed. The core will still process as normal, and your chart plots, will continue to update. So if you receive an Alert message box while you're not in front of the computer, it will remain until someone acknowledges and will not allow you to interact with the UI until it has been acknowledged, but core functions will process as normal.
        Last edited by NinjaTrader_Matthew; 02-11-2015, 09:41 AM.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Yes, I did that already - the problem is that the event is not being triggered. Please take a look at my original post below. My email method works fine - I'm using it on various systems dozens of times per day. The problem is your event not being caught - at least that's the only explanation I can think of.

          Originally posted by NinjaTrader_Matthew View Post
          Yes, anything on the alert level will display a pop up, which are modal. If this is undesired behavior, you would need to implement your own send mail routine under the connection lost event.

          Sorry for the confusion with the documentation, we'll have that corrected with the next NT7 release.

          edit: I should mention, only UI interactions are on hold when the modal window is displayed. The core will still process as normal, and your chart plots, will continue to update. So if you receive an Alert message box while you're not in front of the computer, it will remain until someone acknowledges and will not allow you to interact with the UI until it has been acknowledged, but core functions will process as normal.

          Comment


            #6
            Please be specific.

            Is the entire OnConnnectStaus not being called?

            ConnectionStatus.Disconnected not being called?

            ConnectionStatus.ConnectionLost not being called?
            MatthewNinjaTrader Product Management

            Comment


              #7
              Originally posted by NinjaTrader_Matthew View Post
              Please be specific.

              Is the entire OnConnnectStaus not being called?

              ConnectionStatus.Disconnected not being called?

              ConnectionStatus.ConnectionLost not being called?
              NEITHER of them are being called. I had it running for a few weeks and didn't receive a single email. Again, I'm using the same email method that I use for other strategies - so it's not that this part would be broken.

              Comment


                #8
                I still do not follow: you're saying OnConnectionStatus is never called? Or the logic in your first post does not work as expected in that you did not get an email? Based off the code you posted, I wouldn't expect you to get an email:
                • ConnectionStatus.Disconnect is not called during a lost connection, so that would never fire based off what you're saying. An example of where this would fire from a strategy is if you were connected to two feeds, say Kinetick and CQG, where Kinetick was your price feed and CQG was your order feed-> if you disconnected from CQG your orderStatus would give you ConnectionStatus.Disconnect. If you were not manually disconnecting, you would not see this state called.
                • You have code commented out ConnectionStatus.ConnecitonLost-> was this commented out during your testing period? If so that would be the simple explanation for why you never received an email.


                If not, I suggest you simplify and debug and analyze the Print statements from the code sample you provided to ensure it works as expected. You can use a program like TCPView to temporarily kill the connection to NinjaTrader which would simulate a temporary connection loss.
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  Originally posted by NinjaTrader_Matthew View Post
                  I still do not follow: you're saying OnConnectionStatus is never called? Or the logic in your first post does not work as expected in that you did not get an email? Based off the code you posted, I wouldn't expect you to get an email:
                  • ConnectionStatus.Disconnect is not called during a lost connection, so that would never fire based off what you're saying. An example of where this would fire from a strategy is if you were connected to two feeds, say Kinetick and CQG, where Kinetick was your price feed and CQG was your order feed-> if you disconnected from CQG your orderStatus would give you ConnectionStatus.Disconnect. If you were not manually disconnecting, you would not see this state called.
                  • You have code commented out ConnectionStatus.ConnecitonLost-> was this commented out during your testing period? If so that would be the simple explanation for why you never received an email.


                  If not, I suggest you simplify and debug and analyze the Print statements from the code sample you provided to ensure it works as expected. You can use a program like TCPView to temporarily kill the connection to NinjaTrader which would simulate a temporary connection loss.
                  Thanks for the response - I'm a bit confused about what you are saying. You are now talking about 2 data feeds? When did that become part of the equation?

                  Look, I originally asked how to receive email notifications on disconnects in this thread:



                  You yourself suggested in #7 that I used this very method to accomplish what I'm trying to do. I never brought up two data feeds and I think my question was crystal clear.

                  This thing is getting more and more complicated with various approaches being offered. Can SOMEONE please tell me how to create a mechanism that notifies me when my single Kinetick data feed is disconnected and/or interrupted? Because at this point my head is spinning and I have no idea what is supposed to work

                  Comment


                    #10
                    Originally posted by molecool View Post
                    data feed is disconnected and/or interrupted?
                    - If you want to know when the feed is disconnected, check ConnectionStatus.Disconnected
                    (i.e., the user manually disconnected, or broker forced connection closed due to maintenance)

                    - If you want to know when the data feed it is interrupted, check ConnectionStatus.ConnectionLoss
                    MatthewNinjaTrader Product Management

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    633 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    364 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    105 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    567 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    568 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X