Files
trading_bot_v3/app/api/automation/test-decision/route.js
mindesbunister 167d7ff5bc feat: implement comprehensive AI decision display and reasoning panel
Major Features Added:
- Complete AI decision tracking system with detailed reasoning display
- Prominent gradient-styled AI reasoning panel on automation-v2 page
- Test AI decision generator with realistic trading scenarios
- Enhanced decision transparency showing entry/exit logic and leverage calculations

- Fixed orphaned order cleanup to preserve reduce-only SL/TP orders
- Integrated AI leverage calculator with 100x capability (up from 10x limit)
- Added lastDecision property to automation status for UI display
- Enhanced position monitoring with better cleanup triggers

- Beautiful gradient-styled AI Trading Analysis panel
- Color-coded confidence levels and recommendation displays
- Detailed breakdown of entry strategy, stop loss logic, and take profit targets
- Real-time display of AI leverage reasoning with safety buffer explanations
- Test AI button for demonstration of decision-making process

- SL/TP orders now execute properly (fixed cleanup interference)
- AI calculates sophisticated leverage (8.8x-42.2x vs previous 1x hardcoded)
- Complete decision audit trail with execution details
- Risk management transparency with liquidation safety calculations

- Why This Decision? - Prominent reasoning section
- Entry & Exit Strategy - Price levels with color coding
- AI Leverage Decision - Detailed calculation explanations
- Execution status with success/failure indicators
- Transaction IDs and comprehensive trade details

All systems now provide full transparency of AI decision-making process.
2025-07-26 22:41:55 +02:00

65 lines
2.4 KiB
JavaScript

import { NextResponse } from 'next/server';
import { simpleAutomation } from '@/lib/simple-automation';
export async function POST(request) {
try {
const { action, analysis, config } = await request.json();
if (action === 'generate_test_decision') {
// Set up test config
simpleAutomation.config = config || {
selectedTimeframes: ['15m', '1h', '4h'],
symbol: 'SOLUSD',
mode: 'LIVE',
enableTrading: true,
tradingAmount: 62
};
// Generate decision using the analysis
const shouldExecute = simpleAutomation.shouldExecuteTrade(analysis);
if (shouldExecute && simpleAutomation.lastDecision) {
// Add execution details for demo
simpleAutomation.lastDecision.executed = true;
simpleAutomation.lastDecision.executionDetails = {
side: analysis.recommendation?.toLowerCase().includes('buy') ? 'BUY' : 'SELL',
amount: config.tradingAmount || 62,
leverage: 12.5,
currentPrice: analysis.currentPrice || analysis.entry?.price || 186.12,
stopLoss: analysis.stopLoss,
takeProfit: analysis.takeProfit,
aiReasoning: `AI calculated 12.5x leverage based on:
• Stop loss distance: ${((Math.abs(analysis.currentPrice - analysis.stopLoss) / analysis.currentPrice) * 100).toFixed(1)}% (tight risk control)
• Account balance: $${config.tradingAmount || 62} available
• Safety buffer: 8% (liquidation protection)
• Risk assessment: MODERATE-LOW
• Position value: $${((config.tradingAmount || 62) * 12.5).toFixed(0)} (12.5x leverage)
• Maximum loss if stopped: $${(((Math.abs(analysis.currentPrice - analysis.stopLoss) / analysis.currentPrice) * (config.tradingAmount || 62) * 12.5)).toFixed(0)} (risk controlled)`,
txId: `test_decision_${Date.now()}`,
aiStopLossPercent: analysis.stopLossPercent || 'AI calculated'
};
}
return NextResponse.json({
success: true,
message: 'Test decision generated',
decision: simpleAutomation.lastDecision,
shouldExecute
});
}
return NextResponse.json({
success: false,
message: 'Unknown action'
}, { status: 400 });
} catch (error) {
console.error('Test decision error:', error);
return NextResponse.json({
success: false,
error: 'Failed to generate test decision',
message: error.message
}, { status: 500 });
}
}