+ {/* Header Controls */}
+
+
+
+
Real-Time Price Monitor
+
+ Tracks active trades and triggers analysis when approaching TP/SL
+
+
+
+
+ {monitoringActive ? 'π’ Active' : 'π΄ Stopped'}
+
+ {monitoringActive ? (
+
+ ) : (
+
+ )}
+
+
+
+ {lastUpdated && (
+
+ Last updated: {new Date(lastUpdated).toLocaleString()}
+
+ )}
+
+
+ {/* Active Alerts */}
+ {alerts.length > 0 && (
+
+
π¨ Active Alerts
+
+ {alerts.map((alert) => (
+
+
+
+ {alert.symbol}
+
+ {alert.alertType.replace('_', ' ')}
+
+
+
+ Current: {formatCurrency(alert.currentPrice)} β Target: {formatCurrency(alert.targetPrice)}
+
+
+
+ ))}
+
+
+ )}
+
+ {/* Current Prices */}
+
+
π° Current Prices
+
+ {Object.entries(prices).map(([symbol, price]) => (
+
+
+ {symbol}
+
+
+
+ {formatCurrency(price)}
+
+
+ ))}
+
+
+
+ {/* Active Trades Monitoring */}
+
+
π Active Trades Monitor
+
+ {monitoringData.length === 0 ? (
+
No active trades to monitor
+ ) : (
+
+ {monitoringData.map((trade) => (
+
+ {/* Trade Header */}
+
+
+
+ {trade.side}
+
+ {trade.symbol}
+
+ {trade.status.replace('_', ' ')}
+
+
+
+
+ Current: {formatCurrency(trade.currentPrice)}
+
+
+ Entry: {formatCurrency(trade.entryPrice)}
+
+
+
+
+ {/* Trade Details Grid */}
+
+
+
P&L
+
+ {formatCurrency(trade.currentPnL)}
+
+
+ {formatPercentage(trade.pnlPercentage)}
+
+
+
+
+
Take Profit
+
{formatCurrency(trade.takeProfit)}
+
+ {trade.distanceToTP ? `${formatDistance(trade.distanceToTP)} away` : 'N/A'}
+
+
+
+
+
Stop Loss
+
{formatCurrency(trade.stopLoss)}
+
+ {trade.distanceToSL ? `${formatDistance(trade.distanceToSL)} away` : 'N/A'}
+
+
+
+
+
Status
+
+ {trade.status === 'CRITICAL' ? 'π¨ Critical' :
+ trade.status === 'APPROACHING_TP' ? 'π― Near TP' :
+ trade.status === 'APPROACHING_SL' ? 'β οΈ Near SL' : 'β
Normal'}
+
+
+
+
+ ))}
+
+ )}
+
+
+ )
+}
diff --git a/lib/automation-service-simple.ts b/lib/automation-service-simple.ts
index b2fff84..eacbfe8 100644
--- a/lib/automation-service-simple.ts
+++ b/lib/automation-service-simple.ts
@@ -3,9 +3,10 @@ import { aiAnalysisService, AnalysisResult } from './ai-analysis'
import { jupiterDEXService } from './jupiter-dex-service'
import { enhancedScreenshotService } from './enhanced-screenshot-simple'
import { TradingViewCredentials } from './tradingview-automation'
-import { progressTracker } from './progress-tracker'
+import { progressTracker, ProgressStatus } from './progress-tracker'
import aggressiveCleanup from './aggressive-cleanup'
import { analysisCompletionFlag } from './analysis-completion-flag'
+import priceMonitorService from './price-monitor'
const prisma = new PrismaClient()
@@ -110,6 +111,31 @@ export class AutomationService {
// Start automation cycle
this.startAutomationCycle()
+ // Start price monitoring
+ await priceMonitorService.startMonitoring()
+
+ // Set up price monitor event listeners for automatic analysis triggering
+ priceMonitorService.on('tp_approach', async (data) => {
+ if (data.symbol === this.config?.symbol) {
+ console.log(`π― TP approach detected for ${data.symbol}, triggering analysis...`)
+ await this.triggerPriceBasedAnalysis('TP_APPROACH', data)
+ }
+ })
+
+ priceMonitorService.on('sl_approach', async (data) => {
+ if (data.symbol === this.config?.symbol) {
+ console.log(`β οΈ SL approach detected for ${data.symbol}, triggering analysis...`)
+ await this.triggerPriceBasedAnalysis('SL_APPROACH', data)
+ }
+ })
+
+ priceMonitorService.on('critical_level', async (data) => {
+ if (data.symbol === this.config?.symbol) {
+ console.log(`π¨ Critical level reached for ${data.symbol}, triggering urgent analysis...`)
+ await this.triggerPriceBasedAnalysis('CRITICAL', data)
+ }
+ })
+
return true
} catch (error) {
console.error('Failed to start automation:', error)
@@ -791,6 +817,14 @@ ${validResults.map(r => `β’ ${r.timeframe}: ${r.analysis?.recommendation} (${r.
this.intervalId = null
}
+ // Stop price monitoring
+ try {
+ await priceMonitorService.stopMonitoring()
+ console.log('π Price monitoring stopped')
+ } catch (error) {
+ console.error('Failed to stop price monitoring:', error)
+ }
+
// Update database session status to STOPPED
if (this.config) {
await prisma.automationSession.updateMany({
@@ -951,6 +985,111 @@ ${validResults.map(r => `β’ ${r.timeframe}: ${r.analysis?.recommendation} (${r.
}
}
}
+
+ /**
+ * Trigger analysis based on price movement alerts
+ */
+ private async triggerPriceBasedAnalysis(
+ trigger: 'TP_APPROACH' | 'SL_APPROACH' | 'CRITICAL',
+ data: any
+ ): Promise