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:
mindesbunister
2025-07-26 22:41:55 +02:00
parent 30eb869ca4
commit 167d7ff5bc
23 changed files with 3233 additions and 52 deletions

77
test-last-decision.js Normal file
View File

@@ -0,0 +1,77 @@
#!/usr/bin/env node
/**
* Test Last Decision Tracking in Automation
*/
const { simpleAutomation } = require('./lib/simple-automation.js');
async function testLastDecisionTracking() {
console.log('🧪 Testing Last Decision Tracking...');
// Set up mock config
simpleAutomation.config = {
symbol: 'SOLUSD',
tradingAmount: 100,
leverage: 1,
mode: 'SIMULATION',
selectedTimeframes: ['60', '240']
};
// Test scenario 1: Low confidence - should not execute
console.log('\n1⃣ Testing Low Confidence Decision...');
const lowConfidenceAnalysis = {
recommendation: 'BUY',
confidence: 65, // Below 75% threshold
reasoning: 'Weak bullish signal with mixed indicators',
currentPrice: 186.50
};
const shouldTrade1 = simpleAutomation.shouldExecuteTrade(lowConfidenceAnalysis);
console.log('Decision:', shouldTrade1 ? 'EXECUTE' : 'NO TRADE');
console.log('Last Decision:', simpleAutomation.stats.lastDecision);
// Test scenario 2: High confidence - should execute (but in simulation)
console.log('\n2⃣ Testing High Confidence Decision...');
const highConfidenceAnalysis = {
recommendation: 'BUY',
confidence: 85, // Above 75% threshold
reasoning: 'Strong bullish breakout with volume confirmation',
currentPrice: 186.50
};
const shouldTrade2 = simpleAutomation.shouldExecuteTrade(highConfidenceAnalysis);
console.log('Decision:', shouldTrade2 ? 'EXECUTE' : 'NO TRADE');
console.log('Last Decision:', simpleAutomation.stats.lastDecision);
// Test scenario 3: Live mode simulation
console.log('\n3⃣ Testing Live Mode Decision...');
simpleAutomation.config.mode = 'LIVE';
const liveAnalysis = {
recommendation: 'SELL',
confidence: 88,
reasoning: 'Strong bearish reversal pattern with RSI divergence',
currentPrice: 186.50
};
const shouldTrade3 = simpleAutomation.shouldExecuteTrade(liveAnalysis);
console.log('Decision:', shouldTrade3 ? 'EXECUTE' : 'NO TRADE');
console.log('Last Decision:', simpleAutomation.stats.lastDecision);
// Test execution tracking
if (shouldTrade3) {
console.log('\n4⃣ Testing Execution Tracking...');
try {
await simpleAutomation.executeTrade(liveAnalysis);
console.log('Updated Last Decision with Execution:', simpleAutomation.stats.lastDecision);
} catch (error) {
console.log('Execution test completed (expected error in test environment)');
}
}
console.log('\n✅ Last Decision Tracking Test Complete!');
console.log('\n📊 Final Status:', simpleAutomation.getStatus());
}
testLastDecisionTracking();