Skip to content

Commit

Permalink
Merge pull request #92 from Polymarket/feat/markets-endpoints-pagination
Browse files Browse the repository at this point in the history
Pagination payload on /markets endpoint
  • Loading branch information
poly-rodr authored Jul 7, 2023
2 parents 1e0a23e + 25363a8 commit fc79a63
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
23 changes: 23 additions & 0 deletions examples/getMarkets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { config as dotenvConfig } from "dotenv";
import { resolve } from "path";
import { Chain, ClobClient } from "../src";

dotenvConfig({ path: resolve(__dirname, "../.env") });

async function main() {
const host = process.env.CLOB_API_URL || "http://localhost:8080";
const chainId = parseInt(`${process.env.CHAIN_ID || Chain.MUMBAI}`) as Chain;
const clobClient = new ClobClient(host, chainId);

console.log("market", await clobClient.getMarket("condition_id"));

console.log("markets", await clobClient.getMarkets());

console.log("simplified markets", await clobClient.getSimplifiedMarkets());

console.log("sampling markets", await clobClient.getSamplingMarkets());

console.log("sampling simplified markets", await clobClient.getSamplingSimplifiedMarkets());
}

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": "2.5.0",
"version": "2.6.0",
"contributors": [
{
"name": "Jonathan Amenechi",
Expand Down
20 changes: 18 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
TickSize,
OrdersScoringParams,
PriceHistoryFilterParams,
PaginationPayload,
} from "./types";
import { createL1Headers, createL2Headers } from "./headers";
import {
Expand Down Expand Up @@ -77,6 +78,9 @@ import {
IS_ORDER_SCORING,
GET_TICK_SIZE,
ARE_ORDERS_SCORING,
GET_SIMPLIFIED_MARKETS,
GET_SAMPLING_SIMPLIFIED_MARKETS,
GET_SAMPLING_MARKETS,
} from "./endpoints";
import { OrderBuilder } from "./order-builder/builder";

Expand Down Expand Up @@ -130,8 +134,20 @@ export class ClobClient {
return get(`${this.host}${TIME}`);
}

public async getMarkets(): Promise<any[]> {
return get(`${this.host}${GET_MARKETS}`);
public async getSamplingSimplifiedMarkets(next_cursor = "MA=="): Promise<PaginationPayload> {
return get(`${this.host}${GET_SAMPLING_SIMPLIFIED_MARKETS}?next_cursor=${next_cursor}`);
}

public async getSamplingMarkets(next_cursor = "MA=="): Promise<PaginationPayload> {
return get(`${this.host}${GET_SAMPLING_MARKETS}?next_cursor=${next_cursor}`);
}

public async getSimplifiedMarkets(next_cursor = "MA=="): Promise<PaginationPayload> {
return get(`${this.host}${GET_SIMPLIFIED_MARKETS}?next_cursor=${next_cursor}`);
}

public async getMarkets(next_cursor = "MA=="): Promise<PaginationPayload> {
return get(`${this.host}${GET_MARKETS}?next_cursor=${next_cursor}`);
}

public async getMarket(conditionID: string): Promise<any> {
Expand Down
3 changes: 3 additions & 0 deletions src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export const DELETE_API_KEY = "/delete-api-key";
export const DERIVE_API_KEY = "/derive-api-key";

// Markets
export const GET_SAMPLING_SIMPLIFIED_MARKETS = "/sampling-simplified-markets";
export const GET_SAMPLING_MARKETS = "/sampling-markets";
export const GET_SIMPLIFIED_MARKETS = "/simplified-markets";
export const GET_MARKETS = "/markets";
export const GET_MARKET = "/markets/";
export const GET_ORDER_BOOK = "/book";
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,10 @@ export interface RoundConfig {
export interface TickSizes {
[tokenId: string]: TickSize;
}

export interface PaginationPayload {
readonly limit: number;
readonly count: number;
readonly next_cursor: string;
readonly data: any[];
}

0 comments on commit fc79a63

Please sign in to comment.