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();