feat(run,config): operating hours window + timezone-aware lifecycle state
Add OperatingHoursCfg (enabled/timezone/weekdays/start_hhmm/stop_hhmm) so
the run loop can align with NYSE session hours instead of the user's
local wall clock (fixes DST drift between NY and Europe/Bucharest).
- Config parses [options.operating_hours] and resolves ZoneInfo at load,
fail-fast on invalid tz or weekday names. The tz is cached on
_tz_cache so the detection loop pays zero per-tick cost.
- LifecycleState tracks user_paused + last_window_state across ticks.
- Module-scope _should_skip(now, state, cfg, canary) returns skip reason
or None. Weekday check uses datetime.weekday() + a fixed MON..SUN list
(locale-free; strftime('%a') is localized).
- _maybe_log_transition emits market_open / market_closed once per edge.
R2: when last_window_state is None (startup), just seed — do not send
a spurious market_open alert when run_live_async launches in-window.
- _run_tick consults the lifecycle guard before scheduling the heavy
detection thread, so drain + transition logging still happen when the
tick is skipped.
- CLI flags --tz / --weekdays / --oh-start / --oh-stop override TOML.
(Kept distinct from the existing --start-at/--stop-at sleep-until-time
semantics to avoid breaking current deployments — deviation noted.)
- configs/example.toml documents the new [options.operating_hours] table.
Tests: parametrized window matrix (tests #8), transition logging (#9),
notification side-effect (#10), R2 #20 startup suppression, R2 #22
locale-independent weekday, plus guards for user_paused / canary
precedence and config-parse error paths.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -88,6 +88,17 @@ dead_letter_path = "logs/dead_letter.jsonl"
|
||||
[options.alerts]
|
||||
fire_on_phase_skip = true
|
||||
|
||||
# Operating hours — detection only runs on allowed weekdays + HH:MM window.
|
||||
# Timezone is the source of truth (NYSE local); the runtime converts tick
|
||||
# timestamps to this zone so DST rollovers stay aligned with the exchange.
|
||||
# Override from CLI with --tz / --weekdays / --oh-start / --oh-stop.
|
||||
[options.operating_hours]
|
||||
enabled = false
|
||||
timezone = "America/New_York"
|
||||
weekdays = ["MON", "TUE", "WED", "THU", "FRI"]
|
||||
start_hhmm = "09:30"
|
||||
stop_hhmm = "16:00"
|
||||
|
||||
# Per-kind screenshot-attach toggles. All default to true on upgrade.
|
||||
# Accepts either a bare bool (legacy: attach_screenshots = true) or this table.
|
||||
[options.attach_screenshots]
|
||||
|
||||
Reference in New Issue
Block a user