fix: Analytics now shows current runner size instead of original position size

- Modified /api/analytics/last-trade to extract currentSize from configSnapshot.positionManagerState
- For open positions (exitReason === null), displays runner size after TP1 instead of original positionSizeUSD
- Falls back to original positionSizeUSD for closed positions or when Position Manager state unavailable
- Fixes UI showing 2.54 when actual runner is 2.59
- Provides accurate exposure visibility on analytics dashboard

Example: Position opens at 2.54, TP1 closes 70% → runner 2.59 → UI now shows 2.59
This commit is contained in:
mindesbunister
2025-11-15 23:14:17 +01:00
parent 9cd3a015f5
commit 54012ec402

View File

@@ -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,