Skip to content

Commit

Permalink
Merge pull request #136 from Polymarket/feat/closed-only
Browse files Browse the repository at this point in the history
Get close only mode flag
  • Loading branch information
poly-rodr authored Jan 16, 2025
2 parents 3e6667c + 68a44d9 commit 605334a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 15 deletions.
26 changes: 26 additions & 0 deletions examples/getClosedOnlyMode.ts
Original file line number Diff line number Diff line change
@@ -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();
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.12.0",
"version": "4.13.0",
"contributors": [
{
"name": "Jonathan Amenechi",
Expand Down
51 changes: 37 additions & 14 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
UserRewardsEarning,
TotalUserEarning,
NegRisk,
BanStatus,
} from "./types";
import { createL1Headers, createL2Headers } from "./headers";
import {
Expand All @@ -64,6 +65,7 @@ import {
CANCEL_ORDER,
CREATE_API_KEY,
GET_API_KEYS,
CLOSED_ONLY,
GET_ORDER,
POST_ORDER,
TIME,
Expand Down Expand Up @@ -384,6 +386,25 @@ export class ClobClient {
return this.get(`${this.host}${endpoint}`, { headers });
}

public async getClosedOnlyMode(): Promise<BanStatus> {
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<any> {
this.canL2Auth();

Expand Down Expand Up @@ -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 = {
Expand All @@ -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<Notification[]> {
this.canL2Auth();
Expand Down
1 change: 1 addition & 0 deletions src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export interface ApiKeysResponse {
apiKeys: ApiKeyCreds[];
}

export interface BanStatus {
closed_only: boolean;
}

export interface OrderResponse {
success: boolean;
errorMsg: string;
Expand Down

0 comments on commit 605334a

Please sign in to comment.