Skip to content

Commit 4170e4f

Browse files
committed
docs: add readme section about default values
1 parent f738dfe commit 4170e4f

File tree

2 files changed

+49
-67
lines changed

2 files changed

+49
-67
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
[![Bundle Size](https://img.shields.io/bundlephobia/minzip/@dschz/polymarket-clob-client)](https://bundlephobia.com/package/@dschz/polymarket-clob-client)
66
[![CI](https://github.com/dsnchz/polymarket-clob-client/actions/workflows/ci.yaml/badge.svg)](https://github.com/dsnchz/polymarket-clob-client/actions/workflows/ci.yaml)
77

8-
Fork of [Polymarket CLOB Client](https://github.com/Polymarket/clob-client).
8+
> Fork of Polymarket CLOB Client: [GitHub](https://github.com/Polymarket/clob-client) / [NPM](https://www.npmjs.com/package/@polymarket/clob-client)
99
10-
Typescript client for the Polymarket CLOB
10+
Typescript client for the Polymarket Central Limit Order Book (CLOB) API.
1111

1212
## What's Different in This Fork
1313

@@ -58,6 +58,17 @@ export default defineConfig({
5858
});
5959
```
6060

61+
## Configuration Defaults
62+
63+
> 💡 When creating a `ClobClient` instance, the following defaults are used for unspecified parameters:
64+
>
65+
> - **host**: `"https://clob.polymarket.com"` (Polymarket production API)
66+
> - **chainId**: `137` (Polygon mainnet)
67+
> - **signatureType**: `0` (EOA - Externally Owned Account)
68+
> - **funderAddress**: Defaults to the `signer` address when not provided
69+
>
70+
> This means you can create a minimal, _read-only_ client with just `new ClobClient()` which will hit Polygon mainnet. If you want to place trades on mainnet, then you need to configure both `signer` and `creds` via `new ClobClient({ signer, creds })` which you can see the usage examples configure below.
71+
6172
## Usage
6273

6374
#### Browser Environment with Wallet Providers

src/client.ts

Lines changed: 36 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,25 @@ type ClobClientConfig = {
163163
readonly signer?: Wallet | JsonRpcSigner;
164164
/** The credentials to use for Level 2 authentication */
165165
readonly creds?: ApiKeyCreds;
166-
/** The signature type to use for authentication (default: EOA) */
166+
/**
167+
* The signature type to use for authentication (default: `SignatureType.EOA`)
168+
* @see {@link SignatureType}
169+
*/
167170
readonly signatureType?: SignatureType;
171+
/**
172+
* The address to use as the funder for the order (default: `signer.getAddress()`)
173+
*/
168174
readonly funderAddress?: string;
169175
readonly geoBlockToken?: string;
170176
readonly useServerTime?: boolean;
171177
readonly builderConfig?: BuilderConfig;
178+
/**
179+
* Optional function to dynamically resolve the signer.
180+
* If provided, this function will be called to obtain a fresh signer instance
181+
* (e.g., for smart contract wallets or when the signer may change).
182+
* Should return a `Wallet` or `JsonRpcSigner`, or a `Promise` resolving to one.
183+
* If not provided, the static `signer` property is used.
184+
*/
172185
readonly getSigner?: () => Promise<Wallet | JsonRpcSigner> | (Wallet | JsonRpcSigner);
173186
};
174187

@@ -185,13 +198,13 @@ export class ClobClient {
185198
readonly useServerTime?: boolean;
186199
readonly builderConfig?: BuilderConfig;
187200

188-
constructor(config: ClobClientConfig) {
201+
constructor(config: ClobClientConfig = {}) {
189202
const {
190203
host = "https://clob.polymarket.com",
191204
chainId = Chain.POLYGON,
192205
signer,
193206
creds,
194-
signatureType,
207+
signatureType = SignatureType.EOA,
195208
funderAddress,
196209
geoBlockToken,
197210
useServerTime,
@@ -619,17 +632,11 @@ export class ClobClient {
619632
this.canL2Auth();
620633

621634
const endpoint = DROP_NOTIFICATIONS;
622-
const l2HeaderArgs = {
635+
636+
const headers = await this._getL2Headers({
623637
method: DELETE,
624638
requestPath: endpoint,
625-
};
626-
627-
const headers = await createL2Headers(
628-
this.signer as Wallet | JsonRpcSigner,
629-
this.creds as ApiKeyCreds,
630-
l2HeaderArgs,
631-
this.useServerTime ? await this.getServerTime() : undefined,
632-
);
639+
});
633640

634641
return this.del(`${this.host}${endpoint}`, {
635642
headers,
@@ -769,17 +776,11 @@ export class ClobClient {
769776
): Promise<OpenOrdersResponse> {
770777
this.canL2Auth();
771778
const endpoint = GET_OPEN_ORDERS;
772-
const l2HeaderArgs = {
779+
780+
const headers = await this._getL2Headers({
773781
method: GET,
774782
requestPath: endpoint,
775-
};
776-
777-
const headers = await createL2Headers(
778-
this.signer as Wallet | JsonRpcSigner,
779-
this.creds as ApiKeyCreds,
780-
l2HeaderArgs,
781-
this.useServerTime ? await this.getServerTime() : undefined,
782-
);
783+
});
783784

784785
let results: OpenOrder[] = [];
785786
next_cursor = next_cursor || INITIAL_CURSOR;
@@ -813,12 +814,7 @@ export class ClobClient {
813814
body: JSON.stringify(orderPayload),
814815
};
815816

816-
const headers = await createL2Headers(
817-
this.signer as Wallet | JsonRpcSigner,
818-
this.creds as ApiKeyCreds,
819-
l2HeaderArgs,
820-
this.useServerTime ? await this.getServerTime() : undefined,
821-
);
817+
const headers = await this._getL2Headers(l2HeaderArgs);
822818

823819
// builders flow
824820
if (this.canBuilderAuth()) {
@@ -849,12 +845,7 @@ export class ClobClient {
849845
body: JSON.stringify(ordersPayload),
850846
};
851847

852-
const headers = await createL2Headers(
853-
this.signer as Wallet | JsonRpcSigner,
854-
this.creds as ApiKeyCreds,
855-
l2HeaderArgs,
856-
this.useServerTime ? await this.getServerTime() : undefined,
857-
);
848+
const headers = await this._getL2Headers(l2HeaderArgs);
858849

859850
// builders flow
860851
if (this.canBuilderAuth()) {
@@ -873,71 +864,51 @@ export class ClobClient {
873864
public async cancelOrder(payload: OrderPayload): Promise<any> {
874865
this.canL2Auth();
875866
const endpoint = CANCEL_ORDER;
876-
const l2HeaderArgs = {
867+
868+
const headers = await this._getL2Headers({
877869
method: DELETE,
878870
requestPath: endpoint,
879871
body: JSON.stringify(payload),
880-
};
872+
});
881873

882-
const headers = await createL2Headers(
883-
this.signer as Wallet | JsonRpcSigner,
884-
this.creds as ApiKeyCreds,
885-
l2HeaderArgs,
886-
this.useServerTime ? await this.getServerTime() : undefined,
887-
);
888874
return this.del(`${this.host}${endpoint}`, { headers, data: payload });
889875
}
890876

891877
public async cancelOrders(ordersHashes: string[]): Promise<any> {
892878
this.canL2Auth();
893879
const endpoint = CANCEL_ORDERS;
894-
const l2HeaderArgs = {
880+
881+
const headers = await this._getL2Headers({
895882
method: DELETE,
896883
requestPath: endpoint,
897884
body: JSON.stringify(ordersHashes),
898-
};
885+
});
899886

900-
const headers = await createL2Headers(
901-
this.signer as Wallet | JsonRpcSigner,
902-
this.creds as ApiKeyCreds,
903-
l2HeaderArgs,
904-
this.useServerTime ? await this.getServerTime() : undefined,
905-
);
906887
return this.del(`${this.host}${endpoint}`, { headers, data: ordersHashes });
907888
}
908889

909890
public async cancelAll(): Promise<any> {
910891
this.canL2Auth();
911892
const endpoint = CANCEL_ALL;
912-
const l2HeaderArgs = {
893+
894+
const headers = await this._getL2Headers({
913895
method: DELETE,
914896
requestPath: endpoint,
915-
};
897+
});
916898

917-
const headers = await createL2Headers(
918-
this.signer as Wallet | JsonRpcSigner,
919-
this.creds as ApiKeyCreds,
920-
l2HeaderArgs,
921-
this.useServerTime ? await this.getServerTime() : undefined,
922-
);
923899
return this.del(`${this.host}${endpoint}`, { headers });
924900
}
925901

926902
public async cancelMarketOrders(payload: OrderMarketCancelParams): Promise<any> {
927903
this.canL2Auth();
928904
const endpoint = CANCEL_MARKET_ORDERS;
929-
const l2HeaderArgs = {
905+
906+
const headers = await this._getL2Headers({
930907
method: DELETE,
931908
requestPath: endpoint,
932909
body: JSON.stringify(payload),
933-
};
910+
});
934911

935-
const headers = await createL2Headers(
936-
this.signer as Wallet | JsonRpcSigner,
937-
this.creds as ApiKeyCreds,
938-
l2HeaderArgs,
939-
this.useServerTime ? await this.getServerTime() : undefined,
940-
);
941912
return this.del(`${this.host}${endpoint}`, { headers, data: payload });
942913
}
943914

0 commit comments

Comments
 (0)