@keystrokehq/polymarket 0.0.9 → 0.0.16-integration-id-canonicalization.0

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/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @keystrokehq/polymarket
2
+
3
+ Keystroke official integration for [Polymarket](https://polymarket.com) — decentralized prediction market data across the Gamma, CLOB, and Data APIs.
4
+
5
+ Credential sets live under [`./credential-sets`](./src/credential-sets/index.ts). Operations live under [`./operations`](./src/operations/index.ts).
@@ -0,0 +1,2 @@
1
+ import { n as polymarketCredentialSet, t as PolymarketCredentials } from "../polymarket.credential-set-jU6p-ps3.mjs";
2
+ export { type PolymarketCredentials, polymarketCredentialSet };
@@ -0,0 +1,3 @@
1
+ import { t as polymarketCredentialSet } from "../polymarket.credential-set-wbGYLp9q.mjs";
2
+
3
+ export { polymarketCredentialSet };
@@ -1,81 +1,81 @@
1
- import { r as createOfficialOperationFactory, t as polymarket } from "./integration-Bf-3OGOJ.mjs";
2
1
  import { z } from "zod";
3
2
 
4
- //#region src/client.ts
5
- const POLYMARKET_HOSTS = {
6
- gamma: "https://gamma-api.polymarket.com",
7
- clob: "https://clob.polymarket.com",
8
- data: "https://data-api.polymarket.com"
9
- };
10
- /**
11
- * Create a Polymarket API client from resolved credentials.
12
- *
13
- * @param credentials - Resolved credentials containing the API key
14
- * @returns A client with a typed `request` method
15
- */
16
- function createPolymarketClient(credentials) {
17
- const request = async (options) => {
18
- const { host, method, path, body, query } = options;
19
- let url = `${POLYMARKET_HOSTS[host]}${path}`;
20
- if (query) {
21
- const params = new URLSearchParams();
22
- for (const [key, value] of Object.entries(query)) if (value !== void 0) params.set(key, String(value));
23
- const qs = params.toString();
24
- if (qs) url = `${url}?${qs}`;
25
- }
26
- const headers = { Accept: "application/json" };
27
- if (credentials.POLYMARKET_API_KEY) headers.Authorization = `Bearer ${credentials.POLYMARKET_API_KEY}`;
28
- if (body !== void 0) headers["Content-Type"] = "application/json";
29
- const response = await fetch(url, {
30
- method,
31
- headers,
32
- body: body !== void 0 ? JSON.stringify(body) : void 0
33
- });
34
- if (!response.ok) {
35
- const errorBody = await response.text().catch(() => "");
36
- throw new Error(`Polymarket API error (${host}): ${response.status} ${response.statusText}${errorBody ? ` — ${errorBody}` : ""}`);
37
- }
38
- const data = await response.json();
39
- if (data === null || data === void 0) throw new Error(`Polymarket API returned empty response for ${method} ${url} (status ${response.status})`);
40
- return data;
41
- };
42
- return { request };
43
- }
3
+ //#region src/schemas/orderbook.ts
4
+ const orderBookEntrySchema = z.object({
5
+ price: z.string(),
6
+ size: z.string()
7
+ });
8
+ const orderBookSummarySchema = z.object({
9
+ market: z.string().optional(),
10
+ asset_id: z.string(),
11
+ timestamp: z.string().optional(),
12
+ hash: z.string().optional(),
13
+ bids: z.array(orderBookEntrySchema),
14
+ asks: z.array(orderBookEntrySchema),
15
+ min_order_size: z.string().optional(),
16
+ tick_size: z.string().optional(),
17
+ neg_risk: z.boolean().optional()
18
+ }).passthrough();
19
+ const spreadSchema = z.object({
20
+ asset_id: z.string(),
21
+ spread: z.string(),
22
+ bid: z.string().optional(),
23
+ ask: z.string().optional()
24
+ }).passthrough();
44
25
 
45
26
  //#endregion
46
- //#region src/factory.ts
47
- const polymarketOperation = createOfficialOperationFactory(polymarket);
27
+ //#region src/schemas/pricing.ts
28
+ const clobPriceSchema = z.object({ price: z.string() });
29
+ const clobMidpointSchema = z.object({ mid: z.string() });
30
+ const clobPricesMapSchema = z.record(z.string(), z.object({
31
+ BUY: z.string(),
32
+ SELL: z.string()
33
+ }));
34
+ const priceHistoryPointSchema = z.object({
35
+ t: z.number(),
36
+ p: z.number()
37
+ });
38
+ const priceHistoryResponseSchema = z.object({ history: z.array(priceHistoryPointSchema) });
48
39
 
49
40
  //#endregion
50
- //#region src/schemas.ts
51
- /**
52
- * polymarket/schemas.ts
53
- *
54
- * All Zod schemas for Polymarket API objects.
55
- *
56
- * Three APIs with different conventions:
57
- * - Gamma API: Standard JSON types, camelCase fields
58
- * - CLOB API: String-typed numbers (e.g., { price: "0.54" })
59
- * - Data API: Polymarket-specific field names (proxyWallet, conditionId, etc.)
60
- *
61
- * Types are inferred from schemas — never defined separately.
62
- */
63
- /**
64
- * Pagination params used by all list endpoints (offset-based).
65
- */
66
- const paginationParamsSchema = z.object({
67
- limit: z.number().optional(),
68
- offset: z.number().optional()
69
- });
41
+ //#region src/schemas/discovery.ts
70
42
  const tagSchema = z.object({
71
43
  id: z.string(),
72
44
  label: z.string(),
73
45
  slug: z.string().optional()
74
46
  }).passthrough();
75
- /**
76
- * Market object from Gamma API.
77
- * Has 100+ fields — key fields are modeled explicitly with .passthrough() for the rest.
78
- */
47
+ const seriesSchema = z.object({
48
+ id: z.string(),
49
+ title: z.string(),
50
+ slug: z.string().optional(),
51
+ description: z.string().optional()
52
+ }).passthrough();
53
+ const searchResultSchema = z.object({
54
+ events: z.array(z.unknown()).optional(),
55
+ tags: z.array(z.unknown()).optional(),
56
+ profiles: z.array(z.unknown()).optional(),
57
+ pagination: z.object({
58
+ hasMore: z.boolean().optional(),
59
+ totalResults: z.number().optional()
60
+ }).optional()
61
+ });
62
+ const profileSchema = z.object({
63
+ address: z.string(),
64
+ pseudonym: z.string().optional(),
65
+ bio: z.string().optional(),
66
+ profileImage: z.string().optional(),
67
+ displayUsernamePublic: z.boolean().optional()
68
+ }).passthrough();
69
+ const sportsMetadataSchema = z.unknown();
70
+ const sportsMarketTypeSchema = z.unknown();
71
+ const sportsTeamSchema = z.unknown();
72
+
73
+ //#endregion
74
+ //#region src/schemas/markets.ts
75
+ const paginationParamsSchema = z.object({
76
+ limit: z.number().optional(),
77
+ offset: z.number().optional()
78
+ });
79
79
  const marketSchema = z.object({
80
80
  id: z.string(),
81
81
  question: z.string(),
@@ -106,11 +106,6 @@ const marketSchema = z.object({
106
106
  createdAt: z.string().optional(),
107
107
  updatedAt: z.string().optional()
108
108
  }).passthrough();
109
- /**
110
- * Valid order fields for Gamma API /markets endpoint.
111
- * Must match Market object property names (camelCase).
112
- * See: https://docs.polymarket.com/api-reference/markets/list-markets
113
- */
114
109
  const listMarketsOrderSchema = z.enum([
115
110
  "volume24hr",
116
111
  "volumeNum",
@@ -120,9 +115,6 @@ const listMarketsOrderSchema = z.enum([
120
115
  "competitive",
121
116
  "closedTime"
122
117
  ]).optional();
123
- /**
124
- * List markets query params.
125
- */
126
118
  const listMarketsParamsSchema = z.object({
127
119
  limit: z.number().optional(),
128
120
  offset: z.number().optional(),
@@ -144,10 +136,9 @@ const listMarketsParamsSchema = z.object({
144
136
  closed: z.boolean().optional(),
145
137
  active: z.boolean().optional()
146
138
  });
147
- /**
148
- * Event object from Gamma API.
149
- * Rich nested structure with markets[], tags[], categories[].
150
- */
139
+
140
+ //#endregion
141
+ //#region src/schemas/events.ts
151
142
  const eventSchema = z.object({
152
143
  id: z.string(),
153
144
  title: z.string(),
@@ -167,9 +158,6 @@ const eventSchema = z.object({
167
158
  tags: z.array(tagSchema).optional(),
168
159
  categories: z.array(z.unknown()).optional()
169
160
  }).passthrough();
170
- /**
171
- * List events query params.
172
- */
173
161
  const listEventsParamsSchema = z.object({
174
162
  limit: z.number().optional(),
175
163
  offset: z.number().optional(),
@@ -192,87 +180,9 @@ const listEventsParamsSchema = z.object({
192
180
  end_date_min: z.string().optional(),
193
181
  end_date_max: z.string().optional()
194
182
  });
195
- const seriesSchema = z.object({
196
- id: z.string(),
197
- title: z.string(),
198
- slug: z.string().optional(),
199
- description: z.string().optional()
200
- }).passthrough();
201
- const searchResultSchema = z.object({
202
- events: z.array(z.unknown()).optional(),
203
- tags: z.array(z.unknown()).optional(),
204
- profiles: z.array(z.unknown()).optional(),
205
- pagination: z.object({
206
- hasMore: z.boolean().optional(),
207
- totalResults: z.number().optional()
208
- }).optional()
209
- });
210
- const profileSchema = z.object({
211
- address: z.string(),
212
- pseudonym: z.string().optional(),
213
- bio: z.string().optional(),
214
- profileImage: z.string().optional(),
215
- displayUsernamePublic: z.boolean().optional()
216
- }).passthrough();
217
- const sportsMetadataSchema = z.unknown();
218
- const sportsMarketTypeSchema = z.unknown();
219
- const sportsTeamSchema = z.unknown();
220
- /**
221
- * CLOB price response — prices are strings, not numbers.
222
- */
223
- const clobPriceSchema = z.object({ price: z.string() });
224
- /**
225
- * CLOB midpoint response.
226
- */
227
- const clobMidpointSchema = z.object({ mid: z.string() });
228
- /**
229
- * CLOB /prices response — Record<token_id, { BUY: string, SELL: string }>
230
- */
231
- const clobPricesMapSchema = z.record(z.string(), z.object({
232
- BUY: z.string(),
233
- SELL: z.string()
234
- }));
235
- /**
236
- * CLOB price history point.
237
- */
238
- const priceHistoryPointSchema = z.object({
239
- t: z.number(),
240
- p: z.number()
241
- });
242
- /**
243
- * CLOB /prices-history response.
244
- */
245
- const priceHistoryResponseSchema = z.object({ history: z.array(priceHistoryPointSchema) });
246
- /**
247
- * Order book entry (bid or ask) — prices and sizes are strings.
248
- */
249
- const orderBookEntrySchema = z.object({
250
- price: z.string(),
251
- size: z.string()
252
- });
253
- /**
254
- * Order book summary for a token.
255
- */
256
- const orderBookSummarySchema = z.object({
257
- market: z.string().optional(),
258
- asset_id: z.string(),
259
- timestamp: z.string().optional(),
260
- hash: z.string().optional(),
261
- bids: z.array(orderBookEntrySchema),
262
- asks: z.array(orderBookEntrySchema),
263
- min_order_size: z.string().optional(),
264
- tick_size: z.string().optional(),
265
- neg_risk: z.boolean().optional()
266
- }).passthrough();
267
- /**
268
- * Spread for a token.
269
- */
270
- const spreadSchema = z.object({
271
- asset_id: z.string(),
272
- spread: z.string(),
273
- bid: z.string().optional(),
274
- ask: z.string().optional()
275
- }).passthrough();
183
+
184
+ //#endregion
185
+ //#region src/schemas/data.ts
276
186
  const tradeSchema = z.object({
277
187
  id: z.string().optional(),
278
188
  taker_order_id: z.string().optional(),
@@ -333,4 +243,4 @@ const liveVolumeSchema = z.object({
333
243
  }).passthrough();
334
244
 
335
245
  //#endregion
336
- export { spreadSchema as C, createPolymarketClient as D, polymarketOperation as E, sportsTeamSchema as S, tradeSchema as T, profileSchema as _, holderSchema as a, sportsMarketTypeSchema as b, liveVolumeSchema as c, orderBookEntrySchema as d, orderBookSummarySchema as f, priceHistoryResponseSchema as g, priceHistoryPointSchema as h, eventSchema as i, marketSchema as l, positionSchema as m, clobPriceSchema as n, listEventsParamsSchema as o, paginationParamsSchema as p, clobPricesMapSchema as r, listMarketsParamsSchema as s, clobMidpointSchema as t, openInterestSchema as u, searchResultSchema as v, tagSchema as w, sportsMetadataSchema as x, seriesSchema as y };
246
+ export { orderBookEntrySchema as C, priceHistoryResponseSchema as S, spreadSchema as T, tagSchema as _, tradeSchema as a, clobPricesMapSchema as b, listMarketsParamsSchema as c, profileSchema as d, searchResultSchema as f, sportsTeamSchema as g, sportsMetadataSchema as h, positionSchema as i, marketSchema as l, sportsMarketTypeSchema as m, liveVolumeSchema as n, eventSchema as o, seriesSchema as p, openInterestSchema as r, listEventsParamsSchema as s, holderSchema as t, paginationParamsSchema as u, clobMidpointSchema as v, orderBookSummarySchema as w, priceHistoryPointSchema as x, clobPriceSchema as y };