Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdks/typescript/pmxt/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 26 additions & 0 deletions sdks/typescript/tests/hosted-dispatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
Loading