Block trading after 3 PM Central instead of 4 PM
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
c99f6843a7
commit
11144612c7
+36
-11
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user