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:
@@ -891,70 +891,12 @@ class SimpleAutomation {
|
||||
console.warn('⚠️ Pre-trade cleanup error:', cleanupError.message);
|
||||
}
|
||||
|
||||
// 🛡️ MANDATORY RISK MANAGEMENT - NO TRADE WITHOUT PROPER SL/TP
|
||||
console.log('🛡️ ENFORCING MANDATORY RISK MANAGEMENT...');
|
||||
try {
|
||||
const { MandatoryRiskManager } = require('./mandatory-risk-manager');
|
||||
const riskManager = new MandatoryRiskManager();
|
||||
|
||||
// Get current price for risk calculations
|
||||
const currentPrice = analysis.entry?.price || analysis.currentPrice || 185; // fallback
|
||||
|
||||
// Enforce mandatory risk management
|
||||
const validatedTrade = await riskManager.enforceRiskManagement({
|
||||
symbol: this.config.symbol,
|
||||
side: side,
|
||||
amount: this.config.tradingAmount || 49,
|
||||
currentPrice: currentPrice,
|
||||
stopLoss: stopLoss,
|
||||
takeProfit: takeProfit,
|
||||
leverage: optimalLeverage
|
||||
});
|
||||
|
||||
// Update with validated/calculated SL/TP
|
||||
stopLoss = validatedTrade.stopLoss;
|
||||
takeProfit = validatedTrade.takeProfit;
|
||||
|
||||
console.log('✅ MANDATORY RISK MANAGEMENT PASSED');
|
||||
console.log(` Final SL: $${stopLoss.toFixed(2)}`);
|
||||
console.log(` Final TP: $${takeProfit.toFixed(2)}`);
|
||||
|
||||
} catch (riskError) {
|
||||
console.error('🚫 TRADE BLOCKED BY RISK MANAGEMENT:', riskError.message);
|
||||
|
||||
// Log the blocked decision for live analysis panel
|
||||
try {
|
||||
const baseUrl = process.env.INTERNAL_API_URL || 'http://localhost:3000';
|
||||
await fetch(`${baseUrl}/api/automation/live-decisions`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
type: 'TRADE_BLOCKED',
|
||||
action: side?.toUpperCase() || 'UNKNOWN',
|
||||
symbol: this.config.symbol,
|
||||
blocked: true,
|
||||
blockReason: riskError.message,
|
||||
confidence: analysis.confidence || 0,
|
||||
entryPrice: analysis.entry?.price || analysis.currentPrice || 0,
|
||||
stopLoss: analysis.exit?.stopLoss || null,
|
||||
takeProfit: analysis.exit?.takeProfit || null,
|
||||
leverage: optimalLeverage,
|
||||
reasoning: analysis.reasoning || 'No reasoning provided',
|
||||
timestamp: new Date().toISOString(),
|
||||
cycle: this.stats.totalCycles
|
||||
})
|
||||
});
|
||||
} catch (logError) {
|
||||
console.warn('⚠️ Failed to log blocked decision:', logError.message);
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
error: 'Trade blocked by mandatory risk management',
|
||||
details: riskError.message,
|
||||
riskManagementBlocked: true
|
||||
};
|
||||
}
|
||||
// ✅ PROCEED DIRECTLY TO TRADE EXECUTION (Risk management removed)
|
||||
console.log('<EFBFBD> PROCEEDING WITH TRADE EXECUTION...');
|
||||
console.log(` Entry: $${analysis.entry?.price || analysis.currentPrice || 0}`);
|
||||
console.log(` SL: $${stopLoss?.toFixed(2) || 'N/A'}`);
|
||||
console.log(` TP: $${takeProfit?.toFixed(2) || 'N/A'}`);
|
||||
console.log(` Leverage: ${optimalLeverage}x`);
|
||||
|
||||
// Use the trading API with proper fields for Drift
|
||||
const tradePayload = {
|
||||
|
||||
Reference in New Issue
Block a user