@ebowwa/polymarket-client 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +35 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -7
- package/package.json +1 -1
- package/src/client.ts +55 -9
- package/src/index.ts +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @ebowwa/polymarket-client
|
|
3
3
|
*
|
|
4
4
|
* Polymarket API client wrapper for prediction markets integration.
|
|
5
5
|
* Provides access to Gamma API, CLOB API, and Data API.
|
|
@@ -93,7 +93,11 @@ export declare class PolymarketClient {
|
|
|
93
93
|
}): Promise<{
|
|
94
94
|
markets: PolymarketMarket[];
|
|
95
95
|
}>;
|
|
96
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Get a specific market by numeric ID
|
|
98
|
+
* Note: Gamma API expects the numeric 'id' field from list_markets, NOT the conditionId
|
|
99
|
+
*/
|
|
100
|
+
getMarket(marketId: string): Promise<{
|
|
97
101
|
market: PolymarketMarket;
|
|
98
102
|
}>;
|
|
99
103
|
listEvents(params?: {
|
|
@@ -115,13 +119,41 @@ export declare class PolymarketClient {
|
|
|
115
119
|
limit?: number;
|
|
116
120
|
offset?: number;
|
|
117
121
|
}): Promise<any>;
|
|
122
|
+
/**
|
|
123
|
+
* Get orderbook for a token (CLOB markets only)
|
|
124
|
+
* Endpoint: GET /book?token_id={token_id}
|
|
125
|
+
*/
|
|
118
126
|
getOrderbook(tokenId: string): Promise<{
|
|
119
127
|
orderbook: PolymarketOrderBook;
|
|
120
128
|
}>;
|
|
129
|
+
/**
|
|
130
|
+
* Get trade history for a token
|
|
131
|
+
* Endpoint: GET /trades?token_id={token_id}
|
|
132
|
+
*/
|
|
121
133
|
getTrades(tokenId: string, limit?: number): Promise<any>;
|
|
122
|
-
|
|
134
|
+
/**
|
|
135
|
+
* Get current price for a token
|
|
136
|
+
* Endpoint: GET /price?token_id={token_id}&side={buy|sell}
|
|
137
|
+
* Note: The 'side' parameter is required - returns best bid (buy) or best ask (sell)
|
|
138
|
+
*/
|
|
139
|
+
getPrice(tokenId: string, side?: 'buy' | 'sell'): Promise<{
|
|
123
140
|
price: number;
|
|
124
141
|
}>;
|
|
142
|
+
/**
|
|
143
|
+
* Get midpoint price for a token
|
|
144
|
+
* Endpoint: GET /midpoint?token_id={token_id}
|
|
145
|
+
*/
|
|
146
|
+
getMidpoint(tokenId: string): Promise<{
|
|
147
|
+
midpoint: number;
|
|
148
|
+
}>;
|
|
149
|
+
/**
|
|
150
|
+
* Get last trade price for a token (no auth required)
|
|
151
|
+
* Endpoint: GET /last-trade-price?token_id={token_id}
|
|
152
|
+
*/
|
|
153
|
+
getLastTradePrice(tokenId: string): Promise<{
|
|
154
|
+
price: number;
|
|
155
|
+
side: string;
|
|
156
|
+
}>;
|
|
125
157
|
getPositions(walletAddress: string): Promise<any>;
|
|
126
158
|
getWalletTrades(walletAddress: string, params?: {
|
|
127
159
|
limit?: number;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,KAAK,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,OAAO,CAAC;QAChB,MAAM,EAAE,OAAO,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,MAAM,CAAC;QACjB,cAAc,EA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OAGG;IACG,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,MAAY,GAAG,OAAO,CAAC,GAAG,CAAC;IASnE;;;;OAIG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,KAAK,GAAG,MAAc,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAUzF;;;OAGG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAUjE;;;OAGG;IACG,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAc5E,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IASjD,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,GAAE;QACnD,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACZ,GAAG,OAAO,CAAC,GAAG,CAAC;CAatB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,CAAC,EAAE,sBAAsB,GAAG,gBAAgB,CAExF"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -38,8 +38,8 @@ class PolymarketClient {
|
|
|
38
38
|
const data = await response.json();
|
|
39
39
|
return { markets: Array.isArray(data) ? data : [] };
|
|
40
40
|
}
|
|
41
|
-
async getMarket(
|
|
42
|
-
const response = await fetch(`${this.gammaApiBase}/markets/${
|
|
41
|
+
async getMarket(marketId) {
|
|
42
|
+
const response = await fetch(`${this.gammaApiBase}/markets/${marketId}`);
|
|
43
43
|
if (!response.ok) {
|
|
44
44
|
throw new Error(`Gamma API error: ${response.status} ${response.statusText}`);
|
|
45
45
|
}
|
|
@@ -118,7 +118,7 @@ class PolymarketClient {
|
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
async getOrderbook(tokenId) {
|
|
121
|
-
const response = await fetch(`${this.clobApiBase}/
|
|
121
|
+
const response = await fetch(`${this.clobApiBase}/book?token_id=${tokenId}`);
|
|
122
122
|
if (!response.ok) {
|
|
123
123
|
throw new Error(`CLOB API error: ${response.status} ${response.statusText}`);
|
|
124
124
|
}
|
|
@@ -126,19 +126,35 @@ class PolymarketClient {
|
|
|
126
126
|
return { orderbook: data };
|
|
127
127
|
}
|
|
128
128
|
async getTrades(tokenId, limit = 100) {
|
|
129
|
-
const response = await fetch(`${this.clobApiBase}/
|
|
129
|
+
const response = await fetch(`${this.clobApiBase}/trades?token_id=${tokenId}&limit=${limit}`);
|
|
130
130
|
if (!response.ok) {
|
|
131
131
|
throw new Error(`CLOB API error: ${response.status} ${response.statusText}`);
|
|
132
132
|
}
|
|
133
133
|
return response.json();
|
|
134
134
|
}
|
|
135
|
-
async getPrice(tokenId) {
|
|
136
|
-
const response = await fetch(`${this.clobApiBase}/price?token_id=${tokenId}`);
|
|
135
|
+
async getPrice(tokenId, side = "buy") {
|
|
136
|
+
const response = await fetch(`${this.clobApiBase}/price?token_id=${tokenId}&side=${side}`);
|
|
137
137
|
if (!response.ok) {
|
|
138
138
|
throw new Error(`CLOB API error: ${response.status} ${response.statusText}`);
|
|
139
139
|
}
|
|
140
140
|
const data = await response.json();
|
|
141
|
-
return { price: data.price };
|
|
141
|
+
return { price: parseFloat(data.price) || 0 };
|
|
142
|
+
}
|
|
143
|
+
async getMidpoint(tokenId) {
|
|
144
|
+
const response = await fetch(`${this.clobApiBase}/midpoint?token_id=${tokenId}`);
|
|
145
|
+
if (!response.ok) {
|
|
146
|
+
throw new Error(`CLOB API error: ${response.status} ${response.statusText}`);
|
|
147
|
+
}
|
|
148
|
+
const data = await response.json();
|
|
149
|
+
return { midpoint: parseFloat(data.midpoint) || 0 };
|
|
150
|
+
}
|
|
151
|
+
async getLastTradePrice(tokenId) {
|
|
152
|
+
const response = await fetch(`${this.clobApiBase}/last-trade-price?token_id=${tokenId}`);
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
throw new Error(`CLOB API error: ${response.status} ${response.statusText}`);
|
|
155
|
+
}
|
|
156
|
+
const data = await response.json();
|
|
157
|
+
return { price: parseFloat(data.price) || 0.5, side: data.side || "" };
|
|
142
158
|
}
|
|
143
159
|
async getPositions(walletAddress) {
|
|
144
160
|
const response = await fetch(`${this.dataApiBase}/positions?wallet=${walletAddress}`);
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @ebowwa/polymarket-client
|
|
3
3
|
*
|
|
4
4
|
* Polymarket API client wrapper for prediction markets integration.
|
|
5
5
|
* Provides access to Gamma API, CLOB API, and Data API.
|
|
@@ -125,8 +125,12 @@ export class PolymarketClient {
|
|
|
125
125
|
return { markets: Array.isArray(data) ? data : [] };
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Get a specific market by numeric ID
|
|
130
|
+
* Note: Gamma API expects the numeric 'id' field from list_markets, NOT the conditionId
|
|
131
|
+
*/
|
|
132
|
+
async getMarket(marketId: string): Promise<{ market: PolymarketMarket }> {
|
|
133
|
+
const response = await fetch(`${this.gammaApiBase}/markets/${marketId}`);
|
|
130
134
|
if (!response.ok) {
|
|
131
135
|
throw new Error(`Gamma API error: ${response.status} ${response.statusText}`);
|
|
132
136
|
}
|
|
@@ -234,10 +238,15 @@ export class PolymarketClient {
|
|
|
234
238
|
|
|
235
239
|
// ============================================================================
|
|
236
240
|
// CLOB API (Order Book & Trading)
|
|
241
|
+
// Reference: https://docs.polymarket.com/
|
|
237
242
|
// ============================================================================
|
|
238
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Get orderbook for a token (CLOB markets only)
|
|
246
|
+
* Endpoint: GET /book?token_id={token_id}
|
|
247
|
+
*/
|
|
239
248
|
async getOrderbook(tokenId: string): Promise<{ orderbook: PolymarketOrderBook }> {
|
|
240
|
-
const response = await fetch(`${this.clobApiBase}/
|
|
249
|
+
const response = await fetch(`${this.clobApiBase}/book?token_id=${tokenId}`);
|
|
241
250
|
if (!response.ok) {
|
|
242
251
|
throw new Error(`CLOB API error: ${response.status} ${response.statusText}`);
|
|
243
252
|
}
|
|
@@ -246,8 +255,12 @@ export class PolymarketClient {
|
|
|
246
255
|
return { orderbook: data };
|
|
247
256
|
}
|
|
248
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Get trade history for a token
|
|
260
|
+
* Endpoint: GET /trades?token_id={token_id}
|
|
261
|
+
*/
|
|
249
262
|
async getTrades(tokenId: string, limit: number = 100): Promise<any> {
|
|
250
|
-
const response = await fetch(`${this.clobApiBase}/
|
|
263
|
+
const response = await fetch(`${this.clobApiBase}/trades?token_id=${tokenId}&limit=${limit}`);
|
|
251
264
|
if (!response.ok) {
|
|
252
265
|
throw new Error(`CLOB API error: ${response.status} ${response.statusText}`);
|
|
253
266
|
}
|
|
@@ -255,14 +268,47 @@ export class PolymarketClient {
|
|
|
255
268
|
return response.json();
|
|
256
269
|
}
|
|
257
270
|
|
|
258
|
-
|
|
259
|
-
|
|
271
|
+
/**
|
|
272
|
+
* Get current price for a token
|
|
273
|
+
* Endpoint: GET /price?token_id={token_id}&side={buy|sell}
|
|
274
|
+
* Note: The 'side' parameter is required - returns best bid (buy) or best ask (sell)
|
|
275
|
+
*/
|
|
276
|
+
async getPrice(tokenId: string, side: 'buy' | 'sell' = 'buy'): Promise<{ price: number }> {
|
|
277
|
+
const response = await fetch(`${this.clobApiBase}/price?token_id=${tokenId}&side=${side}`);
|
|
260
278
|
if (!response.ok) {
|
|
261
279
|
throw new Error(`CLOB API error: ${response.status} ${response.statusText}`);
|
|
262
280
|
}
|
|
263
281
|
|
|
264
|
-
const data = await response.json() as { price:
|
|
265
|
-
return { price: data.price };
|
|
282
|
+
const data = await response.json() as { price: string };
|
|
283
|
+
return { price: parseFloat(data.price) || 0 };
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Get midpoint price for a token
|
|
288
|
+
* Endpoint: GET /midpoint?token_id={token_id}
|
|
289
|
+
*/
|
|
290
|
+
async getMidpoint(tokenId: string): Promise<{ midpoint: number }> {
|
|
291
|
+
const response = await fetch(`${this.clobApiBase}/midpoint?token_id=${tokenId}`);
|
|
292
|
+
if (!response.ok) {
|
|
293
|
+
throw new Error(`CLOB API error: ${response.status} ${response.statusText}`);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const data = await response.json() as { midpoint: string };
|
|
297
|
+
return { midpoint: parseFloat(data.midpoint) || 0 };
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Get last trade price for a token (no auth required)
|
|
302
|
+
* Endpoint: GET /last-trade-price?token_id={token_id}
|
|
303
|
+
*/
|
|
304
|
+
async getLastTradePrice(tokenId: string): Promise<{ price: number; side: string }> {
|
|
305
|
+
const response = await fetch(`${this.clobApiBase}/last-trade-price?token_id=${tokenId}`);
|
|
306
|
+
if (!response.ok) {
|
|
307
|
+
throw new Error(`CLOB API error: ${response.status} ${response.statusText}`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const data = await response.json() as { price: string; side: string };
|
|
311
|
+
return { price: parseFloat(data.price) || 0.5, side: data.side || '' };
|
|
266
312
|
}
|
|
267
313
|
|
|
268
314
|
// ============================================================================
|
package/src/index.ts
CHANGED