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

Restablishing Connection from the Script

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

    Restablishing Connection from the Script

    Hello Everyone,

    I've been facing some connection loss problems, I can't tell if that is ISP's fault or broker's fault ( I think it is broker's) , but that doesn't matter, what I do notice is that once the connection is lost it doesn't reconnect automatically.

    My question is: Is there way to monitor the connection status, like a try catch or some sort? And then once it is broken, make it try to reconnect? All that from my strategy script?

    Thank you,

    Rodrigo

    #2
    Originally posted by rgaleote View Post
    Hello Everyone,

    I've been facing some connection loss problems, I can't tell if that is ISP's fault or broker's fault ( I think it is broker's) , but that doesn't matter, what I do notice is that once the connection is lost it doesn't reconnect automatically.

    My question is: Is there way to monitor the connection status, like a try catch or some sort? And then once it is broken, make it try to reconnect? All that from my strategy script?

    Thank you,

    Rodrigo
    No. This may change in NT 8?,,,

    Go into Tools->Options-> tab Strategies -> tab NinjaScript, and setup your On Connection Loss. I've noticed the # of restart attempts doesn't always go up to your max on certain conditions... (well that might have been due to the nasty old bug in ZenFire).

    Comment


      #3
      Hello,

      Sledge is correct, you can setup your Connection Loss with the Strategies Tab in options.
      Additionally you can use the OnConnectionStatus() for your script to detect a Connection state change -
      http://www.ninjatrader.com/support/h...nt7/index.html

      Let me know if I can be of further assistance.
      Cal H.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Cal View Post
        Hello,

        Sledge is correct, you can setup your Connection Loss with the Strategies Tab in options.
        Additionally you can use the OnConnectionStatus() for your script to detect a Connection state change -
        http://www.ninjatrader.com/support/h...nt7/index.html

        Let me know if I can be of further assistance.
        Ok, but this is mostly for informative purposes like to send emails, alerts, write logs, etc right? it's not like from ninja script I can treat connection errors and force new connection attempts, right?

        Comment


          #5
          Hello rgaleote,

          Thank you for your response.

          That is correct, you would not be able to re-connect through NinjaScript. This is handled by NinjaTrader and the connectivity technology, but unfortunately not something that can be controlled through NinjaScript.

          Please let me know if I may be of further assistance.

          Comment


            #6
            Originally posted by NinjaTrader_PatrickH View Post
            Hello rgaleote,

            Thank you for your response.

            That is correct, you would not be able to re-connect through NinjaScript. This is handled by NinjaTrader and the connectivity technology, but unfortunately not something that can be controlled through NinjaScript.

            Please let me know if I may be of further assistance.
            One other question, today I got the following error when submitting an order because order server was not connected and that stopped my strategy. How can I check Order Server connection status before even attempting to submit an order, that way I don't get that kind of error and my strategy won't be stopped.

            Thanks

            "22/07/2014 10:30:06 Strategy Strategy 'xxxx/fbbb145e2f964ed617f9d0b65930226' submitted an order that generated the following error 'UnableToSubmitOrder'. Strategy has sent cancel requests, attempted to close the position and terminated itself. "

            Comment


              #7
              Yes,

              With the OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus), the first property is for the orderStatus of the connection -

              A NinjaTrader connection may have two internally may have two separate connections, one for the price server and the other for the order server.

              orderStatus - Status of the broker's order server
              priceStatus - Status of the price server
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Cal View Post
                Yes,

                With the OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus), the first property is for the orderStatus of the connection -

                A NinjaTrader connection may have two internally may have two separate connections, one for the price server and the other for the order server.

                orderStatus - Status of the broker's order server
                priceStatus - Status of the price server
                ok thanks, but that is the event method.. how can I check connection from the OnBarUpdate method? which is where my market enter commands are.

                Comment


                  #9
                  Rodrigo,

                  You wouldn't need to call this in OnBarUpdate()
                  The OnConnectionStatus() will get called when you start the strategy, before any real time data processing is done.

                  Any event where there is a connection status change, this method will get called.
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by rgaleote View Post
                    ok thanks, but that is the event method.. how can I check connection from the OnBarUpdate method? which is where my market enter commands are.
                    ConnectionStatus is an object. You can check its value in OnConnectionStatus() and act accordingly in OnBarUpdate(). Actually, the example in the literature does exactly that.

                    ref: http://www.ninjatrader.com/support/h...tionstatus.htm

                    Comment


                      #11
                      Thanks everyone, still on the topic of losing and reestablishing connections, one thing that I noticed is that every time there is a connection lost error, NT is not being able to reestablish connection by itself, looks like some sort of session is being held somewhere. I have everything properly setup on the loss connection settings (like retry 90 times every 5 minutes).

                      Reason why I say that, it's that when I have a connection problem and try to reconnect manually by disconnecting and reconnecting on File menu, it gives me socket errors , problems on handshake with the server, etc. no matter how much I try, but then if I close NT, kill the process on Windows Task Manager and reopen it, then I'm able to connect right away.

                      That has happened multiple times already, if that is true how can I clear this that appears to be some sleeping session or bad cache? Is there a way to clear that from Ninja Script?

                      Thank you

                      Comment


                        #12
                        Hello rgaleote,

                        Thank you for your response.

                        What connectivity provider are you using?

                        Comment


                          #13
                          Originally posted by NinjaTrader_PatrickH View Post
                          Hello rgaleote,

                          Thank you for your response.

                          What connectivity provider are you using?
                          Clear.

                          Rgds

                          Comment


                            #14
                            Hello rgaleote,

                            Thank you for your response.

                            Please send me your log and trace files for today so that I may look into what occurred. You can do this by going to the Control Center-> Help-> Mail to Support. Please reference this thread in the subject of the email: http://www.ninjatrader.com/support/f...ad.php?t=67584

                            Comment


                              #15
                              Patrick,

                              After I upgraded to latest NT version with corrections to Clear Broker adapter, it looks like this particular problem has been fixed.

                              Still on the same topic, one thing that happens to me everyday is that around 9pm NT gets automatically disconnected from Clear Broker (not sure if this is Clear's policy, or they just simply shut down ports and connections), but the catch is, on the following day in the morning NT is not reestablishing connection automatically. I've got all Loss Connection settings in place, to retry connection for 999 times every two minutes, but it just doesn't work. I have to manually disconnect and reconnect on the following day.

                              My expectation is that I would turn on NT, connect it to Clear on Monday morning and it would stay connect through the entire week, without my manual intervention, even when Clear stops all connections by night, I would expect NT would resume by the morning on the following day. Is this possible? Is this the expected behavior from NT on its connection handling capabilities?

                              Thanks,
                              Rodrigo

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by thanajo, 05-04-2021, 02:11 AM
                              3 responses
                              467 views
                              0 likes
                              Last Post tradingnasdaqprueba  
                              Started by Christopher_R, Today, 12:29 AM
                              0 responses
                              10 views
                              0 likes
                              Last Post Christopher_R  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              166 responses
                              2,235 views
                              0 likes
                              Last Post sidlercom80  
                              Started by thread, Yesterday, 11:58 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post thread
                              by thread
                               
                              Started by jclose, Yesterday, 09:37 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Working...
                              X