Fix automated trading display calculations

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.
This commit is contained in:
mindesbunister
2025-07-20 22:32:16 +02:00
parent 6ce4f364a9
commit 55cea00e5e
22 changed files with 1180 additions and 189 deletions

View File

@@ -1,20 +1,83 @@
import { NextResponse } from 'next/server'
import { automationService } from '@/lib/automation-service-simple'
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
export async function GET() {
try {
const status = await automationService.getStatus()
return NextResponse.json({
success: true,
status: status || null
// 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('Get status error:', error)
return NextResponse.json({
success: false,
error: 'Internal server error',
message: error.message
console.error('Automation status error:', error)
return NextResponse.json({
success: false,
error: 'Failed to get automation status'
}, { status: 500 })
}
}