Files
trading_bot_v3/app/api/automation/start/route.js
mindesbunister 451a8248d8 feat: implement strategy-aware analysis intervals and remove manual leverage controls
- Remove manual leverage field from automation v2 page since AI now handles leverage automatically
- Fix scalping strategy analysis intervals from 60 minutes to 2 minutes for proper high-frequency trading
- Implement intelligent interval detection based on selected timeframes:
  * Scalping: 2 minutes (5m, 3m, or multiple short timeframes)
  * Day trading: 5 minutes (1h, 2h timeframes)
  * Swing trading: 15 minutes (4h, daily timeframes)
- Fix Drift SDK API calls: replace getTotalPerpPositionValue() with getFreeCollateral()
- Clean up UI by removing manual controls since AI systems handle optimization
- Fix syntax errors in automation service and balance API
- Ensure proper margin calculations using correct Drift Protocol methods

Tested: Scalping strategy now correctly analyzes every 2 minutes instead of 60 minutes
2025-07-24 13:25:41 +02:00

42 lines
1.5 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
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 })
}
}