TWS auto logouts everyday. How to let it auto restart?
As everyone knows, IB TWS need to be restart everyday. This is bothered for traders who is doing auto-trading.
We can use a script to mornitor TWS realtime. If it was closed, the script will restart it immediately.
We suggest AutoHotkey to do the job. You can download this tool at the official site http://www.autohotkey.com, or at the download page.
After AutoHotkey installed, you can take the below script as reference to make your script.
AutoRestarTWS.ahk
; Utility code that restarts TWS after it gets killed during daily logout
USER := “edemo”
PASS := “demouser”
TWS_DIR := “C:\Jts\952″
TWSPath := “C:\Jts\952\tws.exe”
Loop
{
SetTitleMatchMode RegEx
If (!WinExist(“IB Trader Workstation”)) and (!WinExist(“Interactive Brokers”))
{
SetTitleMatchMode 3
IfWinNotExist, Login
{
Run, %TWSPath% %Args% username=%USER% password=%PASS%, %TWS_DIR%
}
else
{
SetTitleMatchMode RegEx
WinClose, Login
Run, %TWSPath% %Args% username=%USER% password=%PASS%, %TWS_DIR%
}
}
; check every 2 minutes
Sleep 120000
}
Script also can be download here. AutoRestartTWS.ahk