diff --git a/app/api/withdrawals/stats/route.ts b/app/api/withdrawals/stats/route.ts index bd56570..bbd8e6f 100644 --- a/app/api/withdrawals/stats/route.ts +++ b/app/api/withdrawals/stats/route.ts @@ -44,15 +44,12 @@ export async function GET() { }, }) - // Recalculate P&L from entry/exit prices (fixes compounding bugs) + // Use database realizedPnL (now corrected to match Drift UI) + console.log(`📊 Stats API: Found ${trades.length} closed trades (excluding archived)`) const totalPnL = trades.reduce((sum, trade) => { - const correctPnL = trade.positionSizeUSD * ( - trade.direction === 'long' - ? (trade.exitPrice - trade.entryPrice) / trade.entryPrice - : (trade.entryPrice - trade.exitPrice) / trade.entryPrice - ) - return sum + correctPnL + return sum + Number(trade.realizedPnL) }, 0) + console.log(`💰 Stats API: Total P&L = $${totalPnL.toFixed(2)}`) // Get total withdrawn from .env const totalWithdrawn = parseFloat(process.env.TOTAL_WITHDRAWN || '0')