Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to auto manage IB-Gateway daily restart without causing NT8 to stop working

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

    How to auto manage IB-Gateway daily restart without causing NT8 to stop working

    Hello.

    I am developing strategies for algo trading with no human involved after all was set properly. I am using IB as my broker and also for price quotes (for now any how). My problem is that Interactive Brokers IB-Gatway can either logout at a specific hour, meaning i need some script or manual intervention in orderto log in again or it can shutdown itself and restart (fast process less then 30 `sec i think) itself again once every day.

    I noticed that if i use the IB-Gateway restart option, NT8 will popup panic error on the screen and stop working even after IB-Gateway become operational again after lets say 20 Sec.

    With Logout option NT8 is more "nice" It will give a yellow indication that there is a problem with the conenction and after a dditional short time it will issue panic as well and stop working (logical since no connection to IB).

    I am wondering if there is some option to lets say code inside my startegy that on specific hour NT8 will "freez" for lets say 20 Sec and continue from there as if nothing happens and it was a short connection problem

    If not then how can i make my software code detect the panic, close the panic, read back the account live position status and continue from there?

    #2
    This has been a long long sore issue. The new TWS has an auto-restart option that auto logs you back in but NT does not recognize this and completely stops attempting to reconnect. Supposedly they are currently working on a solution but that is TBD.

    Comment


      #3
      Hello ezrakoper,

      Thank you for your note.

      Development is looking into this and hope to have a resolution for the next release.

      Thank you for your patience.
      Alan P.NinjaTrader Customer Service

      Comment


        #4
        Hi, thanks for your post.

        This is a known issue with Gateway 978. I have a link here for a previous version of gateway where NinjaTrader 8 should re-connect in this version. You may uninstall/reinstall this version if you wish:



        When the issue is resolved it will be in the release notes:


        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hello Chris L.

          I have uninstalled IB latest IB-Gateway and replaced it with yours v973.2. I need to check it resolved the issue.

          Question - In the older version you provided me there is no option to set when the software will restart the connection. Does it mean that it doesn't do the restart? How can i test that this issue is no longer an issue if i cant set when it will do restart (assuming it does restart)?

          Comment


            #6
            Take a look at https://github.com/IbcAlpha/IBC/

            Comment


              #7
              Hello ezrakoper, thanks for your reply.

              The older version doesn't have the auto logoff or auto restart requirement. So your strategy should run without issue. There are separate settings you can use to handle disconnections. Go to Tools>Options>Strategies and look for the Connection lost settings. This is where you can configure how long NinjaTrader will wait to either keep the strategy running or restart the strategy entirely.

              I don't know anything about this GitHub project that cutzpr posted, use at your own risk.

              Please let me know if I can assist any further.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                TWS has always had an auto logout feature. Only recently did IB introduce a feature to auto log you back in after the TWS restart. After 974 I believe. But anything after IB gateway 973 wont work.

                I had to jerry rig my own solution which works well for me.

                Download and install the Gateway 978 link from above and IBC from github. You need to configure the IBC config files to allow it to auto login with your credentials. Follow the Readme.
                After that is working, you need a way to detect if IB or TWS was closed. For that I created a powershell script to check and restart it using the IBC batch files. It also emails me if IB or TWS was offline and if it comes back up.

                Finally I use a task scheduler to run the powershell script every minute. I use Solways Task Scheduler. No frills and works well. Make sure you have it run at startup.


                One thing that is annoying is the PowerShell script window popping up when running. There are several ways to have the window hidden but I opted for turning the ps script to an exe and having the task scheduler run the exe vice the powershell version. Take a look here



                Below is the power shell script that I run. Modify it as you see fit.

                If you would like, you can also create a task scheduler to auto close IB Gateway at a specific time and reopen it.


                Code:
                #$ProcessName=$args[0]
                $ProcessName  = "Trader Workstation"
                $ProcessName1 = "tws"
                $ProcessName2 = "java"
                $Process1_running = $false
                $Process2_running = $false
                $ProcessFile = "C:\IBC\StartGateway.bat"
                Set-PSDebug -Trace 0
                
                function EmailAlert($message)
                {
                    $EmailFrom = "$env:[email protected]"
                    $EmailTo = "[email protected]"
                    $Subject = $message
                    $Body = $message
                    $SMTPServer = "smtp.gmail.com"
                    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
                    $SMTPClient.EnableSsl = $true
                    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("USERNAME", "PASSWORD");
                    $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
                }
                
                if((get-process $ProcessName1 -ErrorAction SilentlyContinue) -ne $Null){$Process1_running = $true}
                if((get-process $ProcessName2 -ErrorAction SilentlyContinue) -ne $Null){$Process2_running = $true}
                
                 echo $ProcessName1" "$Process1_running
                 echo $ProcessName2" "$Process2_running
                
                 if( ($Process1_running ) -or ($Process2_running ) ){echo "$env:COMPUTERNAME - TWS running"}
                 else  
                 {
                    echo "$env:COMPUTERNAME - $ProcessName not running"
                    EmailAlert "$env:COMPUTERNAME - $ProcessName not running"
                
                    Start-Process $ProcessFile
                    Start-Sleep -s 30
                
                    if((get-process $ProcessName1 -ErrorAction SilentlyContinue) -ne $Null){$Process1_running = $true}
                    if((get-process $ProcessName2 -ErrorAction SilentlyContinue) -ne $Null){$Process2_running = $true}
                
                        if(($Process1_running ) -or ($Process2_running ) )
                        {
                         echo $ProcessName " Restarted"
                         EmailAlert "$env:COMPUTERNAME - $ProcessName Started"
                        }
                        else
                        {
                         echo "$env:COMPUTERNAME - $ProcessName Can't be restarted Started"
                         EmailAlert "$env:COMPUTERNAME - $ProcessName Can't be restarted Started"
                        }    
                }
                Last edited by cutzpr; 07-24-2020, 01:56 PM.

                Comment


                  #9
                  Hello cutzpr.

                  What is wrong using IB-Gateway v973.2 as was recommended by NT support?

                  Comment


                    #10
                    Originally posted by ezrakoper View Post
                    Hello cutzpr.

                    What is wrong using IB-Gateway v973.2 as was recommended by NT support?
                    Nothing is wrong. The version NT support gave you is exactly the last version that you need to use. I stated "Download and install the Gateway 978 link from above when I should have said 973 which is what probably caused the confusion.

                    I am just describing a method I use to manage and mitigate TWS or IB Gateway from closing.

                    Comment


                      #11
                      Hello cutzpr.

                      I am just wondering - if IB v973.2 is OK, then why do you need all the overhead of maintaining IBC. If all i am looking for is IB-Gateway that doesn't logout or restart the will the official 973.2 version will do?

                      Comment


                        #12
                        I have real strategies with real money. I take precautions. IB Gateway 973-2 is the last version currently that works that allows Ninja trader to recognize a disconnection and reconnect (as of today).

                        Comment


                          #13
                          I trade also with real strategies with real money. It happened last week that Ninja lost track of STOP and PT for the second order set in a strategy. I suspect this could be related to the IB-GW 973.2h

                          I am still investigating the root cause. Be cautious to use.

                          Comment


                            #14
                            Cutzpr/timko.

                            1. I don't understand the logic behind IB making hard life for algo traders. It looks as if they are pushing us out of IB broker. If anyone has any insights I will love to her.

                            2. I am new to algo trading. I have open an account at IB and placed there lots of money for several moths already however I am actually working only on the paper trade account since I am working on writing code in NT8 and integrating it also with Sharkindicators Bloodhound. So to have all work automatically 24/5.

                            If IB is making hard time why don't you switch to another broker (same to myself if I will give up with IB)?

                            Comment


                              #15
                              ezrakoper rather, I would say, IB does understand how crap the java language is and they do want to guarantee certain degree of software stability to professional traders who generally don't have the sense to take care of software defects, say, memory leaks...

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              167 responses
                              2,260 views
                              0 likes
                              Last Post jeronymite  
                              Started by warreng86, 11-10-2020, 02:04 PM
                              7 responses
                              1,361 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by Perr0Grande, Today, 08:16 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post Perr0Grande  
                              Started by elderan, Today, 08:03 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post elderan
                              by elderan
                               
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post algospoke  
                              Working...
                              X