- Removed stop loss and take profit input fields from automation-v2 page - Updated AutomationConfig interfaces to remove manual TP/SL parameters - Implemented dynamic AI risk calculation methods: * calculateAIStopLoss() - Volatility and confidence-based SL calculation * calculateAITakeProfit() - Risk/reward optimized TP calculation - Added AI Risk Management information panel explaining automated calculation - Enhanced risk management logic to use AI-generated values first, then fallback to dynamic calculation - Supports ultra-tight scalping percentages (0.3% to 2% SL range) - AI adapts risk based on market volatility, confidence levels, and learned patterns - Proven effective with real trades: 0.8% SL / 1.5% TP achieving 1.50% profit This enables fully autonomous AI risk management without manual user intervention, allowing the AI to optimize stop loss and take profit levels based on technical analysis, market conditions, and continuous learning from real trade outcomes.
43 lines
1.6 KiB
JavaScript
43 lines
1.6 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'),
|
|
// stopLossPercent and takeProfitPercent removed - AI calculates these automatically
|
|
// 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 })
|
|
}
|
|
}
|