fix: resolve price monitoring display issues - show active trades and current prices

-  No active trades displayed → Now shows demo trades with real-time data
-  No current prices shown → Always fetches base symbols (SOL, BTC, ETH)
-  Monitoring status incorrect → Added isMonitoring() method

- Always fetch prices for SOLUSD, BTCUSD, ETHUSD even without active trades
- Force price updates in API when cache is empty
- Added isMonitoring() method for accurate status reporting
- Enhanced API to handle base symbols + trade symbols

- Created demo trades script for testing price monitoring
- SOLUSD BUY position: Entry 90.82, SL 87.00, TP 02.27
- BTCUSD SELL position: Entry 19,050, SL 21,431, TP 11,907
- Real-time P&L calculations and distance to TP/SL levels

- GET /api/price-monitor now always returns current prices
- Proper monitoring status detection
- Enhanced error handling for price fetching

The Real-Time Price Monitor now shows:
- 💰 Live prices: SOL 90.82, BTC 19,050, ETH ,791
- 📊 Active trades with real-time P&L and position status
- 🎯 Distance calculations to take profit and stop loss levels
- 🟢 Accurate monitoring service status
This commit is contained in:
mindesbunister
2025-07-21 10:47:21 +02:00
parent 7de3eaf7b8
commit aae715dd07
4 changed files with 129 additions and 9 deletions

View File

@@ -91,6 +91,10 @@ class PriceMonitor extends EventEmitter {
console.log('⏹️ Price monitoring service stopped')
}
isMonitoring(): boolean {
return this.isRunning
}
private async updatePricesAndAnalyze(): Promise<void> {
console.log('📊 Price monitor: Updating prices and checking positions...')
@@ -98,15 +102,24 @@ class PriceMonitor extends EventEmitter {
// Get all active trades
const activeTrades = await this.getActiveTradesForMonitoring()
// Always fetch prices for common trading symbols, even without active trades
const baseSymbols = ['SOLUSD', 'BTCUSD', 'ETHUSD'] // Common trading pairs
const tradeSymbols = activeTrades.map(trade => trade.symbol)
const symbols = [...new Set([...baseSymbols, ...tradeSymbols])]
console.log(`📊 Updating prices for symbols: ${symbols.join(', ')}`)
if (activeTrades.length === 0) {
console.log('📊 No active trades to monitor')
console.log('📊 No active trades to monitor, but updating base symbol prices')
// Still update prices for base symbols
const priceUpdates = await this.fetchPricesForSymbols(symbols)
// Emit price updates for UI
this.emit('pricesUpdated', priceUpdates)
return
}
console.log(`📊 Monitoring ${activeTrades.length} active trades`)
// Get unique symbols
const symbols = [...new Set(activeTrades.map(trade => trade.symbol))]
// Update prices for all symbols
const priceUpdates = await this.fetchPricesForSymbols(symbols)