On 2026-10-12 the Gateway answered account requests but every bar request timed out from 09:50 to 10:24 ET: make gateway reported OK, so the Gateway was never restarted, and six retries 5 minutes apart gave up after 35 minutes. The data came back only with the Gateway's daily restart. ibkr-quant gateway --history also requires SPY daily bars within 30 s; the trade job's ExecStartPre passes it, so ensure-gateway.sh restarts a Gateway whose data farm is down. The trade job now retries every 10 minutes until about 15:30 ET (34 starts in 6 h) instead of giving up after 35 minutes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
1.1 KiB
Bash
Executable File
29 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# Probe IB Gateway and restart it when it stays unable to serve account requests.
|
|
# Gateway can lose IBKR's servers, fail the reconnect and sit on an error dialog
|
|
# with its API port still open (2026-09-29, for 9 hours): every request times
|
|
# out, yet java keeps running, so systemd's Restart= never fires.
|
|
# Runs before each job (ExecStartPre=make gateway) and by hand as `make gateway`.
|
|
# Arguments go to the probe: `--history` also requires daily bars, because the
|
|
# historical data farm can fail while account requests work (2026-10-12).
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
|
|
PROBE_ARGS="$*"
|
|
probe() { uv run ibkr-quant gateway $PROBE_ARGS; }
|
|
|
|
probe && exit 0
|
|
# Gateway rides out short outages by reconnecting on its own; give it a minute.
|
|
sleep 60
|
|
probe && exit 0
|
|
|
|
echo "restarting ibgateway.service" >&2
|
|
systemctl --user restart ibgateway.service || exit 1
|
|
# IBC logged in 28 s after a restart on 2026-09-29; leave room for a slow proxy.
|
|
deadline=$(($(date +%s) + 300))
|
|
while [ "$(date +%s)" -lt "$deadline" ]; do
|
|
sleep 20
|
|
probe && exit 0
|
|
done
|
|
echo "IB Gateway still not serving requests 5 min after the restart" >&2
|
|
exit 1
|