pmxt-core 2.9.1 → 2.10.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.
@@ -149,16 +149,34 @@ export declare abstract class PredictionMarketExchange {
149
149
  constructor(credentials?: ExchangeCredentials);
150
150
  abstract get name(): string;
151
151
  /**
152
- * Load and cache markets from the exchange.
153
- * This method populates `this.markets` and `this.marketsBySlug`.
152
+ * Load and cache all markets from the exchange into `this.markets` and `this.marketsBySlug`.
153
+ * Subsequent calls return the cached result without hitting the API again.
154
154
  *
155
- * @param reload - Force a reload of markets from the API even if already loaded
155
+ * This is the correct way to paginate or iterate over markets without drift.
156
+ * Because `fetchMarkets()` always hits the API, repeated calls with different `offset`
157
+ * values may return inconsistent results if the exchange reorders or adds markets between
158
+ * requests. Use `loadMarkets()` once to get a stable snapshot, then paginate over
159
+ * `Object.values(exchange.markets)` locally.
160
+ *
161
+ * @param reload - Force a fresh fetch from the API even if markets are already loaded
156
162
  * @returns Dictionary of markets indexed by marketId
163
+ *
164
+ * @example-ts Stable pagination
165
+ * await exchange.loadMarkets();
166
+ * const all = Object.values(exchange.markets);
167
+ * const page1 = all.slice(0, 100);
168
+ * const page2 = all.slice(100, 200);
169
+ *
170
+ * @example-python Stable pagination
171
+ * exchange.load_markets()
172
+ * all = list(exchange.markets.values())
173
+ * page1 = all[:100]
174
+ * page2 = all[100:200]
157
175
  */
158
176
  loadMarkets(reload?: boolean): Promise<Record<string, UnifiedMarket>>;
159
177
  /**
160
178
  * Fetch markets with optional filtering, search, or slug lookup.
161
- * This is the primary method for retrieving markets.
179
+ * Always hits the exchange API results reflect the live state at the time of the call.
162
180
  *
163
181
  * @param params - Optional parameters for filtering and search
164
182
  * @param params.query - Search keyword to filter markets
@@ -169,6 +187,10 @@ export declare abstract class PredictionMarketExchange {
169
187
  * @param params.searchIn - Where to search ('title' | 'description' | 'both')
170
188
  * @returns Array of unified markets
171
189
  *
190
+ * @note Calling this repeatedly with different `offset` values does not guarantee stable
191
+ * ordering — exchanges may reorder or add markets between requests. For stable iteration
192
+ * across pages, use `loadMarkets()` and paginate over `Object.values(exchange.markets)`.
193
+ *
172
194
  * @note Some exchanges (like Limitless) may only support status 'active' for search results.
173
195
  *
174
196
  * @example-ts Fetch markets
@@ -71,11 +71,29 @@ class PredictionMarketExchange {
71
71
  });
72
72
  }
73
73
  /**
74
- * Load and cache markets from the exchange.
75
- * This method populates `this.markets` and `this.marketsBySlug`.
74
+ * Load and cache all markets from the exchange into `this.markets` and `this.marketsBySlug`.
75
+ * Subsequent calls return the cached result without hitting the API again.
76
76
  *
77
- * @param reload - Force a reload of markets from the API even if already loaded
77
+ * This is the correct way to paginate or iterate over markets without drift.
78
+ * Because `fetchMarkets()` always hits the API, repeated calls with different `offset`
79
+ * values may return inconsistent results if the exchange reorders or adds markets between
80
+ * requests. Use `loadMarkets()` once to get a stable snapshot, then paginate over
81
+ * `Object.values(exchange.markets)` locally.
82
+ *
83
+ * @param reload - Force a fresh fetch from the API even if markets are already loaded
78
84
  * @returns Dictionary of markets indexed by marketId
85
+ *
86
+ * @example-ts Stable pagination
87
+ * await exchange.loadMarkets();
88
+ * const all = Object.values(exchange.markets);
89
+ * const page1 = all.slice(0, 100);
90
+ * const page2 = all.slice(100, 200);
91
+ *
92
+ * @example-python Stable pagination
93
+ * exchange.load_markets()
94
+ * all = list(exchange.markets.values())
95
+ * page1 = all[:100]
96
+ * page2 = all[100:200]
79
97
  */
80
98
  async loadMarkets(reload = false) {
81
99
  if (this.loadedMarkets && !reload) {
@@ -98,7 +116,7 @@ class PredictionMarketExchange {
98
116
  }
99
117
  /**
100
118
  * Fetch markets with optional filtering, search, or slug lookup.
101
- * This is the primary method for retrieving markets.
119
+ * Always hits the exchange API results reflect the live state at the time of the call.
102
120
  *
103
121
  * @param params - Optional parameters for filtering and search
104
122
  * @param params.query - Search keyword to filter markets
@@ -109,6 +127,10 @@ class PredictionMarketExchange {
109
127
  * @param params.searchIn - Where to search ('title' | 'description' | 'both')
110
128
  * @returns Array of unified markets
111
129
  *
130
+ * @note Calling this repeatedly with different `offset` values does not guarantee stable
131
+ * ordering — exchanges may reorder or add markets between requests. For stable iteration
132
+ * across pages, use `loadMarkets()` and paginate over `Object.values(exchange.markets)`.
133
+ *
112
134
  * @note Some exchanges (like Limitless) may only support status 'active' for search results.
113
135
  *
114
136
  * @example-ts Fetch markets
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/kalshi/Kalshi.yaml
3
- * Generated at: 2026-02-18T16:13:58.523Z
3
+ * Generated at: 2026-02-19T11:56:56.608Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const kalshiApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.kalshiApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/kalshi/Kalshi.yaml
6
- * Generated at: 2026-02-18T16:13:58.523Z
6
+ * Generated at: 2026-02-19T11:56:56.608Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.kalshiApiSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/limitless/Limitless.yaml
3
- * Generated at: 2026-02-18T16:13:58.561Z
3
+ * Generated at: 2026-02-19T11:56:56.657Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const limitlessApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.limitlessApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/limitless/Limitless.yaml
6
- * Generated at: 2026-02-18T16:13:58.561Z
6
+ * Generated at: 2026-02-19T11:56:56.657Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.limitlessApiSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/myriad/myriad.yaml
3
- * Generated at: 2026-02-18T16:13:58.572Z
3
+ * Generated at: 2026-02-19T11:56:56.675Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const myriadApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.myriadApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/myriad/myriad.yaml
6
- * Generated at: 2026-02-18T16:13:58.572Z
6
+ * Generated at: 2026-02-19T11:56:56.675Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.myriadApiSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/PolymarketClobAPI.yaml
3
- * Generated at: 2026-02-18T16:13:58.529Z
3
+ * Generated at: 2026-02-19T11:56:56.616Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const polymarketClobSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.polymarketClobSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/PolymarketClobAPI.yaml
6
- * Generated at: 2026-02-18T16:13:58.529Z
6
+ * Generated at: 2026-02-19T11:56:56.616Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.polymarketClobSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/Polymarket_Data_API.yaml
3
- * Generated at: 2026-02-18T16:13:58.541Z
3
+ * Generated at: 2026-02-19T11:56:56.634Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const polymarketDataSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.polymarketDataSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/Polymarket_Data_API.yaml
6
- * Generated at: 2026-02-18T16:13:58.541Z
6
+ * Generated at: 2026-02-19T11:56:56.634Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.polymarketDataSpec = {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/PolymarketGammaAPI.yaml
3
- * Generated at: 2026-02-18T16:13:58.539Z
3
+ * Generated at: 2026-02-19T11:56:56.631Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const polymarketGammaSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.polymarketGammaSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/polymarket/PolymarketGammaAPI.yaml
6
- * Generated at: 2026-02-18T16:13:58.539Z
6
+ * Generated at: 2026-02-19T11:56:56.631Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.polymarketGammaSpec = {
@@ -46,9 +46,25 @@ export declare class PolymarketExchange extends PredictionMarketExchange {
46
46
  */
47
47
  private ensureAuth;
48
48
  /**
49
- * Pre-warm the SDK's internal caches for a token by fetching tick size,
50
- * fee rate, and neg-risk in parallel. Call this when you start watching
51
- * a market so that subsequent createOrder calls hit only POST /order.
49
+ * Pre-warm the SDK's internal caches for a market outcome.
50
+ *
51
+ * Fetches tick size, fee rate, and neg-risk in parallel so that subsequent
52
+ * `createOrder` calls skip those lookups and hit only `POST /order`.
53
+ * Call this when you start watching a market.
54
+ *
55
+ * @param outcomeId - The CLOB Token ID for the outcome (use `outcome.outcomeId`)
56
+ *
57
+ * @example-ts Pre-warm before placing orders
58
+ * const markets = await exchange.fetchMarkets({ query: 'Trump' });
59
+ * const outcomeId = markets[0].outcomes[0].outcomeId;
60
+ * await exchange.preWarmMarket(outcomeId);
61
+ * // Subsequent createOrder calls are faster
62
+ *
63
+ * @example-python Pre-warm before placing orders
64
+ * markets = exchange.fetch_markets(query='Trump')
65
+ * outcome_id = markets[0].outcomes[0].outcome_id
66
+ * exchange.pre_warm_market(outcome_id)
67
+ * # Subsequent create_order calls are faster
52
68
  */
53
69
  preWarmMarket(outcomeId: string): Promise<void>;
54
70
  createOrder(params: CreateOrderParams): Promise<Order>;
@@ -185,9 +185,25 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
185
185
  return this.auth;
186
186
  }
187
187
  /**
188
- * Pre-warm the SDK's internal caches for a token by fetching tick size,
189
- * fee rate, and neg-risk in parallel. Call this when you start watching
190
- * a market so that subsequent createOrder calls hit only POST /order.
188
+ * Pre-warm the SDK's internal caches for a market outcome.
189
+ *
190
+ * Fetches tick size, fee rate, and neg-risk in parallel so that subsequent
191
+ * `createOrder` calls skip those lookups and hit only `POST /order`.
192
+ * Call this when you start watching a market.
193
+ *
194
+ * @param outcomeId - The CLOB Token ID for the outcome (use `outcome.outcomeId`)
195
+ *
196
+ * @example-ts Pre-warm before placing orders
197
+ * const markets = await exchange.fetchMarkets({ query: 'Trump' });
198
+ * const outcomeId = markets[0].outcomes[0].outcomeId;
199
+ * await exchange.preWarmMarket(outcomeId);
200
+ * // Subsequent createOrder calls are faster
201
+ *
202
+ * @example-python Pre-warm before placing orders
203
+ * markets = exchange.fetch_markets(query='Trump')
204
+ * outcome_id = markets[0].outcomes[0].outcome_id
205
+ * exchange.pre_warm_market(outcome_id)
206
+ * # Subsequent create_order calls are faster
191
207
  */
192
208
  async preWarmMarket(outcomeId) {
193
209
  const auth = this.ensureAuth();
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/probable/probable.yaml
3
- * Generated at: 2026-02-18T16:13:58.565Z
3
+ * Generated at: 2026-02-19T11:56:56.667Z
4
4
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
5
5
  */
6
6
  export declare const probableApiSpec: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.probableApiSpec = void 0;
4
4
  /**
5
5
  * Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/probable/probable.yaml
6
- * Generated at: 2026-02-18T16:13:58.565Z
6
+ * Generated at: 2026-02-19T11:56:56.667Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.probableApiSpec = {
@@ -26,7 +26,43 @@ export declare class ProbableExchange extends PredictionMarketExchange {
26
26
  private ensureAuth;
27
27
  protected fetchMarketsImpl(params?: MarketFetchParams): Promise<UnifiedMarket[]>;
28
28
  protected fetchEventsImpl(params: EventFetchParams): Promise<UnifiedEvent[]>;
29
+ /**
30
+ * Fetch a single event by its numeric ID (Probable only).
31
+ *
32
+ * @param id - The numeric event ID
33
+ * @returns The UnifiedEvent, or null if not found
34
+ *
35
+ * @example-ts Get event by ID
36
+ * const event = await exchange.getEventById('42');
37
+ * if (event) {
38
+ * console.log(event.title);
39
+ * console.log(event.markets.length, 'markets');
40
+ * }
41
+ *
42
+ * @example-python Get event by ID
43
+ * event = exchange.get_event_by_id('42')
44
+ * if event:
45
+ * print(event.title)
46
+ * print(len(event.markets), 'markets')
47
+ */
29
48
  getEventById(id: string): Promise<UnifiedEvent | null>;
49
+ /**
50
+ * Fetch a single event by its URL slug (Probable only).
51
+ *
52
+ * @param slug - The event's URL slug (e.g. `"trump-2024-election"`)
53
+ * @returns The UnifiedEvent, or null if not found
54
+ *
55
+ * @example-ts Get event by slug
56
+ * const event = await exchange.getEventBySlug('trump-2024-election');
57
+ * if (event) {
58
+ * console.log(event.title);
59
+ * }
60
+ *
61
+ * @example-python Get event by slug
62
+ * event = exchange.get_event_by_slug('trump-2024-election')
63
+ * if event:
64
+ * print(event.title)
65
+ */
30
66
  getEventBySlug(slug: string): Promise<UnifiedEvent | null>;
31
67
  fetchOrderBook(id: string): Promise<OrderBook>;
32
68
  fetchOHLCV(id: string, params: OHLCVParams | HistoryFilterParams): Promise<PriceCandle[]>;
@@ -82,9 +82,45 @@ class ProbableExchange extends BaseExchange_1.PredictionMarketExchange {
82
82
  async fetchEventsImpl(params) {
83
83
  return (0, fetchEvents_1.fetchEvents)(params, this.http, (tokenId) => this.callApi('getPublicApiV1Midpoint', { token_id: tokenId }), (queryParams) => this.callApi('getPublicApiV1PublicSearch', queryParams));
84
84
  }
85
+ /**
86
+ * Fetch a single event by its numeric ID (Probable only).
87
+ *
88
+ * @param id - The numeric event ID
89
+ * @returns The UnifiedEvent, or null if not found
90
+ *
91
+ * @example-ts Get event by ID
92
+ * const event = await exchange.getEventById('42');
93
+ * if (event) {
94
+ * console.log(event.title);
95
+ * console.log(event.markets.length, 'markets');
96
+ * }
97
+ *
98
+ * @example-python Get event by ID
99
+ * event = exchange.get_event_by_id('42')
100
+ * if event:
101
+ * print(event.title)
102
+ * print(len(event.markets), 'markets')
103
+ */
85
104
  async getEventById(id) {
86
105
  return (0, fetchEvents_1.fetchEventById)(id, this.http, (tokenId) => this.callApi('getPublicApiV1Midpoint', { token_id: tokenId }));
87
106
  }
107
+ /**
108
+ * Fetch a single event by its URL slug (Probable only).
109
+ *
110
+ * @param slug - The event's URL slug (e.g. `"trump-2024-election"`)
111
+ * @returns The UnifiedEvent, or null if not found
112
+ *
113
+ * @example-ts Get event by slug
114
+ * const event = await exchange.getEventBySlug('trump-2024-election');
115
+ * if (event) {
116
+ * console.log(event.title);
117
+ * }
118
+ *
119
+ * @example-python Get event by slug
120
+ * event = exchange.get_event_by_slug('trump-2024-election')
121
+ * if event:
122
+ * print(event.title)
123
+ */
88
124
  async getEventBySlug(slug) {
89
125
  return (0, fetchEvents_1.fetchEventBySlug)(slug, this.http, (tokenId) => this.callApi('getPublicApiV1Midpoint', { token_id: tokenId }));
90
126
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxt-core",
3
- "version": "2.9.1",
3
+ "version": "2.10.0",
4
4
  "description": "pmxt is a unified prediction market data API. The ccxt for prediction markets.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,8 +29,8 @@
29
29
  "test": "jest -c jest.config.js",
30
30
  "server": "tsx watch src/server/index.ts",
31
31
  "server:prod": "node dist/server/index.js",
32
- "generate:sdk:python": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g python -o ../sdks/python/generated --package-name pmxt_internal --additional-properties=projectName=pmxt-internal,packageVersion=2.9.1,library=urllib3",
33
- "generate:sdk:typescript": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g typescript-fetch -o ../sdks/typescript/generated --additional-properties=npmName=pmxtjs,npmVersion=2.9.1,supportsES6=true,typescriptThreePlus=true && node ../sdks/typescript/scripts/fix-generated.js",
32
+ "generate:sdk:python": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g python -o ../sdks/python/generated --package-name pmxt_internal --additional-properties=projectName=pmxt-internal,packageVersion=2.10.0,library=urllib3",
33
+ "generate:sdk:typescript": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g typescript-fetch -o ../sdks/typescript/generated --additional-properties=npmName=pmxtjs,npmVersion=2.10.0,supportsES6=true,typescriptThreePlus=true && node ../sdks/typescript/scripts/fix-generated.js",
34
34
  "fetch:openapi": "node scripts/fetch-openapi-specs.js",
35
35
  "extract:jsdoc": "node ../scripts/extract-jsdoc.js",
36
36
  "generate:docs": "npm run extract:jsdoc && node ../scripts/generate-api-docs.js",