// Debug P&L calculation const currentPrice = 175.82 // Example trade from database const trade = { side: 'BUY', amount: 2.04, price: 100.3703837088441, status: 'COMPLETED' } console.log('=== P&L CALCULATION DEBUG ===') console.log(`Trade: ${trade.side} ${trade.amount} @ $${trade.price}`) console.log(`Current Price: $${currentPrice}`) console.log(`Price Difference: $${currentPrice - trade.price}`) console.log(`Expected P&L: $${(currentPrice - trade.price) * trade.amount}`) // Check if logic is working const priceChange = trade.side === 'BUY' ? (currentPrice - trade.price) : (trade.price - currentPrice) const realizedPnL = trade.status === 'COMPLETED' ? priceChange * trade.amount : null console.log(`Calculated P&L: $${realizedPnL}`) console.log(`Should be profitable: ${realizedPnL > 0 ? 'YES' : 'NO'}`)