🔧 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

48
fix-system-user.js Normal file
View File

@@ -0,0 +1,48 @@
const { PrismaClient } = require('@prisma/client');
async function fixSystemUser() {
const prisma = new PrismaClient({
datasources: {
db: {
url: 'file:./prisma/dev.db'
}
}
});
try {
// Check if system user exists
let systemUser = await prisma.users.findUnique({
where: { id: 'system' }
});
if (!systemUser) {
console.log('🔧 Creating system user for Enhanced Risk Manager...');
systemUser = await prisma.users.create({
data: {
id: 'system',
email: 'system@enhanced-risk-manager.ai',
name: 'Enhanced Risk Manager System',
createdAt: new Date(),
updatedAt: new Date()
}
});
console.log('✅ System user created successfully!');
} else {
console.log('✅ System user already exists');
}
// Check current users
const users = await prisma.users.findMany();
console.log(`📊 Total users in database: ${users.length}`);
users.forEach(user => {
console.log(` - ${user.id}: ${user.email}`);
});
} catch (error) {
console.error('❌ Error:', error.message);
} finally {
await prisma.$disconnect();
}
}
fixSystemUser();