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
17 changes: 15 additions & 2 deletions sdks/typescript/pmxt/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1900,12 +1900,25 @@ export abstract class Exchange {
* ```
*/
async watchOrderBooks(
outcomeIds: (string | MarketOutcome)[],
outcomeIds?: (string | MarketOutcome)[] | { ids?: (string | MarketOutcome)[] },
limit?: number,
params: Record<string, any> = {},
): Promise<Record<string, OrderBook>> {
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);
Expand Down
40 changes: 40 additions & 0 deletions sdks/typescript/tests/watch-order-books-compat.test.ts
Original file line number Diff line number Diff line change
@@ -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" }]);
});
});
Loading