Skip to content

fix(typescript): replace any with proper types for Exchange router methods#1419

Open
AbhilashG12 wants to merge 8 commits into
pmxt-dev:mainfrom
AbhilashG12:fix/typescript-router-params
Open

fix(typescript): replace any with proper types for Exchange router methods#1419
AbhilashG12 wants to merge 8 commits into
pmxt-dev:mainfrom
AbhilashG12:fix/typescript-router-params

Conversation

@AbhilashG12

Copy link
Copy Markdown
Contributor

What this PR does

Adds proper TypeScript types to Exchange router methods.

The Problem

Five Exchange methods used params?: any instead of typed params:

  • fetchMarketMatches
  • fetchEventMatches
  • compareMarketPrices
  • fetchMatchedPrices
  • fetchArbitrage

The Fix

  • Added typed param interfaces in router.ts
  • Updated all five methods to use proper types
  • Added proper return types

Why it matters

TypeScript users now get proper type checking when calling these methods.

Fixes #1403

@realfishsam

Copy link
Copy Markdown
Contributor

PR Review: FAIL

What This Does

This PR is intended to tighten TypeScript SDK typings for router/matching methods. In the final head commit, however, the regenerated client.ts reverts those router methods back to any and removes hosted-mode dispatch branches for several trading/account methods, which would matter directly to hosted SDK consumers.

Blast Radius

TypeScript SDK only (sdks/typescript/pmxt/client.ts), affecting router/matching method type surfaces and hosted trading/account reads/writes (cancelOrder, fetchOrder, fetchOpenOrders, fetchMyTrades, fetchPositions, fetchBalance).

Consumer Verification

Before (base branch):
Static inspection of the base TypeScript SDK shows hosted-mode dispatch exists for these methods; for example cancelOrder calls _hostedCancelOrder(orderId) before falling back to the local sidecar route, and fetchPositions uses HOSTED_METHOD_ROUTES + _tradingRequest to call hosted /api/p2p/my-style routes.

After (PR branch):
On PR head d33d23d8, sdks/typescript/pmxt/client.ts:1168 cancelOrder, :1194 fetchOrder, :1220 fetchOpenOrders, :1246 fetchMyTrades, :1324 fetchPositions, and :1350 fetchBalance no longer check this.isHosted and instead post to ${baseUrl}/api/${exchangeName}/<method> with sidecar-style { args, credentials }. A hosted SDK consumer with PMXT_API_KEY/hosted base URL would hit the wrong endpoint shape for these methods instead of the hosted route helpers.

Test Results

  • Build: NOT VERIFIED — npm run build --workspace=pmxtjs is blocked in this review checkout by missing generated SDK artifacts: pmxt/client.ts(15,8): error TS2307: Cannot find module '../generated/src/index.js' and pmxt/server-manager.ts(7,43): error TS2307.
  • Unit tests: NOT RUN because the TypeScript SDK build is blocked by missing generated artifacts.
  • Server starts: NOT RUN; this is an SDK-only change and build artifacts were missing.
  • E2E smoke: FAIL by static consumer-path trace for hosted SDK methods: the PR removes hosted dispatch and routes hosted consumers to sidecar-style endpoints.

Findings

  1. sdks/typescript/pmxt/client.ts:1168, 1194, 1220, 1246, 1324, 1350 — Blocking regression: the final regenerated client removes the hosted-mode branches for order/account methods. Those methods now always use /api/${exchangeName}/... sidecar calls with { args, credentials }, bypassing HOSTED_METHOD_ROUTES, _tradingRequest, resolveWalletAddress, and the hosted mappers. This breaks hosted TypeScript consumers for cancelOrder, fetchOrder, fetchOpenOrders, fetchMyTrades, fetchPositions, and fetchBalance.
  2. sdks/typescript/pmxt/client.ts:1450, 1477, 1525, 1603, 1650 — The stated fix is not present in the final head. fetchMarketMatches, fetchEventMatches, compareMarketPrices, fetchMatchedPrices, and fetchArbitrage are still declared as params?: any / Promise<any[]> (or params: any), so the PR does not resolve the any typing issue it claims to fix.

PMXT Pipeline Check

  • Field propagation (3-layer): N/A
  • OpenAPI sync: N/A
  • Financial precision: N/A
  • Type safety: ISSUE — target router methods remain any in the final head.
  • Auth safety: ISSUE — hosted authenticated trading/account methods no longer use the hosted auth/route path.

Semver Impact

patch if fixed -- intended SDK type-only bug fix, but current head contains a breaking hosted SDK regression.

Risk

I could not run the full TypeScript build because generated SDK artifacts are absent in the review checkout, but the blocking issues above are visible in the checked-in source and do not depend on build output.

@realfishsam

Copy link
Copy Markdown
Contributor

PR Review: FAIL

What This Does

This PR is intended to replace any with concrete TypeScript types for Exchange router/matching methods in the TypeScript SDK. At the current head, the generated client still exposes those methods as any, so the consumer-facing type-safety fix is not present.

Blast Radius

TypeScript SDK client method declarations in sdks/typescript/pmxt/client.ts, specifically exchange methods around router/matching APIs (fetchMarketMatches, fetchEventMatches, compareMarketPrices, fetchMatchedMarkets, fetchMatchedPrices, fetchArbitrage). Runtime HTTP dispatch is largely unchanged for those methods; the blast radius is the published TypeScript declaration/API surface.

Consumer Verification

Before (base branch):
The SDK client exposes the router/matching methods as broad any types, e.g.:

async fetchMarketMatches(params?: any): Promise<any[]>
async compareMarketPrices(params: any): Promise<any[]>

This is the issue the PR title/body says it fixes.

After (PR branch):
On current PR head dcf955103e384547fa66331e4eb10b4d07197070, the consumer-visible methods are still typed as any:

// sdks/typescript/pmxt/client.ts:1552
async fetchMarketMatches(params?: any): Promise<any[]>

// sdks/typescript/pmxt/client.ts:1602
async fetchEventMatches(params?: any): Promise<any[]>

// sdks/typescript/pmxt/client.ts:1627
async compareMarketPrices(params: any): Promise<any[]>

// sdks/typescript/pmxt/client.ts:1677
async fetchMatchedMarkets(params?: any): Promise<any[]>

So a TypeScript SDK consumer still receives no typed params/results for these Exchange methods.

Test Results

  • Build: PASS for npm run build --workspace=pmxt-core
  • Unit tests: PASS for core Jest suite (46 passed, 1 skipped; 809 passed, 3 skipped)
  • Server starts: PASS during root verification script
  • E2E smoke: NOT VERIFIED — root npm test then failed on environment setup (/usr/bin/python3: No module named pytest), and this PR is a type-surface change rather than a sidecar behavior change.

Findings

  1. sdks/typescript/pmxt/client.ts:1552, 1602, 1627, 1677 — The current PR head still publishes any params/results for the Exchange router/matching methods. This leaves the claimed fix unresolved for SDK consumers. The earlier typed method signatures shown in commit 1 were overwritten by the later regeneration commit, so the durable generated/source-of-truth output still contains any.

PMXT Pipeline Check

  • Field propagation (3-layer): N/A — no response field/schema change.
  • OpenAPI sync: N/A for runtime schema; issue is generated TS client typing durability.
  • Financial precision: N/A.
  • Type safety: ISSUE — the target Exchange methods still expose any in the PR head.
  • Auth safety: N/A.

Semver Impact

patch -- intended type-only SDK fix, but the current head does not deliver the advertised type improvement.

Risk

Because client.ts is generated/regenerated, hand-editing it is not durable unless the generator/source-of-truth emits the typed signatures. The current regenerated output demonstrates the typed signatures were lost, so the published package would still have the original any problem.

@AbhilashG12

Copy link
Copy Markdown
Contributor Author

PR Updated ✅

The rebase is complete and all conflicts are resolved.

Changes:

  • Added proper types to 5 router methods in client.ts
  • Updated generate-client-methods.js to recognize the new types
  • Added parameter interfaces in models.ts
Method Before After
fetchMarketMatches params?: anyPromise<any[]> params?: FetchMarketMatchesParamsPromise<MatchResult[]>
fetchEventMatches params?: anyPromise<any[]> params?: FetchEventMatchesParamsPromise<EventMatchResult[]>
compareMarketPrices params: anyPromise<any[]> params: CompareMarketPricesParamsPromise<PriceComparison[]>
fetchMatchedPrices params?: anyPromise<any[]> params?: FetchMatchedPricesParamsPromise<PriceComparison[]>
fetchArbitrage params?: anyPromise<any[]> params?: FetchArbitrageParamsPromise<ArbitrageOpportunity[]>

Ready for review! 🙏

@realfishsam

Copy link
Copy Markdown
Contributor

PR Review: FAIL

What This Does

Replaces several any types on TypeScript router/matching SDK methods with model types and updates the generator. This should improve SDK type safety for cross-venue router/match consumers.

Blast Radius

TypeScript SDK hand-written/generated client surface and generator: sdks/typescript/pmxt/client.ts, models.ts, and scripts/generate-client-methods.js. It also unexpectedly changes hosted trading branches in the same client file.

Consumer Verification

Before (base branch):
Router/match methods returned broad any[] types, but hosted trading methods such as cancelOrder, fetchOpenOrders, fetchMyTrades, fetchPositions, and fetchBalance had hosted-specific request/mapping branches.

After (PR branch):
Router/match methods have narrower types, but the diff removes hosted-mode branches for cancelOrder, fetchOpenOrders, and fetchMyTrades, and narrows fetchPositions / fetchBalance response handling to arrays only. Hosted SDK consumers would route those methods to the local sidecar or drop object-wrapped hosted responses instead of using the hosted trading API.

Test Results

  • Build: PASS for current main core build during scheduled run
  • Unit tests: PASS for current main core Jest (699 passed, 3 skipped)
  • Server starts: NOT VERIFIED for this PR head
  • E2E smoke: FAIL by static hosted SDK consumer-path trace

Findings

  1. sdks/typescript/pmxt/client.ts in the PR removes the if (this.isHosted) return this._hostedCancelOrder(orderId); branch from cancelOrder. Hosted-mode consumers will no longer use the hosted cancel route.
  2. sdks/typescript/pmxt/client.ts removes hosted branches from fetchOpenOrders and fetchMyTrades. Those methods previously used _tradingRequest and hosted route metadata; after the PR they POST to the local sidecar path even in hosted mode.
  3. sdks/typescript/pmxt/client.ts changes hosted fetchPositions / fetchBalance to accept only raw arrays, dropping the previous { positions: [...] } / { balances: [...] } envelope handling. Existing hosted responses with object envelopes would become empty arrays.

PMXT Pipeline Check

  • Field propagation (3-layer): N/A
  • OpenAPI sync: N/A
  • Financial precision: N/A
  • Type safety: ISSUE (the intended router type tightening is mixed with unrelated hosted runtime regressions)
  • Auth safety: OK/unchanged

Semver Impact

patch if limited to type tightening, but the current diff contains breaking hosted SDK behavior.

Risk

High for hosted TypeScript SDK consumers: trading/account methods can silently use the wrong transport or return empty lists.

…enerate SDKs

- Add FetchMarketMatchesParams, FetchEventMatchesParams
- Add CompareMarketPricesParams, FetchMatchedPricesParams, FetchArbitrageParams
- Update BaseExchange.ts with proper types
- Update generator to recognize new types
- Regenerate client.ts with proper types

Fixes pmxt-dev#1403
@AbhilashG12 AbhilashG12 force-pushed the fix/typescript-router-params branch from 2b86396 to 3a86f80 Compare July 10, 2026 05:50
@realfishsam

Copy link
Copy Markdown
Contributor

PR Review: FAIL

What This Does

Attempts to replace any return/parameter types for TypeScript router methods with concrete router model types, and updates generated API docs/schema artifacts. This matters to TypeScript SDK consumers because these method signatures are part of the published package surface.

Blast Radius

BaseExchange router method typing, TypeScript SDK generated client methods/generator, Python exchange wrappers, OpenAPI/docs artifacts.

Consumer Verification

Before (base branch):
Router helper methods such as fetchMarketMatches, compareMarketPrices, and fetchArbitrage were exposed with broad any/any[] TypeScript signatures.

After (PR branch):
The TypeScript SDK no longer builds from the PR checkout:

npm install
npm run build --workspace=pmxtjs

Relevant output:

pmxt/client.ts(1625,39): error TS2304: Cannot find name 'FetchMarketMatchesParams'.
pmxt/client.ts(1625,74): error TS2552: Cannot find name 'MatchResult'. Did you mean 'XPathResult'?
pmxt/client.ts(1675,38): error TS2304: Cannot find name 'FetchEventMatchesParams'.
pmxt/client.ts(1700,39): error TS2304: Cannot find name 'CompareMarketPricesParams'.
pmxt/client.ts(1825,35): error TS2304: Cannot find name 'FetchArbitrageParams'.

I also inspected the generated Python exchange wrapper signatures with AST. Polymarket.__init__ and Hunch.__init__ no longer accept wallet_address/signer, and Myriad.__init__ forwards wallet_address as private_key, changing hosted/auth constructor behavior unrelated to router typing.

Test Results

  • Build: FAIL (npm run build --workspace=pmxtjs)
  • Unit tests: NOT RUN (blocked by TypeScript build failure)
  • Server starts: N/A
  • E2E smoke: FAIL (published TypeScript SDK cannot build)

Findings

  1. sdks/typescript/pmxt/client.ts:49 and generated method signatures around sdks/typescript/pmxt/client.ts:1625 -- the new concrete router types are used but not imported into client.ts. This produces TS2304/TS2552 build errors for FetchMarketMatchesParams, MatchResult, FetchEventMatchesParams, EventMatchResult, CompareMarketPricesParams, PriceComparison, FetchMatchedPricesParams, FetchArbitrageParams, and ArbitrageOpportunity.
  2. sdks/python/pmxt/_exchanges.py:21 / sdks/python/pmxt/_exchanges.py:532 -- the regenerated Python wrapper removes previously exposed hosted-mode constructor arguments (wallet_address, signer) from venues such as Polymarket and Hunch. That is an unrelated breaking SDK API change for Python consumers and is not justified by the router type-safety fix.
  3. sdks/python/pmxt/_exchanges.py:270-274 -- Myriad still accepts wallet_address but forwards it to private_key=wallet_address, changing the credential meaning from wallet address to private key in the base Exchange credential dictionary.

PMXT Pipeline Check

  • Field propagation (3-layer): N/A
  • OpenAPI sync: OK for generated docs/schema presence, but generated SDK surface has regressions.
  • Financial precision: N/A
  • Type safety: ISSUE (new TS types are not imported, so the SDK does not compile).
  • Auth safety: ISSUE (Python wrapper credential forwarding changes wallet/private-key semantics).

Semver Impact

major if shipped as-is -- removes/changes Python constructor parameters and breaks TypeScript package builds.

Risk

The intended TypeScript type improvements are not consumable until the import/generator issue is fixed and the unrelated Python wrapper regressions are reverted or deliberately handled as a breaking change.

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.

TypeScript SDK Exchange client: router passthrough methods use params?: any instead of typed params

2 participants