From 230df50e225c6b02efdbb9e5c70ab3a2cd8f8ba1 Mon Sep 17 00:00:00 2001 From: Samuel Tinnerholm Date: Tue, 23 Jun 2026 06:38:05 +0000 Subject: [PATCH] fix(ts-sdk): validate hosted limit order price --- sdks/typescript/pmxt/client.ts | 3 +++ sdks/typescript/tests/hosted-dispatch.test.ts | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/sdks/typescript/pmxt/client.ts b/sdks/typescript/pmxt/client.ts index 0c19edc9..9df1bc8f 100644 --- a/sdks/typescript/pmxt/client.ts +++ b/sdks/typescript/pmxt/client.ts @@ -2514,6 +2514,9 @@ export abstract class Exchange { if (!(Number(params.amount) > 0)) { throw new InvalidOrder("amount must be positive"); } + if (orderType !== "market" && !(Number(params.price) > 0)) { + throw new InvalidOrder("limit orders require a positive price"); + } // to6dec throws InvalidOrder for sub-micro precision. const amount6dec = to6dec(params.amount as number).toString(); diff --git a/sdks/typescript/tests/hosted-dispatch.test.ts b/sdks/typescript/tests/hosted-dispatch.test.ts index 88223938..ea0156d7 100644 --- a/sdks/typescript/tests/hosted-dispatch.test.ts +++ b/sdks/typescript/tests/hosted-dispatch.test.ts @@ -351,6 +351,32 @@ describe("hosted write dispatch", () => { expect("market_id" in body).toBe(false); }); + it("buildOrder rejects limit orders without a positive price before dispatch", async () => { + const spy = installFetchSpy(() => jsonResponse(buildResponsePayload("buy"))); + const api = makePolymarket({ withSigner: true }); + + await expect( + api.buildOrder({ + outcomeId: "22222222-2222-4222-8222-222222222222", + side: "buy", + type: "limit", + amount: 5, + denom: "shares", + } as any), + ).rejects.toThrow("limit orders require a positive price"); + await expect( + api.buildOrder({ + outcomeId: "22222222-2222-4222-8222-222222222222", + side: "buy", + type: "limit", + amount: 5, + denom: "shares", + price: 0, + } as any), + ).rejects.toThrow("limit orders require a positive price"); + expect(captured(spy)).toHaveLength(0); + }); + it("cancelOrder → POST cancel/build then POST cancel", async () => { let call = 0; const spy = installFetchSpy(() => {