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:
@@ -18,6 +18,16 @@ export async function GET() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Format the trade data for the frontend
|
// 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 = {
|
const formattedTrade = {
|
||||||
id: trade.id,
|
id: trade.id,
|
||||||
symbol: trade.symbol,
|
symbol: trade.symbol,
|
||||||
@@ -29,7 +39,7 @@ export async function GET() {
|
|||||||
exitReason: trade.exitReason || undefined,
|
exitReason: trade.exitReason || undefined,
|
||||||
realizedPnL: trade.realizedPnL || undefined,
|
realizedPnL: trade.realizedPnL || undefined,
|
||||||
realizedPnLPercent: trade.realizedPnLPercent || undefined,
|
realizedPnLPercent: trade.realizedPnLPercent || undefined,
|
||||||
positionSizeUSD: trade.positionSizeUSD,
|
positionSizeUSD: displaySize, // Use current size for open positions
|
||||||
leverage: trade.leverage,
|
leverage: trade.leverage,
|
||||||
stopLossPrice: trade.stopLossPrice,
|
stopLossPrice: trade.stopLossPrice,
|
||||||
takeProfit1Price: trade.takeProfit1Price,
|
takeProfit1Price: trade.takeProfit1Price,
|
||||||
|
|||||||
Reference in New Issue
Block a user