diff --git a/sdks/typescript/pmxt/client.ts b/sdks/typescript/pmxt/client.ts index 0c19edc9..3550635b 100644 --- a/sdks/typescript/pmxt/client.ts +++ b/sdks/typescript/pmxt/client.ts @@ -1900,12 +1900,25 @@ export abstract class Exchange { * ``` */ async watchOrderBooks( - outcomeIds: (string | MarketOutcome)[], + outcomeIds?: (string | MarketOutcome)[] | { ids?: (string | MarketOutcome)[] }, limit?: number, params: Record = {}, ): Promise> { await this.initPromise; - const resolvedIds = outcomeIds.map(resolveOutcomeId); + let effectiveOutcomeIds = outcomeIds; + if (Array.isArray((outcomeIds as { ids?: unknown })?.ids)) { + console.warn("Parameter 'ids' is deprecated, use 'outcomeIds' instead."); + effectiveOutcomeIds = (outcomeIds as { ids: (string | MarketOutcome)[] }).ids; + } else if (effectiveOutcomeIds === undefined && Array.isArray(params.ids)) { + console.warn("Parameter 'ids' is deprecated, use 'outcomeIds' instead."); + effectiveOutcomeIds = params.ids as (string | MarketOutcome)[]; + const { ids: _deprecatedIds, ...restParams } = params; + params = restParams; + } + if (!Array.isArray(effectiveOutcomeIds)) { + throw new TypeError("Missing required argument: 'outcomeIds'"); + } + const resolvedIds = effectiveOutcomeIds.map(resolveOutcomeId); const args: any[] = [resolvedIds]; if (limit !== undefined) { args.push(limit); diff --git a/sdks/typescript/tests/watch-order-books-compat.test.ts b/sdks/typescript/tests/watch-order-books-compat.test.ts new file mode 100644 index 00000000..13932003 --- /dev/null +++ b/sdks/typescript/tests/watch-order-books-compat.test.ts @@ -0,0 +1,40 @@ +import { Polymarket } from "../pmxt/client"; + +function makeClientWithWs(capturedArgs: unknown[][]): Polymarket { + const client = new Polymarket({ autoStartServer: false }) as any; + client.getOrCreateWs = async () => ({ + subscribeBatch: async (_exchange: unknown, _method: unknown, args: unknown[]) => { + capturedArgs.push(args as unknown[]); + return { "outcome-1": { bids: [], asks: [] } }; + }, + }); + return client; +} + +afterEach(() => { + jest.restoreAllMocks(); +}); + +describe("watchOrderBooks deprecated ids compatibility", () => { + it("accepts an ids object as a backwards-compatible alias", async () => { + const capturedArgs: unknown[][] = []; + const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined); + const client = makeClientWithWs(capturedArgs); + + await client.watchOrderBooks({ ids: ["outcome-1"] }); + + expect(warn).toHaveBeenCalledWith("Parameter 'ids' is deprecated, use 'outcomeIds' instead."); + expect(capturedArgs[0]).toEqual([["outcome-1"]]); + }); + + it("accepts params.ids when outcomeIds is omitted and strips it from sidecar params", async () => { + const capturedArgs: unknown[][] = []; + const warn = jest.spyOn(console, "warn").mockImplementation(() => undefined); + const client = makeClientWithWs(capturedArgs); + + await client.watchOrderBooks(undefined, undefined, { ids: ["outcome-1"], foo: "bar" }); + + expect(warn).toHaveBeenCalledWith("Parameter 'ids' is deprecated, use 'outcomeIds' instead."); + expect(capturedArgs[0]).toEqual([["outcome-1"], undefined, { foo: "bar" }]); + }); +});