Skip to content

fix(ts-sdk): validate hosted limit order price#1291

Open
realfishsam wants to merge 1 commit into
mainfrom
fix/issue-1287-ts-hosted-price-validation-1782196341
Open

fix(ts-sdk): validate hosted limit order price#1291
realfishsam wants to merge 1 commit into
mainfrom
fix/issue-1287-ts-hosted-price-validation-1782196341

Conversation

@realfishsam

Copy link
Copy Markdown
Contributor

Summary

  • Add TypeScript hosted buildOrder validation for limit-order price presence and positivity.
  • Cover missing/zero limit prices with a regression test that verifies no hosted request is dispatched.

Fixes #1287

Test Plan

  • npm test -- --runTestsByPath tests/hosted-dispatch.test.ts -t "positive price" --runInBand (pass; used local untracked generated/src stubs because this checkout cannot regenerate TypeScript OpenAPI output: java is unavailable)
  • npm test -- --runTestsByPath tests/hosted-dispatch.test.ts --runInBand (blocked by pre-existing/local generated-stub limitations outside this change: fetchBalance empty stub response and NotSupported instanceof mismatch)
  • npm run generate:sdk:typescript --workspace=pmxt-core (blocked locally: java: not found)
  • git diff --check

@realfishsam

Copy link
Copy Markdown
Contributor Author

CI note: the scoped TypeScript hosted price-validation change is covered by the targeted regression test, but generated-sync checks are currently red from unrelated repo-wide drift on main (Hunch exchange surfacing plus generated client/API reference diffs such as market_id/fee trade fields and source_exchange filters). I did not fold that broad drift into this focused fix PR.

Local checks run:

  • npm test -- --runTestsByPath tests/hosted-dispatch.test.ts -t "positive price" --runInBand — PASS (with local untracked generated-client stubs because this checkout cannot regenerate OpenAPI output: java is unavailable)
  • git diff --check — PASS

Blocked checks observed on GitHub:

@realfishsam

Copy link
Copy Markdown
Contributor Author

PR Review: PASS (NOT VERIFIED)

What This Does

Adds client-side validation in the TypeScript hosted order build path so limit orders must include a positive price before dispatching to hosted PMXT.

Blast Radius

TypeScript SDK hosted trading helper _hostedBuildOrderBody and buildOrder/createOrder hosted dispatch validation. Core exchange execution, OpenAPI schemas, and Python SDK are not changed.

Consumer Verification

Before (base branch):
A hosted limit order with missing/zero/non-positive price could be serialized into the hosted build body and sent onward, leaving validation to the backend:

await api.buildOrder({ outcomeId, side: "buy", type: "limit", amount: 5 } as any)
// base: local body construction did not reject before fetch

After (PR branch):
Static review shows _hostedBuildOrderBody now rejects non-market orders unless Number(params.price) > 0, before to6dec and before any network dispatch:

if (orderType !== "market" && !(Number(params.price) > 0)) {
  throw new InvalidOrder("limit orders require a positive price");
}

The added test asserts buildOrder throws InvalidOrder and makes zero fetch calls for a limit order without a price.

Test Results

  • Build: PASS (npm run build --workspace=pmxt-core)
  • Unit tests: NOT VERIFIED. npx jest -c sdks/typescript/jest.config.cjs sdks/typescript/tests/hosted-dispatch.test.ts --runInBand failed before tests ran with sdks/typescript/pmxt/client.ts:15:8 - TS2307: Cannot find module '../generated/src/index.js'.
  • Server starts: NOT RUN (local SDK pre-dispatch validation only)
  • E2E smoke: NOT VERIFIED (no hosted credentials/back-end dispatch exercised)

Findings

No blocking findings.

PMXT Pipeline Check

  • Field propagation (3-layer): N/A
  • OpenAPI sync: N/A
  • Financial precision: OK; no new price arithmetic, only positive-presence validation.
  • Type safety: OK in changed path; full TS test compile blocked by missing generated imports.
  • Auth safety: N/A

Semver Impact

patch -- client-side validation fix for an invalid limit-order path.

Risk

This intentionally rejects price=0; that is consistent with limit-order semantics here, but I did not verify hosted backend behavior end-to-end because tests could not run past missing generated artifacts.

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.

SDK drift: Python hosted _hosted_build_order_request validates limit-order price presence and positivity; TypeScript _hostedBuildOrderBody does not

1 participant