|
4 registered members (TipmyPip, Angerbeer, qin, 1 invisible),
9,869
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#489020
12/17/25 15:18
12/17/25 15:18
|
Joined: Jan 2021
Posts: 7 Austin, TX, USA
Jack_Zodiac
Newbie
|
Newbie
Joined: Jan 2021
Posts: 7
Austin, TX, USA
|
Hi, is this still the state of things? I am wondering about trying to programmatically issue the re-connect commands to Zorro.
I'm using TWS, and it accepts connection fine after its daily re-start -- but Zorro has to be given 'stop', 'don't close trades', 'do stop trading', and then 'trade' button clicks, load prices, run through the lookback, and then everything works.
|
|
|
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#489059
12/31/25 21:11
12/31/25 21:11
|
Joined: Jan 2021
Posts: 7 Austin, TX, USA
Jack_Zodiac
Newbie
|
Newbie
Joined: Jan 2021
Posts: 7
Austin, TX, USA
|
I made a work-around for this that seems to be working reliably enough for me. (I consider it a convenience rather than mission-critical.)
It involves using the system() command to kick off another Zorro instance shortly after the TWS restart, and quit() to kill the original one.
My implementation is likely sub-optimal, so comments welcomed. (But, no need to lecture me about global variables.)
I am running 64-bit Zorro C++ scripts on a Windows 11 machine, with an S-level license.
The following code is pieced together from the various functions where it actually resides and hasn't been tested in this exact form, so consider it just a sketch of concept. The core commands are in the last few lines, the rest is infrastructure.
(Edit: oops, I left out showing where Last_Started_Day is written to the state file. In practice I update the state file every 15th minute based on a tod(0) check.)
-----------------------
// Globals int Last_Started_Day, UTC_offset; bool SOD_Business, SOD_Business Done, EOD_Business, EOD_Business_Done; // SOD = start of day, EOD = end of day string State_File;
DLLFUNC void main() { // Delay to ensure previous Zorro instance has ended if (is(TRADEMODE) && is(COMMAND)) { printf("10 second delay for Zorro instance handoff..."); wait(10000); }
State_File = "Data\\My_State_File.csv"; // other main() stuff....
}
DLLFUNC void run() { if (Bar == StartBar) { printf("\n"); printf("\nLoading State File..."); // Script-wide variables Last_Started_Day = (int)(getvar(State_File, "Last_Started_Day")); EOD_Business_Done = (bool)(getvar(State_File, "EOD_Business_Done"));
// other state stuff.... } // TIME ZONE OFFSET if (dst(EST,0)==1) { UTC_offset = -4; } else { UTC_offset = -5; }
start_time = 0400 - UTC_offset*100; // Daily business SOD_Business_Done = day(0) == Last_Started_Day; SOD_Business = tod(0) >= start_time && tod(0) < 2300 && !SOD_Business_Done;
if (SOD_Business) { Last_Started_Day = day(0); SOD_Business_Done = true; EOD_Business_Done = false;
// other start of day stuff ... }
int EOD_time; bool EOD_Window; if (dst(EST,0)==1) { EOD_time = 2350; EOD_Window = tod(0) >= EOD_time; } else { EOD_time = 50; EOD_Window = tod(0) >= EOD_time && tod(0) < 200; }
// TWS daily restart should be set for slightly before the EOD_time. E.g. currently I use 00:30 GMT
EOD_Business = EOD_Window && !EOD_Business_Done;
if (EOD_Business) { if (is(TRADEMODE) && Bar > StartBar && !EOD_Business_Done) { login(4); EOD_Business_Done = true; putvar(State_File, "EOD_Business_Done", (var)(EOD_Business_Done)); wait(10000); system("Zorro64.exe -trade My_Script.cpp"); quit("!Restarting Zorro session to cope with IBKR lockout."); } }
}
Last edited by Jack_Zodiac; 01/01/26 05:07.
|
|
|
|