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.
This commit is contained in:
@@ -35,6 +35,7 @@ class SimpleAutomation {
|
||||
this.config = null;
|
||||
this.intervalId = null;
|
||||
this.riskManager = null; // Autonomous AI Risk Manager
|
||||
this.lastDecision = null; // Store last AI decision for UI display
|
||||
this.stats = {
|
||||
totalCycles: 0,
|
||||
totalTrades: 0,
|
||||
@@ -393,6 +394,18 @@ class SimpleAutomation {
|
||||
|
||||
console.log('🎯 TRADE DECISION: ' + recommendation + ' (' + confidence + '%) - Min: ' + minConfidence + '%');
|
||||
|
||||
// Store decision data for UI display
|
||||
this.lastDecision = {
|
||||
timestamp: new Date().toISOString(),
|
||||
recommendation: analysis.recommendation || 'HOLD',
|
||||
confidence: confidence,
|
||||
minConfidenceRequired: minConfidence,
|
||||
reasoning: analysis.reasoning || analysis.summary || 'No detailed reasoning available',
|
||||
executed: false, // Will be updated if trade is executed
|
||||
executionDetails: null,
|
||||
executionError: null
|
||||
};
|
||||
|
||||
return isHighConfidence && isClearDirection;
|
||||
}
|
||||
|
||||
@@ -456,6 +469,7 @@ class SimpleAutomation {
|
||||
|
||||
// Calculate optimal leverage using AI Leverage Calculator
|
||||
let optimalLeverage = 1; // Default fallback
|
||||
let leverageResult = null; // Store leverage calculation result for UI display
|
||||
console.log('🔧 DEBUG: Starting leverage calculation...');
|
||||
try {
|
||||
const AILeverageCalculator = await importAILeverageCalculator();
|
||||
@@ -487,19 +501,23 @@ class SimpleAutomation {
|
||||
|
||||
console.log(`🧮 Calculating optimal leverage: Entry=$${currentPrice}, StopLoss=$${stopLoss}`);
|
||||
|
||||
const leverageResult = AILeverageCalculator.calculateOptimalLeverage({
|
||||
const leverageCalcResult = AILeverageCalculator.calculateOptimalLeverage({
|
||||
accountValue,
|
||||
availableBalance,
|
||||
entryPrice: currentPrice,
|
||||
stopLossPrice: stopLoss,
|
||||
side: side === 'BUY' ? 'long' : 'short',
|
||||
maxLeverageAllowed: 10, // Drift platform max
|
||||
maxLeverageAllowed: 100, // Drift platform max (can go up to 101x)
|
||||
safetyBuffer: 0.10 // 10% safety buffer
|
||||
});
|
||||
|
||||
optimalLeverage = leverageResult.recommendedLeverage;
|
||||
console.log(`🎯 AI Calculated Leverage: ${optimalLeverage.toFixed(1)}x (Risk: ${leverageResult.riskAssessment})`);
|
||||
console.log(`📊 Leverage Details: ${leverageResult.reasoning}`);
|
||||
// Store the result for UI display
|
||||
leverageResult = leverageCalcResult;
|
||||
optimalLeverage = leverageCalcResult.recommendedLeverage;
|
||||
|
||||
optimalLeverage = leverageCalcResult.recommendedLeverage;
|
||||
console.log(`🎯 AI Calculated Leverage: ${optimalLeverage.toFixed(1)}x (Risk: ${leverageCalcResult.riskAssessment})`);
|
||||
console.log(`📊 Leverage Details: ${leverageCalcResult.reasoning}`);
|
||||
} else {
|
||||
console.log('🔧 DEBUG: Skipping leverage calc - Calculator:', !!AILeverageCalculator, 'StopLoss:', !!stopLoss);
|
||||
}
|
||||
@@ -536,8 +554,30 @@ class SimpleAutomation {
|
||||
console.log('✅ TRADE EXECUTED: ' + result.message);
|
||||
this.stats.totalTrades = (this.stats.totalTrades || 0) + 1;
|
||||
this.stats.successfulTrades = (this.stats.successfulTrades || 0) + 1;
|
||||
|
||||
// Update last decision with execution details
|
||||
if (this.lastDecision) {
|
||||
this.lastDecision.executed = true;
|
||||
this.lastDecision.executionDetails = {
|
||||
side: side,
|
||||
amount: tradePayload.amount,
|
||||
leverage: optimalLeverage,
|
||||
currentPrice: analysis.entry?.price || analysis.currentPrice,
|
||||
stopLoss: stopLoss,
|
||||
takeProfit: takeProfit,
|
||||
aiReasoning: leverageResult ? leverageResult.reasoning : 'AI leverage calculation not available',
|
||||
txId: result.transactionId || result.signature,
|
||||
aiStopLossPercent: analysis.stopLossPercent || 'Not specified'
|
||||
};
|
||||
}
|
||||
} else {
|
||||
console.log('❌ TRADE FAILED: ' + result.error);
|
||||
|
||||
// Update last decision with execution error
|
||||
if (this.lastDecision) {
|
||||
this.lastDecision.executed = false;
|
||||
this.lastDecision.executionError = result.error || 'Unknown execution error';
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -556,6 +596,7 @@ class SimpleAutomation {
|
||||
symbol: this.config?.symbol || 'SOLUSD',
|
||||
timeframes: this.config?.selectedTimeframes || [],
|
||||
automationType: 'SIMPLE',
|
||||
lastDecision: this.lastDecision, // Include last AI decision for UI display
|
||||
...this.stats
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user