TWS自动重启AutoHotKey脚本

用法:将以下脚本复制到文本编辑器,修改tws目录、路径、帐号、密码,然后保存为ahk格式的文件(例如twsAutostarter.ahk),用autohotkey运行即可。也可将该文件用autohotkey编译成exe文件运行,这样就看不到帐号和密码,更具安全性。

; Compile to EXE with encryption to save password
; Utility code that restarts TWS after it gets killed during daily logout 

;tws的目录
TWS_DIR := “C:\Jts”

;帐号密码
USER := “edemo”
PASS := “demouser”

;tws的路径配置
Javaw := “C:\Jts\tws.exe”

Loop
{
SetTitleMatchMode RegEx
If (!WinExist(“IB Trader Workstation”)) and (!WinExist(“Interactive Brokers”))
{
SetTitleMatchMode 3
IfWinNotExist, Login
{
Run, %Javaw% %Args% username=%USER% password=%PASS%, %TWS_DIR%
}
else
{
SetTitleMatchMode RegEx
WinClose, Login
Run, %Javaw% %Args% username=%USER% password=%PASS%, %TWS_DIR%
}
}
; 每2分钟检查一次
Sleep 120000
}