// Test the enhanced automation system for scalping re-entry const SimpleAutomation = require('./lib/simple-automation.js'); async function testScalpingReEntry() { console.log('๐Ÿงช TESTING: Enhanced scalping automation for immediate re-entry'); try { // Create automation instance configured for scalping const automation = new SimpleAutomation(); // Configure for 5-minute scalping (aggressive re-entry) const config = { symbol: 'SOLUSD', selectedTimeframes: ['5m', '15m'], // Scalping timeframes enableTrading: true, mode: 'LIVE', layouts: ['ai', 'diy'] }; automation.updateConfig(config); console.log('\n๐Ÿ“Š CONFIGURATION:'); console.log('Symbol:', config.symbol); console.log('Timeframes:', config.selectedTimeframes.join(', ')); console.log('Trading Mode:', config.mode); // Test interval calculation for no position scenario console.log('\n๐Ÿ• TESTING INTERVAL CALCULATION:'); const interval = await automation.getNextInterval(); const intervalMinutes = interval / (60 * 1000); console.log(`โฐ Next analysis interval: ${intervalMinutes} minutes`); console.log(`๐Ÿƒโ€โ™‚๏ธ Scalping mode: ${intervalMinutes <= 5 ? 'ACTIVE' : 'STANDARD'}`); // Test position monitoring integration console.log('\n๐Ÿ“ TESTING POSITION MONITOR INTEGRATION:'); const baseUrl = process.env.INTERNAL_API_URL || 'http://localhost:9001'; const response = await fetch(`${baseUrl}/api/automation/position-monitor`); if (response.ok) { const data = await response.json(); const hasPosition = data.monitor?.hasPosition; const recommendation = data.monitor?.recommendation; const activeOrders = data.monitor?.orphanedOrderCleanup?.summary?.activeOrders || 0; console.log(`Position Status: ${hasPosition ? 'ACTIVE' : 'NO POSITION'}`); console.log(`Monitor Recommendation: ${recommendation}`); console.log(`Active Orders: ${activeOrders}`); if (!hasPosition && recommendation === 'START_TRADING') { console.log('โœ… CONDITION MET: No position + START_TRADING recommendation'); console.log('๐Ÿš€ SCALPING ACTION: System should immediately scan for new opportunities'); console.log(`โšก Expected interval: 2 minutes (actual: ${intervalMinutes} minutes)`); } else if (!hasPosition) { console.log('โš ๏ธ NO POSITION: But recommendation is not START_TRADING'); console.log('๐Ÿ” System should still scan more frequently for opportunities'); } else { console.log('๐Ÿ“Š POSITION EXISTS: Normal monitoring intervals apply'); } } console.log('\n๐ŸŽฏ CONFIDENCE TESTING:'); // Test confidence thresholds for scalping const mockAnalysis = { recommendation: 'BUY LONG', confidence: 67, reasoning: 'Mock analysis for testing confidence thresholds' }; const shouldTrade = automation.shouldExecuteTrade(mockAnalysis); console.log(`Mock Analysis: ${mockAnalysis.recommendation} (${mockAnalysis.confidence}%)`); console.log(`Should Execute: ${shouldTrade ? 'YES' : 'NO'}`); console.log(`Scalping Advantage: Lower confidence threshold when no position exists`); console.log('\nโœ… ENHANCED AUTOMATION FEATURES:'); console.log('1. โœ… Immediate position monitor check each cycle'); console.log('2. โœ… Automatic orphaned order cleanup before new entry'); console.log('3. โœ… Ultra-fast 2-minute intervals for scalping when no position'); console.log('4. โœ… Aggressive confidence thresholds (65-70%) for faster re-entry'); console.log('5. โœ… Real-time position status integration'); } catch (error) { console.error('โŒ Test failed:', error.message); } } // Run the test testScalpingReEntry();