Add automation timer and individual timeframe analysis display

Features Added:
 Analysis Timer: Shows countdown to next analysis with progress bar
 Individual Timeframe Results: Display analysis for each timeframe separately
 Real-time Countdown: Updates every second showing time until next analysis
 Enhanced Status API: Includes timing data and individual results
 Cycle Counter: Shows current automation cycle number

UI Improvements:
- Analysis Timer panel with countdown and progress bar
- Individual Timeframe Analysis panel showing recommendation and confidence for each timeframe
- Real-time updates of countdown timer
- Visual indicators for BUY/SELL/HOLD recommendations
- Analysis interval display (15m/1h/etc)

Technical Changes:
- Enhanced AutomationService with timing tracking
- Added nextAnalysisIn, analysisInterval, currentCycle to status
- Individual timeframe results stored and displayed
- Real-time countdown effect in React
- Progress bar visualization of analysis cycle
- Enhanced status API endpoint with automation service integration

Example Display:
 15m analysis: SELL (80% confidence)
 1h analysis: HOLD (65% confidence)

Next Analysis In: 14m 32s [Progress Bar]
Cycle #5 | Analysis Interval: 15m
This commit is contained in:
mindesbunister
2025-07-23 14:39:17 +02:00
parent abc94c06e2
commit a09b4bf8b2
3 changed files with 133 additions and 53 deletions

View File

@@ -1,21 +1,12 @@
import { NextResponse } from 'next/server'
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
import { automationService } from '../../../../lib/automation-service-simple'
export async function GET() {
try {
// Get the latest automation session with correct data
const session = await prisma.automationSession.findFirst({
where: {
userId: 'default-user',
symbol: 'SOLUSD',
timeframe: '1h'
},
orderBy: { createdAt: 'desc' }
})
if (!session) {
// Get status from the automation service directly (includes timing and individual results)
const status = await automationService.getStatus()
if (!status) {
return NextResponse.json({
success: true,
status: {
@@ -27,51 +18,18 @@ export async function GET() {
successfulTrades: 0,
winRate: 0,
totalPnL: 0,
errorCount: 0
errorCount: 0,
nextAnalysisIn: 0,
analysisInterval: 3600,
currentCycle: 0,
individualTimeframeResults: []
}
})
}
// Get actual trade data to calculate real statistics
const trades = await prisma.trade.findMany({
where: {
userId: session.userId,
symbol: session.symbol
},
orderBy: { createdAt: 'desc' }
})
const completedTrades = trades.filter(t => t.status === 'COMPLETED')
const successfulTrades = completedTrades.filter(t => {
const profit = t.profit || 0
return profit > 0
})
const totalPnL = completedTrades.reduce((sum, trade) => {
const profit = trade.profit || 0
return sum + profit
}, 0)
const winRate = completedTrades.length > 0 ?
(successfulTrades.length / completedTrades.length * 100) : 0
return NextResponse.json({
success: true,
status: {
isActive: session.status === 'ACTIVE',
mode: session.mode,
symbol: session.symbol,
timeframe: session.timeframe,
totalTrades: completedTrades.length,
successfulTrades: successfulTrades.length,
winRate: Math.round(winRate * 10) / 10, // Round to 1 decimal
totalPnL: Math.round(totalPnL * 100) / 100, // Round to 2 decimals
lastAnalysis: session.lastAnalysis,
lastTrade: session.lastTrade,
nextScheduled: session.nextScheduled,
errorCount: session.errorCount,
lastError: session.lastError
}
status: status
})
} catch (error) {
console.error('Automation status error:', error)