Add configurable trading hours setting
Dropdown on settings page with two options: - Full CME (5:00 PM – 3:00 PM CT) with 5 min buffer - Equity Hours (8:30 AM – 3:00 PM CT) with 5 min buffer Setting is read live each tick, no restart needed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
11144612c7
commit
f498594b16
+34
-19
@@ -51,39 +51,54 @@ function mapFirmConfig(firm: FirmWithAccounts): FirmConfig {
|
||||
// ── helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Returns true when trading is not allowed based on the trading_hours setting.
|
||||
*
|
||||
* "full_cme" — Sun 5:05 PM – Fri 2:55 PM Central (5 min buffer on each side)
|
||||
* "equity_hours" — 8:35 AM – 2:55 PM Central, Mon–Fri (5 min buffer on each side)
|
||||
*/
|
||||
function isInNoTradeWindow(): boolean {
|
||||
const now = new Date();
|
||||
const centralTime = new Intl.DateTimeFormat('en-US', {
|
||||
const centralParts = new Intl.DateTimeFormat('en-US', {
|
||||
hour: 'numeric',
|
||||
minute: 'numeric',
|
||||
hour12: false,
|
||||
timeZone: 'America/Chicago',
|
||||
});
|
||||
const centralDay = new Intl.DateTimeFormat('en-US', {
|
||||
}).formatToParts(now);
|
||||
const hour = parseInt(centralParts.find((p) => p.type === 'hour')!.value, 10);
|
||||
const minute = parseInt(centralParts.find((p) => p.type === 'minute')!.value, 10);
|
||||
const day = 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"
|
||||
}).format(now); // "Sun", "Mon", ... "Sat"
|
||||
const timeMinutes = hour * 60 + minute; // minutes since midnight
|
||||
|
||||
const mode = getSetting('trading_hours') ?? 'full_cme';
|
||||
|
||||
if (mode === 'equity_hours') {
|
||||
// Equity hours: 8:30 AM – 3:00 PM Central with 5 min buffer = 8:35 AM – 2:55 PM
|
||||
// Weekdays only
|
||||
if (day === 'Sat' || day === 'Sun') return true;
|
||||
const open = 8 * 60 + 35; // 8:35 AM
|
||||
const close = 14 * 60 + 55; // 2:55 PM
|
||||
return timeMinutes < open || timeMinutes >= close;
|
||||
}
|
||||
|
||||
// Full CME: Sun 5:00 PM – Fri 4:00 PM Central with 5 min buffer
|
||||
// Open: 5:05 PM, Close: 2:55 PM (stop early), Daily halt: 2:55 PM – 5:05 PM
|
||||
|
||||
// Saturday — market closed all day
|
||||
if (day === 'Sat') return true;
|
||||
|
||||
// Sunday — market opens at 5 PM Central
|
||||
if (day === 'Sun' && hour < 17) return true;
|
||||
// Sunday — market opens at 5:05 PM Central
|
||||
const cmeOpen = 17 * 60 + 5; // 5:05 PM
|
||||
if (day === 'Sun') return timeMinutes < cmeOpen;
|
||||
|
||||
// Friday — stop trading after 3 PM Central
|
||||
if (day === 'Fri' && hour >= 15) return true;
|
||||
// Friday — stop trading at 2:55 PM Central
|
||||
const cmeClose = 14 * 60 + 55; // 2:55 PM
|
||||
if (day === 'Fri' && timeMinutes >= cmeClose) 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;
|
||||
// Mon–Thu: block 2:55 PM – 5:05 PM Central (early stop + daily halt + buffer)
|
||||
if (timeMinutes >= cmeClose && timeMinutes < cmeOpen) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user