🔧 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:
66
test-intelligent-screenshot-trigger.js
Normal file
66
test-intelligent-screenshot-trigger.js
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Test Enhanced Risk Manager with Intelligent Screenshot Analysis
|
||||
*
|
||||
* Simulates different distance scenarios to test when screenshot analysis triggers
|
||||
*/
|
||||
|
||||
console.log('🧪 TESTING INTELLIGENT SCREENSHOT ANALYSIS TRIGGERING');
|
||||
console.log('='.repeat(70));
|
||||
|
||||
async function testScreenshotTrigger() {
|
||||
const EnhancedAutonomousRiskManager = require('./lib/enhanced-autonomous-risk-manager');
|
||||
const riskManager = new EnhancedAutonomousRiskManager();
|
||||
|
||||
console.log('🔧 Risk Manager Configuration:');
|
||||
console.log(` Screenshot Analysis Threshold: ${riskManager.screenshotAnalysisThreshold}%`);
|
||||
console.log(` Analysis Interval: ${riskManager.screenshotAnalysisInterval / 1000 / 60} minutes`);
|
||||
console.log(` API URL: ${riskManager.baseApiUrl}`);
|
||||
|
||||
// Test scenarios
|
||||
const testScenarios = [
|
||||
{ distance: 8.5, description: 'Safe position - far from SL' },
|
||||
{ distance: 4.2, description: 'Medium risk - approaching threshold' },
|
||||
{ distance: 2.8, description: 'High risk - should trigger screenshot' },
|
||||
{ distance: 1.5, description: 'Critical risk - should trigger screenshot' },
|
||||
{ distance: 0.8, description: 'Emergency - should trigger screenshot' }
|
||||
];
|
||||
|
||||
console.log('\n📊 Testing Screenshot Trigger Logic:');
|
||||
console.log('='.repeat(50));
|
||||
|
||||
for (const scenario of testScenarios) {
|
||||
const shouldTrigger = riskManager.shouldTriggerScreenshotAnalysis(scenario.distance);
|
||||
const emoji = shouldTrigger ? '📸' : '⏭️';
|
||||
const action = shouldTrigger ? 'TRIGGER ANALYSIS' : 'numerical only';
|
||||
|
||||
console.log(`${emoji} ${scenario.distance}% - ${scenario.description}: ${action}`);
|
||||
|
||||
// Simulate time passing for interval testing
|
||||
if (shouldTrigger) {
|
||||
console.log(` ⏰ Last analysis time updated to prevent immediate re-trigger`);
|
||||
riskManager.lastScreenshotAnalysis = new Date();
|
||||
|
||||
// Test immediate re-trigger (should be blocked)
|
||||
const immediateRetrigger = riskManager.shouldTriggerScreenshotAnalysis(scenario.distance);
|
||||
console.log(` 🔄 Immediate re-trigger test: ${immediateRetrigger ? 'ALLOWED' : 'BLOCKED (correct)'}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('\n🎯 OPTIMAL STRATEGY SUMMARY:');
|
||||
console.log('✅ Safe positions (>3%): Fast numerical monitoring only');
|
||||
console.log('📸 Risk positions (<3%): Trigger intelligent chart analysis');
|
||||
console.log('⏰ Rate limiting: Max 1 analysis per 5 minutes');
|
||||
console.log('🧠 Smart decisions: Combine numerical + visual data');
|
||||
|
||||
console.log('\n💡 BENEFITS:');
|
||||
console.log('• Fast 30-second monitoring for normal conditions');
|
||||
console.log('• Detailed chart analysis only when needed');
|
||||
console.log('• Prevents screenshot analysis spam');
|
||||
console.log('• Smarter risk decisions with visual confirmation');
|
||||
console.log('• Optimal resource usage');
|
||||
}
|
||||
|
||||
// Test the triggering logic
|
||||
testScreenshotTrigger().catch(console.error);
|
||||
Reference in New Issue
Block a user