Skip to content

fix: guard Map.get() on candle buckets in polymarket normalizer#608

Merged
realfishsam merged 1 commit into
mainfrom
fix/321-polymarket-normalizer
May 24, 2026
Merged

fix: guard Map.get() on candle buckets in polymarket normalizer#608
realfishsam merged 1 commit into
mainfrom
fix/321-polymarket-normalizer

Conversation

@realfishsam

Copy link
Copy Markdown
Contributor

Fixes #321

@realfishsam

Copy link
Copy Markdown
Contributor Author

PR Review: VERIFIED

What This Does

Guards Map.get(snappedMs) with an if (candle) check instead of using the non-null assertion buckets.get(snappedMs)! in the Polymarket normalizer's OHLCV candle-bucketing logic.

Blast Radius

Single file: core/src/exchanges/polymarket/normalizer.ts. One code path in normalizeOHLCV. The else branch is only entered when buckets.has(snappedMs) is true (the preceding if (!buckets.has(snappedMs)) sets the entry), so get() will always return a value in practice. The guard is purely defensive.

Findings

  • The guard is correct and safe. If get() somehow returned undefined (impossible given the has() check above, but defensive), the price point is silently skipped. This is acceptable for OHLCV data -- a missing candle update is better than a crash.
  • Mutation concern: The candle object retrieved from the Map is still mutated in-place (candle.high = ..., candle.low = ..., etc.). This is a pre-existing pattern and not introduced by this PR. Since the Map owns these objects and they are only used locally within this method before being returned as an array, in-place mutation is acceptable here.
  • No non-null assertions remain in this code path.

Semver Impact

patch -- defensive guard, no behavioral change in practice.

Risk

Low.

@realfishsam realfishsam merged commit 79467ac into main May 24, 2026
9 of 12 checks passed
@realfishsam realfishsam deleted the fix/321-polymarket-normalizer branch May 24, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[non-null] polymarket/normalizer.ts: unsafe Map.get()! on candle buckets

1 participant