No announcement yet.

Partner 728x90


Reconnection logic

  • Filter
  • Time
  • Show
Clear All
new posts

    Reconnection logic

    I think I'm having a problem with my data provider. I dont know if it's an NT8 problem or a TDA problem actually.

    Some days, the data stream just stops updating. NT8 still thinks it is connected, but no stock data, or any visible data is coming in.
    If I disconnect, and reconnect I again start getting data.

    If this is a NT8 problem, what can I do?

    If this is a TDA problem, I need to be able to disconnect and reconnect without disabling my strategy or canceling orders. How can I do that?
    In theory, I would like to detect in code if data is coming in or not, and if there is nothing for 30 seconds, I want to disconnect, and reconnect, leaving all strategies and indicators untouched, all through code.
    Can this be done?

    Hello DieSlower,

    Is this happening during the trading session or during the weekend?

    Typically there is maintenance on the weekend with most brokerage servers on Friday night and / or Saturday.
    Most brokerages will have the maintenance completed Sunday after 2PM Eastern. You will need to restart NinjaTrader if NinjaTrader is open during this time.

    This may be further extended due to the US Holiday Monday September 7th.

    If a connection is fully disconnected, it is not possible to keep a strategy running or enable a strategy through code.
    Chelsea B.NinjaTrader Customer Service


      Hi Chelsea,

      This is happening usually during the night on weekdays, but sometimes right in the middle of a trading period, which is why i need a way to close and reopen the connection in code without interrupting my running strategies.



        Hello Maxim,

        Unfortunately, it is not possible for a strategy to remain enabled after a connection is disconnected.

        A server going down for maintenance during the weekend would cause a full disconnection.

        Are you having connection losses and automatic re-connections occurring due to latency?

        The 'On connection loss' handling controls how many reconnections can be attempted before a strategy is disabled, recalculates, or keeps running.
        Chelsea B.NinjaTrader Customer Service


          Hi Chelsea,

          Is it possible to build in an option like that?

          The problem is that NT does not detect that the connection is dead. It might only be partially dead, but no stock data is being received.
          The problem is that right now I manually disconnect, which kills my strategy, and reconnect a second later.
          The "Keep Running" option in the link you sent seems like the item I need, but I need to be able to trigger the disconnect and reconnect through code, I guess the same what NT does on connection loss. Just under different circumstances. I'm guessing NT is looking for a server port connection, and as long as that's open, it thinks the connection is ok. I'm still seeing the port open, but nothing is coming through from the TDA server until I close the port and reopen it.

          I can write something that can tell me if i'm getting data, but are there some commands to trigger connection and disconnection through code?



            Hello Maxim,

            Unfortunately, it is not possible for a strategy to remain enabled after manually disconnecting a connection.

            The, connection needs to be manually reconnected, any historical data would be downloaded, then strategy must be manually re-enabled and recalculate using the newly downloaded historical data.

            A connection loss indicates that the "heartbeat" (ping) that is measured between your PC and the data provider / brokerage servers was lost in transmission. While other internet services may be functioning properly, this is a sign that the quality of the internet connection has degraded which introduces a latency between you and these servers.

            We realize that lost connections can be frustrating. The connection state between NinjaTrader and your broker/market data vendor is not dictated by NinjaTrader and is subject to the internet connection, PC settings, and anti-virus/firewall. The NinjaTrader application only reports the connection state as it is reported by the API you are connected through. NinjaTrader behaves like a radio receiver in that it receives signals from the connected server. If the signals are not coming through, the underlying broker/market data vendor API reports this to the NinjaTrader application which in turn reports this back to you. Once a loss of connection is reported, NinjaTrader or the underlying API will continuously try to re-establish a connection.

            Common reasons that contribute to connection instability are:
            • Distance from local computer to the connection servers
            • Connection through a mobile hotspot (high latency)
            • Connecting through Wifi (connecting wirelessly contributes to latency)
            • Using a VPN (Virtual Private Networks may have a much lower bandwidth and will also contrinute to latency)
            • ISP issues
            • Hardware firewall changing IP addresses frequently
            • Dynamic IP addresses changing frequently intraday. Usually this happens once a week but you may want to check with your ISP. If they do change daily, requesting a static IP address may help.
            • Broker/market data servers may be experiencing temporary downtime, such as scheduled weekend maintenance
            To troubleshoot this, I recommend the following steps:
            • Unplug your internet modem, and (if a separate device) router for at least 60 seconds, and also restart the Computer
            • Ensure exceptions have been added into any firewall/antivirus/backup programs for the (My) Documents/NinjaTrader 8 folder
            • Ensure you are using the latest release of NinjaTrader
            • If you are not already and the option is available to you, I highly recommend connecting to the internet using an ethernet cable. Wireless connections are significantly more unreliable
            • Disconnect from any VPN if connected
            • Ensure that your computer is not turning off your Network Adapter to conserve power:
              • Right-click on your Start button
              • Select 'Device Manager'
              • Expand 'Network Adapters'
              • Right-click on your Network Adapter and select Properties > Power Management
              • Uncheck 'Allow the computer to turn off this device to save power' option
              • Click 'OK' to save the changes
              • Do this for all Network Adapters
            • Clear your DNS
            • If the above steps do not help, contact your ISP and let them know you are experiencing a highly unstable connection. An issue of connectivity may exist on their end
            • If your ISP is unable to resolve the issue from there, consider looking into a Virtual Private Server (VPS) to run NinjaTrader on. This will provide a strong and uninterrupted connection to the appropriate data servers
            If questions come up, please let us know.​
            Last edited by NinjaTrader_ChelseaB; 11-02-2021, 11:08 AM.
            Chelsea B.NinjaTrader Customer Service


              Hi Chelsea,

              I understand everything you are saying about connection types and how the API works. (I am a software architect) It seems however that it's not a total disconnect, that's why NT8 does not go into its reconnection routine, and just sits there waiting....

              I don't believe the problem is with the connection or NT8, but maybe with the broker itself. However, as i said, the connection can be restored with a reset.

              In the link you sent me...what does "Keep Running" option do for a strategy? It seems that it pretends to run, without any interruptions while a reconnection happens? That's the exact behavior I want to accomplish, but with my own code.... I want to be able to trigger it.

              I saw that there are server messages and controls in the following namespaces:

              I just need some kind of an example or API explanation for server controls and message description. Basically I'm looking for a way to tell NT8, "hey, pretend there is a connection loss and do a reconnect"
              If you say that "the underlying broker/market data vendor API reports" the connection loss, then there is some message that carries this information, and as long as I know what message is needed, it can be replicated...



                Hello Maxim,

                There is not anything exposed in NinjaScript to simulate a connection loss.

                We send your log and trace files to our development to have them look into the connection not fully reconnecting.

                Please send an email to platformsupport [at] ninjatrader [dot] com, with a link to this forum thread, and we can get the behavior reported.
                Chelsea B.NinjaTrader Customer Service


                  Hi Chelsea,

                  Thank you for the link, I'll play around with that API, and I'll send over the logs....



                    Hi Chelsea,

                    Did you ever create a reference number for this ticket?



                      Hello DieSlower,

                      This is Jim responding on behalf of Chelsea who is out of the office at this time.

                      A ticket has been opened with our Quality Assurance team and is currently being tacked with the ticket ID QA-5194.

                      We look forward to assisting.
                      JimNinjaTrader Customer Service


                      Latest Posts


                      Topics Statistics Last Post
                      Started by Board game geek, Yesterday, 09:46 AM
                      10 responses
                      Last Post Board game geek  
                      Started by love2code2trade, 09-21-2023, 09:32 PM
                      5 responses
                      Last Post NinjaTrader_ChelseaB  
                      Started by sebdgo, 09-22-2023, 06:41 AM
                      4 responses
                      Last Post NinjaTrader_Jesse  
                      Started by Atomic, Yesterday, 05:36 AM
                      3 responses
                      Last Post NinjaTrader_BrandonH  
                      Started by ganeshinbarajan, Yesterday, 08:46 PM
                      1 response
                      Last Post NinjaTrader_Jesse