fix: emergency automation fix - stop runaway trading loops
- Replace automation service with emergency rate-limited version - Add 5-minute minimum interval between automation starts - Implement forced Chromium process cleanup on stop - Backup broken automation service as .broken file - Emergency service prevents multiple simultaneous automations - Fixed 1400+ Chromium process accumulation issue - Tested and confirmed: rate limiting works, processes stay at 0
This commit is contained in:
@@ -1,41 +1,18 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { automationService } from '@/lib/automation-service-simple'
|
||||
import { emergencyAutomation } from '@/lib/emergency-automation'
|
||||
|
||||
export async function POST(request) {
|
||||
try {
|
||||
const config = await request.json()
|
||||
console.log('🚨 EMERGENCY: Automation start request received')
|
||||
|
||||
// Add a default userId for now (in production, get from auth)
|
||||
const automationConfig = {
|
||||
userId: 'default-user',
|
||||
...config,
|
||||
// Map asset to symbol if asset is provided
|
||||
symbol: config.asset || config.symbol,
|
||||
// Map simulation to mode
|
||||
mode: config.simulation ? 'SIMULATION' : (config.mode || 'SIMULATION'),
|
||||
// stopLossPercent and takeProfitPercent removed - AI calculates these automatically
|
||||
// Map tradeSize to tradingAmount
|
||||
tradingAmount: config.tradeSize || config.tradingAmount,
|
||||
// Set defaults for missing fields
|
||||
maxDailyTrades: config.maxDailyTrades || 5,
|
||||
dexProvider: config.dexProvider || 'DRIFT',
|
||||
selectedTimeframes: config.selectedTimeframes || [config.timeframe || '1h']
|
||||
}
|
||||
const result = await emergencyAutomation.start(config)
|
||||
|
||||
const success = await automationService.startAutomation(automationConfig)
|
||||
|
||||
if (success) {
|
||||
return NextResponse.json({ success: true, message: 'Automation started successfully' })
|
||||
} else {
|
||||
return NextResponse.json({ success: false, error: 'Failed to start automation' }, { status: 500 })
|
||||
}
|
||||
return Response.json(result)
|
||||
} catch (error) {
|
||||
console.error('Start automation error:', error)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Internal server error',
|
||||
message: error.message,
|
||||
stack: error.stack
|
||||
console.error('Emergency start failed:', error)
|
||||
return Response.json({
|
||||
success: false,
|
||||
message: 'Emergency start failed: ' + error.message
|
||||
}, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user