#!/usr/bin/env node /** * Test script for the new optimized multi-timeframe analysis * This demonstrates the speed improvements over traditional sequential processing */ console.log('šŸš€ Testing Optimized Multi-Timeframe Analysis') console.log('=' .repeat(60)) async function testOptimizedAnalysis() { try { // Test configuration - multiple timeframes const config = { symbol: 'SOLUSD', timeframes: ['1h', '4h'], // Start with 2 timeframes layouts: ['ai', 'diy'], analyze: true } console.log('šŸ“‹ Test Configuration:') console.log(` Symbol: ${config.symbol}`) console.log(` Timeframes: ${config.timeframes.join(', ')}`) console.log(` Layouts: ${config.layouts.join(', ')}`) console.log(` Expected Screenshots: ${config.timeframes.length * config.layouts.length}`) console.log(` Traditional Time Estimate: ~${config.timeframes.length * 15}s`) console.log('') // Test API endpoint availability console.log('šŸ” Checking optimized API endpoint...') try { const healthResponse = await fetch('http://localhost:3000/api/analysis-optimized') if (!healthResponse.ok) { throw new Error(`API endpoint not available: ${healthResponse.status}`) } const healthData = await healthResponse.json() console.log('āœ… Optimized API endpoint available') console.log(` šŸ“„ Description: ${healthData.description}`) console.log('') } catch (healthError) { console.error('āŒ API endpoint health check failed:', healthError.message) console.log('\nšŸ’” Make sure to start the development server:') console.log(' npm run docker:dev') console.log(' # OR') console.log(' npm run dev') process.exit(1) } // Perform the optimized analysis console.log('šŸ”„ Starting optimized multi-timeframe analysis...') const startTime = Date.now() const response = await fetch('http://localhost:3000/api/analysis-optimized', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(config) }) const endTime = Date.now() const actualDuration = ((endTime - startTime) / 1000).toFixed(2) if (!response.ok) { const errorData = await response.json() throw new Error(`API request failed: ${errorData.error || response.statusText}`) } const result = await response.json() console.log('\nāœ… OPTIMIZED ANALYSIS COMPLETED!') console.log('=' .repeat(60)) // Performance metrics console.log('šŸ“Š PERFORMANCE METRICS:') console.log(` ā±ļø Actual Duration: ${actualDuration}s`) console.log(` ⚔ Reported Duration: ${result.optimization?.totalTime || 'N/A'}`) console.log(` šŸ“ˆ Efficiency Gain: ${result.optimization?.efficiency || 'N/A'}`) console.log(` šŸ–¼ļø Screenshots Captured: ${result.screenshots?.length || 0}`) console.log(` šŸ¤– AI Calls Made: ${result.optimization?.aiCalls || 0}`) console.log('') // Screenshot results if (result.screenshots?.length > 0) { console.log('šŸ“ø SCREENSHOT RESULTS:') const timeframeGroups = {} result.screenshots.forEach((screenshot, index) => { const tf = screenshot.timeframe if (!timeframeGroups[tf]) timeframeGroups[tf] = [] timeframeGroups[tf].push(screenshot) console.log(` ${index + 1}. ${screenshot.timeframe} ${screenshot.layout}: ${screenshot.url}`) }) console.log('') console.log('šŸ“Š SCREENSHOT DISTRIBUTION:') Object.entries(timeframeGroups).forEach(([timeframe, screenshots]) => { console.log(` ${timeframe}: ${screenshots.length} screenshots`) }) console.log('') } // AI Analysis results if (result.analysis) { console.log('šŸ¤– AI ANALYSIS RESULTS:') console.log(` šŸ“Š Overall Sentiment: ${result.analysis.marketSentiment}`) console.log(` šŸ“ˆ Recommendation: ${result.analysis.overallRecommendation}`) console.log(` šŸŽÆ Confidence: ${result.analysis.confidence}%`) console.log('') // Multi-timeframe breakdown if (result.analysis.multiTimeframeAnalysis) { console.log('ā° MULTI-TIMEFRAME BREAKDOWN:') Object.entries(result.analysis.multiTimeframeAnalysis).forEach(([timeframe, data]) => { console.log(` ${timeframe}:`) console.log(` šŸ“Š Sentiment: ${data.sentiment}`) console.log(` šŸ’Ŗ Strength: ${data.strength}%`) console.log(` šŸŽÆ Support: $${data.keyLevels?.support?.join(', $') || 'N/A'}`) console.log(` šŸ”“ Resistance: $${data.keyLevels?.resistance?.join(', $') || 'N/A'}`) }) console.log('') } // Consensus if (result.analysis.consensus) { console.log('šŸŽÆ CONSENSUS ANALYSIS:') console.log(` šŸ“ˆ Direction: ${result.analysis.consensus.direction}`) console.log(` šŸŽÆ Confidence: ${result.analysis.consensus.confidence}%`) console.log(` šŸ’” Reasoning: ${result.analysis.consensus.reasoning}`) if (result.analysis.consensus.conflictingSignals?.length > 0) { console.log(` āš ļø Conflicts: ${result.analysis.consensus.conflictingSignals.join(', ')}`) } console.log('') } // Trading setup if (result.analysis.tradingSetup) { const setup = result.analysis.tradingSetup console.log('šŸ’° TRADING SETUP:') console.log(` šŸŽÆ Entry: $${setup.entry.price}${setup.entry.buffer ? ' ' + setup.entry.buffer : ''}`) console.log(` šŸ›‘ Stop Loss: $${setup.stopLoss.price}`) console.log(` šŸ„‰ TP1: $${setup.takeProfits.tp1.price} (${setup.takeProfits.tp1.description})`) console.log(` 🄈 TP2: $${setup.takeProfits.tp2.price} (${setup.takeProfits.tp2.description})`) console.log(` āš–ļø Risk/Reward: ${setup.riskToReward}`) console.log(` šŸŽšļø Leverage: ${setup.timeframeRisk.leverageRecommendation}`) console.log('') } } else { console.log('āš ļø No AI analysis results received') console.log('') } // Success summary console.log('šŸŽ‰ TEST SUMMARY:') console.log(` āœ… API Response: ${response.ok ? 'Success' : 'Failed'}`) console.log(` ā±ļø Duration: ${actualDuration}s`) console.log(` šŸ“ø Screenshots: ${result.screenshots?.length || 0}/${config.timeframes.length * config.layouts.length}`) console.log(` šŸ¤– Analysis: ${result.analysis ? 'Complete' : 'Missing'}`) console.log(` šŸ“Š Success Rate: ${((result.screenshots?.length || 0) / (config.timeframes.length * config.layouts.length) * 100).toFixed(0)}%`) if (result.optimization) { console.log(` šŸš€ Optimization: ${result.optimization.efficiency}`) console.log(` šŸ’° Cost Savings: ${config.timeframes.length - (result.optimization.aiCalls || 0)} fewer AI calls`) } console.log('\nšŸŽÆ The optimized analysis system is working correctly!') } catch (error) { console.error('\nāŒ Test failed:', error.message) console.error('Stack trace:', error.stack) process.exit(1) } } // Run the test testOptimizedAnalysis()