Files
trading_bot_v3/app/api/automation/start/route.js
mindesbunister 91cc8baead Fix automation API config mapping and verify AI risk management
- Map asset->symbol, simulation->mode for API compatibility
- Fix trade storage validation and error handling
- Confirm AI risk management working: 3.5%/8% SL/TP optimization
- Successfully executed live trade with AI-calculated parameters
2025-07-23 16:32:10 +02:00

46 lines
1.7 KiB
JavaScript

import { NextResponse } from 'next/server'
import { automationService } from '@/lib/automation-service-simple'
export async function POST(request) {
try {
const config = await request.json()
// 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'),
// Map stopLoss to stopLossPercent
stopLossPercent: config.stopLoss || config.stopLossPercent,
// Map takeProfit to takeProfitPercent
takeProfitPercent: config.takeProfit || config.takeProfitPercent,
// Map tradeSize to tradingAmount
tradingAmount: config.tradeSize || config.tradingAmount,
// Set defaults for missing fields
maxLeverage: config.maxLeverage || 2,
maxDailyTrades: config.maxDailyTrades || 5,
dexProvider: config.dexProvider || 'DRIFT',
selectedTimeframes: config.selectedTimeframes || [config.timeframe || '1h']
}
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 })
}
} catch (error) {
console.error('Start automation error:', error)
return NextResponse.json({
success: false,
error: 'Internal server error',
message: error.message,
stack: error.stack
}, { status: 500 })
}
}