fix: Force batch processing even in automation mode

CRITICAL FIX: The automation mode was bypassing batch processing entirely,
causing it to fall back to old sequential behavior (2 screenshots instead of 6)
and wrong timeframes (1h instead of scalp timeframes).

Changes:
- Removed early automation service call that bypassed batch processing
- Batch processing now ALWAYS runs first (gets all 6 screenshots for scalp)
- Automation service starts AFTER batch analysis completes
- This ensures scalp (5,15,30) * 2 layouts = 6 screenshots as expected

This fixes the core regression where optimized mode wasn't actually optimized.
This commit is contained in:
mindesbunister
2025-07-24 17:58:23 +02:00
parent 1da9ec5673
commit ab8fb7c202

View File

@@ -25,47 +25,12 @@ export async function POST(request) {
symbol,
timeframes: targetTimeframes,
layouts,
automationMode
automationMode,
mode
})
// If this is automation mode, integrate with automation service
if (automationMode) {
console.log('🔄 Automation Mode: Integrating with automation service...')
// Import automation service for background processing
const { automationService } = await import('../../../lib/automation-service-simple')
// Create automation config
const automationConfig = {
userId: 'default-user',
symbol: symbol || 'SOLUSD',
timeframe: targetTimeframes[0] || '15', // Primary timeframe for database
selectedTimeframes: targetTimeframes,
mode: mode, // Use the mode passed from frontend
dexProvider: dexProvider,
tradingAmount: tradingAmount,
balancePercentage: balancePercentage,
maxLeverage: 3, // Required field for automation
riskPercentage: 2, // Required field for automation
maxDailyTrades: 5,
useOptimizedAnalysis: true // Flag to use our optimized batch processing
}
const success = await automationService.startAutomation(automationConfig)
if (success) {
return NextResponse.json({
success: true,
message: 'Optimized automation started successfully',
mode: 'automation'
})
} else {
return NextResponse.json({
success: false,
error: 'Failed to start optimized automation'
}, { status: 500 })
}
}
// ALWAYS use batch processing first - even for automation mode
// Then integrate with automation service if needed
// Generate unique session ID for progress tracking
const sessionId = `optimized_analysis_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
@@ -244,6 +209,38 @@ export async function POST(request) {
console.log(`💰 Trade executed: ${tradeResult.direction}`)
}
// If this is automation mode, NOW start the automation service with the batch analysis results
if (automationMode) {
console.log('🔄 Starting automation service with batch analysis results...')
try {
// Import automation service for background processing
const { automationService } = await import('../../../lib/automation-service-simple')
// Create automation config
const automationConfig = {
userId: 'default-user',
symbol: symbol || 'SOLUSD',
timeframe: targetTimeframes[0] || '15', // Primary timeframe for database
selectedTimeframes: targetTimeframes,
mode: mode, // Use the mode passed from frontend
dexProvider: dexProvider,
tradingAmount: tradingAmount,
balancePercentage: balancePercentage,
maxLeverage: 3, // Required field for automation
riskPercentage: 2, // Required field for automation
maxDailyTrades: 5,
useOptimizedAnalysis: true // Flag to use our optimized batch processing
}
const automationSuccess = await automationService.startAutomation(automationConfig)
console.log('🤖 Automation service started:', automationSuccess)
} catch (automationError) {
console.error('⚠️ Failed to start automation service:', automationError)
// Don't fail the whole request - batch analysis still succeeded
}
}
return NextResponse.json(result)
} catch (error) {