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:
@@ -7,14 +7,22 @@ export async function GET() {
|
||||
const monitoringData = await priceMonitor.getTradeMonitoringData()
|
||||
const activeAlerts = priceMonitor.getActiveAlerts()
|
||||
|
||||
// Get price cache for quick reference
|
||||
const priceData = {}
|
||||
const symbols = [...new Set(monitoringData.map(trade => trade.symbol))]
|
||||
// Get price cache for all common trading symbols + active trade symbols
|
||||
const baseSymbols = ['SOLUSD', 'BTCUSD', 'ETHUSD'] // Always show these
|
||||
const tradeSymbols = monitoringData.map(trade => trade.symbol)
|
||||
const allSymbols = [...new Set([...baseSymbols, ...tradeSymbols])]
|
||||
|
||||
for (const symbol of symbols) {
|
||||
const priceData = {}
|
||||
for (const symbol of allSymbols) {
|
||||
const price = priceMonitor.getCurrentPrice(symbol)
|
||||
if (price) {
|
||||
priceData[symbol] = price
|
||||
} else {
|
||||
// Force fetch price if not cached
|
||||
const fetchedPrice = await priceMonitor.forceUpdatePrice(symbol)
|
||||
if (fetchedPrice) {
|
||||
priceData[symbol] = fetchedPrice
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +33,7 @@ export async function GET() {
|
||||
alerts: activeAlerts,
|
||||
prices: priceData,
|
||||
lastUpdated: new Date().toISOString(),
|
||||
monitoringActive: true
|
||||
monitoringActive: priceMonitor.isMonitoring()
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user