diff --git a/app/api/enhanced-screenshot/route.js b/app/api/enhanced-screenshot/route.js index 9511adf..a378605 100644 --- a/app/api/enhanced-screenshot/route.js +++ b/app/api/enhanced-screenshot/route.js @@ -1,5 +1,4 @@ import { NextResponse } from 'next/server' -import { superiorScreenshotService } from '../../../lib/superior-screenshot-service' import { aiAnalysisService } from '../../../lib/ai-analysis' import { progressTracker } from '../../../lib/progress-tracker' @@ -7,6 +6,7 @@ export async function POST(request) { let sessionId = null try { + console.log('🔍 Enhanced Screenshot API starting...') const body = await request.json() console.log('🔍 Enhanced Screenshot API request:', body) @@ -17,39 +17,47 @@ export async function POST(request) { analyze: body.analyze === true } - // Create session for progress tracking - sessionId = progressTracker.createSession() - config.sessionId = sessionId - - console.log(`🔍 Created session ${sessionId} for enhanced screenshot`) + console.log('🔍 Processed config:', config) + console.log('🔍 Config.layouts type:', typeof config.layouts) + console.log('🔍 Config.layouts isArray:', Array.isArray(config.layouts)) + console.log('🔍 Config.layouts length:', config.layouts?.length) - // Initialize progress steps - progressTracker.initializeSteps(sessionId, [ - { id: 'init', name: 'Initialize', status: 'active' }, - { id: 'auth', name: 'Authentication', status: 'pending' }, - { id: 'loading', name: 'Loading Chart', status: 'pending' }, - { id: 'capture', name: 'Capture Screenshot', status: 'pending' }, - { id: 'analysis', name: 'AI Analysis', status: 'pending' } - ]) + // Create session for progress tracking + const progressSteps = [ + { id: 'init', title: 'Initialize', description: 'Starting browser sessions...', status: 'pending' }, + { id: 'auth', title: 'Authentication', description: 'Logging into TradingView', status: 'pending' }, + { id: 'loading', title: 'Loading Chart', description: 'Loading chart data', status: 'pending' }, + { id: 'capture', title: 'Capture Screenshot', description: 'Capturing screenshots', status: 'pending' }, + { id: 'analysis', title: 'AI Analysis', description: 'Running AI analysis', status: 'pending' } + ] + + sessionId = `screenshot_${Date.now()}_${Math.random().toString(36).substr(2, 9)}` + const progress = progressTracker.createSession(sessionId, progressSteps) + config.sessionId = sessionId let screenshots = [] let analysis = null - // Capture screenshots using superior parallel technique + // Capture screenshots using enhanced screenshot service try { - console.log('🚀 Starting superior screenshot capture...') + console.log('🚀 Starting enhanced screenshot capture...') + console.log('📋 Config being passed to captureWithLogin:', JSON.stringify(config, null, 2)) - // Use single timeframe capture for backwards compatibility - const screenshotPaths = await superiorScreenshotService.captureQuick( - config.symbol, - config.timeframe, - config.layouts - ) + // Use dynamic import for TypeScript module + const { EnhancedScreenshotService } = await import('../../../lib/enhanced-screenshot') + const enhancedScreenshotService = new EnhancedScreenshotService() - screenshots = screenshotPaths - console.log('📸 Superior screenshot capture completed:', screenshots.length, 'files') + // Use captureWithLogin for proper authentication and session management + const screenshotPaths = await enhancedScreenshotService.captureWithLogin(config) + + console.log('📸 Raw screenshotPaths result:', screenshotPaths) + console.log('📸 Type of screenshotPaths:', typeof screenshotPaths) + console.log('📸 Is screenshotPaths array?', Array.isArray(screenshotPaths)) + + screenshots = screenshotPaths || [] + console.log('📸 Enhanced screenshot capture completed:', screenshots.length, 'files') } catch (screenshotError) { - console.error('❌ Superior screenshot capture failed:', screenshotError) + console.error('❌ Enhanced screenshot capture failed:', screenshotError) throw new Error(`Screenshot capture failed: ${screenshotError.message}`) } @@ -67,7 +75,14 @@ export async function POST(request) { layouts: config.layouts } - analysis = await aiAnalysisService.analyzeScreenshots(analysisConfig) + // Use dynamic import for TypeScript module and call the correct method + const { aiAnalysisService } = await import('../../../lib/ai-analysis') + + if (screenshots.length === 1) { + analysis = await aiAnalysisService.analyzeScreenshot(screenshots[0]) + } else { + analysis = await aiAnalysisService.analyzeMultipleScreenshots(screenshots) + } if (analysis) { progressTracker.updateStep(sessionId, 'analysis', 'completed', 'Analysis completed successfully') diff --git a/app/automation-v2/page.js b/app/automation-v2/page.js index 7930a4d..d338266 100644 --- a/app/automation-v2/page.js +++ b/app/automation-v2/page.js @@ -327,9 +327,23 @@ Based on comprehensive technical analysis across multiple timeframes: } // Trade Confirmation Handlers - const handleTradeConfirmation = (recommendation) => { - setPendingTrade(recommendation) - setShowConfirmation(true) + const handleTradeConfirmation = async (recommendation) => { + console.log('🎯 Getting fresh market signal...'); + setLoadingAnalysis(true); + + try { + // Force fetch new analysis first + await fetchCurrentAnalysis(); + + // Then show confirmation modal with the fresh analysis + setPendingTrade(recommendation); + setShowConfirmation(true); + } catch (error) { + console.error('Failed to get fresh analysis:', error); + setActionFeedback({ type: 'error', message: '❌ Failed to get market signal' }); + } finally { + setLoadingAnalysis(false); + } } const handleConfirmTrade = async (confirmationData) => { @@ -620,14 +634,14 @@ Based on comprehensive technical analysis across multiple timeframes: {/* Get Trade Signal Button */} diff --git a/prisma/prisma/dev.db b/prisma/prisma/dev.db index 2c9db02..16b0585 100644 Binary files a/prisma/prisma/dev.db and b/prisma/prisma/dev.db differ