From 6f3bd04dc669f55d13552fc9c1c4d91560e43550 Mon Sep 17 00:00:00 2001 From: Samuel Tinnerholm Date: Sat, 11 Jul 2026 06:38:37 +0000 Subject: [PATCH] fix(ts-sdk): make history params optional --- sdks/typescript/pmxt/client.ts | 9 +++-- .../tests/history-optional-params.test.ts | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 sdks/typescript/tests/history-optional-params.test.ts diff --git a/sdks/typescript/pmxt/client.ts b/sdks/typescript/pmxt/client.ts index 41eadab9..9ab7ccfa 100644 --- a/sdks/typescript/pmxt/client.ts +++ b/sdks/typescript/pmxt/client.ts @@ -1868,12 +1868,15 @@ export abstract class Exchange { */ async fetchOHLCV( outcomeId: string | MarketOutcome, - params: any + params: any = {} ): Promise { await this.initPromise; const resolvedOutcomeId = resolveOutcomeId(outcomeId); try { - const paramsDict: any = { resolution: params.resolution }; + const paramsDict: any = {}; + if (params.resolution) { + paramsDict.resolution = params.resolution; + } if (params.start) { paramsDict.start = params.start.toISOString(); } @@ -1906,7 +1909,7 @@ export abstract class Exchange { */ async fetchTrades( outcomeId: string | MarketOutcome, - params: any + params: any = {} ): Promise { await this.initPromise; const resolvedOutcomeId = resolveOutcomeId(outcomeId); diff --git a/sdks/typescript/tests/history-optional-params.test.ts b/sdks/typescript/tests/history-optional-params.test.ts new file mode 100644 index 00000000..7cc2fcd5 --- /dev/null +++ b/sdks/typescript/tests/history-optional-params.test.ts @@ -0,0 +1,36 @@ +import { Polymarket } from "../pmxt/client"; +import { LOCAL_URL } from "../pmxt/constants"; + +function makePolymarket(): Polymarket { + return new Polymarket({ autoStartServer: false, baseUrl: LOCAL_URL }); +} + +describe("optional history params", () => { + it("fetchOHLCV accepts only an outcome ID", async () => { + const api = makePolymarket(); + const read = jest + .spyOn(api as any, "sidecarReadRequest") + .mockResolvedValue({ success: true, data: [] }); + + await expect(api.fetchOHLCV("outcome-1")).resolves.toEqual([]); + expect(read).toHaveBeenCalledWith( + "fetchOHLCV", + { outcomeId: "outcome-1" }, + ["outcome-1", {}], + ); + }); + + it("fetchTrades accepts only an outcome ID", async () => { + const api = makePolymarket(); + const read = jest + .spyOn(api as any, "sidecarReadRequest") + .mockResolvedValue({ success: true, data: [] }); + + await expect(api.fetchTrades("outcome-1")).resolves.toEqual([]); + expect(read).toHaveBeenCalledWith( + "fetchTrades", + { outcomeId: "outcome-1" }, + ["outcome-1", {}], + ); + }); +});