fix: Add proper analysis timer functionality to automation status
FIXES: - Add nextAnalysisIn and analysisInterval fields to AutomationStatus interface - Calculate countdown timer based on nextScheduled time from database - Update nextScheduled time in database at start of each automation cycle - Frontend timer will now show proper countdown instead of 'Analyzing now...' - Analysis Timer will show: '4:32' (next analysis in 4 min 32 sec) - Progress bar will display proper countdown visualization - Timer updates every second showing time until next analysis cycle
This commit is contained in:
@@ -37,6 +37,9 @@ export interface AutomationStatus {
|
|||||||
nextScheduled?: Date
|
nextScheduled?: Date
|
||||||
errorCount: number
|
errorCount: number
|
||||||
lastError?: string
|
lastError?: string
|
||||||
|
nextAnalysisIn?: number // Seconds until next analysis
|
||||||
|
analysisInterval?: number // Analysis interval in seconds
|
||||||
|
currentCycle?: number // Current automation cycle
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AutomationService {
|
export class AutomationService {
|
||||||
@@ -184,6 +187,26 @@ export class AutomationService {
|
|||||||
try {
|
try {
|
||||||
console.log(`🔍 Running automation cycle for ${this.config.symbol} ${this.config.timeframe}`)
|
console.log(`🔍 Running automation cycle for ${this.config.symbol} ${this.config.timeframe}`)
|
||||||
|
|
||||||
|
// Update next scheduled time in database for timer display
|
||||||
|
const intervalMs = this.getIntervalFromTimeframe(this.config.timeframe)
|
||||||
|
const nextScheduled = new Date(Date.now() + intervalMs)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await prisma.automationSession.updateMany({
|
||||||
|
where: {
|
||||||
|
userId: this.config.userId,
|
||||||
|
status: 'ACTIVE'
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
nextScheduled: nextScheduled,
|
||||||
|
lastAnalysis: new Date()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log(`⏰ Next analysis scheduled for: ${nextScheduled.toLocaleTimeString()}`)
|
||||||
|
} catch (dbError) {
|
||||||
|
console.error('Failed to update next scheduled time:', dbError)
|
||||||
|
}
|
||||||
|
|
||||||
// Step 1: Check daily trade limit
|
// Step 1: Check daily trade limit
|
||||||
const todayTrades = await this.getTodayTradeCount(this.config.userId)
|
const todayTrades = await this.getTodayTradeCount(this.config.userId)
|
||||||
if (todayTrades >= this.config.maxDailyTrades) {
|
if (todayTrades >= this.config.maxDailyTrades) {
|
||||||
@@ -1132,6 +1155,16 @@ ${validResults.map(r => `• ${r.timeframe}: ${r.analysis?.recommendation} (${r.
|
|||||||
console.log('🔄 Found active session but automation not running, attempting auto-restart...')
|
console.log('🔄 Found active session but automation not running, attempting auto-restart...')
|
||||||
await this.autoRestartFromSession(session)
|
await this.autoRestartFromSession(session)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate next analysis timing
|
||||||
|
const analysisInterval = 300 // 5 minutes in seconds
|
||||||
|
let nextAnalysisIn = 0
|
||||||
|
|
||||||
|
if (this.isRunning && session.nextScheduled) {
|
||||||
|
const nextScheduledTime = new Date(session.nextScheduled).getTime()
|
||||||
|
const currentTime = Date.now()
|
||||||
|
nextAnalysisIn = Math.max(0, Math.floor((nextScheduledTime - currentTime) / 1000))
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isActive: this.isRunning && this.config !== null,
|
isActive: this.isRunning && this.config !== null,
|
||||||
@@ -1146,7 +1179,10 @@ ${validResults.map(r => `• ${r.timeframe}: ${r.analysis?.recommendation} (${r.
|
|||||||
lastError: session.lastError || undefined,
|
lastError: session.lastError || undefined,
|
||||||
lastAnalysis: session.lastAnalysis || undefined,
|
lastAnalysis: session.lastAnalysis || undefined,
|
||||||
lastTrade: session.lastTrade || undefined,
|
lastTrade: session.lastTrade || undefined,
|
||||||
nextScheduled: session.nextScheduled || undefined
|
nextScheduled: session.nextScheduled || undefined,
|
||||||
|
nextAnalysisIn: nextAnalysisIn,
|
||||||
|
analysisInterval: analysisInterval,
|
||||||
|
currentCycle: session.totalTrades || 0
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to get automation status:', error)
|
console.error('Failed to get automation status:', error)
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user