diff --git a/app/api/analytics/last-trade/route.ts b/app/api/analytics/last-trade/route.ts index 22ce144..e1febeb 100644 --- a/app/api/analytics/last-trade/route.ts +++ b/app/api/analytics/last-trade/route.ts @@ -18,6 +18,16 @@ export async function GET() { } // Format the trade data for the frontend + // For open positions, use currentSize from Position Manager state if available + const configSnapshot = trade.configSnapshot as any + const positionManagerState = configSnapshot?.positionManagerState + const currentSize = positionManagerState?.currentSize + + // Use currentSize for open positions (after TP1), fallback to original positionSizeUSD + const displaySize = trade.exitReason === null && currentSize + ? currentSize + : trade.positionSizeUSD + const formattedTrade = { id: trade.id, symbol: trade.symbol, @@ -29,7 +39,7 @@ export async function GET() { exitReason: trade.exitReason || undefined, realizedPnL: trade.realizedPnL || undefined, realizedPnLPercent: trade.realizedPnLPercent || undefined, - positionSizeUSD: trade.positionSizeUSD, + positionSizeUSD: displaySize, // Use current size for open positions leverage: trade.leverage, stopLossPrice: trade.stopLossPrice, takeProfit1Price: trade.takeProfit1Price,