Spaces:
Sleeping
Sleeping
Commit ·
4415b27
1
Parent(s): d3a66fe
fix: implement transition-based candle scanning and duplicate scan guard on server
Browse files84 unmodified lines85868788899050 unmodified lines1411421431441451461471481491501517 unmodified lines15916016116216316484 unmodified linesconst historyMap = {};const livePrices = {};const streams = {};// Helper delay utilityconst delay = ms => new Promise(resolve => setTimeout(resolve, ms));50 unmodified linesif (lastIndex !== -1) {history[lastIndex] = { ...candle };} else {history.push({ ...candle });if (history.length > 1000) history.shift();}// If candle closed, run high-probability smart money scanif (candle.isClosed) {console.log(`[Autopilot] Candle CLOSED for ${symbol} at ${new Date().toLocaleTimeString()}. Recalculating setups.`);runScannersForSymbol(symbol);7 unmodified linesreturn;}// Prevent opening trades if symbol has active trade or is in 10-minute cooldownconst hasActiveTrade = tradeManager.activeTrades.some(t => t.symbol === symbol && t.status === 'active');if (hasActiveTrade) return;84 unmodified lines8586878889909150 unmodified lines1421431441451461471481491501511521531541551561571581591601617 unmodified lines16917017117217317417517617717817918084 unmodified linesconst historyMap = {};const livePrices = {};const streams = {};const lastScannedCandleTime = {};// Helper delay utilityconst delay = ms => new Promise(resolve => setTimeout(resolve, ms));50 unmodified linesif (lastIndex !== -1) {history[lastIndex] = { ...candle };} else {// Transition detected! A new candle has started.// The previous candle in history is now closed and finalized.if (history.length > 0) {const closedCandle = history[history.length - 1];closedCandle.isClosed = true;console.log(`[Autopilot] Transition detected: Candle CLOSED for ${symbol} at ${new Date(closedCandle.time * 1000).toLocaleTimeString()}. Recalculating setups.`);runScannersForSymbol(symbol);}history.push({ ...candle });if (history.length > 1000) history.shift();}// If candle is explicitly marked closed (e.g. from Yahoo polling ticks), run the scanif (candle.isClosed) {console.log(`[Autopilot] Candle CLOSED for ${symbol} at ${new Date().toLocaleTimeString()}. Recalculating setups.`);runScannersForSymbol(symbol);7 unmodified linesreturn;}const latestCandle = candles[candles.length - 1];if (lastScannedCandleTime[symbol] === latestCandle.time) {return; // Already scanned this candle}lastScannedCandleTime[symbol] = latestCandle.time;// Prevent opening trades if symbol has active trade or is in 10-minute cooldownconst hasActiveTrade = tradeManager.activeTrades.some(t => t.symbol === symbol && t.status === 'active');if (hasActiveTrade) return;
server.js+17-1