diff --git a/lib/auto-trade.ts b/lib/auto-trade.ts index 0ccd214..2180007 100644 --- a/lib/auto-trade.ts +++ b/lib/auto-trade.ts @@ -112,6 +112,20 @@ export async function runTrade(action: 'Buy' | 'Sell' | 'Auto', symbol: string) console.log('[auto-trade] CME market closed — skipping'); return []; } + + // Block if any account still has an open position (same gate as the scheduler tick) + const allClients = getClients(); + const allFirms = getFirms(); + const openPositions = allFirms.reduce((count, firm) => { + const c = allClients.get(firm.id); + if (!c) return count; + return count + c.accountList.filter(acc => !!c.positions[acc.id]).length; + }, 0); + if (openPositions > 0) { + console.log(`[auto-trade] ${openPositions} position(s) still open — skipping`); + return []; + } + // Resolve 'Auto' symbol once per batch so all accounts trade the same symbol let resolvedSymbol = symbol; if (symbol === 'Auto') {