Skip to content

fix: initialize Baozi order book resolver queues#509

Merged
realfishsam merged 3 commits into
pmxt-dev:mainfrom
iccccccccccccc:fix-baozi-orderbook-resolvers
May 24, 2026
Merged

fix: initialize Baozi order book resolver queues#509
realfishsam merged 3 commits into
pmxt-dev:mainfrom
iccccccccccccc:fix-baozi-orderbook-resolvers

Conversation

@iccccccccccccc

@iccccccccccccc iccccccccccccc commented May 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #261

Changes

  • Replace the guarded orderBookResolvers.get(...)! push path with an explicit queue initializer.
  • Add a regression test so Baozi websocket resolver queueing does not reintroduce the non-null assertion pattern.
  • Fix the Python exchange generator's underscore handling so polymarket_us is exported as PolymarketUS; this keeps the existing exchange drift gate green.
  • Preserve the generated SDK fetchOrderBook special handling for params-without-limit and historical range responses.
  • Refresh API reference output from the existing generator.

Verification

  • npm --workspace=pmxt-core test -- --runTestsByPath test/pipeline/baozi-websocket-resolvers.test.ts --runInBand
  • npx tsc -p core/tsconfig.json --noEmit
  • node core/scripts/check-exchange-drift.js
  • node sdks/typescript/scripts/generate-client-methods.js; git diff --exit-code sdks/typescript/pmxt/client.ts
  • node sdks/python/scripts/generate-client-methods.js; git diff --exit-code sdks/python/pmxt/client.py
  • python -m py_compile sdks/python/pmxt/_exchanges.py sdks/python/pmxt/__init__.py sdks/python/pmxt/client.py
  • git diff --check

@realfishsam

Copy link
Copy Markdown
Contributor

PR Review: PASS (NOT VERIFIED)

What This Does

Three fixes bundled in one PR: (1) eliminates a non-null assertion (!) on a Map.get() in the Baozi WebSocket order book resolver queue by extracting a getOrderBookQueue helper method, (2) fixes the Python exchange generator so polymarket_us produces the class name PolymarketUS instead of Polymarket_us, and (3) adds hardcoded fetchOrderBook overrides in both SDK client generators to handle the params-without-limit positional arg gap and OrderBook[] historical range responses.

Blast Radius

  • Baozi exchange: WebSocket order book watching path only. The getOrderBookQueue refactor is semantically identical to the old code but removes the ! assertion. No behavior change.
  • Python SDK: Polymarket_us class renamed to PolymarketUS in _exchanges.py and __init__.py. This is a breaking change for existing Python users of pmxt.Polymarket_us().
  • SDK generators (both TS + Python): fetchOrderBook now has a hardcoded override in the generator to handle OrderBook | OrderBook[] return type and params-without-limit gap. The generated client files already match.
  • API_REFERENCE.md (both SDKs): Regenerated from current BaseExchange.ts -- includes incidental changes like testDummyMethod -> close and FetchOrderBookParams type documentation.

Test Results

  • Build: NOT RUN (permission issue in sandbox)
  • Unit tests: NOT RUN (permission issue in sandbox)

Findings

  1. Breaking change: Polymarket_us -> PolymarketUS (sdks/python/pmxt/_exchanges.py:368, init.py:20,146) -- Any Python user doing pmxt.Polymarket_us() will get an ImportError after upgrading. The sidecar routing key (exchange_name="polymarket_us") is unaffected. Given this exchange is relatively new (added recently via 5c000a8), the blast radius may be small, but it is technically a semver-breaking rename. Consider whether a deprecation alias is warranted.

  2. any[] in fetchOrderBook TS generator (sdks/typescript/scripts/generate-client-methods.js:389) -- The hardcoded override uses const args: any[] = []. This is consistent with the existing pattern used by all other generated methods (line 327), so it is not a new regression, but worth noting.

  3. Incidental API_REFERENCE changes bundled in commit 3 -- The testDummyMethod -> close change and TradesParams description removal are side effects of re-running the API reference generator against the current BaseExchange.ts. These are legitimate but unrelated to the PR title. Not blocking.

  4. Regression test reads source file from disk (core/test/pipeline/baozi-websocket-resolvers.test.ts:6-11) -- The test reads the websocket.ts file as a string and regex-matches against it. This is a pattern lint test, not a runtime test. It will correctly fail if someone reintroduces the ! pattern. Acceptable approach for this kind of guardrail.

PMXT Pipeline Check

  • Field propagation (3-layer): N/A (no new unified type fields)
  • OpenAPI sync: N/A (no BaseExchange.ts changes)
  • Type safety: OK (no new any beyond existing generator pattern)

Semver Impact

minor (or arguably major due to finding #1) -- The PolymarketUS rename breaks the public Python API. If Polymarket_us was ever documented or used by consumers, this is a major change. If it was always considered a generator bug that shipped before anyone used it, minor is defensible.

Risk

  • Tests were not run due to sandbox permission restrictions. The PR author's verification commands should be run before merge.
  • The Polymarket_us -> PolymarketUS rename is a public API break for the Python SDK. Assess whether any users depend on the old name.

@realfishsam realfishsam merged commit 184e556 into pmxt-dev:main May 24, 2026
6 checks passed
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] baozi/websocket.ts: unsafe Map.get()! assertion on orderBookResolvers

2 participants