fix: AI-calculated SL/TP system with fallback risk management
- Added fallback SL/TP calculation when AI values missing (rate limits) - Stop loss: 1.5% from entry (scalping-optimized) - Take profit: 3% from entry (2:1 risk/reward) - Relaxed API validation to require only stop loss (most critical) - Disabled problematic import in position-history route - System now guarantees risk management on every trade No more unprotected positions - works with or without AI analysis
This commit is contained in:
@@ -64,19 +64,7 @@ export async function POST(request) {
|
||||
)
|
||||
}
|
||||
|
||||
// 🛡️ MANDATORY RISK MANAGEMENT VALIDATION - NO TRADE WITHOUT SL/TP
|
||||
if (!stopLoss && !takeProfit) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'RISK MANAGEMENT REQUIRED: Both stop-loss and take-profit are missing',
|
||||
details: 'Every trade must have proper risk management. Provide at least stop-loss or take-profit.',
|
||||
riskManagementFailed: true
|
||||
},
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
// 🛡️ MANDATORY RISK MANAGEMENT VALIDATION - STOP LOSS REQUIRED
|
||||
if (!stopLoss) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
@@ -89,19 +77,12 @@ export async function POST(request) {
|
||||
)
|
||||
}
|
||||
|
||||
// Take profit is recommended but not mandatory for entry
|
||||
if (!takeProfit) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: 'TAKE-PROFIT REQUIRED: No take-profit provided',
|
||||
details: 'Every trade must have a take-profit to secure gains.',
|
||||
riskManagementFailed: true
|
||||
},
|
||||
{ status: 400 }
|
||||
)
|
||||
console.log('⚠️ No take profit provided - trade will rely on manual exit or stop loss');
|
||||
}
|
||||
|
||||
console.log(`✅ RISK MANAGEMENT VALIDATION PASSED - SL: $${stopLoss}, TP: $${takeProfit}`);
|
||||
console.log(`✅ RISK MANAGEMENT VALIDATION PASSED - SL: $${stopLoss}, TP: $${takeProfit || 'NONE'}`);
|
||||
|
||||
if (!useRealDEX) {
|
||||
// Simulation mode
|
||||
|
||||
Reference in New Issue
Block a user