Fixed position size calculation: 00 investment now shows 00 position (was 04.76) Fixed token amount display: Now shows correct tokens (~0.996) for 00 investment (was 2.04) Corrected API route: /api/automation/analysis-details now returns 200 instead of 405 Technical changes: - Updated route calculation logic: tradingAmount / trade.price for correct token amounts - Fixed displayPositionSize to show intended investment amount - Used Docker Compose v2 for container management - Resolved Next.js module export issues The API now correctly displays trade details matching user investment intentions.
84 lines
2.3 KiB
JavaScript
84 lines
2.3 KiB
JavaScript
import { NextResponse } from 'next/server'
|
|
import { PrismaClient } from '@prisma/client'
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
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) {
|
|
return NextResponse.json({
|
|
success: true,
|
|
status: {
|
|
isActive: false,
|
|
mode: 'SIMULATION',
|
|
symbol: 'SOLUSD',
|
|
timeframe: '1h',
|
|
totalTrades: 0,
|
|
successfulTrades: 0,
|
|
winRate: 0,
|
|
totalPnL: 0,
|
|
errorCount: 0
|
|
}
|
|
})
|
|
}
|
|
|
|
// 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
|
|
}
|
|
})
|
|
} catch (error) {
|
|
console.error('Automation status error:', error)
|
|
return NextResponse.json({
|
|
success: false,
|
|
error: 'Failed to get automation status'
|
|
}, { status: 500 })
|
|
}
|
|
}
|