✅ Restore working dashboard and TradingView analysis
- Fixed layout conflicts by removing minimal layout.tsx in favor of complete layout.js - Restored original AI Analysis page with full TradingView integration - Connected enhanced screenshot API to real TradingView automation service - Fixed screenshot gallery to handle both string and object formats - Added image serving API route for screenshot display - Resolved hydration mismatch issues with suppressHydrationWarning - All navigation pages working (Analysis, Trading, Automation, Settings) - TradingView automation successfully capturing screenshots from AI and DIY layouts - Docker Compose v2 compatibility ensured Working features: - Homepage with hero section and status cards - Navigation menu with Trading Bot branding - Real TradingView screenshot capture - AI-powered chart analysis - Multi-layout support (AI + DIY module) - Screenshot gallery with image serving - API endpoints for balance, status, screenshots, trading
This commit is contained in:
89
app/api/enhanced-screenshot/route.js
Normal file
89
app/api/enhanced-screenshot/route.js
Normal file
@@ -0,0 +1,89 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { enhancedScreenshotService } from '../../../lib/enhanced-screenshot-simple'
|
||||
import { aiAnalysisService } from '../../../lib/ai-analysis'
|
||||
|
||||
export async function POST(request) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const { symbol, layouts, timeframes, selectedLayouts, analyze = true } = body
|
||||
|
||||
console.log('📊 Enhanced screenshot request:', { symbol, layouts, timeframes, selectedLayouts })
|
||||
|
||||
// Prepare configuration for screenshot service
|
||||
const config = {
|
||||
symbol: symbol || 'BTCUSD',
|
||||
timeframe: timeframes?.[0] || '60', // Use first timeframe for now
|
||||
layouts: layouts || selectedLayouts || ['ai'],
|
||||
credentials: {
|
||||
email: process.env.TRADINGVIEW_EMAIL,
|
||||
password: process.env.TRADINGVIEW_PASSWORD
|
||||
}
|
||||
}
|
||||
|
||||
console.log('🔧 Using config:', config)
|
||||
|
||||
// Capture screenshots using the working service
|
||||
const screenshots = await enhancedScreenshotService.captureWithLogin(config)
|
||||
console.log('📸 Screenshots captured:', screenshots)
|
||||
|
||||
let analysis = null
|
||||
|
||||
// Perform AI analysis if requested and screenshots were captured
|
||||
if (analyze && screenshots.length > 0) {
|
||||
try {
|
||||
console.log('🤖 Starting AI analysis...')
|
||||
|
||||
// Extract just the filenames from full paths
|
||||
const filenames = screenshots.map(path => path.split('/').pop())
|
||||
|
||||
if (filenames.length === 1) {
|
||||
analysis = await aiAnalysisService.analyzeScreenshot(filenames[0])
|
||||
} else {
|
||||
analysis = await aiAnalysisService.analyzeMultipleScreenshots(filenames)
|
||||
}
|
||||
|
||||
console.log('✅ AI analysis completed')
|
||||
} catch (analysisError) {
|
||||
console.error('❌ AI analysis failed:', analysisError)
|
||||
// Continue without analysis rather than failing the whole request
|
||||
}
|
||||
}
|
||||
|
||||
const result = {
|
||||
success: true,
|
||||
timestamp: Date.now(),
|
||||
symbol: config.symbol,
|
||||
layouts: config.layouts,
|
||||
timeframes: [config.timeframe],
|
||||
screenshots: screenshots.map(path => ({
|
||||
layout: config.layouts[0], // For now, assume one layout
|
||||
timeframe: config.timeframe,
|
||||
url: `/screenshots/${path.split('/').pop()}`,
|
||||
timestamp: Date.now()
|
||||
})),
|
||||
analysis: analysis,
|
||||
message: `Successfully captured ${screenshots.length} screenshot(s)${analysis ? ' with AI analysis' : ''}`
|
||||
}
|
||||
|
||||
return NextResponse.json(result)
|
||||
} catch (error) {
|
||||
console.error('Enhanced screenshot API error:', error)
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'Analysis failed',
|
||||
message: error.message
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json({
|
||||
message: 'Enhanced Screenshot API - use POST method for analysis',
|
||||
endpoints: {
|
||||
POST: '/api/enhanced-screenshot - Run analysis with parameters'
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
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']
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user