From 6bb6a3e8cd883c789cdf62c385a8dcb7e93acb05 Mon Sep 17 00:00:00 2001 From: "Samuel EF. Tinnerholm" Date: Sun, 24 May 2026 17:51:50 +0300 Subject: [PATCH] fix: map cashValue to unrealizedPnL in polymarket_us Fixes #533 --- core/src/exchanges/polymarket_us/normalizer.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/exchanges/polymarket_us/normalizer.ts b/core/src/exchanges/polymarket_us/normalizer.ts index 1b9efccc..baa417f0 100644 --- a/core/src/exchanges/polymarket_us/normalizer.ts +++ b/core/src/exchanges/polymarket_us/normalizer.ts @@ -459,16 +459,20 @@ export class PolymarketUSNormalizer { const totalCost = fromAmount(pos.cost); const entryPrice = size > 0 ? Math.abs(totalCost) / size : 0; + // cashValue is the current mark-to-market value of the position. + // unrealizedPnL = cashValue - abs(cost). + const cashValue = fromAmount(pos.cashValue); + const unrealizedPnL = cashValue - Math.abs(totalCost); + const currentPrice = size > 0 ? cashValue / size : 0; + results.push({ marketId: slug, outcomeId: isLong ? `${slug}:long` : `${slug}:short`, outcomeLabel: isLong ? 'long' : 'short', size, entryPrice, - // SDK does not expose live mark on the position object. - // Callers must enrich with current price if needed. - currentPrice: 0, - unrealizedPnL: 0, + currentPrice, + unrealizedPnL, realizedPnL: fromAmount(pos.realized), }); }