Skip to content

fix(live): skip market-triggered ticks while the market is closed - #1253

Open
he-yufeng wants to merge 1 commit into
HKUDS:mainfrom
he-yufeng:fix/market-trigger-hours-gate
Open

fix(live): skip market-triggered ticks while the market is closed#1253
he-yufeng wants to merge 1 commit into
HKUDS:mainfrom
he-yufeng:fix/market-trigger-hours-gate

Conversation

@he-yufeng

Copy link
Copy Markdown
Collaborator

Summary

  • _jobs_from_triggers downgraded a MARKET trigger to a plain 60s interval job and the tick never re-checked the session: due_now sat imported in runtime/runner.py with zero call sites. Weekend ticks ran the full pipeline and submitted orders that queue into the Monday open.
  • The runner now gates the tick on the trigger layer the jobs came from: with MARKET triggers attached, a tick proceeds only when at least one of their markets is open at the tick instant.

Why

Refs #1207 (Phase 0, item 5). The design always intended this: _jobs_from_triggers' docstring says the tick itself re-checks market state, but nothing ever called it.

Changes

  • runner._any_market_open: union over attached MARKET triggers via the trigger layer's due_now. Runners without MARKET triggers never gate; 24/7 markets (crypto) report open at every instant.
  • run_once returns a new market_closed outcome before reconcile when every attached market is closed, so a closed session costs no broker calls and writes no audit records (a 60s watch cadence all weekend would otherwise flood the ledger).

Test Plan

  • New tests in test_runtime_runner.py: pre-open skip stops after the mandate check with no reconcile/invoke/audit, mid-session ticks proceed, a closed us_equity plus 24/7 crypto union stays open, interval-only runners ignore the gate.
  • pytest agent/tests/test_runtime_runner.py -q: 29 passed. Live safety set (flatten, sweep latch, api runtime, order gate, mandate enforcement, killswitch, readonly): 150 passed.
  • Full suite and e2e not run; change is confined to the tick gate. ruff check clean on the touched files (two pre-existing F401s in runner.py left alone).

Risk: fail-closed in the trading direction only. Ticks outside market hours become no-ops; nothing about open-session behavior changes. Rollback is a plain revert.

Prepared with AI assistance (Kimi K3); all verification above was run locally.

_jobs_from_triggers downgraded a MARKET trigger to a plain 60s interval
job, and the tick never re-checked the session: due_now sat imported
with zero call sites, so weekend ticks ran the full pipeline and
submitted orders that queue into the Monday open. The runner now gates
on the trigger layer the jobs were synthesized from: with MARKET
triggers attached, a tick proceeds only when at least one of their
markets is open at the tick instant. Interval-only and 24/7 (crypto)
channels never block, and the skip stops before reconcile, so a closed
session costs no broker calls and writes no audit records.

Refs HKUDS#1207 (Phase 0, item 5).

Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant