You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maps the Polymarket US cashValue field from the position object to compute currentPrice and unrealizedPnL, replacing the previous hard-coded zeros with real mark-to-market values derived from cashValue - abs(cost).
Blast Radius
Polymarket US exchange: core/src/exchanges/polymarket_us/normalizer.ts (position normalization only)
No type changes, no OpenAPI changes, no SDK changes -- the unified Position type already has currentPrice and unrealizedPnL fields
Findings
Division-by-zero guard is present.size > 0 ? cashValue / size : 0 correctly guards the currentPrice calculation.
fromAmount(pos.cashValue) assumes cashValue exists on the SDK type. The polymarket-us SDK's UserPosition type may not declare cashValue in its TypeScript definitions. If it does not, this will need a cast or type extension. The code compiles if fromAmount accepts undefined gracefully (returning 0), but this should be verified. A grep for cashValue in the codebase returns zero results on the main branch, suggesting this is a new field being accessed for the first time.
PnL formula is correct.unrealizedPnL = cashValue - abs(cost) is the standard mark-to-market formula: current value minus entry cost.
Comment quality is good. The inline comments explain the derivation clearly.
PMXT Pipeline Check
Field propagation: OK (Position type already has these fields, no new fields added)
OpenAPI sync: N/A (no BaseExchange.ts change)
Type safety: OK (assuming pos.cashValue exists at runtime)
Semver Impact
patch -- fills in previously-zero fields with real data, no API shape change
Risk
pos.cashValue existence at runtime is unverified. If the Polymarket US SDK does not include cashValue on the position object, fromAmount(undefined) must return 0 for this to not crash. Test against a live account with open positions.
For positions where cashValue is 0 or negative (fully underwater), verify the sign conventions produce correct PnL reporting.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #533