fix: Remove problematic mandatory risk management blocker
- Completely removed MandatoryRiskManager from automation flow - Eliminated confusing 'LONG position' errors for SELL trades - Removed blocker that was preventing valid AI trading decisions - AI can now execute trades based on its own analysis FIXED ISSUES: - No more 'Stop-loss for LONG position must be BELOW current price' for SELL trades - No more risk validation blocking valid trades - AI decisions now proceed directly to execution - Successful trades still logged to live decisions panel 'man that blocker is nonsense. the ai is trying to sell and the blocker is talking stuff about a long position. remove that blocker system. it is not working' AUTOMATION NOW WORKS AS INTENDED: - AI analyzes market conditions - AI determines BUY/SELL decision with SL/TP - Trade executes directly without interference - Live decisions panel shows actual executed trades - No more false blocking of valid trading signals The AI trading system is now free to execute its decisions without the broken risk management interference.
This commit is contained in:
112
test-risk-management-integration.js
Normal file
112
test-risk-management-integration.js
Normal file
@@ -0,0 +1,112 @@
|
||||
const https = require('https');
|
||||
|
||||
function makeRequest(url, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const urlObj = new URL(url);
|
||||
const reqOptions = {
|
||||
hostname: urlObj.hostname,
|
||||
port: urlObj.port,
|
||||
path: urlObj.pathname,
|
||||
method: options.method || 'GET',
|
||||
headers: options.headers || {}
|
||||
};
|
||||
|
||||
const req = https.request(reqOptions, (res) => {
|
||||
let data = '';
|
||||
res.on('data', (chunk) => data += chunk);
|
||||
res.on('end', () => {
|
||||
try {
|
||||
resolve({ status: res.statusCode, json: () => JSON.parse(data) });
|
||||
} catch (e) {
|
||||
resolve({ status: res.statusCode, text: () => data });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', reject);
|
||||
if (options.body) req.write(options.body);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
async function testFixedRiskManagement() {
|
||||
console.log('🧪 Testing FIXED risk management integration...');
|
||||
|
||||
// Test 1: Valid BUY trade (should NOT be blocked)
|
||||
console.log('\n📝 Test 1: Valid BUY trade...');
|
||||
const validTrade = {
|
||||
action: 'BUY',
|
||||
symbol: 'SOLUSD',
|
||||
confidence: 85,
|
||||
entryPrice: 245.50,
|
||||
stopLoss: 243.00, // ✅ BELOW entry (correct for BUY)
|
||||
takeProfit: 250.00, // ✅ ABOVE entry (correct for BUY)
|
||||
leverage: 5,
|
||||
amount: 100,
|
||||
reasoning: 'Valid BUY trade with proper risk management - SL below entry, TP above entry'
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch('http://localhost:9001/api/automation/live-decisions', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(validTrade)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
console.log('✅ Valid trade result:', result.success ? 'ACCEPTED' : 'BLOCKED');
|
||||
if (result.decision?.blocked) {
|
||||
console.log('❌ Block reason:', result.decision.blockReason);
|
||||
} else {
|
||||
console.log('✅ Trade would be executed with proper risk management');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Error testing valid trade:', error.message);
|
||||
}
|
||||
|
||||
// Test 2: Invalid BUY trade (should be blocked)
|
||||
console.log('\n📝 Test 2: Invalid BUY trade (wrong SL direction)...');
|
||||
const invalidTrade = {
|
||||
action: 'BUY',
|
||||
symbol: 'SOLUSD',
|
||||
confidence: 85,
|
||||
entryPrice: 245.50,
|
||||
stopLoss: 248.00, // ❌ ABOVE entry (wrong for BUY)
|
||||
takeProfit: 250.00,
|
||||
leverage: 5,
|
||||
amount: 100,
|
||||
reasoning: 'Invalid BUY trade - stop loss in wrong direction (should be blocked)'
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch('http://localhost:9001/api/automation/live-decisions', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(invalidTrade)
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
console.log('✅ Invalid trade result:', result.decision?.blocked ? 'CORRECTLY BLOCKED' : 'INCORRECTLY ACCEPTED');
|
||||
if (result.decision?.blocked) {
|
||||
console.log('✅ Block reason:', result.decision.blockReason);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Error testing invalid trade:', error.message);
|
||||
}
|
||||
|
||||
// Get final decisions
|
||||
console.log('\n📋 Current live decisions:');
|
||||
try {
|
||||
const response = await fetch('http://localhost:9001/api/automation/live-decisions');
|
||||
const data = await response.json();
|
||||
console.log(`📊 Total decisions: ${data.decisions?.length || 0}`);
|
||||
data.decisions?.slice(0, 2).forEach((decision, i) => {
|
||||
console.log(`${i + 1}. ${decision.action} ${decision.symbol}: ${decision.blocked ? '🚫 BLOCKED' : '✅ VALID'}`);
|
||||
if (decision.blocked) console.log(` Reason: ${decision.blockReason}`);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('❌ Error getting decisions:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
testFixedRiskManagement();
|
||||
Reference in New Issue
Block a user