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()