Files
trading_bot_v3/test-mandatory-risk-management-fixed.js
mindesbunister f86359bcdc feat: Complete live trading decisions visibility system
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)
2025-07-28 23:42:28 +02:00

108 lines
3.2 KiB
JavaScript

const { MandatoryRiskManager } = require('./lib/mandatory-risk-manager');
async function testMandatoryRiskManagement() {
console.log('🧪 TESTING MANDATORY RISK MANAGEMENT SYSTEM');
console.log('============================================================');
const riskManager = new MandatoryRiskManager();
// Test 1: Trade with missing SL/TP (should auto-calculate)
console.log('\n📋 TEST 1: Trade with missing SL/TP');
try {
const test1 = {
symbol: 'SOLUSD',
side: 'BUY',
amount: 0.5,
currentPrice: 185,
leverage: 1
};
const result = await riskManager.enforceRiskManagement(test1);
console.log('✅ Test 1 PASSED - Auto-calculated SL/TP');
console.log(` SL: $${result.stopLoss}, TP: $${result.takeProfit}`);
} catch (error) {
console.log('❌ Test 1 FAILED:', error.message);
}
// Test 2: Trade with proper SL/TP (should pass)
console.log('\n📋 TEST 2: Trade with proper SL/TP');
try {
const test2 = {
symbol: 'SOLUSD',
side: 'BUY',
amount: 0.5,
currentPrice: 185,
stopLoss: 182, // 1.6% risk
takeProfit: 192, // 3.8% reward
leverage: 2
};
const result = await riskManager.enforceRiskManagement(test2);
console.log('✅ Test 2 PASSED - Proper SL/TP accepted');
} catch (error) {
console.log('❌ Test 2 FAILED:', error.message);
}
// Test 3: Trade with wrong SL direction (should fail)
console.log('\n📋 TEST 3: Trade with wrong SL direction');
try {
const test3 = {
symbol: 'SOLUSD',
side: 'BUY',
amount: 1,
currentPrice: 185,
stopLoss: 190, // Wrong direction for BUY
takeProfit: 180, // Wrong direction for BUY
leverage: 10
};
await riskManager.enforceRiskManagement(test3);
console.log('❌ Test 3 FAILED - Should have been blocked');
} catch (error) {
console.log('✅ Test 3 PASSED - Correctly blocked:', error.message);
}
// Test 4: High risk trade (should fail)
console.log('\n📋 TEST 4: High risk trade with 20x leverage');
try {
const test4 = {
symbol: 'SOLUSD',
side: 'BUY',
amount: 1,
currentPrice: 185,
stopLoss: 180,
takeProfit: 190,
leverage: 20
};
await riskManager.enforceRiskManagement(test4);
console.log('❌ Test 4 FAILED - Should have been blocked');
} catch (error) {
console.log('✅ Test 4 PASSED - Correctly blocked high risk:', error.message);
}
// Test 5: Poor risk/reward ratio (should fail)
console.log('\n📋 TEST 5: Poor risk/reward ratio');
try {
const test5 = {
symbol: 'SOLUSD',
side: 'BUY',
amount: 1,
currentPrice: 185,
stopLoss: 175, // Large risk
takeProfit: 190, // Small reward
leverage: 10
};
await riskManager.enforceRiskManagement(test5);
console.log('❌ Test 5 FAILED - Should have been blocked');
} catch (error) {
console.log('✅ Test 5 PASSED - Correctly blocked poor ratio:', error.message);
}
console.log('\n🎯 MANDATORY RISK MANAGEMENT TESTING COMPLETE');
console.log('💡 System will now BLOCK trades without proper SL/TP');
}
testMandatoryRiskManagement();