✅ Major Achievement: - Implemented comprehensive multi-screenshot AI analysis - Both AI and DIY layout screenshots analyzed simultaneously - Cross-layout comparison for enhanced trading decisions - Cost-optimized with GPT-4o mini (~0.6 cents per analysis) 🔧 Technical Implementation: - Added analyzeMultipleScreenshots() method to AIAnalysisService - Enhanced API to handle single vs multi-screenshot analysis - Updated UI to display layout comparison insights - Fixed deprecated gpt-4-vision-preview → gpt-4o-mini 🎯 AI Analysis Features: - Layout-specific insights (AI Layout vs DIY Module) - Consensus detection between different chart views - Divergence analysis for conflicting signals - Enhanced confidence scoring based on multi-layout agreement - Comprehensive trading setup with entry/stop/targets 💰 Cost Optimization: - Switched from GPT-4o (/usr/bin/bash.048/analysis) to GPT-4o mini (/usr/bin/bash.006/analysis) - 8x cost reduction while maintaining analysis quality - ~.80/month for 10 daily analyses 🖥️ Enhanced UI Components: - Multi-layout analysis display sections - Cross-layout consensus indicators - Layout comparison visualization - Enhanced trading setup presentation 📊 Test Results: - Both AI and DIY screenshots captured successfully - Multi-layout analysis working flawlessly - Comprehensive trading recommendations generated - Entry/stop/target levels provided with rationale Ready for production trading analysis! 🚀
87 lines
2.8 KiB
TypeScript
87 lines
2.8 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { enhancedScreenshotService } from '../../../lib/enhanced-screenshot-simple'
|
|
import { AIAnalysisService } from '../../../lib/ai-analysis'
|
|
|
|
export async function POST(req: NextRequest) {
|
|
try {
|
|
const { symbol, timeframe, layouts, credentials, analyze = false } = await req.json()
|
|
|
|
if (!symbol) {
|
|
return NextResponse.json({ error: 'Missing symbol' }, { status: 400 })
|
|
}
|
|
|
|
console.log('Enhanced screenshot API called with:', { symbol, timeframe, layouts, analyze })
|
|
|
|
const config = {
|
|
symbol,
|
|
timeframe: timeframe || '240',
|
|
layouts: layouts || ['ai', 'diy'],
|
|
credentials
|
|
}
|
|
|
|
const screenshots = await enhancedScreenshotService.captureWithLogin(config)
|
|
|
|
let analysis = null
|
|
if (analyze && screenshots.length > 0) {
|
|
console.log('🤖 Starting AI analysis of screenshots...')
|
|
try {
|
|
const aiAnalysisService = new AIAnalysisService()
|
|
|
|
// Extract filenames from screenshot paths for analysis
|
|
const filenames = screenshots.map(path => path.split('/').pop() || '').filter(Boolean)
|
|
|
|
if (filenames.length > 0) {
|
|
console.log(`🔍 Analyzing ${filenames.length} screenshots: ${filenames.join(', ')}`)
|
|
|
|
if (filenames.length === 1) {
|
|
// Single screenshot analysis
|
|
analysis = await aiAnalysisService.analyzeScreenshot(filenames[0])
|
|
} else {
|
|
// Multi-screenshot analysis for comprehensive trading advice
|
|
analysis = await aiAnalysisService.analyzeMultipleScreenshots(filenames)
|
|
}
|
|
|
|
console.log('✅ AI analysis completed:', analysis ? 'Success' : 'Failed')
|
|
} else {
|
|
console.warn('⚠️ No valid screenshot filenames found for analysis')
|
|
}
|
|
} catch (analysisError: any) {
|
|
console.error('❌ AI analysis failed:', analysisError.message)
|
|
// Don't fail the whole request if analysis fails
|
|
}
|
|
}
|
|
|
|
const response = {
|
|
success: true,
|
|
screenshots,
|
|
analysis,
|
|
message: `Captured ${screenshots.length} screenshot(s) for ${symbol} with layouts: ${layouts?.join(', ') || 'default'}`
|
|
}
|
|
|
|
if (analysis) {
|
|
response.message += '. AI analysis completed.'
|
|
}
|
|
|
|
return NextResponse.json(response)
|
|
|
|
} catch (error: any) {
|
|
console.error('Enhanced screenshot API error:', error)
|
|
return NextResponse.json({
|
|
error: error.message,
|
|
success: false
|
|
}, { status: 500 })
|
|
}
|
|
}
|
|
|
|
export async function GET() {
|
|
return NextResponse.json({
|
|
message: 'Enhanced Screenshot API',
|
|
methods: ['POST'],
|
|
example: {
|
|
symbol: 'SOLUSD',
|
|
timeframe: '240',
|
|
layouts: ['ai', 'diy']
|
|
}
|
|
})
|
|
}
|