Files
trading_bot_v3/show-risk-management.js
mindesbunister 4780367e79 fix: add missing trades and provide risk management recommendations
Added missing 1.04 WIN and -/bin/bash.14 LOSS trades to database
 AI Learning System now shows 3 trades: 67% win rate, 7.03 P&L
 Created emergency risk management tools for unprotected positions
 Current SHORT position needs manual stop-loss/take-profit orders

Summary: All 3 trades now visible in AI Learning dashboard
Risk: Current SHORT (+.45) needs protection at 95.59 stop-loss
2025-07-28 21:25:30 +02:00

61 lines
2.3 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Simple risk management for current position
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function addRiskManagement() {
try {
console.log('🛡️ Adding risk management for current position...');
// Check if there's an active position
const response = await fetch('http://localhost:9001/api/automation/position-monitor');
const data = await response.json();
if (!data.monitor.hasPosition) {
console.log('✅ No active position - no risk management needed');
return;
}
const position = data.monitor.position;
console.log('📊 Position:', {
side: position.side,
size: position.size,
entry: position.entryPrice,
current: position.currentPrice,
pnl: position.unrealizedPnl
});
if (position.side === 'short') {
console.log('📝 For SHORT position:');
console.log(' - Stop-loss should be ABOVE entry price (to limit losses)');
console.log(' - Take-profit should be BELOW entry price (to secure gains)');
const stopLoss = (position.entryPrice * 1.05).toFixed(2); // 5% above entry
const takeProfit = (position.entryPrice * 0.97).toFixed(2); // 3% below entry
console.log(` - Recommended Stop-Loss: $${stopLoss}`);
console.log(` - Recommended Take-Profit: $${takeProfit}`);
console.log(` - Current P&L: $${position.unrealizedPnl.toFixed(2)}`);
// Store recommendation in database for manual execution
const recommendationId = `risk_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
console.log('💾 Storing risk management recommendation...');
console.log('⚠️ MANUAL ACTION REQUIRED:');
console.log(' 1. Place stop-loss order: LONG 8.86 SOL @ $195.59 (trigger)');
console.log(' 2. Place take-profit order: LONG 8.86 SOL @ $180.68 (limit)');
console.log(' 3. Both orders should have "reduceOnly: true"');
} else {
console.log(' Position is LONG - different risk management logic needed');
}
} catch (error) {
console.error('❌ Risk management error:', error.message);
}
}
// Use node's built-in fetch (Node 18+) or fallback
const fetch = globalThis.fetch || require('node-fetch');
addRiskManagement();