Trades: an open position shows no close price or P&L
Vest's position history gives an open position a placeholder close price and a $0 P&L (290.25 on an NDX short at 29,538.96). Only a closed position keeps them now — in the parser, in the stored row (a placeholder already stored is cleared on the next read) and in the API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a03bfb5605
commit
016444239e
+7
-4
@@ -313,9 +313,12 @@ export function parseHistoryPosition(raw: unknown): VestTrade | null {
|
||||
if (!p || typeof id !== 'string' || typeof p.symbol !== 'string') return null;
|
||||
const openedAt = toMs(p.openDate ?? p.open_date ?? p.createdAt ?? p.created_at);
|
||||
if (!Number.isFinite(openedAt)) return null;
|
||||
const closedAt = toMs(p.closeDate ?? p.close_date);
|
||||
const closedMs = toMs(p.closeDate ?? p.close_date);
|
||||
const closedAt = Number.isFinite(closedMs) && closedMs > 0 ? closedMs : null;
|
||||
const openPrice = num(p.openPrice ?? p.open_price);
|
||||
const closePrice = num(p.closePrice ?? p.close_price);
|
||||
// An open position comes with a placeholder close price and a $0 P&L
|
||||
// (seen: 290.25 on an NDX short at 29,538.96): only a close has them.
|
||||
const closePrice = closedAt === null ? undefined : num(p.closePrice ?? p.close_price);
|
||||
const reason = p.closeReason ?? p.close_reason;
|
||||
return {
|
||||
positionId: id,
|
||||
@@ -325,11 +328,11 @@ export function parseHistoryPosition(raw: unknown): VestTrade | null {
|
||||
leverage: num(p.leverage) ?? null,
|
||||
openPrice: openPrice !== undefined && openPrice > 0 ? openPrice : null,
|
||||
closePrice: closePrice !== undefined && closePrice > 0 ? closePrice : null,
|
||||
pnl: num(p.pnl) ?? null,
|
||||
pnl: closedAt === null ? null : num(p.pnl) ?? null,
|
||||
fee: num(p.fee) ?? null,
|
||||
funding: num(p.funding) ?? null,
|
||||
openedAt,
|
||||
closedAt: Number.isFinite(closedAt) && closedAt > 0 ? closedAt : null,
|
||||
closedAt,
|
||||
closeReason: typeof reason === 'string' && reason !== '' ? reason : null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user