Skip to content

Commit 75cd86a

Browse files
Forward TS order optional params (#1065)
1 parent 2e93ee9 commit 75cd86a

2 files changed

Lines changed: 122 additions & 0 deletions

File tree

sdks/typescript/pmxt/client.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,15 @@ export abstract class Exchange {
21042104
if (params.fee !== undefined) {
21052105
paramsDict.fee = params.fee;
21062106
}
2107+
if (params.tickSize !== undefined) {
2108+
paramsDict.tickSize = params.tickSize;
2109+
}
2110+
if (params.negRisk !== undefined) {
2111+
paramsDict.negRisk = params.negRisk;
2112+
}
2113+
if (params.onBehalfOf !== undefined) {
2114+
paramsDict.onBehalfOf = params.onBehalfOf;
2115+
}
21072116

21082117
const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/buildOrder`, {
21092118
method: 'POST',
@@ -2406,6 +2415,15 @@ export abstract class Exchange {
24062415
if (params.fee !== undefined) {
24072416
paramsDict.fee = params.fee;
24082417
}
2418+
if (params.tickSize !== undefined) {
2419+
paramsDict.tickSize = params.tickSize;
2420+
}
2421+
if (params.negRisk !== undefined) {
2422+
paramsDict.negRisk = params.negRisk;
2423+
}
2424+
if (params.onBehalfOf !== undefined) {
2425+
paramsDict.onBehalfOf = params.onBehalfOf;
2426+
}
24092427

24102428
const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/createOrder`, {
24112429
method: 'POST',
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { Polymarket } from "../pmxt/client";
2+
import { LOCAL_URL } from "../pmxt/constants";
3+
4+
interface CapturedFetch {
5+
url: string;
6+
init?: RequestInit;
7+
}
8+
9+
function installFetchSpy(handler: (req: CapturedFetch) => Response): jest.SpyInstance {
10+
const captured: CapturedFetch[] = [];
11+
const spy = jest.spyOn(global, "fetch").mockImplementation(async (input, init) => {
12+
const url = typeof input === "string" ? input : (input as URL | Request).toString();
13+
const rec: CapturedFetch = { url, init };
14+
captured.push(rec);
15+
return handler(rec);
16+
});
17+
(spy as unknown as { captured: CapturedFetch[] }).captured = captured;
18+
return spy;
19+
}
20+
21+
function captured(spy: jest.SpyInstance): CapturedFetch[] {
22+
return (spy as unknown as { captured: CapturedFetch[] }).captured;
23+
}
24+
25+
function jsonResponse(payload: unknown, status = 200): Response {
26+
return new Response(JSON.stringify(payload), {
27+
status,
28+
headers: { "Content-Type": "application/json" },
29+
});
30+
}
31+
32+
function makePolymarket(): Polymarket {
33+
return new Polymarket({ autoStartServer: false, baseUrl: LOCAL_URL });
34+
}
35+
36+
afterEach(() => {
37+
jest.restoreAllMocks();
38+
});
39+
40+
describe("sidecar order param forwarding", () => {
41+
it("buildOrder forwards tickSize, negRisk, and onBehalfOf", async () => {
42+
const spy = installFetchSpy(() =>
43+
jsonResponse({
44+
success: true,
45+
data: { id: "built-1" },
46+
}),
47+
);
48+
const api = makePolymarket();
49+
50+
await api.buildOrder({
51+
marketId: "market-1",
52+
outcomeId: "outcome-1",
53+
side: "buy",
54+
type: "limit",
55+
amount: 10,
56+
price: 0.45,
57+
tickSize: 0.01,
58+
negRisk: false,
59+
onBehalfOf: 123,
60+
});
61+
62+
const reqs = captured(spy);
63+
expect(reqs).toHaveLength(1);
64+
expect(reqs[0].url).toBe(`${LOCAL_URL}/api/polymarket/buildOrder`);
65+
const body = JSON.parse((reqs[0].init?.body as string) ?? "{}");
66+
expect(body.args[0]).toMatchObject({
67+
tickSize: 0.01,
68+
negRisk: false,
69+
onBehalfOf: 123,
70+
});
71+
});
72+
73+
it("createOrder forwards tickSize, negRisk, and onBehalfOf", async () => {
74+
const spy = installFetchSpy(() =>
75+
jsonResponse({
76+
success: true,
77+
data: { id: "order-1", status: "open" },
78+
}),
79+
);
80+
const api = makePolymarket();
81+
82+
await api.createOrder({
83+
marketId: "market-1",
84+
outcomeId: "outcome-1",
85+
side: "buy",
86+
type: "limit",
87+
amount: 10,
88+
price: 0.45,
89+
tickSize: 0.01,
90+
negRisk: false,
91+
onBehalfOf: 0,
92+
});
93+
94+
const reqs = captured(spy);
95+
expect(reqs).toHaveLength(1);
96+
expect(reqs[0].url).toBe(`${LOCAL_URL}/api/polymarket/createOrder`);
97+
const body = JSON.parse((reqs[0].init?.body as string) ?? "{}");
98+
expect(body.args[0]).toMatchObject({
99+
tickSize: 0.01,
100+
negRisk: false,
101+
onBehalfOf: 0,
102+
});
103+
});
104+
});

0 commit comments

Comments
 (0)