feat: Complete live trading decisions visibility system

LIVE TRADING ANALYSIS PANEL - Real-time decision tracking
- Live decisions API endpoint (/api/automation/live-decisions)
- Complete automation-v2 page with enhanced AI trading analysis
- Real-time visibility into AI's trading decisions and reasoning
- Block reason display showing why trades are prevented
- Execution details with entry, SL, TP, leverage, and reasoning
- Auto-refreshing decision history (30-second intervals)
- Enhanced risk management integration

 MANDATORY RISK MANAGEMENT SYSTEM
- Mandatory risk manager with strict validation
- Emergency position protection system
- Stop loss direction validation (below entry for BUY, above for SELL)
- Integration with automation system for real-time blocking

 AUTOMATION PAGE ENHANCEMENT
- All original automation-v2 features preserved
- Multi-timeframe selection with presets
- Trading configuration controls
- Account balance and position monitoring
- Enhanced AI Learning Panel integration
- Live status indicators and feedback

 COMPREHENSIVE TESTING
- Live decisions API testing harness
- Risk management validation tests
- Sample decision data for development

The system now provides complete transparency into:
-  Trade execution decisions with full reasoning
-  Risk management blocks with specific reasons
-  AI analysis and confidence levels
-  Real-time decision tracking and history
-  Entry, stop loss, take profit details
-  Leverage calculations and risk assessment

Tested and working on development container (port 9001:3000)
This commit is contained in:
mindesbunister
2025-07-28 23:42:28 +02:00
parent 4780367e79
commit f86359bcdc
13 changed files with 3396 additions and 868 deletions

View File

@@ -64,6 +64,45 @@ 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 }
)
}
if (!stopLoss) {
return NextResponse.json(
{
success: false,
error: 'STOP-LOSS REQUIRED: No stop-loss provided',
details: 'Every trade must have a stop-loss to limit potential losses.',
riskManagementFailed: true
},
{ status: 400 }
)
}
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(`✅ RISK MANAGEMENT VALIDATION PASSED - SL: $${stopLoss}, TP: $${takeProfit}`);
if (!useRealDEX) {
// Simulation mode
console.log('🎮 Executing SIMULATED Drift perpetual trade')