From 11144612c77a12fac6be1ed41796fec42d034808 Mon Sep 17 00:00:00 2001 From: Senofy <63175905+Senofy@users.noreply.github.com> Date: Sun, 15 Mar 2026 14:49:49 -0500 Subject: [PATCH] Block trading after 3 PM Central instead of 4 PM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gives a full hour buffer before the CME daily halt at 4 PM. No-trade window is now 3:00 PM – 5:00 PM Central (Mon–Thu), and after 3:00 PM on Fridays. Co-Authored-By: Claude Opus 4.6 --- lib/auto-trade.ts | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/lib/auto-trade.ts b/lib/auto-trade.ts index 8a31288..afe8f8d 100644 --- a/lib/auto-trade.ts +++ b/lib/auto-trade.ts @@ -50,24 +50,49 @@ function mapFirmConfig(firm: FirmWithAccounts): FirmConfig { // ── helpers ─────────────────────────────────────────────────────────────────── -/** Returns true during the 3:00 PM – 4:59 PM Central no-trade window. */ +/** + * Returns true when CME futures markets are closed. + * CME hours: Sunday 5:00 PM – Friday 4:00 PM Central, with a daily halt 4:00–5:00 PM. + * So we block trading when: + * - It's 3:00 PM – 4:59 PM Central (stop early + daily halt) + * - It's Saturday (all day) + * - It's Sunday before 5:00 PM Central + * - It's Friday after 3:00 PM Central + */ function isInNoTradeWindow(): boolean { - const hour = parseInt( - new Intl.DateTimeFormat('en-US', { - hour: 'numeric', - hour12: false, - timeZone: 'America/Chicago', - }).format(new Date()), - 10 - ); - return hour >= 15 && hour < 17; + const now = new Date(); + const centralTime = new Intl.DateTimeFormat('en-US', { + hour: 'numeric', + hour12: false, + timeZone: 'America/Chicago', + }); + const centralDay = new Intl.DateTimeFormat('en-US', { + weekday: 'short', + timeZone: 'America/Chicago', + }); + const hour = parseInt(centralTime.format(now), 10); + const day = centralDay.format(now); // "Sun", "Mon", ... "Sat" + + // Saturday — market closed all day + if (day === 'Sat') return true; + + // Sunday — market opens at 5 PM Central + if (day === 'Sun' && hour < 17) return true; + + // Friday — stop trading after 3 PM Central + if (day === 'Fri' && hour >= 15) return true; + + // Mon–Thu: stop trading after 3 PM Central (market halts at 4 PM, reopens 5 PM) + if (hour >= 15 && hour < 17) return true; + + return false; } // ── core trade logic ────────────────────────────────────────────────────────── export async function runTrade(action: 'Buy' | 'Sell' | 'Random', symbol: string) { if (isInNoTradeWindow()) { - console.log('[auto-trade] no-trade window active (3–5 PM Central) — skipping'); + console.log('[auto-trade] CME market closed — skipping'); return []; } // Resolve 'Random' symbol once per batch so all accounts trade the same symbol