Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a new param to avoid the auto-pagination in get trades and orders #125

Merged
merged 1 commit into from
Oct 17, 2024
Merged
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
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
Loading