Files
trading_bot_v3/generate-test-decision.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

114 lines
4.0 KiB
JavaScript

// Generate a test AI decision to display reasoning panel
async function generateTestDecision() {
console.log('🧪 Generating Test AI Decision for UI Display...\n');
try {
// Create a realistic analysis with detailed reasoning
const testAnalysis = {
recommendation: 'STRONG BUY',
confidence: 89,
reasoning: `🎯 BULLISH CONVERGENCE DETECTED:
📈 Technical Analysis:
• RSI bounced from oversold (28→54) showing strong recovery momentum
• MACD histogram turning positive with bullish crossover confirmed
• Price broke above key resistance at $185.40 with 3x normal volume
• 20 EMA (184.92) providing strong support, price trending above all major EMAs
📊 Market Structure:
• Higher lows pattern intact since yesterday's session
• Volume profile shows accumulation at current levels
• Order book depth favoring buyers (67% buy-side liquidity)
⚡ Entry Trigger:
• Breakout candle closed above $186.00 resistance with conviction
• Next resistance target: $189.75 (2.1% upside potential)
• Risk/Reward ratio: 1:2.3 (excellent risk management setup)
🛡️ Risk Management:
• Stop loss at $184.20 (1.0% below entry) protects against false breakout
• Position sizing optimized for 2% account risk tolerance`,
summary: 'Multi-timeframe bullish convergence with strong momentum confirmation',
stopLoss: 184.20,
takeProfit: 189.75,
entry: { price: 186.12 },
currentPrice: 186.12,
stopLossPercent: '1.0% protective stop'
};
// Send test analysis to automation system
const response = await fetch('http://localhost:9001/api/automation/test-decision', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
action: 'generate_test_decision',
analysis: testAnalysis,
config: {
selectedTimeframes: ['15m', '1h', '4h'],
symbol: 'SOLUSD',
mode: 'LIVE',
enableTrading: true
}
})
});
if (response.ok) {
const result = await response.json();
console.log('✅ Test decision generated:', result);
} else {
// Fallback: directly inject into automation if API doesn't exist
console.log('📝 Using direct injection method...');
const { simpleAutomation } = require('./lib/simple-automation.js');
// Set up test config
simpleAutomation.config = {
selectedTimeframes: ['15m', '1h', '4h'],
symbol: 'SOLUSD',
mode: 'LIVE',
enableTrading: true,
tradingAmount: 62
};
// Generate decision
const shouldExecute = simpleAutomation.shouldExecuteTrade(testAnalysis);
if (shouldExecute && simpleAutomation.lastDecision) {
// Add execution details
simpleAutomation.lastDecision.executed = true;
simpleAutomation.lastDecision.executionDetails = {
side: 'BUY',
amount: 62,
leverage: 12.5,
currentPrice: 186.12,
stopLoss: 184.20,
takeProfit: 189.75,
aiReasoning: `AI calculated 12.5x leverage based on:
• Stop loss distance: 1.0% (tight risk control)
• Account balance: $62.08 available
• Safety buffer: 8% (liquidation at $171.45 - safe margin)
• Risk assessment: MODERATE-LOW
• Position value: $775 (12.5x of $62)
• Maximum loss if stopped: $119 (1.92% of account)`,
txId: `test_${Date.now()}`,
aiStopLossPercent: '1.0% protective stop'
};
}
console.log('✅ Test decision injected successfully!');
console.log(`📊 Decision stored: ${!!simpleAutomation.lastDecision}`);
console.log(`⚡ Executed: ${simpleAutomation.lastDecision?.executed}`);
}
console.log('\n🎯 Test completed! Check the automation-v2 page to see the reasoning panel.');
console.log('📝 The AI reasoning should now be prominently displayed.');
} catch (error) {
console.error('❌ Error generating test decision:', error.message);
}
}
generateTestDecision().catch(console.error);