@varla/polymarket 1.0.0 → 1.1.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/AGENTS.md +221 -10
- package/README.md +284 -97
- package/dist/index.js +473 -5104
- package/package.json +12 -7
package/AGENTS.md
CHANGED
|
@@ -6,6 +6,8 @@ This file provides context for AI coding assistants (Cursor, Cline, Copilot, etc
|
|
|
6
6
|
|
|
7
7
|
`@varla/polymarket` is a high-performance Polymarket SDK that's **139% faster** than the official `@polymarket/clob-client`. It provides full trading support for Polymarket's CLOB and Gamma APIs.
|
|
8
8
|
|
|
9
|
+
**Total API Coverage: 91 methods across 6 clients**
|
|
10
|
+
|
|
9
11
|
## Tech Stack
|
|
10
12
|
|
|
11
13
|
| Technology | Purpose |
|
|
@@ -14,7 +16,6 @@ This file provides context for AI coding assistants (Cursor, Cline, Copilot, etc
|
|
|
14
16
|
| **viem** | Ethereum wallet/signing (not ethers.js) |
|
|
15
17
|
| **Web Crypto API** | HMAC/SHA256 (not node:crypto) |
|
|
16
18
|
| **fetch** | HTTP (not axios) |
|
|
17
|
-
| **SQLite** | Order persistence (via @varla/db) |
|
|
18
19
|
| **Biome** | Linting & formatting |
|
|
19
20
|
|
|
20
21
|
## Critical Rules
|
|
@@ -57,13 +58,15 @@ await Bun.write("path", content);
|
|
|
57
58
|
packages/polymarket/
|
|
58
59
|
├── src/
|
|
59
60
|
│ ├── index.ts # Public exports
|
|
60
|
-
│ ├──
|
|
61
|
-
│ ├── clob-
|
|
61
|
+
│ ├── gamma-client.ts # Gamma API (28 methods)
|
|
62
|
+
│ ├── clob-client.ts # Public CLOB API (5 methods)
|
|
63
|
+
│ ├── clob-trading-client.ts # Authenticated trading (30 methods)
|
|
64
|
+
│ ├── data-api-client.ts # Data/Analytics API (16 methods)
|
|
65
|
+
│ ├── bridge-client.ts # Bridge API (5 methods)
|
|
66
|
+
│ ├── clob-ws.ts # WebSocket client (7 methods)
|
|
62
67
|
│ ├── clob-auth.ts # API key management, EIP712 auth
|
|
63
68
|
│ ├── clob-orders.ts # Order building & signing
|
|
64
|
-
│ ├── clob-persistence.ts #
|
|
65
|
-
│ ├── clob-ws.ts # WebSocket client
|
|
66
|
-
│ ├── gamma-client.ts # Gamma API (markets, metadata)
|
|
69
|
+
│ ├── clob-persistence.ts # Order tracking (in-memory)
|
|
67
70
|
│ ├── signing/ # HMAC & EIP712 signatures
|
|
68
71
|
│ ├── config/ # Contract addresses, endpoints
|
|
69
72
|
│ └── abi/ # Contract ABIs
|
|
@@ -77,6 +80,212 @@ packages/polymarket/
|
|
|
77
80
|
└── SDK_COMPARISON.md # Official SDK comparison
|
|
78
81
|
```
|
|
79
82
|
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Complete API Reference
|
|
86
|
+
|
|
87
|
+
### GammaClient (28 methods)
|
|
88
|
+
|
|
89
|
+
Market discovery, metadata, and content API.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { GammaClient } from "@varla/polymarket";
|
|
93
|
+
const gamma = new GammaClient(opts?: GammaClientOpts);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
| Method | Parameters | Returns |
|
|
97
|
+
|--------|------------|---------|
|
|
98
|
+
| **Markets** | | |
|
|
99
|
+
| `listMarkets` | `{ active?, closed?, limit?, offset?, tag_id? }` | `Promise<GammaMarket[]>` |
|
|
100
|
+
| `getMarketsByConditionIds` | `conditionIds: string[]` | `Promise<GammaMarket[]>` |
|
|
101
|
+
| `getMarketById` | `id: string` | `Promise<GammaMarket>` |
|
|
102
|
+
| `getMarketBySlug` | `slug: string` | `Promise<GammaMarket>` |
|
|
103
|
+
| `getMarketTags` | `marketId: string` | `Promise<GammaTag[]>` |
|
|
104
|
+
| **Events** | | |
|
|
105
|
+
| `listEvents` | `{ active?, closed?, limit?, offset?, tag_id?, series_id?, order?, ascending? }` | `Promise<GammaEvent[]>` |
|
|
106
|
+
| `getEventById` | `id: string` | `Promise<GammaEvent>` |
|
|
107
|
+
| `getEventBySlug` | `slug: string` | `Promise<GammaEvent>` |
|
|
108
|
+
| `getEventTags` | `eventId: string` | `Promise<GammaTag[]>` |
|
|
109
|
+
| **Tags** | | |
|
|
110
|
+
| `listTags` | `{ limit?, offset? }` | `Promise<GammaTag[]>` |
|
|
111
|
+
| `getTagById` | `id: string` | `Promise<GammaTag>` |
|
|
112
|
+
| `getTagBySlug` | `slug: string` | `Promise<GammaTag>` |
|
|
113
|
+
| `getRelatedTagsById` | `id: string` | `Promise<GammaTag[]>` |
|
|
114
|
+
| `getRelatedTagsBySlug` | `slug: string` | `Promise<GammaTag[]>` |
|
|
115
|
+
| `getTagRelationshipsById` | `id: string` | `Promise<GammaTagRelationship[]>` |
|
|
116
|
+
| `getTagRelationshipsBySlug` | `slug: string` | `Promise<GammaTagRelationship[]>` |
|
|
117
|
+
| **Sports** | | |
|
|
118
|
+
| `getSports` | — | `Promise<GammaSport[]>` |
|
|
119
|
+
| `listTeams` | `{ sport?, limit?, offset? }` | `Promise<GammaTeam[]>` |
|
|
120
|
+
| `getValidSportsMarketTypes` | — | `Promise<GammaSportsMarketType[]>` |
|
|
121
|
+
| **Series** | | |
|
|
122
|
+
| `listSeries` | `{ limit?, offset? }` | `Promise<GammaSeries[]>` |
|
|
123
|
+
| `getSeriesById` | `id: string` | `Promise<GammaSeries>` |
|
|
124
|
+
| **Search** | | |
|
|
125
|
+
| `search` | `query: string, { limit?, offset? }` | `Promise<GammaSearchResult>` |
|
|
126
|
+
| **Profiles** | | |
|
|
127
|
+
| `getPublicProfile` | `address: string` | `Promise<GammaPublicProfile>` |
|
|
128
|
+
| **Comments** | | |
|
|
129
|
+
| `listComments` | `{ eventId?, marketId?, limit?, offset? }` | `Promise<GammaComment[]>` |
|
|
130
|
+
| `getCommentById` | `id: string` | `Promise<GammaComment>` |
|
|
131
|
+
| `getCommentsByUser` | `address: string, { limit?, offset? }` | `Promise<GammaComment[]>` |
|
|
132
|
+
| **Builders** | | |
|
|
133
|
+
| `getBuilderLeaderboard` | `{ period?, limit?, offset? }` | `Promise<GammaBuilderLeaderboardEntry[]>` |
|
|
134
|
+
| `getBuilderVolume` | `{ address?, startDate?, endDate? }` | `Promise<GammaBuilderVolumePoint[]>` |
|
|
135
|
+
| **Health** | | |
|
|
136
|
+
| `healthCheck` | — | `Promise<{ status: string }>` |
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
### ClobClient (5 methods)
|
|
141
|
+
|
|
142
|
+
Public orderbook, prices (read-only with circuit breaker & rate limiting).
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { ClobClient } from "@varla/polymarket";
|
|
146
|
+
const clob = new ClobClient(config?: Partial<ClobClientConfig>);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
| Method | Parameters | Returns |
|
|
150
|
+
|--------|------------|---------|
|
|
151
|
+
| `getMidpoint` | `tokenId: string` | `Promise<ClobMidpointResponse>` |
|
|
152
|
+
| `getBook` | `tokenId: string` | `Promise<ClobBookResponse>` |
|
|
153
|
+
| `getPricesHistory` | `{ tokenId, startTs, endTs, interval, fidelity? }` | `Promise<ClobPricesHistoryResponse>` |
|
|
154
|
+
| `getMetrics` | — | `ClobClientMetrics` |
|
|
155
|
+
| `getCircuitState` | — | `CircuitState` |
|
|
156
|
+
| `resetCircuitBreaker` | — | `void` |
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
### ClobTradingClient (30 methods)
|
|
161
|
+
|
|
162
|
+
Authenticated trading operations.
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { ClobTradingClient } from "@varla/polymarket";
|
|
166
|
+
const client = new ClobTradingClient(walletClient, config?: ClobTradingClientConfig);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
| Method | Parameters | Returns |
|
|
170
|
+
|--------|------------|---------|
|
|
171
|
+
| **Initialization** | | |
|
|
172
|
+
| `init` | — | `Promise<void>` |
|
|
173
|
+
| `isInitialized` | — | `boolean` |
|
|
174
|
+
| `getCredentials` | — | `ApiKeyCreds` |
|
|
175
|
+
| `setCredentials` | `creds: ApiKeyCreds` | `void` |
|
|
176
|
+
| **Orders** | | |
|
|
177
|
+
| `createOrder` | `params: OrderParams, options: MarketOptions` | `Promise<SignedOrder>` |
|
|
178
|
+
| `postOrder` | `signedOrder: SignedOrder, orderType?: OrderType` | `Promise<OrderResponse>` |
|
|
179
|
+
| `createAndPostOrder` | `params: OrderParams, options: MarketOptions, orderType?: OrderType` | `Promise<OrderResponse>` |
|
|
180
|
+
| `postOrders` | `signedOrders: SignedOrder[], orderType?: OrderType` | `Promise<BatchOrderResponse>` |
|
|
181
|
+
| `createAndPostOrders` | `ordersParams: Array<{params, options}>, orderType?: OrderType` | `Promise<BatchOrderResponse>` |
|
|
182
|
+
| `getOrder` | `orderId: string` | `Promise<Order>` |
|
|
183
|
+
| `getOpenOrders` | `filter?: OpenOrdersFilter` | `Promise<Order[]>` |
|
|
184
|
+
| **Market Orders** | | |
|
|
185
|
+
| `marketBuy` | `params: MarketBuyParams, options: MarketOptions, timeInForce?: TimeInForce` | `Promise<OrderResponse>` |
|
|
186
|
+
| `marketSell` | `params: MarketSellParams, options: MarketOptions, timeInForce?: TimeInForce` | `Promise<OrderResponse>` |
|
|
187
|
+
| `getOrderBook` | `tokenId: string` | `Promise<OrderBook>` |
|
|
188
|
+
| **Cancellation** | | |
|
|
189
|
+
| `cancelOrder` | `orderId: string` | `Promise<CancelResponse>` |
|
|
190
|
+
| `cancelOrders` | `orderIds: string[]` | `Promise<CancelResponse>` |
|
|
191
|
+
| `cancelMarketOrders` | `{ market?, asset_id? }` | `Promise<CancelResponse>` |
|
|
192
|
+
| `cancelAll` | — | `Promise<CancelResponse>` |
|
|
193
|
+
| **Account** | | |
|
|
194
|
+
| `getClosedOnlyMode` | — | `Promise<{ closedOnly: boolean; reason?: string }>` |
|
|
195
|
+
| `getApiKeys` | — | `Promise<{ apiKeys: Array<{apiKey, createdAt}> }>` |
|
|
196
|
+
| `deleteApiKey` | — | `Promise<void>` |
|
|
197
|
+
| **Trades & History** | | |
|
|
198
|
+
| `getTrades` | `filter?: TradeHistoryFilter` | `Promise<Trade[]>` |
|
|
199
|
+
| `heartbeat` | — | `Promise<HeartbeatResponse>` |
|
|
200
|
+
| **Rewards** | | |
|
|
201
|
+
| `getEarningsForDay` | `date: string` | `Promise<UserEarnings>` |
|
|
202
|
+
| `getTotalEarningsForDay` | `date: string` | `Promise<UserEarnings>` |
|
|
203
|
+
| `getLiquidityRewardPercentages` | — | `Promise<LiquidityRewardPercentages>` |
|
|
204
|
+
| `getRewardsMarkets` | — | `Promise<RewardsMarket[]>` |
|
|
205
|
+
| **Builder API** | | |
|
|
206
|
+
| `createBuilderApiKey` | — | `Promise<BuilderApiKey>` |
|
|
207
|
+
| `getBuilderApiKeys` | — | `Promise<BuilderApiKeyInfo[]>` |
|
|
208
|
+
| `revokeBuilderApiKey` | — | `Promise<void>` |
|
|
209
|
+
| `getBuilderTrades` | `filter?: BuilderTradesFilter, cursor?: string` | `Promise<BuilderTradesResponse>` |
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
### DataApiClient (16 methods)
|
|
214
|
+
|
|
215
|
+
Positions, trades, leaderboards, and analytics.
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
import { DataApiClient } from "@varla/polymarket";
|
|
219
|
+
const data = new DataApiClient(opts?: DataApiClientOpts);
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
| Method | Parameters | Returns |
|
|
223
|
+
|--------|------------|---------|
|
|
224
|
+
| **Positions** | | |
|
|
225
|
+
| `getCurrentPositions` | `{ address, conditionId?, limit?, offset? }` | `Promise<DataPosition[]>` |
|
|
226
|
+
| `getClosedPositions` | `{ address, limit?, offset? }` | `Promise<DataClosedPosition[]>` |
|
|
227
|
+
| `getTotalPositionValue` | `address: string` | `Promise<DataPositionValue>` |
|
|
228
|
+
| **Trades & Activity** | | |
|
|
229
|
+
| `getTrades` | `{ address?, conditionId?, limit?, offset? }` | `Promise<DataTrade[]>` |
|
|
230
|
+
| `getUserActivity` | `{ address, limit?, offset? }` | `Promise<DataActivity[]>` |
|
|
231
|
+
| **Analytics** | | |
|
|
232
|
+
| `getTopHolders` | `{ conditionId, outcomeIndex?, limit? }` | `Promise<DataTopHolder[]>` |
|
|
233
|
+
| `getTraderLeaderboard` | `{ period?, category?, order?, limit?, offset? }` | `Promise<DataLeaderboardEntry[]>` |
|
|
234
|
+
| `getOpenInterest` | `{ conditionId?, asset? }` | `Promise<DataOpenInterest>` |
|
|
235
|
+
| `getLiveVolume` | `{ eventId?, conditionId? }` | `Promise<DataVolume>` |
|
|
236
|
+
| **Pricing & Orderbook** | | |
|
|
237
|
+
| `getPriceHistory` | `{ tokenId, interval?, startTs?, endTs?, fidelity? }` | `Promise<DataPriceHistory>` |
|
|
238
|
+
| `getOrderBookSummary` | `tokenId: string` | `Promise<DataOrderBookSummary>` |
|
|
239
|
+
| `getOrderBookSummaries` | `tokenIds: string[]` | `Promise<DataOrderBookSummary[]>` |
|
|
240
|
+
| `getSpreads` | `tokenIds: string[]` | `Promise<DataSpread[]>` |
|
|
241
|
+
| **Misc** | | |
|
|
242
|
+
| `getTotalMarketsTraded` | `address: string` | `Promise<DataMarketsTraded>` |
|
|
243
|
+
| `getAccountingSnapshot` | `address: string` | `Promise<Response>` |
|
|
244
|
+
| `healthCheck` | — | `Promise<{ status: string }>` |
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
### BridgeClient (5 methods)
|
|
249
|
+
|
|
250
|
+
Deposit/withdrawal through Relay bridge.
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
import { BridgeClient } from "@varla/polymarket";
|
|
254
|
+
const bridge = new BridgeClient(opts?: BridgeClientOpts);
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
| Method | Parameters | Returns |
|
|
258
|
+
|--------|------------|---------|
|
|
259
|
+
| `createDepositAddresses` | `{ userAddress, chain, asset? }` | `Promise<BridgeDepositAddress>` |
|
|
260
|
+
| `createWithdrawalAddresses` | `{ userAddress, destinationAddress, chain, asset, amount }` | `Promise<BridgeWithdrawalAddress>` |
|
|
261
|
+
| `getQuote` | `{ fromChain, toChain, fromAsset, toAsset, amount }` | `Promise<BridgeQuote>` |
|
|
262
|
+
| `getSupportedAssets` | — | `Promise<BridgeSupportedAsset[]>` |
|
|
263
|
+
| `getTransactionStatus` | `transactionId: string` | `Promise<BridgeTransactionStatus>` |
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
### ClobWsClient (7 methods)
|
|
268
|
+
|
|
269
|
+
Real-time WebSocket updates.
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
import { ClobWsClient } from "@varla/polymarket";
|
|
273
|
+
const ws = new ClobWsClient(events?: ClobWsEvents, config?: ClobWsConfig);
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
| Method | Parameters | Returns |
|
|
277
|
+
|--------|------------|---------|
|
|
278
|
+
| `connect` | — | `void` |
|
|
279
|
+
| `close` | — | `void` |
|
|
280
|
+
| `subscribeMarket` | `market: string` | `void` |
|
|
281
|
+
| `unsubscribeMarket` | `market: string` | `void` |
|
|
282
|
+
| `subscribeMarkets` | `markets: string[]` | `void` |
|
|
283
|
+
| `getState` | — | `ClobWsState` |
|
|
284
|
+
| `isConnected` | — | `boolean` |
|
|
285
|
+
| `getSubscribedMarkets` | — | `string[]` |
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
80
289
|
## Key Patterns
|
|
81
290
|
|
|
82
291
|
### EIP712 Signing (Orders & Auth)
|
|
@@ -178,10 +387,12 @@ describe("Feature", () => {
|
|
|
178
387
|
|
|
179
388
|
### Add New API Method
|
|
180
389
|
|
|
181
|
-
1. Add type to `src/clob-trading-types.ts`
|
|
182
|
-
2. Add method to
|
|
183
|
-
3. Add test to `test/unit
|
|
184
|
-
4.
|
|
390
|
+
1. Add type to `src/types.ts` or `src/clob-trading-types.ts`
|
|
391
|
+
2. Add method to appropriate client file
|
|
392
|
+
3. Add unit test to `test/unit/`
|
|
393
|
+
4. Add live test to `test/live/` (optional)
|
|
394
|
+
5. Update `src/index.ts` exports if needed
|
|
395
|
+
6. Update this AGENTS.md API reference
|
|
185
396
|
|
|
186
397
|
### Add New Config
|
|
187
398
|
|