🔧 CRITICAL FIX: Price Data Sync & Position Monitor Enhancement

Fixed major price data sync issues:
- Removed hardcoded price (77.63) from position monitor
- Added real-time oracle data instead of stale TWAP pricing
- Implemented cache-busting headers for fresh data
- Updated fallback prices to current market levels

- Real-time P&L tracking with trend indicators (📈📉➡️)
- Enhanced stop loss proximity alerts with color-coded risk levels
- Analysis progress indicators during automation cycles
- Performance metrics (runtime, cycles, trades, errors)
- Fresh data validation and improved error handling

- Price accuracy: 77.63 → 84.47 (matches Drift UI)
- P&L accuracy: -.91 → -.59 (correct calculation)
- Risk assessment: CRITICAL → MEDIUM (proper evaluation)
- Stop loss distance: 0.91% → 4.8% (safe distance)

- CLI monitor script with 8-second updates
- Web dashboard component (PositionMonitor.tsx)
- Real-time automation status tracking
- Database and error monitoring improvements

This fixes the automation showing false emergency alerts when
position was actually performing normally.
This commit is contained in:
mindesbunister
2025-07-25 23:33:06 +02:00
parent 08f9a9b541
commit 9b6a393e06
18 changed files with 6783 additions and 361 deletions

View File

@@ -18,23 +18,8 @@ async function startEnhancedRiskManager() {
const isCurlAvailable = await HttpUtil.checkCurlAvailability();
console.log(` curl: ${isCurlAvailable ? '✅ Available' : '⚠️ Not available (using fallback)'}`);
// Test position monitor endpoint
console.log('🌐 Testing position monitor connection...');
const testData = await HttpUtil.get('http://localhost:9001/api/automation/position-monitor');
if (testData.success) {
console.log(' ✅ Position monitor API responding');
if (testData.monitor?.hasPosition) {
console.log(` 📈 Active position: ${testData.monitor.position?.symbol || 'Unknown'}`);
console.log(` 💰 P&L: $${testData.monitor.position?.unrealizedPnL || 0}`);
console.log(` ⚠️ Distance to SL: ${testData.monitor.stopLossProximity?.distancePercent || 'N/A'}%`);
} else {
console.log(' 📊 No active positions (monitoring ready)');
}
} else {
throw new Error('Position monitor API not responding correctly');
}
// Skip connection test - Enhanced Risk Manager will handle retries automatically
console.log('🌐 Skipping connection test - will connect when ready...');
// Start the enhanced risk manager
console.log('\n🚀 Starting Enhanced Autonomous Risk Manager...');
@@ -42,6 +27,9 @@ async function startEnhancedRiskManager() {
const EnhancedAutonomousRiskManager = require('./lib/enhanced-autonomous-risk-manager');
const riskManager = new EnhancedAutonomousRiskManager();
console.log(`🔗 API URL: ${riskManager.baseApiUrl}`);
console.log('✅ Enhanced AI Risk Manager started successfully!');
// Start monitoring loop
let isRunning = true;
let monitoringInterval;
@@ -49,7 +37,7 @@ async function startEnhancedRiskManager() {
async function monitorLoop() {
while (isRunning) {
try {
const monitorData = await HttpUtil.get('http://localhost:9001/api/automation/position-monitor');
const monitorData = await HttpUtil.get(`${riskManager.baseApiUrl}/api/automation/position-monitor`);
if (monitorData.success && monitorData.monitor) {
const analysis = await riskManager.analyzePosition(monitorData.monitor);