I'm having an issue where Zorro doesn't reconnect to the IBKR gateway after the daily restart. As you can see status is green, but no port is open or data sent/recieved. I've tested restart during market hours and outside.
Any help or advice would be much appreciated.
Thanks, Adam
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#488688 04/01/2511:2604/01/2511:26
I don't know a problem with a daily restart, but there is one with the automated weekly gateway shutdown. You must manually close and restart the gateway on any weekend. Zorro needs not be restarted, but the current gateway version won't recover properly from its automated shutdown.
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#488689 04/01/2512:3804/01/2512:38
thanks for your response. I'm finding that zorro doesn't reconnect to the gateway after the daily restart, weekly or manual restart. I have to manually stop/start zorro trading after every auto gateway restart.
I've tried multiple strategies and they are all the same. None of them reopen a port in the gateway.
Adam
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#488690 04/01/2516:0904/01/2516:09
I was referring to the weekly shutdown, but if you have set it up for daily shutdown, it's the same. Shutdown requires manually closing and opening the gateway. Zorro can reconnect automatically, you can even set BarMode to let it explicitly disconnect and re-connect, but it won't help. After a shutdown, the gateway is in a state that it does not accept API connections. Only closing it solves that.
I hope that this behavior changes with a new gateway version, but so far, all versions behave this way.
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#488696 04/09/2511:0204/09/2511:02
the gateway restarts every day by default. All I can do is change the time. This is what I'm referring to. I know the weekly restart/shutdown is different.
Any thoughts on why it won't reconnect? I can add a video if that helps. The zorro log just shows it isn't restablishing a connection. ¯\_(?)_/¯
I'll try BarMode to force reconnection and set StartDate to NOW, so I don't keep missing trades.
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#488807 06/30/2511:5406/30/2511:54
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]
#489021 12/18/2508:4312/18/2508:43
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...");
Hi, are there any furthe news on this, or suggested workarounds? I am facing the same issue with the IB Gateway and Zorro. I am using IBC to keep the Gateway logged in after the daily restart, but once the Gateway has been restarted once, Zorro seems to lose the connectivity to it, even if the Gateway is back on line.
Thanks
Re: Zorro not reconnecting to IB gateway after restart
[Re: clint000]
#489200 02/20/2618:5502/20/2618:55
Hi, I am sorry to say that the IB connection is still not working reliably with the IB Gateway after the upgrade to Zorro v3.01. There are 2 systematic issues as far as I can gather:
- The first time I press on trade (demo), it connects to the Gateway but does nothing. Then I click on Stop, then on Trade again and it connects to the Gateway and this second time it starts downloading data, etc as normal. This behaviour did not happen with the previous versions of Zorro.
- Every time the Gateway restarts (every day), even if it re-opens and re-logins automatically, Zorro loses the connection to it permanently (red square in the connection status).
Any clue on how to resolve the above?
Thanks
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#489260 02/26/2615:1702/26/2615:17
We can confirm the Gateway issue. The automated Gateway restart leaves it in an unstable state. It does not accept an API connection in that state. But if you close and restart the Gateway manually, Zorro can connect.
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#489307 03/10/2621:3003/10/2621:30
Ok, thanks for the confirmation. In order for Zorro S 3.01 to re-connect to the Gateway, does it need any user intervention?
At the moment, when the connection status shows red and I restart the gateway manually, the Zorro connection keeps on being red. It is only when I stop and restart trading in Zorro (Stop --> Trade) that it reconnects and shows as green. I can manage to restart the Gateway automatically every day with IBC and a scheduled task, but it would be great if there was a way for Zorro to re-connect automatically?
Thanks!
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#489309 03/11/2613:3003/11/2613:30
However when the connection is red, the first time I click on Trade it connects to the API but it doesn't receive any data (times out and Zorro shows errors 011, 046 and 047 as it doesn't receive any data from the API). Then I need to click Stop and Trade again and the second time it does connect to the API and is able to retrieve data normally.
DId you also experience this issue?
Thanks
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#489313 03/13/2600:0903/13/2600:09
In case it helps, this is the Log from the Gateway the first time Zorro connects to it after a restart.
2026-03-12 22:43:01.971 [TC] INFO [JTS-SocketListener-55] - State: HEADER, IsAPI: UNKNOWN 2026-03-12 22:43:02.007 [TC] INFO [JTS-SocketListener-55] - State: STOP, IsAPI: YES 2026-03-12 22:43:02.522 [TC] INFO [JTS-SocketListener-55] - ArEServer: Adding 105670462 with id - 2026-03-12 22:43:02.599 [TC] INFO [JTS-SocketListener-55] - eServersChanged: 1 2026-03-12 22:43:02.828 [TC] INFO [JTS-EServerSocketNotifier-101] - Starting async queue thread 2026-03-12 22:43:02.864 [TC] INFO [JTS-EServerSocket-100] - [-:180:180:1:0:0:0:SYS] Starting new conversation with client on 127.0.0.1 2026-03-12 22:43:02.903 [TC] INFO [JTS-EServerSocket-100] - [-:180:180:1:0:0:0:SYS] Server version is 180 2026-03-12 22:43:02.903 [TC] INFO [JTS-EServerSocket-100] - [-:180:180:1:0:0:0:SYS] Client version is 180 2026-03-12 22:43:02.906 [TC] INFO [JTS-EServerSocket-100] - [-:180:180:1:0:0:0:SYS] is 3rdParty true 2026-03-12 22:43:06.839 [TC] INFO [JTS-EServerSocket-100] - Ignoring API request 'jextend.bk' since API is not accepted. 2026-03-12 22:43:06.846 [TC] INFO [JTS-EServerSocket-100] - ArEServer: Removing 105670462 with id - 2026-03-12 22:43:06.848 [TC] INFO [JTS-EServerSocket-100] - eServersChanged: 0 2026-03-12 22:43:06.897 [TC] INFO [JTS-EServerSocketNotifier-101] - Terminating async queue thread 2026-03-12 22:43:06.976 [TC] INFO [JTS-EServerSocket-100] - Cleaning up [serverId: -]... 2026-03-12 22:43:07.063 [TC] INFO [JTS-EServerSocket-100] - Cleaning up [serverId: -]... 2026-03-12 22:43:07.135 [TC] INFO [JTS-EServerSocket-100] - Cleaning up [serverId: -]... 2026-03-12 22:43:07.172 [TC] INFO [JTS-EServerSocket-100] - [ApiAccountAdditionMgr] Cleaning up [serverId=-]... 2026-03-12 22:43:07.226 [TC] INFO [JTS-EServerSocket-100] - ============ EServerSocket messages stats ============ 2026-03-12 22:43:07.228 [TC] INFO [JTS-EServerSocket-100] - Number of socket messages pushed to updates queue: 0 2026-03-12 22:43:07.228 [TC] INFO [JTS-EServerSocket-100] - Number of socket messages sent directly: 0 2026-03-12 22:43:07.229 [TC] INFO [JTS-EServerSocket-100] - ======================================================= 2026-03-12 22:43:07.235 [TC] INFO [JTS-EWriter1-102] - [-:180:180:1:0:0:0:SYS] Writer thread terminated for socket client{-}. 2026-03-12 22:43:07.269 [TC] INFO [JTS-EServerSocket-100] - There are no API orders being processed. 2026-03-12 22:43:07.269 [TC] INFO [JTS-EServerSocket-100] - SecDefRequestTimeOut: There are no timed out SecDef requests. 2026-03-12 22:43:07.278 [TC] INFO [JTS-EServerSocket-100] - UnhandledOrderPresetRequest: There are no unprocessed order preset requests. 2026-03-12 22:43:07.279 [TC] INFO [JTS-EServerSocket-100] - [-:180:180:1:0:0:0:SYS] Ending conversation with client{-} at 127.0.0.1
After I click on Stop and then Trade again, it works. This is the log:
2026-03-12 22:45:44.196 [TC] INFO [JTS-SocketListener-55] - State: HEADER, IsAPI: UNKNOWN 2026-03-12 22:45:44.197 [TC] INFO [JTS-SocketListener-55] - State: STOP, IsAPI: YES 2026-03-12 22:45:44.205 [TC] INFO [JTS-SocketListener-55] - ArEServer: Adding 1513967017 with id - 2026-03-12 22:45:44.205 [TC] INFO [JTS-SocketListener-55] - eServersChanged: 1 2026-03-12 22:45:44.210 [TC] INFO [JTS-EServerSocket-105] - [-:180:180:1:0:0:0:SYS] Starting new conversation with client on 127.0.0.1 2026-03-12 22:45:44.210 [TC] INFO [JTS-EServerSocketNotifier-106] - Starting async queue thread 2026-03-12 22:45:44.210 [TC] INFO [JTS-EServerSocket-105] - [-:180:180:1:0:0:0:SYS] Server version is 180 2026-03-12 22:45:44.210 [TC] INFO [JTS-EServerSocket-105] - [-:180:180:1:0:0:0:SYS] Client version is 180 2026-03-12 22:45:44.211 [TC] INFO [JTS-EServerSocket-105] - [-:180:180:1:0:0:0:SYS] is 3rdParty true 2026-03-12 22:45:44.531 [TC] INFO [JTS-EServerSocket-105] - Start API message, ClientID=1 2026-03-12 22:45:48.732 [TC] INFO [JTS-EServerSocket-105] - FAController: set useBackEndAliases to false 2026-03-12 22:45:48.760 [TC] INFO [JTS-EMsgPacer-109] - Starting compressor 2026-03-12 22:45:48.767 [TC] INFO [JTS-EMsgPacer-109] - Shutting down compressor. FlatLen:0 2026-03-12 22:45:48.768 [TC] INFO [JTS-EMsgPacer-109] - CM setting requested API account spec to DUO493542.(API) 2026-03-12 22:45:48.783 [TC] INFO [JTS-EMsgPacer-109] - CM Sending current account image DUO493542 to API 2026-03-12 22:45:49.304 [TC] INFO [JTS-QuickMktDataWrapper-112] - Farm cashfarm/UNCONNECTED: Creating ServiceConnection for:cashfarm 2026-03-12 22:45:49.305 [TC] INFO [JTS-QuickMktDataWrapper-112] - Farm cashfarm/UNCONNECTED: Starting connection thread 2026-03-12 22:45:49.305 [TC] INFO [JTS-QuickMktDataWrapper-112] - Added message to queue [serviceName=cashfarm,state=STARTING,size=1]... 2026-03-12 22:45:49.374 [TC] INFO [JTS-cashfarmServiceConnector-114] - Farm cashfarm/STARTING: Connecting natively (cashfarm)... 2026-03-12 22:45:49.375 [TC] INFO [JTS-cashfarmServiceConnector-114] - InnerConnection.connectOrTransfer()[endPoint=ndc1.ibllc.com:4000,serviceType=MARKET_DATA,farmName=cashfarm,usesCcpConman=false]... 2026-03-12 22:45:49.386 [TC] INFO [JTS-cashfarmServiceConnector-114] - InnerConnection.updateEndPointIfNeeded()[endPoint=ndc1.ibllc.com:4000,serviceType=MARKET_DATA,farmName=cashfarm,mainConnUseSsl=true,useSslFarmList=]. 2026-03-12 22:45:49.388 [TC] INFO [JTS-cashfarmServiceConnector-114] - Connecting ndc1.ibllc.com:4000 timeout=0... 2026-03-12 22:45:49.388 [TC] INFO [JTS-cashfarmServiceConnector-114] - CONN CALC: Last connection set as now:22:45:49:388 2026-03-12 22:45:49.489 [TC] INFO [JTS-cashfarmServiceConnector-114] - Connected to ndc1.ibllc.com:4000/64.190.197.40 remote-ip on local port 0 socket local addrs:port /38.141.14.52:60428 2026-03-12 22:45:49.490 [TC] INFO [JTS-cashfarmServiceConnector-114] - Updating machine info [connectionAddress=/38.141.14.52]... 2026-03-12 22:45:49.492 [TC] INFO [JTS-cashfarmServiceConnector-114] - Farm cashfarm/PRE_NATIVE: Connected, sending secure connect and/or auth 2026-03-12 22:45:49.492 [TC] INFO [JTS-cashfarmServiceConnector-114] - Added to valid hosts list: ndc1.ibllc.com 2026-03-12 22:45:49.495 [TC] INFO [JTS-cashfarmListenerS10-116] - Starting listener thread [sessionID=10]... 2026-03-12 22:45:49.511 [TC] INFO [JTS-cashfarmServiceConnector-114] - InnerConnection.onConnected() [sessionID=10,secureConnectEnabled=true,logonReplySigned=false]. 2026-03-12 22:45:49.520 [TC] INFO [JTS-cashfarmListenerS10-116] - Initial listener buffer size is 131072. 2026-03-12 22:45:49.520 [TC] INFO [JTS-cashfarmListenerS10-116] - Capping listener buffer size at 65536. 2026-03-12 22:45:49.531 [TC] INFO [JTS-cashfarmListenerS10-116] - Listener thread [sessionID=10] is ready to process messages. 2026-03-12 22:45:49.532 [TC] INFO [JTS-cashfarmDispatcherS10-117S10-118] - Starting dispatcher thread [sessionID=10]...
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#489317 03/15/2607:4803/15/2607:48
Ok, thanks. However I find the TWS shows a similar behaviour. I have tried it over the last couple of days and when the TWS restarts, Zorro loses the connection and will not reconnect despite using the broker command SET_RESTART at a specified time (I assume the broker command is to be placed inside the run() function, correct?).
I am really at a loss here, ran out of ideas to try out. Is there really a solution that works reliably for Interactive Brokers?
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#489325 03/19/2607:4203/19/2607:42
I also found that sometimes Zorro after pressing "Trade" it connects to the API but will not receive price data, therefore it stops the strategy (error 047). Then without doing anything to the TWS, if I close Zorro and re-open it again, when I click on "Trade" it will connect to the API and retrieve the price data OK. Based on the above, I believe that there could be some issues on Zorro side.
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#489326 03/19/2609:1803/19/2609:18
Pressing Stop is equivalent to closing and restarting Zorro, but not equivalent to SET_RESTART. SET_RESTART releases the TWS API, while Stop only resets the connection on the Zorro side. Both does not 100% guarantee to reconnect, since the TWS or Gateway can stay blocked despite their API reset. For reconnecting with 100% certainty they must be externally closed and restarted. From our experience, external restart is necessary with the Gateway, but not with the TWS. However this can of course change with any new version.
Re: Zorro not reconnecting to IB gateway after restart
[Re: jcl]
#489359 04/08/2621:5604/08/2621:56
ok thanks. Is there a way to tell Zorro to Stop and then Trade at a particular time, by script? I have managed to keep the Gateway stable by logging out every day and restarting it through IBC, however when Zorro is connected to the gateway and this logout+new start process happens on the gateway, it will not reconnect again unless I press Stop and Trade. Tried the SET_RESTART but it will not reconnect to the gateway after a restart...
Thanks
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#489361 04/13/2609:3404/13/2609:34
You can stop trading at a particular time, but not restart it since when Zorro is stopped, no script is running. But you can stop and start a trading Zorro process at a particular time. The procedure is described under https://zorro-project.com/manual/en/engine.htm.
Re: Zorro not reconnecting to IB gateway after restart
[Re: opm]
#489368 04/25/2614:0604/25/2614:06
For info in case it helps, I have finally been able to get around the IB gateway daily restart issues by using IBC to manage the gateway restart business, and within Zorro use the tock() function right after the gateway restarts in order to do an API reset and log back in. Seems to be working okay as a workaround...