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:
@@ -25,47 +25,12 @@ export async function POST(request) {
|
|||||||
symbol,
|
symbol,
|
||||||
timeframes: targetTimeframes,
|
timeframes: targetTimeframes,
|
||||||
layouts,
|
layouts,
|
||||||
automationMode
|
automationMode,
|
||||||
|
mode
|
||||||
})
|
})
|
||||||
|
|
||||||
// If this is automation mode, integrate with automation service
|
// ALWAYS use batch processing first - even for automation mode
|
||||||
if (automationMode) {
|
// Then integrate with automation service if needed
|
||||||
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 })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate unique session ID for progress tracking
|
// Generate unique session ID for progress tracking
|
||||||
const sessionId = `optimized_analysis_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
|
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}`)
|
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)
|
return NextResponse.json(result)
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user