Restart the Gateway when its historical data farm stops serving

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>
This commit is contained in:
2026-10-12 23:27:16 -07:00
parent 8238651af6
commit e55c4ffbdb
5 changed files with 53 additions and 13 deletions

View File

@@ -62,3 +62,24 @@ def test_check_explains_snapshot_result(monkeypatch, capsys, mode, error, price,
assert absent not in output
if error:
assert f"IBKR {error[0]}: {error[1]}" in output
@pytest.mark.parametrize("bars, ok", [(0, False), (5, True)])
def test_gateway_probe_requires_historical_bars(monkeypatch, capsys, bars, ok):
import pandas as pd
cfg = load_config(Path(__file__).resolve().parents[1] / "config.toml")
broker = Broker(cfg.ib)
broker.account = "DU123"
frame = pd.DataFrame({"date": pd.date_range("2026-10-06", periods=bars), "symbol": "SPY", "close": 1.0})
monkeypatch.setattr(Broker, "__aenter__", AsyncMock(return_value=broker))
monkeypatch.setattr(Broker, "__aexit__", AsyncMock(return_value=None))
monkeypatch.setattr(cli, "Broker", lambda _: broker)
monkeypatch.setattr(broker.ib.client, "serverVersion", Mock(return_value=178))
monkeypatch.setattr(broker, "qualify_stocks", AsyncMock(return_value=({"SPY": Stock("SPY", "SMART", "USD")}, [])))
monkeypatch.setattr(broker, "daily_bars", AsyncMock(return_value=(frame, [] if bars else ["SPY"])))
if ok:
asyncio.run(cli.probe_gateway(cfg, history=True))
assert "historical data OK" in capsys.readouterr().out
else:
with pytest.raises(SystemExit, match="historical data farm"):
asyncio.run(cli.probe_gateway(cfg, history=True))