Skip to content

Commit

Permalink
Adding a new param to avoid the auto-pagination in get trades and orders
Browse files Browse the repository at this point in the history
  • Loading branch information
poly-rodr committed Oct 17, 2024
1 parent 2a820e3 commit 7bedebd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
10 changes: 10 additions & 0 deletions examples/getOpenOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ async function main() {
market: "0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1",
}),
);

// only first page - do not paginate
console.log(
await clobClient.getOpenOrders(
{
market: "0x5f65177b394277fd294cd75650044e32ba009a95022d88a0c1d565897d72f8f1",
},
true,
),
);
}

main();
10 changes: 10 additions & 0 deletions examples/getTrades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 8 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,11 @@ export class ClobClient {
return this.get(`${this.host}${endpoint}`, { headers });
}

public async getTrades(params?: TradeParams, next_cursor?: string): Promise<Trade[]> {
public async getTrades(
params?: TradeParams,
only_first_page = false,
next_cursor?: string,
): Promise<Trade[]> {
this.canL2Auth();

const endpoint = GET_TRADES;
Expand All @@ -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,
Expand Down Expand Up @@ -611,6 +615,7 @@ export class ClobClient {

public async getOpenOrders(
params?: OpenOrderParams,
only_first_page = false,
next_cursor?: string,
): Promise<OpenOrdersResponse> {
this.canL2Auth();
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7bedebd

Please sign in to comment.