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
9 changes: 6 additions & 3 deletions sdks/typescript/pmxt/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1868,12 +1868,15 @@ export abstract class Exchange {
*/
async fetchOHLCV(
outcomeId: string | MarketOutcome,
params: any
params: any = {}
): Promise<PriceCandle[]> {
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();
}
Expand Down Expand Up @@ -1906,7 +1909,7 @@ export abstract class Exchange {
*/
async fetchTrades(
outcomeId: string | MarketOutcome,
params: any
params: any = {}
): Promise<Trade[]> {
await this.initPromise;
const resolvedOutcomeId = resolveOutcomeId(outcomeId);
Expand Down
36 changes: 36 additions & 0 deletions sdks/typescript/tests/history-optional-params.test.ts
Original file line number Diff line number Diff line change
@@ -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", {}],
);
});
});
Loading