From 346c3562223a2904ea0e55d3e5bdccd85774b355 Mon Sep 17 00:00:00 2001 From: Brandon Li Date: Sun, 6 Sep 2026 15:35:03 -0500 Subject: [PATCH] Report daily session-open delay to the master dashboard Co-Authored-By: Claude Fable 5 --- lib/auto-trade.ts | 14 ++++++++++---- lib/master-protocol.ts | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/auto-trade.ts b/lib/auto-trade.ts index 57713df..2d98881 100644 --- a/lib/auto-trade.ts +++ b/lib/auto-trade.ts @@ -138,6 +138,14 @@ function openJitterMinutes(centralDay: string): number { return jitter; } +/** Today's session-open delay in minutes, for reporting to the master. */ +export function todaysSessionOpenDelay(): number { + const centralDay = new Intl.DateTimeFormat('en-CA', { + timeZone: 'America/Chicago', + }).format(new Date()); + return openJitterMinutes(centralDay); +} + /** * Returns true when trading is not allowed based on the trading_hours setting. * @@ -162,10 +170,7 @@ function isInNoTradeWindow(): boolean { timeZone: 'America/Chicago', }).format(now); // "Sun", "Mon", ... "Sat" const timeMinutes = hour * 60 + minute; // minutes since midnight - const centralDay = new Intl.DateTimeFormat('en-CA', { - timeZone: 'America/Chicago', - }).format(now); // "2026-09-06" - const jitter = openJitterMinutes(centralDay); + const jitter = todaysSessionOpenDelay(); const mode = getSetting('trading_hours') ?? 'full_cme'; @@ -727,5 +732,6 @@ export function getSchedulerStatus() { lastRun: state.lastRun, intervalSeconds: parseInt(getSetting('tick_interval_seconds') ?? '60', 10), stopAfterAll: state.stopAfterAll, + sessionOpenDelayMin: todaysSessionOpenDelay(), }; } diff --git a/lib/master-protocol.ts b/lib/master-protocol.ts index 958383f..212e922 100644 --- a/lib/master-protocol.ts +++ b/lib/master-protocol.ts @@ -33,6 +33,9 @@ export interface SchedulerState { lastRun: string | null; intervalSeconds: number; stopAfterAll?: boolean; + /** Today's random session-open delay in minutes (1–20), drawn once per + * Central-time day. Optional so an older master simply ignores it. */ + sessionOpenDelayMin?: number; } export interface AutomationSummary {