From 7bedebde7013e09a036368c7e7aff33567cea5d4 Mon Sep 17 00:00:00 2001 From: Rodrigo <95635797+poly-rodr@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:59:49 -0300 Subject: [PATCH] Adding a new param to avoid the auto-pagination in get trades and orders --- examples/getOpenOrders.ts | 10 ++++++++++ examples/getTrades.ts | 10 ++++++++++ package.json | 2 +- src/client.ts | 11 ++++++++--- tests/utilities.test.ts | 2 +- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/examples/getOpenOrders.ts b/examples/getOpenOrders.ts index fd75186..68bf0f6 100644 --- a/examples/getOpenOrders.ts +++ b/examples/getOpenOrders.ts @@ -38,6 +38,16 @@ async function main() { market: "0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1", }), ); + + // only first page - do not paginate + console.log( + await clobClient.getOpenOrders( + { + market: "0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1", + }, + true, + ), + ); } main(); diff --git a/examples/getTrades.ts b/examples/getTrades.ts index 21a7d7e..a15c097 100644 --- a/examples/getTrades.ts +++ b/examples/getTrades.ts @@ -40,6 +40,16 @@ async function main() { maker_address: await wallet.getAddress(), }), ); + + // only first page - do not paginate + console.log( + await clobClient.getTrades( + { + market: "0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1", + }, + true, + ), + ); } main(); diff --git a/package.json b/package.json index 54acca4..34e27e7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@polymarket/clob-client", "description": "Typescript client for Polymarket's CLOB", - "version": "4.10.0", + "version": "4.11.0", "contributors": [ { "name": "Jonathan Amenechi", diff --git a/src/client.ts b/src/client.ts index 913392a..689f5a2 100644 --- a/src/client.ts +++ b/src/client.ts @@ -422,7 +422,11 @@ export class ClobClient { return this.get(`${this.host}${endpoint}`, { headers }); } - public async getTrades(params?: TradeParams, next_cursor?: string): Promise { + public async getTrades( + params?: TradeParams, + only_first_page = false, + next_cursor?: string, + ): Promise { this.canL2Auth(); const endpoint = GET_TRADES; @@ -440,7 +444,7 @@ export class ClobClient { let results: Trade[] = []; next_cursor = next_cursor || INITIAL_CURSOR; - while (next_cursor != END_CURSOR) { + while (next_cursor != END_CURSOR && (next_cursor === INITIAL_CURSOR || !only_first_page)) { const _params: any = { ...params, next_cursor, @@ -611,6 +615,7 @@ export class ClobClient { public async getOpenOrders( params?: OpenOrderParams, + only_first_page = false, next_cursor?: string, ): Promise { this.canL2Auth(); @@ -629,7 +634,7 @@ export class ClobClient { let results: OpenOrder[] = []; next_cursor = next_cursor || INITIAL_CURSOR; - while (next_cursor != END_CURSOR) { + while (next_cursor != END_CURSOR && (next_cursor === INITIAL_CURSOR || !only_first_page)) { const _params: any = { ...params, next_cursor, diff --git a/tests/utilities.test.ts b/tests/utilities.test.ts index 17b28f2..99215a8 100644 --- a/tests/utilities.test.ts +++ b/tests/utilities.test.ts @@ -5538,7 +5538,7 @@ describe("utilities", () => { expect(roundDown(0.57, 4)).to.equal(0.57); }); - it.only("generateOrderBookSummaryHash", () => { + it("generateOrderBookSummaryHash", () => { let orderbook = { market: "0xaabbcc", asset_id: "100",