Files
trading_bot_v3/test-pnl-direct.js
mindesbunister 55cea00e5e 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.
2025-07-20 22:32:16 +02:00

39 lines
1.1 KiB
JavaScript

const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
async function testPnLCalculation() {
try {
const trades = await prisma.trade.findMany({
orderBy: { createdAt: 'desc' },
take: 3
})
const currentPrice = 175.82
console.log('=== P&L CALCULATION TEST ===')
trades.forEach((trade, i) => {
const pnl = trade.status === 'COMPLETED' ?
((trade.side === 'BUY' ? (currentPrice - trade.price) * trade.amount : (trade.price - currentPrice) * trade.amount)) :
0
console.log(`\nTrade ${i + 1}:`)
console.log(` Side: ${trade.side}`)
console.log(` Amount: ${trade.amount}`)
console.log(` Price: ${trade.price}`)
console.log(` Status: ${trade.status}`)
console.log(` Current Price: ${currentPrice}`)
console.log(` Price Diff: ${currentPrice - trade.price}`)
console.log(` Raw P&L: ${pnl}`)
console.log(` Formatted P&L: ${pnl.toFixed(2)}`)
})
} catch (error) {
console.error('Error:', error)
} finally {
await prisma.$disconnect()
}
}
testPnLCalculation()