diff --git a/examples/getClosedOnlyMode.ts b/examples/getClosedOnlyMode.ts new file mode 100644 index 0000000..54878bb --- /dev/null +++ b/examples/getClosedOnlyMode.ts @@ -0,0 +1,26 @@ +import { ethers } from "ethers"; +import { config as dotenvConfig } from "dotenv"; +import { resolve } from "path"; +import { ApiKeyCreds, Chain, ClobClient } from "../src"; + +dotenvConfig({ path: resolve(__dirname, "../.env") }); + +async function main() { + const wallet = new ethers.Wallet(`${process.env.PK}`); + const chainId = parseInt(`${process.env.CHAIN_ID || Chain.AMOY}`) as Chain; + console.log(`Address: ${await wallet.getAddress()}, chainId: ${chainId}`); + + const host = process.env.CLOB_API_URL || "http://localhost:8080"; + const creds: ApiKeyCreds = { + key: `${process.env.CLOB_API_KEY}`, + secret: `${process.env.CLOB_SECRET}`, + passphrase: `${process.env.CLOB_PASS_PHRASE}`, + }; + const clobClient = new ClobClient(host, chainId, wallet, creds); + + console.log(`Response: `); + const resp = await clobClient.getClosedOnlyMode(); + console.log(resp); +} + +main(); diff --git a/package.json b/package.json index 6be113e..f9f21f1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@polymarket/clob-client", "description": "Typescript client for Polymarket's CLOB", - "version": "4.12.0", + "version": "4.13.0", "contributors": [ { "name": "Jonathan Amenechi", diff --git a/src/client.ts b/src/client.ts index 2cab3ed..945d28e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -40,6 +40,7 @@ import { UserRewardsEarning, TotalUserEarning, NegRisk, + BanStatus, } from "./types"; import { createL1Headers, createL2Headers } from "./headers"; import { @@ -64,6 +65,7 @@ import { CANCEL_ORDER, CREATE_API_KEY, GET_API_KEYS, + CLOSED_ONLY, GET_ORDER, POST_ORDER, TIME, @@ -384,6 +386,25 @@ export class ClobClient { return this.get(`${this.host}${endpoint}`, { headers }); } + public async getClosedOnlyMode(): Promise { + this.canL2Auth(); + + const endpoint = CLOSED_ONLY; + const headerArgs = { + method: GET, + requestPath: endpoint, + }; + + const headers = await createL2Headers( + this.signer as Wallet | JsonRpcSigner, + this.creds as ApiKeyCreds, + headerArgs, + this.useServerTime ? await this.getServerTime() : undefined, + ); + + return this.get(`${this.host}${endpoint}`, { headers }); + } + public async deleteApiKey(): Promise { this.canL2Auth(); @@ -459,12 +480,11 @@ export class ClobClient { return results; } - - public async getTradesPaginated( - params?: TradeParams, - next_cursor?: string - ): Promise<{trades: Trade[], next_cursor: string, limit: number, count: number }> { - this.canL2Auth(); + public async getTradesPaginated( + params?: TradeParams, + next_cursor?: string, + ): Promise<{ trades: Trade[]; next_cursor: string; limit: number; count: number }> { + this.canL2Auth(); const endpoint = GET_TRADES; const headerArgs = { @@ -483,18 +503,21 @@ export class ClobClient { const _params: any = { ...params, next_cursor }; - const {data, ...rest }: { - data: Trade[], - next_cursor: string, - limit: number, - count: number - } = await this.get(`${this.host}${endpoint}`, { + const { + data, + ...rest + }: { + data: Trade[]; + next_cursor: string; + limit: number; + count: number; + } = await this.get(`${this.host}${endpoint}`, { headers, params: _params, }); - return { trades: Array.isArray(data) ? [...data] :[], ...rest} - } + return { trades: Array.isArray(data) ? [...data] : [], ...rest }; + } public async getNotifications(): Promise { this.canL2Auth(); diff --git a/src/endpoints.ts b/src/endpoints.ts index 1482324..fbcbc6a 100644 --- a/src/endpoints.ts +++ b/src/endpoints.ts @@ -6,6 +6,7 @@ export const CREATE_API_KEY = "/auth/api-key"; export const GET_API_KEYS = "/auth/api-keys"; export const DELETE_API_KEY = "/auth/api-key"; export const DERIVE_API_KEY = "/auth/derive-api-key"; +export const CLOSED_ONLY = "/auth/ban-status/closed-only"; // Markets export const GET_SAMPLING_SIMPLIFIED_MARKETS = "/sampling-simplified-markets"; diff --git a/src/types.ts b/src/types.ts index 7950c15..61bd2ab 100644 --- a/src/types.ts +++ b/src/types.ts @@ -152,6 +152,10 @@ export interface ApiKeysResponse { apiKeys: ApiKeyCreds[]; } +export interface BanStatus { + closed_only: boolean; +} + export interface OrderResponse { success: boolean; errorMsg: string;