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)
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
import { NextResponse } from 'next/server'
|
|
|
|
// In-memory store for live trading decisions and risk management blocks
|
|
let liveDecisions = []
|
|
let maxDecisions = 10 // Keep last 10 decisions
|
|
|
|
export async function GET() {
|
|
try {
|
|
// Return the most recent decisions with full context
|
|
const response = {
|
|
success: true,
|
|
decisions: liveDecisions,
|
|
latest: liveDecisions[0] || null,
|
|
timestamp: new Date().toISOString()
|
|
}
|
|
|
|
return NextResponse.json(response)
|
|
} catch (error) {
|
|
console.error('❌ Live decisions API error:', error)
|
|
return NextResponse.json(
|
|
{ success: false, error: error.message },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|
|
export async function POST(request) {
|
|
try {
|
|
const decision = await request.json()
|
|
|
|
// Add timestamp if not provided
|
|
if (!decision.timestamp) {
|
|
decision.timestamp = new Date().toISOString()
|
|
}
|
|
|
|
// Add to the beginning of the array (most recent first)
|
|
liveDecisions.unshift(decision)
|
|
|
|
// Keep only the last maxDecisions
|
|
if (liveDecisions.length > maxDecisions) {
|
|
liveDecisions = liveDecisions.slice(0, maxDecisions)
|
|
}
|
|
|
|
console.log('📊 Live decision recorded:', {
|
|
type: decision.type,
|
|
action: decision.action,
|
|
blocked: decision.blocked,
|
|
confidence: decision.confidence
|
|
})
|
|
|
|
return NextResponse.json({ success: true, total: liveDecisions.length })
|
|
} catch (error) {
|
|
console.error('❌ Live decisions POST error:', error)
|
|
return NextResponse.json(
|
|
{ success: false, error: error.message },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|