pmxt-core 2.0.7 → 2.0.8
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/BaseExchange.d.ts +310 -73
- package/dist/BaseExchange.js +310 -73
- package/dist/exchanges/limitless/index.d.ts +30 -3
- package/dist/exchanges/limitless/index.js +30 -3
- package/package.json +5 -4
package/dist/BaseExchange.d.ts
CHANGED
|
@@ -101,40 +101,52 @@ export declare abstract class PredictionMarketExchange {
|
|
|
101
101
|
abstract get name(): string;
|
|
102
102
|
/**
|
|
103
103
|
* Fetch markets with optional filtering, search, or slug lookup.
|
|
104
|
-
* This is the primary method for retrieving markets
|
|
104
|
+
* This is the primary method for retrieving markets.
|
|
105
105
|
*
|
|
106
106
|
* @param params - Optional parameters for filtering and search
|
|
107
107
|
* @param params.query - Search keyword to filter markets
|
|
108
108
|
* @param params.slug - Market slug/ticker for direct lookup
|
|
109
109
|
* @param params.limit - Maximum number of results
|
|
110
110
|
* @param params.offset - Pagination offset
|
|
111
|
-
* @param params.sort - Sort order
|
|
112
|
-
* @param params.searchIn - Where to search (title
|
|
111
|
+
* @param params.sort - Sort order ('volume' | 'liquidity' | 'newest')
|
|
112
|
+
* @param params.searchIn - Where to search ('title' | 'description' | 'both')
|
|
113
113
|
* @returns Array of unified markets
|
|
114
114
|
*
|
|
115
|
-
* @example Fetch
|
|
116
|
-
* await exchange.fetchMarkets()
|
|
115
|
+
* @example-ts Fetch markets
|
|
116
|
+
* const markets = await exchange.fetchMarkets({ query: 'Trump', limit: 20 });
|
|
117
|
+
* console.log(markets[0].title);
|
|
117
118
|
*
|
|
118
|
-
* @example
|
|
119
|
-
* await exchange.fetchMarkets({
|
|
119
|
+
* @example-ts Get market by slug
|
|
120
|
+
* const markets = await exchange.fetchMarkets({ slug: 'will-trump-win' });
|
|
120
121
|
*
|
|
121
|
-
* @example
|
|
122
|
-
*
|
|
122
|
+
* @example-python Fetch markets
|
|
123
|
+
* markets = exchange.fetch_markets(query='Trump', limit=20)
|
|
124
|
+
* print(markets[0].title)
|
|
125
|
+
*
|
|
126
|
+
* @example-python Get market by slug
|
|
127
|
+
* markets = exchange.fetch_markets(slug='will-trump-win')
|
|
123
128
|
*/
|
|
124
129
|
fetchMarkets(params?: MarketFetchParams): Promise<UnifiedMarket[]>;
|
|
125
130
|
/**
|
|
126
131
|
* Fetch events with optional keyword search.
|
|
127
|
-
* Events group related markets together.
|
|
132
|
+
* Events group related markets together (e.g., "Who will be Fed Chair?" contains multiple candidate markets).
|
|
128
133
|
*
|
|
129
134
|
* @param params - Optional parameters for search and filtering
|
|
130
|
-
* @param params.query - Search keyword to filter events
|
|
135
|
+
* @param params.query - Search keyword to filter events (required)
|
|
131
136
|
* @param params.limit - Maximum number of results
|
|
132
137
|
* @param params.offset - Pagination offset
|
|
133
|
-
* @param params.searchIn - Where to search (title
|
|
138
|
+
* @param params.searchIn - Where to search ('title' | 'description' | 'both')
|
|
134
139
|
* @returns Array of unified events
|
|
135
140
|
*
|
|
136
|
-
* @example Search events
|
|
137
|
-
* await exchange.fetchEvents({ query: '
|
|
141
|
+
* @example-ts Search events
|
|
142
|
+
* const events = await exchange.fetchEvents({ query: 'Fed Chair' });
|
|
143
|
+
* const fedEvent = events[0];
|
|
144
|
+
* console.log(fedEvent.title, fedEvent.markets.length, 'markets');
|
|
145
|
+
*
|
|
146
|
+
* @example-python Search events
|
|
147
|
+
* events = exchange.fetch_events(query='Fed Chair')
|
|
148
|
+
* fed_event = events[0]
|
|
149
|
+
* print(fed_event.title, len(fed_event.markets), 'markets')
|
|
138
150
|
*/
|
|
139
151
|
fetchEvents(params?: EventFetchParams): Promise<UnifiedEvent[]>;
|
|
140
152
|
/**
|
|
@@ -149,138 +161,363 @@ export declare abstract class PredictionMarketExchange {
|
|
|
149
161
|
*/
|
|
150
162
|
protected fetchEventsImpl(params: EventFetchParams): Promise<UnifiedEvent[]>;
|
|
151
163
|
/**
|
|
152
|
-
* Fetch historical price data for a specific market outcome.
|
|
153
|
-
*
|
|
164
|
+
* Fetch historical OHLCV (candlestick) price data for a specific market outcome.
|
|
165
|
+
*
|
|
166
|
+
* @param id - The Outcome ID (outcomeId). Use outcome.outcomeId, NOT market.marketId
|
|
154
167
|
* @param params - OHLCV parameters including resolution (required)
|
|
168
|
+
* @returns Array of price candles
|
|
169
|
+
*
|
|
170
|
+
* @example-ts Fetch hourly candles
|
|
171
|
+
* const markets = await exchange.fetchMarkets({ query: 'Trump' });
|
|
172
|
+
* const outcomeId = markets[0].yes.outcomeId;
|
|
173
|
+
* const candles = await exchange.fetchOHLCV(outcomeId, {
|
|
174
|
+
* resolution: '1h',
|
|
175
|
+
* limit: 100
|
|
176
|
+
* });
|
|
177
|
+
* console.log(`Latest close: ${candles[candles.length - 1].close}`);
|
|
178
|
+
*
|
|
179
|
+
* @example-python Fetch hourly candles
|
|
180
|
+
* markets = exchange.fetch_markets(query='Trump')
|
|
181
|
+
* outcome_id = markets[0].yes.outcome_id
|
|
182
|
+
* candles = exchange.fetch_ohlcv(outcome_id, resolution='1h', limit=100)
|
|
183
|
+
* print(f"Latest close: {candles[-1].close}")
|
|
184
|
+
*
|
|
185
|
+
* @notes **CRITICAL**: Use `outcome.outcomeId` (TS) / `outcome.outcome_id` (Python), not the market ID.
|
|
186
|
+
* @notes Polymarket: outcomeId is the CLOB Token ID. Kalshi: outcomeId is the Market Ticker.
|
|
187
|
+
* @notes Resolution options: '1m' | '5m' | '15m' | '1h' | '6h' | '1d'
|
|
155
188
|
*/
|
|
156
189
|
fetchOHLCV(id: string, params: OHLCVParams | HistoryFilterParams): Promise<PriceCandle[]>;
|
|
157
190
|
/**
|
|
158
191
|
* Fetch the current order book (bids/asks) for a specific outcome.
|
|
159
|
-
* Essential for calculating
|
|
192
|
+
* Essential for calculating spread, depth, and execution prices.
|
|
193
|
+
*
|
|
194
|
+
* @param id - The Outcome ID (outcomeId)
|
|
195
|
+
* @returns Current order book with bids and asks
|
|
196
|
+
*
|
|
197
|
+
* @example-ts Fetch order book
|
|
198
|
+
* const book = await exchange.fetchOrderBook(outcome.outcomeId);
|
|
199
|
+
* console.log(`Best bid: ${book.bids[0].price}`);
|
|
200
|
+
* console.log(`Best ask: ${book.asks[0].price}`);
|
|
201
|
+
* console.log(`Spread: ${(book.asks[0].price - book.bids[0].price) * 100}%`);
|
|
202
|
+
*
|
|
203
|
+
* @example-python Fetch order book
|
|
204
|
+
* book = exchange.fetch_order_book(outcome.outcome_id)
|
|
205
|
+
* print(f"Best bid: {book.bids[0].price}")
|
|
206
|
+
* print(f"Best ask: {book.asks[0].price}")
|
|
207
|
+
* print(f"Spread: {(book.asks[0].price - book.bids[0].price) * 100:.2f}%")
|
|
160
208
|
*/
|
|
161
209
|
fetchOrderBook(id: string): Promise<OrderBook>;
|
|
162
210
|
/**
|
|
163
|
-
* Fetch raw trade history.
|
|
164
|
-
*
|
|
165
|
-
* @param
|
|
211
|
+
* Fetch raw trade history for a specific outcome.
|
|
212
|
+
*
|
|
213
|
+
* @param id - The Outcome ID (outcomeId)
|
|
214
|
+
* @param params - Trade filter parameters
|
|
215
|
+
* @returns Array of recent trades
|
|
216
|
+
*
|
|
217
|
+
* @example-ts Fetch recent trades
|
|
218
|
+
* const trades = await exchange.fetchTrades(outcome.outcomeId, { limit: 100 });
|
|
219
|
+
* for (const trade of trades) {
|
|
220
|
+
* console.log(`${trade.side} ${trade.amount} @ ${trade.price}`);
|
|
221
|
+
* }
|
|
222
|
+
*
|
|
223
|
+
* @example-python Fetch recent trades
|
|
224
|
+
* trades = exchange.fetch_trades(outcome.outcome_id, limit=100)
|
|
225
|
+
* for trade in trades:
|
|
226
|
+
* print(f"{trade.side} {trade.amount} @ {trade.price}")
|
|
227
|
+
*
|
|
228
|
+
* @notes Polymarket requires an API key for trade history. Use fetchOHLCV for public historical data.
|
|
166
229
|
*/
|
|
167
230
|
fetchTrades(id: string, params: TradesParams | HistoryFilterParams): Promise<Trade[]>;
|
|
168
231
|
/**
|
|
169
|
-
* Place a new order.
|
|
232
|
+
* Place a new order on the exchange.
|
|
233
|
+
*
|
|
234
|
+
* @param params - Order parameters
|
|
235
|
+
* @returns The created order
|
|
236
|
+
*
|
|
237
|
+
* @example-ts Place a limit order
|
|
238
|
+
* const order = await exchange.createOrder({
|
|
239
|
+
* marketId: market.marketId,
|
|
240
|
+
* outcomeId: market.yes.outcomeId,
|
|
241
|
+
* side: 'buy',
|
|
242
|
+
* type: 'limit',
|
|
243
|
+
* amount: 10,
|
|
244
|
+
* price: 0.55
|
|
245
|
+
* });
|
|
246
|
+
* console.log(`Order ${order.id}: ${order.status}`);
|
|
247
|
+
*
|
|
248
|
+
* @example-ts Place a market order
|
|
249
|
+
* const order = await exchange.createOrder({
|
|
250
|
+
* marketId: market.marketId,
|
|
251
|
+
* outcomeId: market.yes.outcomeId,
|
|
252
|
+
* side: 'buy',
|
|
253
|
+
* type: 'market',
|
|
254
|
+
* amount: 5
|
|
255
|
+
* });
|
|
256
|
+
*
|
|
257
|
+
* @example-python Place a limit order
|
|
258
|
+
* order = exchange.create_order(
|
|
259
|
+
* market_id=market.market_id,
|
|
260
|
+
* outcome_id=market.yes.outcome_id,
|
|
261
|
+
* side='buy',
|
|
262
|
+
* type='limit',
|
|
263
|
+
* amount=10,
|
|
264
|
+
* price=0.55
|
|
265
|
+
* )
|
|
266
|
+
* print(f"Order {order.id}: {order.status}")
|
|
267
|
+
*
|
|
268
|
+
* @example-python Place a market order
|
|
269
|
+
* order = exchange.create_order(
|
|
270
|
+
* market_id=market.market_id,
|
|
271
|
+
* outcome_id=market.yes.outcome_id,
|
|
272
|
+
* side='buy',
|
|
273
|
+
* type='market',
|
|
274
|
+
* amount=5
|
|
275
|
+
* )
|
|
170
276
|
*/
|
|
171
277
|
createOrder(params: CreateOrderParams): Promise<Order>;
|
|
172
278
|
/**
|
|
173
|
-
* Cancel an existing order.
|
|
279
|
+
* Cancel an existing open order.
|
|
280
|
+
*
|
|
281
|
+
* @param orderId - The order ID to cancel
|
|
282
|
+
* @returns The cancelled order
|
|
283
|
+
*
|
|
284
|
+
* @example-ts Cancel an order
|
|
285
|
+
* const cancelled = await exchange.cancelOrder('order-123');
|
|
286
|
+
* console.log(cancelled.status); // 'cancelled'
|
|
287
|
+
*
|
|
288
|
+
* @example-python Cancel an order
|
|
289
|
+
* cancelled = exchange.cancel_order('order-123')
|
|
290
|
+
* print(cancelled.status) # 'cancelled'
|
|
174
291
|
*/
|
|
175
292
|
cancelOrder(orderId: string): Promise<Order>;
|
|
176
293
|
/**
|
|
177
294
|
* Fetch a specific order by ID.
|
|
295
|
+
*
|
|
296
|
+
* @param orderId - The order ID to look up
|
|
297
|
+
* @returns The order details
|
|
298
|
+
*
|
|
299
|
+
* @example-ts Fetch order status
|
|
300
|
+
* const order = await exchange.fetchOrder('order-456');
|
|
301
|
+
* console.log(`Filled: ${order.filled}/${order.amount}`);
|
|
302
|
+
*
|
|
303
|
+
* @example-python Fetch order status
|
|
304
|
+
* order = exchange.fetch_order('order-456')
|
|
305
|
+
* print(f"Filled: {order.filled}/{order.amount}")
|
|
178
306
|
*/
|
|
179
307
|
fetchOrder(orderId: string): Promise<Order>;
|
|
180
308
|
/**
|
|
181
|
-
* Fetch all open orders.
|
|
182
|
-
*
|
|
309
|
+
* Fetch all open orders, optionally filtered by market.
|
|
310
|
+
*
|
|
311
|
+
* @param marketId - Optional market ID to filter by
|
|
312
|
+
* @returns Array of open orders
|
|
313
|
+
*
|
|
314
|
+
* @example-ts Fetch all open orders
|
|
315
|
+
* const orders = await exchange.fetchOpenOrders();
|
|
316
|
+
* for (const order of orders) {
|
|
317
|
+
* console.log(`${order.side} ${order.amount} @ ${order.price}`);
|
|
318
|
+
* }
|
|
319
|
+
*
|
|
320
|
+
* @example-ts Fetch orders for a specific market
|
|
321
|
+
* const orders = await exchange.fetchOpenOrders('FED-25JAN');
|
|
322
|
+
*
|
|
323
|
+
* @example-python Fetch all open orders
|
|
324
|
+
* orders = exchange.fetch_open_orders()
|
|
325
|
+
* for order in orders:
|
|
326
|
+
* print(f"{order.side} {order.amount} @ {order.price}")
|
|
327
|
+
*
|
|
328
|
+
* @example-python Fetch orders for a specific market
|
|
329
|
+
* orders = exchange.fetch_open_orders('FED-25JAN')
|
|
183
330
|
*/
|
|
184
331
|
fetchOpenOrders(marketId?: string): Promise<Order[]>;
|
|
185
332
|
/**
|
|
186
|
-
* Fetch current user positions.
|
|
333
|
+
* Fetch current user positions across all markets.
|
|
334
|
+
*
|
|
335
|
+
* @returns Array of user positions
|
|
336
|
+
*
|
|
337
|
+
* @example-ts Fetch positions
|
|
338
|
+
* const positions = await exchange.fetchPositions();
|
|
339
|
+
* for (const pos of positions) {
|
|
340
|
+
* console.log(`${pos.outcomeLabel}: ${pos.size} @ $${pos.entryPrice}`);
|
|
341
|
+
* console.log(`Unrealized P&L: $${pos.unrealizedPnL.toFixed(2)}`);
|
|
342
|
+
* }
|
|
343
|
+
*
|
|
344
|
+
* @example-python Fetch positions
|
|
345
|
+
* positions = exchange.fetch_positions()
|
|
346
|
+
* for pos in positions:
|
|
347
|
+
* print(f"{pos.outcome_label}: {pos.size} @ ${pos.entry_price}")
|
|
348
|
+
* print(f"Unrealized P&L: ${pos.unrealized_pnl:.2f}")
|
|
187
349
|
*/
|
|
188
350
|
fetchPositions(): Promise<Position[]>;
|
|
189
351
|
/**
|
|
190
352
|
* Fetch account balances.
|
|
353
|
+
*
|
|
354
|
+
* @returns Array of account balances
|
|
355
|
+
*
|
|
356
|
+
* @example-ts Fetch balance
|
|
357
|
+
* const balances = await exchange.fetchBalance();
|
|
358
|
+
* console.log(`Available: $${balances[0].available}`);
|
|
359
|
+
*
|
|
360
|
+
* @example-python Fetch balance
|
|
361
|
+
* balances = exchange.fetch_balance()
|
|
362
|
+
* print(f"Available: ${balances[0].available}")
|
|
191
363
|
*/
|
|
192
364
|
fetchBalance(): Promise<Balance[]>;
|
|
365
|
+
/**
|
|
366
|
+
* Calculate the volume-weighted average execution price for a given order size.
|
|
367
|
+
* Returns 0 if the order cannot be fully filled.
|
|
368
|
+
*
|
|
369
|
+
* @param orderBook - The current order book
|
|
370
|
+
* @param side - 'buy' or 'sell'
|
|
371
|
+
* @param amount - Number of contracts to simulate
|
|
372
|
+
* @returns Average execution price, or 0 if insufficient liquidity
|
|
373
|
+
*
|
|
374
|
+
* @example-ts Get execution price
|
|
375
|
+
* const book = await exchange.fetchOrderBook(outcome.outcomeId);
|
|
376
|
+
* const price = exchange.getExecutionPrice(book, 'buy', 100);
|
|
377
|
+
* console.log(`Avg price for 100 contracts: ${price}`);
|
|
378
|
+
*
|
|
379
|
+
* @example-python Get execution price
|
|
380
|
+
* book = exchange.fetch_order_book(outcome.outcome_id)
|
|
381
|
+
* price = exchange.get_execution_price(book, 'buy', 100)
|
|
382
|
+
* print(f"Avg price for 100 contracts: {price}")
|
|
383
|
+
*/
|
|
193
384
|
getExecutionPrice(orderBook: OrderBook, side: 'buy' | 'sell', amount: number): number;
|
|
385
|
+
/**
|
|
386
|
+
* Calculate detailed execution price information including partial fill data.
|
|
387
|
+
*
|
|
388
|
+
* @param orderBook - The current order book
|
|
389
|
+
* @param side - 'buy' or 'sell'
|
|
390
|
+
* @param amount - Number of contracts to simulate
|
|
391
|
+
* @returns Detailed execution result with price, filled amount, and fill status
|
|
392
|
+
*
|
|
393
|
+
* @example-ts Get detailed execution price
|
|
394
|
+
* const book = await exchange.fetchOrderBook(outcome.outcomeId);
|
|
395
|
+
* const result = exchange.getExecutionPriceDetailed(book, 'buy', 100);
|
|
396
|
+
* console.log(`Price: ${result.price}`);
|
|
397
|
+
* console.log(`Filled: ${result.filledAmount}/${100}`);
|
|
398
|
+
* console.log(`Fully filled: ${result.fullyFilled}`);
|
|
399
|
+
*
|
|
400
|
+
* @example-python Get detailed execution price
|
|
401
|
+
* book = exchange.fetch_order_book(outcome.outcome_id)
|
|
402
|
+
* result = exchange.get_execution_price_detailed(book, 'buy', 100)
|
|
403
|
+
* print(f"Price: {result.price}")
|
|
404
|
+
* print(f"Filled: {result.filled_amount}/100")
|
|
405
|
+
* print(f"Fully filled: {result.fully_filled}")
|
|
406
|
+
*/
|
|
194
407
|
getExecutionPriceDetailed(orderBook: OrderBook, side: 'buy' | 'sell', amount: number): ExecutionPriceResult;
|
|
195
408
|
/**
|
|
196
|
-
* Filter
|
|
409
|
+
* Filter a list of markets by criteria.
|
|
410
|
+
* Can filter by string query, structured criteria object, or custom filter function.
|
|
197
411
|
*
|
|
198
412
|
* @param markets - Array of markets to filter
|
|
199
|
-
* @param criteria - Filter criteria
|
|
413
|
+
* @param criteria - Filter criteria: string (text search), object (structured), or function (predicate)
|
|
200
414
|
* @returns Filtered array of markets
|
|
201
415
|
*
|
|
202
|
-
* @example Simple text search
|
|
203
|
-
*
|
|
416
|
+
* @example-ts Simple text search
|
|
417
|
+
* const filtered = exchange.filterMarkets(markets, 'Trump');
|
|
204
418
|
*
|
|
205
|
-
* @example Advanced
|
|
206
|
-
*
|
|
207
|
-
* text: '
|
|
208
|
-
* searchIn: ['title', 'tags'],
|
|
419
|
+
* @example-ts Advanced criteria
|
|
420
|
+
* const undervalued = exchange.filterMarkets(markets, {
|
|
421
|
+
* text: 'Election',
|
|
209
422
|
* volume24h: { min: 10000 },
|
|
210
|
-
*
|
|
211
|
-
*
|
|
423
|
+
* price: { outcome: 'yes', max: 0.4 }
|
|
424
|
+
* });
|
|
425
|
+
*
|
|
426
|
+
* @example-ts Custom predicate
|
|
427
|
+
* const volatile = exchange.filterMarkets(markets,
|
|
428
|
+
* m => m.yes?.priceChange24h < -0.1
|
|
429
|
+
* );
|
|
430
|
+
*
|
|
431
|
+
* @example-python Simple text search
|
|
432
|
+
* filtered = exchange.filter_markets(markets, 'Trump')
|
|
433
|
+
*
|
|
434
|
+
* @example-python Advanced criteria
|
|
435
|
+
* undervalued = exchange.filter_markets(markets, {
|
|
436
|
+
* 'text': 'Election',
|
|
437
|
+
* 'volume_24h': {'min': 10000},
|
|
438
|
+
* 'price': {'outcome': 'yes', 'max': 0.4}
|
|
212
439
|
* })
|
|
213
440
|
*
|
|
214
|
-
* @example Custom predicate
|
|
215
|
-
*
|
|
441
|
+
* @example-python Custom predicate
|
|
442
|
+
* volatile = exchange.filter_markets(markets,
|
|
443
|
+
* lambda m: m.yes and m.yes.price_change_24h < -0.1
|
|
444
|
+
* )
|
|
216
445
|
*/
|
|
217
446
|
filterMarkets(markets: UnifiedMarket[], criteria: string | MarketFilterCriteria | MarketFilterFunction): UnifiedMarket[];
|
|
218
447
|
/**
|
|
219
|
-
* Filter
|
|
448
|
+
* Filter a list of events by criteria.
|
|
449
|
+
* Can filter by string query, structured criteria object, or custom filter function.
|
|
220
450
|
*
|
|
221
451
|
* @param events - Array of events to filter
|
|
222
|
-
* @param criteria - Filter criteria
|
|
452
|
+
* @param criteria - Filter criteria: string (text search), object (structured), or function (predicate)
|
|
223
453
|
* @returns Filtered array of events
|
|
224
454
|
*
|
|
225
|
-
* @example
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
* @example Advanced filtering
|
|
229
|
-
* api.filterEvents(events, {
|
|
230
|
-
* text: 'Election',
|
|
231
|
-
* searchIn: ['title', 'tags'],
|
|
455
|
+
* @example-ts Filter by category
|
|
456
|
+
* const filtered = exchange.filterEvents(events, {
|
|
232
457
|
* category: 'Politics',
|
|
233
458
|
* marketCount: { min: 5 }
|
|
234
|
-
* })
|
|
459
|
+
* });
|
|
235
460
|
*
|
|
236
|
-
* @example
|
|
237
|
-
*
|
|
461
|
+
* @example-python Filter by category
|
|
462
|
+
* filtered = exchange.filter_events(events, {
|
|
463
|
+
* 'category': 'Politics',
|
|
464
|
+
* 'market_count': {'min': 5}
|
|
465
|
+
* })
|
|
238
466
|
*/
|
|
239
467
|
filterEvents(events: UnifiedEvent[], criteria: string | EventFilterCriteria | EventFilterFunction): UnifiedEvent[];
|
|
240
468
|
/**
|
|
241
|
-
* Watch
|
|
242
|
-
* Returns a promise that resolves with the
|
|
243
|
-
* The orderbook is maintained internally with incremental updates.
|
|
244
|
-
*
|
|
245
|
-
* Usage (async iterator pattern):
|
|
246
|
-
* ```typescript
|
|
247
|
-
* while (true) {
|
|
248
|
-
* const orderbook = await exchange.watchOrderBook(outcomeId);
|
|
249
|
-
* console.log(orderbook);
|
|
250
|
-
* }
|
|
251
|
-
* ```
|
|
469
|
+
* Watch order book updates in real-time via WebSocket.
|
|
470
|
+
* Returns a promise that resolves with the next order book update. Call repeatedly in a loop to stream updates (CCXT Pro pattern).
|
|
252
471
|
*
|
|
253
472
|
* @param id - The Outcome ID to watch
|
|
254
473
|
* @param limit - Optional limit for orderbook depth
|
|
255
474
|
* @returns Promise that resolves with the current orderbook state
|
|
475
|
+
*
|
|
476
|
+
* @example-ts Stream order book
|
|
477
|
+
* while (true) {
|
|
478
|
+
* const book = await exchange.watchOrderBook(outcome.outcomeId);
|
|
479
|
+
* console.log(`Bid: ${book.bids[0]?.price} Ask: ${book.asks[0]?.price}`);
|
|
480
|
+
* }
|
|
481
|
+
*
|
|
482
|
+
* @example-python Stream order book
|
|
483
|
+
* while True:
|
|
484
|
+
* book = exchange.watch_order_book(outcome.outcome_id)
|
|
485
|
+
* print(f"Bid: {book.bids[0].price} Ask: {book.asks[0].price}")
|
|
256
486
|
*/
|
|
257
487
|
watchOrderBook(id: string, limit?: number): Promise<OrderBook>;
|
|
258
488
|
/**
|
|
259
489
|
* Watch trade executions in real-time via WebSocket.
|
|
260
|
-
* Returns a promise that resolves with
|
|
261
|
-
*
|
|
262
|
-
* Usage (async iterator pattern):
|
|
263
|
-
* ```typescript
|
|
264
|
-
* while (true) {
|
|
265
|
-
* const trades = await exchange.watchTrades(outcomeId);
|
|
266
|
-
* console.log(trades);
|
|
267
|
-
* }
|
|
268
|
-
* ```
|
|
490
|
+
* Returns a promise that resolves with the next trade(s). Call repeatedly in a loop to stream updates (CCXT Pro pattern).
|
|
269
491
|
*
|
|
270
492
|
* @param id - The Outcome ID to watch
|
|
271
493
|
* @param since - Optional timestamp to filter trades from
|
|
272
494
|
* @param limit - Optional limit for number of trades
|
|
273
495
|
* @returns Promise that resolves with recent trades
|
|
496
|
+
*
|
|
497
|
+
* @example-ts Stream trades
|
|
498
|
+
* while (true) {
|
|
499
|
+
* const trades = await exchange.watchTrades(outcome.outcomeId);
|
|
500
|
+
* for (const trade of trades) {
|
|
501
|
+
* console.log(`${trade.side} ${trade.amount} @ ${trade.price}`);
|
|
502
|
+
* }
|
|
503
|
+
* }
|
|
504
|
+
*
|
|
505
|
+
* @example-python Stream trades
|
|
506
|
+
* while True:
|
|
507
|
+
* trades = exchange.watch_trades(outcome.outcome_id)
|
|
508
|
+
* for trade in trades:
|
|
509
|
+
* print(f"{trade.side} {trade.amount} @ {trade.price}")
|
|
274
510
|
*/
|
|
275
511
|
watchTrades(id: string, since?: number, limit?: number): Promise<Trade[]>;
|
|
276
512
|
/**
|
|
277
513
|
* Close all WebSocket connections and clean up resources.
|
|
278
|
-
*
|
|
514
|
+
* Call this when you're done streaming to properly release connections.
|
|
279
515
|
*
|
|
280
|
-
*
|
|
281
|
-
* ```typescript
|
|
516
|
+
* @example-ts Close connections
|
|
282
517
|
* await exchange.close();
|
|
283
|
-
*
|
|
518
|
+
*
|
|
519
|
+
* @example-python Close connections
|
|
520
|
+
* exchange.close()
|
|
284
521
|
*/
|
|
285
522
|
close(): Promise<void>;
|
|
286
523
|
}
|
package/dist/BaseExchange.js
CHANGED
|
@@ -11,42 +11,54 @@ class PredictionMarketExchange {
|
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Fetch markets with optional filtering, search, or slug lookup.
|
|
14
|
-
* This is the primary method for retrieving markets
|
|
14
|
+
* This is the primary method for retrieving markets.
|
|
15
15
|
*
|
|
16
16
|
* @param params - Optional parameters for filtering and search
|
|
17
17
|
* @param params.query - Search keyword to filter markets
|
|
18
18
|
* @param params.slug - Market slug/ticker for direct lookup
|
|
19
19
|
* @param params.limit - Maximum number of results
|
|
20
20
|
* @param params.offset - Pagination offset
|
|
21
|
-
* @param params.sort - Sort order
|
|
22
|
-
* @param params.searchIn - Where to search (title
|
|
21
|
+
* @param params.sort - Sort order ('volume' | 'liquidity' | 'newest')
|
|
22
|
+
* @param params.searchIn - Where to search ('title' | 'description' | 'both')
|
|
23
23
|
* @returns Array of unified markets
|
|
24
24
|
*
|
|
25
|
-
* @example Fetch
|
|
26
|
-
* await exchange.fetchMarkets()
|
|
25
|
+
* @example-ts Fetch markets
|
|
26
|
+
* const markets = await exchange.fetchMarkets({ query: 'Trump', limit: 20 });
|
|
27
|
+
* console.log(markets[0].title);
|
|
27
28
|
*
|
|
28
|
-
* @example
|
|
29
|
-
* await exchange.fetchMarkets({
|
|
29
|
+
* @example-ts Get market by slug
|
|
30
|
+
* const markets = await exchange.fetchMarkets({ slug: 'will-trump-win' });
|
|
30
31
|
*
|
|
31
|
-
* @example
|
|
32
|
-
*
|
|
32
|
+
* @example-python Fetch markets
|
|
33
|
+
* markets = exchange.fetch_markets(query='Trump', limit=20)
|
|
34
|
+
* print(markets[0].title)
|
|
35
|
+
*
|
|
36
|
+
* @example-python Get market by slug
|
|
37
|
+
* markets = exchange.fetch_markets(slug='will-trump-win')
|
|
33
38
|
*/
|
|
34
39
|
async fetchMarkets(params) {
|
|
35
40
|
return this.fetchMarketsImpl(params);
|
|
36
41
|
}
|
|
37
42
|
/**
|
|
38
43
|
* Fetch events with optional keyword search.
|
|
39
|
-
* Events group related markets together.
|
|
44
|
+
* Events group related markets together (e.g., "Who will be Fed Chair?" contains multiple candidate markets).
|
|
40
45
|
*
|
|
41
46
|
* @param params - Optional parameters for search and filtering
|
|
42
|
-
* @param params.query - Search keyword to filter events
|
|
47
|
+
* @param params.query - Search keyword to filter events (required)
|
|
43
48
|
* @param params.limit - Maximum number of results
|
|
44
49
|
* @param params.offset - Pagination offset
|
|
45
|
-
* @param params.searchIn - Where to search (title
|
|
50
|
+
* @param params.searchIn - Where to search ('title' | 'description' | 'both')
|
|
46
51
|
* @returns Array of unified events
|
|
47
52
|
*
|
|
48
|
-
* @example Search events
|
|
49
|
-
* await exchange.fetchEvents({ query: '
|
|
53
|
+
* @example-ts Search events
|
|
54
|
+
* const events = await exchange.fetchEvents({ query: 'Fed Chair' });
|
|
55
|
+
* const fedEvent = events[0];
|
|
56
|
+
* console.log(fedEvent.title, fedEvent.markets.length, 'markets');
|
|
57
|
+
*
|
|
58
|
+
* @example-python Search events
|
|
59
|
+
* events = exchange.fetch_events(query='Fed Chair')
|
|
60
|
+
* fed_event = events[0]
|
|
61
|
+
* print(fed_event.title, len(fed_event.markets), 'markets')
|
|
50
62
|
*/
|
|
51
63
|
async fetchEvents(params) {
|
|
52
64
|
if (!params?.query) {
|
|
@@ -73,24 +85,75 @@ class PredictionMarketExchange {
|
|
|
73
85
|
throw new Error("Method fetchEventsImpl not implemented.");
|
|
74
86
|
}
|
|
75
87
|
/**
|
|
76
|
-
* Fetch historical price data for a specific market outcome.
|
|
77
|
-
*
|
|
88
|
+
* Fetch historical OHLCV (candlestick) price data for a specific market outcome.
|
|
89
|
+
*
|
|
90
|
+
* @param id - The Outcome ID (outcomeId). Use outcome.outcomeId, NOT market.marketId
|
|
78
91
|
* @param params - OHLCV parameters including resolution (required)
|
|
92
|
+
* @returns Array of price candles
|
|
93
|
+
*
|
|
94
|
+
* @example-ts Fetch hourly candles
|
|
95
|
+
* const markets = await exchange.fetchMarkets({ query: 'Trump' });
|
|
96
|
+
* const outcomeId = markets[0].yes.outcomeId;
|
|
97
|
+
* const candles = await exchange.fetchOHLCV(outcomeId, {
|
|
98
|
+
* resolution: '1h',
|
|
99
|
+
* limit: 100
|
|
100
|
+
* });
|
|
101
|
+
* console.log(`Latest close: ${candles[candles.length - 1].close}`);
|
|
102
|
+
*
|
|
103
|
+
* @example-python Fetch hourly candles
|
|
104
|
+
* markets = exchange.fetch_markets(query='Trump')
|
|
105
|
+
* outcome_id = markets[0].yes.outcome_id
|
|
106
|
+
* candles = exchange.fetch_ohlcv(outcome_id, resolution='1h', limit=100)
|
|
107
|
+
* print(f"Latest close: {candles[-1].close}")
|
|
108
|
+
*
|
|
109
|
+
* @notes **CRITICAL**: Use `outcome.outcomeId` (TS) / `outcome.outcome_id` (Python), not the market ID.
|
|
110
|
+
* @notes Polymarket: outcomeId is the CLOB Token ID. Kalshi: outcomeId is the Market Ticker.
|
|
111
|
+
* @notes Resolution options: '1m' | '5m' | '15m' | '1h' | '6h' | '1d'
|
|
79
112
|
*/
|
|
80
113
|
async fetchOHLCV(id, params) {
|
|
81
114
|
throw new Error("Method fetchOHLCV not implemented.");
|
|
82
115
|
}
|
|
83
116
|
/**
|
|
84
117
|
* Fetch the current order book (bids/asks) for a specific outcome.
|
|
85
|
-
* Essential for calculating
|
|
118
|
+
* Essential for calculating spread, depth, and execution prices.
|
|
119
|
+
*
|
|
120
|
+
* @param id - The Outcome ID (outcomeId)
|
|
121
|
+
* @returns Current order book with bids and asks
|
|
122
|
+
*
|
|
123
|
+
* @example-ts Fetch order book
|
|
124
|
+
* const book = await exchange.fetchOrderBook(outcome.outcomeId);
|
|
125
|
+
* console.log(`Best bid: ${book.bids[0].price}`);
|
|
126
|
+
* console.log(`Best ask: ${book.asks[0].price}`);
|
|
127
|
+
* console.log(`Spread: ${(book.asks[0].price - book.bids[0].price) * 100}%`);
|
|
128
|
+
*
|
|
129
|
+
* @example-python Fetch order book
|
|
130
|
+
* book = exchange.fetch_order_book(outcome.outcome_id)
|
|
131
|
+
* print(f"Best bid: {book.bids[0].price}")
|
|
132
|
+
* print(f"Best ask: {book.asks[0].price}")
|
|
133
|
+
* print(f"Spread: {(book.asks[0].price - book.bids[0].price) * 100:.2f}%")
|
|
86
134
|
*/
|
|
87
135
|
async fetchOrderBook(id) {
|
|
88
136
|
throw new Error("Method fetchOrderBook not implemented.");
|
|
89
137
|
}
|
|
90
138
|
/**
|
|
91
|
-
* Fetch raw trade history.
|
|
92
|
-
*
|
|
93
|
-
* @param
|
|
139
|
+
* Fetch raw trade history for a specific outcome.
|
|
140
|
+
*
|
|
141
|
+
* @param id - The Outcome ID (outcomeId)
|
|
142
|
+
* @param params - Trade filter parameters
|
|
143
|
+
* @returns Array of recent trades
|
|
144
|
+
*
|
|
145
|
+
* @example-ts Fetch recent trades
|
|
146
|
+
* const trades = await exchange.fetchTrades(outcome.outcomeId, { limit: 100 });
|
|
147
|
+
* for (const trade of trades) {
|
|
148
|
+
* console.log(`${trade.side} ${trade.amount} @ ${trade.price}`);
|
|
149
|
+
* }
|
|
150
|
+
*
|
|
151
|
+
* @example-python Fetch recent trades
|
|
152
|
+
* trades = exchange.fetch_trades(outcome.outcome_id, limit=100)
|
|
153
|
+
* for trade in trades:
|
|
154
|
+
* print(f"{trade.side} {trade.amount} @ {trade.price}")
|
|
155
|
+
*
|
|
156
|
+
* @notes Polymarket requires an API key for trade history. Use fetchOHLCV for public historical data.
|
|
94
157
|
*/
|
|
95
158
|
async fetchTrades(id, params) {
|
|
96
159
|
// Deprecation warning for resolution parameter
|
|
@@ -104,45 +167,195 @@ class PredictionMarketExchange {
|
|
|
104
167
|
// Trading Methods
|
|
105
168
|
// ----------------------------------------------------------------------------
|
|
106
169
|
/**
|
|
107
|
-
* Place a new order.
|
|
170
|
+
* Place a new order on the exchange.
|
|
171
|
+
*
|
|
172
|
+
* @param params - Order parameters
|
|
173
|
+
* @returns The created order
|
|
174
|
+
*
|
|
175
|
+
* @example-ts Place a limit order
|
|
176
|
+
* const order = await exchange.createOrder({
|
|
177
|
+
* marketId: market.marketId,
|
|
178
|
+
* outcomeId: market.yes.outcomeId,
|
|
179
|
+
* side: 'buy',
|
|
180
|
+
* type: 'limit',
|
|
181
|
+
* amount: 10,
|
|
182
|
+
* price: 0.55
|
|
183
|
+
* });
|
|
184
|
+
* console.log(`Order ${order.id}: ${order.status}`);
|
|
185
|
+
*
|
|
186
|
+
* @example-ts Place a market order
|
|
187
|
+
* const order = await exchange.createOrder({
|
|
188
|
+
* marketId: market.marketId,
|
|
189
|
+
* outcomeId: market.yes.outcomeId,
|
|
190
|
+
* side: 'buy',
|
|
191
|
+
* type: 'market',
|
|
192
|
+
* amount: 5
|
|
193
|
+
* });
|
|
194
|
+
*
|
|
195
|
+
* @example-python Place a limit order
|
|
196
|
+
* order = exchange.create_order(
|
|
197
|
+
* market_id=market.market_id,
|
|
198
|
+
* outcome_id=market.yes.outcome_id,
|
|
199
|
+
* side='buy',
|
|
200
|
+
* type='limit',
|
|
201
|
+
* amount=10,
|
|
202
|
+
* price=0.55
|
|
203
|
+
* )
|
|
204
|
+
* print(f"Order {order.id}: {order.status}")
|
|
205
|
+
*
|
|
206
|
+
* @example-python Place a market order
|
|
207
|
+
* order = exchange.create_order(
|
|
208
|
+
* market_id=market.market_id,
|
|
209
|
+
* outcome_id=market.yes.outcome_id,
|
|
210
|
+
* side='buy',
|
|
211
|
+
* type='market',
|
|
212
|
+
* amount=5
|
|
213
|
+
* )
|
|
108
214
|
*/
|
|
109
215
|
async createOrder(params) {
|
|
110
216
|
throw new Error("Method createOrder not implemented.");
|
|
111
217
|
}
|
|
112
218
|
/**
|
|
113
|
-
* Cancel an existing order.
|
|
219
|
+
* Cancel an existing open order.
|
|
220
|
+
*
|
|
221
|
+
* @param orderId - The order ID to cancel
|
|
222
|
+
* @returns The cancelled order
|
|
223
|
+
*
|
|
224
|
+
* @example-ts Cancel an order
|
|
225
|
+
* const cancelled = await exchange.cancelOrder('order-123');
|
|
226
|
+
* console.log(cancelled.status); // 'cancelled'
|
|
227
|
+
*
|
|
228
|
+
* @example-python Cancel an order
|
|
229
|
+
* cancelled = exchange.cancel_order('order-123')
|
|
230
|
+
* print(cancelled.status) # 'cancelled'
|
|
114
231
|
*/
|
|
115
232
|
async cancelOrder(orderId) {
|
|
116
233
|
throw new Error("Method cancelOrder not implemented.");
|
|
117
234
|
}
|
|
118
235
|
/**
|
|
119
236
|
* Fetch a specific order by ID.
|
|
237
|
+
*
|
|
238
|
+
* @param orderId - The order ID to look up
|
|
239
|
+
* @returns The order details
|
|
240
|
+
*
|
|
241
|
+
* @example-ts Fetch order status
|
|
242
|
+
* const order = await exchange.fetchOrder('order-456');
|
|
243
|
+
* console.log(`Filled: ${order.filled}/${order.amount}`);
|
|
244
|
+
*
|
|
245
|
+
* @example-python Fetch order status
|
|
246
|
+
* order = exchange.fetch_order('order-456')
|
|
247
|
+
* print(f"Filled: {order.filled}/{order.amount}")
|
|
120
248
|
*/
|
|
121
249
|
async fetchOrder(orderId) {
|
|
122
250
|
throw new Error("Method fetchOrder not implemented.");
|
|
123
251
|
}
|
|
124
252
|
/**
|
|
125
|
-
* Fetch all open orders.
|
|
126
|
-
*
|
|
253
|
+
* Fetch all open orders, optionally filtered by market.
|
|
254
|
+
*
|
|
255
|
+
* @param marketId - Optional market ID to filter by
|
|
256
|
+
* @returns Array of open orders
|
|
257
|
+
*
|
|
258
|
+
* @example-ts Fetch all open orders
|
|
259
|
+
* const orders = await exchange.fetchOpenOrders();
|
|
260
|
+
* for (const order of orders) {
|
|
261
|
+
* console.log(`${order.side} ${order.amount} @ ${order.price}`);
|
|
262
|
+
* }
|
|
263
|
+
*
|
|
264
|
+
* @example-ts Fetch orders for a specific market
|
|
265
|
+
* const orders = await exchange.fetchOpenOrders('FED-25JAN');
|
|
266
|
+
*
|
|
267
|
+
* @example-python Fetch all open orders
|
|
268
|
+
* orders = exchange.fetch_open_orders()
|
|
269
|
+
* for order in orders:
|
|
270
|
+
* print(f"{order.side} {order.amount} @ {order.price}")
|
|
271
|
+
*
|
|
272
|
+
* @example-python Fetch orders for a specific market
|
|
273
|
+
* orders = exchange.fetch_open_orders('FED-25JAN')
|
|
127
274
|
*/
|
|
128
275
|
async fetchOpenOrders(marketId) {
|
|
129
276
|
throw new Error("Method fetchOpenOrders not implemented.");
|
|
130
277
|
}
|
|
131
278
|
/**
|
|
132
|
-
* Fetch current user positions.
|
|
279
|
+
* Fetch current user positions across all markets.
|
|
280
|
+
*
|
|
281
|
+
* @returns Array of user positions
|
|
282
|
+
*
|
|
283
|
+
* @example-ts Fetch positions
|
|
284
|
+
* const positions = await exchange.fetchPositions();
|
|
285
|
+
* for (const pos of positions) {
|
|
286
|
+
* console.log(`${pos.outcomeLabel}: ${pos.size} @ $${pos.entryPrice}`);
|
|
287
|
+
* console.log(`Unrealized P&L: $${pos.unrealizedPnL.toFixed(2)}`);
|
|
288
|
+
* }
|
|
289
|
+
*
|
|
290
|
+
* @example-python Fetch positions
|
|
291
|
+
* positions = exchange.fetch_positions()
|
|
292
|
+
* for pos in positions:
|
|
293
|
+
* print(f"{pos.outcome_label}: {pos.size} @ ${pos.entry_price}")
|
|
294
|
+
* print(f"Unrealized P&L: ${pos.unrealized_pnl:.2f}")
|
|
133
295
|
*/
|
|
134
296
|
async fetchPositions() {
|
|
135
297
|
throw new Error("Method fetchPositions not implemented.");
|
|
136
298
|
}
|
|
137
299
|
/**
|
|
138
300
|
* Fetch account balances.
|
|
301
|
+
*
|
|
302
|
+
* @returns Array of account balances
|
|
303
|
+
*
|
|
304
|
+
* @example-ts Fetch balance
|
|
305
|
+
* const balances = await exchange.fetchBalance();
|
|
306
|
+
* console.log(`Available: $${balances[0].available}`);
|
|
307
|
+
*
|
|
308
|
+
* @example-python Fetch balance
|
|
309
|
+
* balances = exchange.fetch_balance()
|
|
310
|
+
* print(f"Available: ${balances[0].available}")
|
|
139
311
|
*/
|
|
140
312
|
async fetchBalance() {
|
|
141
313
|
throw new Error("Method fetchBalance not implemented.");
|
|
142
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Calculate the volume-weighted average execution price for a given order size.
|
|
317
|
+
* Returns 0 if the order cannot be fully filled.
|
|
318
|
+
*
|
|
319
|
+
* @param orderBook - The current order book
|
|
320
|
+
* @param side - 'buy' or 'sell'
|
|
321
|
+
* @param amount - Number of contracts to simulate
|
|
322
|
+
* @returns Average execution price, or 0 if insufficient liquidity
|
|
323
|
+
*
|
|
324
|
+
* @example-ts Get execution price
|
|
325
|
+
* const book = await exchange.fetchOrderBook(outcome.outcomeId);
|
|
326
|
+
* const price = exchange.getExecutionPrice(book, 'buy', 100);
|
|
327
|
+
* console.log(`Avg price for 100 contracts: ${price}`);
|
|
328
|
+
*
|
|
329
|
+
* @example-python Get execution price
|
|
330
|
+
* book = exchange.fetch_order_book(outcome.outcome_id)
|
|
331
|
+
* price = exchange.get_execution_price(book, 'buy', 100)
|
|
332
|
+
* print(f"Avg price for 100 contracts: {price}")
|
|
333
|
+
*/
|
|
143
334
|
getExecutionPrice(orderBook, side, amount) {
|
|
144
335
|
return (0, math_1.getExecutionPrice)(orderBook, side, amount);
|
|
145
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Calculate detailed execution price information including partial fill data.
|
|
339
|
+
*
|
|
340
|
+
* @param orderBook - The current order book
|
|
341
|
+
* @param side - 'buy' or 'sell'
|
|
342
|
+
* @param amount - Number of contracts to simulate
|
|
343
|
+
* @returns Detailed execution result with price, filled amount, and fill status
|
|
344
|
+
*
|
|
345
|
+
* @example-ts Get detailed execution price
|
|
346
|
+
* const book = await exchange.fetchOrderBook(outcome.outcomeId);
|
|
347
|
+
* const result = exchange.getExecutionPriceDetailed(book, 'buy', 100);
|
|
348
|
+
* console.log(`Price: ${result.price}`);
|
|
349
|
+
* console.log(`Filled: ${result.filledAmount}/${100}`);
|
|
350
|
+
* console.log(`Fully filled: ${result.fullyFilled}`);
|
|
351
|
+
*
|
|
352
|
+
* @example-python Get detailed execution price
|
|
353
|
+
* book = exchange.fetch_order_book(outcome.outcome_id)
|
|
354
|
+
* result = exchange.get_execution_price_detailed(book, 'buy', 100)
|
|
355
|
+
* print(f"Price: {result.price}")
|
|
356
|
+
* print(f"Filled: {result.filled_amount}/100")
|
|
357
|
+
* print(f"Fully filled: {result.fully_filled}")
|
|
358
|
+
*/
|
|
146
359
|
getExecutionPriceDetailed(orderBook, side, amount) {
|
|
147
360
|
return (0, math_1.getExecutionPriceDetailed)(orderBook, side, amount);
|
|
148
361
|
}
|
|
@@ -150,26 +363,42 @@ class PredictionMarketExchange {
|
|
|
150
363
|
// Filtering Methods
|
|
151
364
|
// ----------------------------------------------------------------------------
|
|
152
365
|
/**
|
|
153
|
-
* Filter
|
|
366
|
+
* Filter a list of markets by criteria.
|
|
367
|
+
* Can filter by string query, structured criteria object, or custom filter function.
|
|
154
368
|
*
|
|
155
369
|
* @param markets - Array of markets to filter
|
|
156
|
-
* @param criteria - Filter criteria
|
|
370
|
+
* @param criteria - Filter criteria: string (text search), object (structured), or function (predicate)
|
|
157
371
|
* @returns Filtered array of markets
|
|
158
372
|
*
|
|
159
|
-
* @example Simple text search
|
|
160
|
-
*
|
|
373
|
+
* @example-ts Simple text search
|
|
374
|
+
* const filtered = exchange.filterMarkets(markets, 'Trump');
|
|
161
375
|
*
|
|
162
|
-
* @example Advanced
|
|
163
|
-
*
|
|
164
|
-
* text: '
|
|
165
|
-
* searchIn: ['title', 'tags'],
|
|
376
|
+
* @example-ts Advanced criteria
|
|
377
|
+
* const undervalued = exchange.filterMarkets(markets, {
|
|
378
|
+
* text: 'Election',
|
|
166
379
|
* volume24h: { min: 10000 },
|
|
167
|
-
*
|
|
168
|
-
*
|
|
380
|
+
* price: { outcome: 'yes', max: 0.4 }
|
|
381
|
+
* });
|
|
382
|
+
*
|
|
383
|
+
* @example-ts Custom predicate
|
|
384
|
+
* const volatile = exchange.filterMarkets(markets,
|
|
385
|
+
* m => m.yes?.priceChange24h < -0.1
|
|
386
|
+
* );
|
|
387
|
+
*
|
|
388
|
+
* @example-python Simple text search
|
|
389
|
+
* filtered = exchange.filter_markets(markets, 'Trump')
|
|
390
|
+
*
|
|
391
|
+
* @example-python Advanced criteria
|
|
392
|
+
* undervalued = exchange.filter_markets(markets, {
|
|
393
|
+
* 'text': 'Election',
|
|
394
|
+
* 'volume_24h': {'min': 10000},
|
|
395
|
+
* 'price': {'outcome': 'yes', 'max': 0.4}
|
|
169
396
|
* })
|
|
170
397
|
*
|
|
171
|
-
* @example Custom predicate
|
|
172
|
-
*
|
|
398
|
+
* @example-python Custom predicate
|
|
399
|
+
* volatile = exchange.filter_markets(markets,
|
|
400
|
+
* lambda m: m.yes and m.yes.price_change_24h < -0.1
|
|
401
|
+
* )
|
|
173
402
|
*/
|
|
174
403
|
filterMarkets(markets, criteria) {
|
|
175
404
|
// Handle predicate function
|
|
@@ -297,25 +526,24 @@ class PredictionMarketExchange {
|
|
|
297
526
|
});
|
|
298
527
|
}
|
|
299
528
|
/**
|
|
300
|
-
* Filter
|
|
529
|
+
* Filter a list of events by criteria.
|
|
530
|
+
* Can filter by string query, structured criteria object, or custom filter function.
|
|
301
531
|
*
|
|
302
532
|
* @param events - Array of events to filter
|
|
303
|
-
* @param criteria - Filter criteria
|
|
533
|
+
* @param criteria - Filter criteria: string (text search), object (structured), or function (predicate)
|
|
304
534
|
* @returns Filtered array of events
|
|
305
535
|
*
|
|
306
|
-
* @example
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* @example Advanced filtering
|
|
310
|
-
* api.filterEvents(events, {
|
|
311
|
-
* text: 'Election',
|
|
312
|
-
* searchIn: ['title', 'tags'],
|
|
536
|
+
* @example-ts Filter by category
|
|
537
|
+
* const filtered = exchange.filterEvents(events, {
|
|
313
538
|
* category: 'Politics',
|
|
314
539
|
* marketCount: { min: 5 }
|
|
315
|
-
* })
|
|
540
|
+
* });
|
|
316
541
|
*
|
|
317
|
-
* @example
|
|
318
|
-
*
|
|
542
|
+
* @example-python Filter by category
|
|
543
|
+
* filtered = exchange.filter_events(events, {
|
|
544
|
+
* 'category': 'Politics',
|
|
545
|
+
* 'market_count': {'min': 5}
|
|
546
|
+
* })
|
|
319
547
|
*/
|
|
320
548
|
filterEvents(events, criteria) {
|
|
321
549
|
// Handle predicate function
|
|
@@ -392,53 +620,62 @@ class PredictionMarketExchange {
|
|
|
392
620
|
// WebSocket Streaming Methods
|
|
393
621
|
// ----------------------------------------------------------------------------
|
|
394
622
|
/**
|
|
395
|
-
* Watch
|
|
396
|
-
* Returns a promise that resolves with the
|
|
397
|
-
* The orderbook is maintained internally with incremental updates.
|
|
398
|
-
*
|
|
399
|
-
* Usage (async iterator pattern):
|
|
400
|
-
* ```typescript
|
|
401
|
-
* while (true) {
|
|
402
|
-
* const orderbook = await exchange.watchOrderBook(outcomeId);
|
|
403
|
-
* console.log(orderbook);
|
|
404
|
-
* }
|
|
405
|
-
* ```
|
|
623
|
+
* Watch order book updates in real-time via WebSocket.
|
|
624
|
+
* Returns a promise that resolves with the next order book update. Call repeatedly in a loop to stream updates (CCXT Pro pattern).
|
|
406
625
|
*
|
|
407
626
|
* @param id - The Outcome ID to watch
|
|
408
627
|
* @param limit - Optional limit for orderbook depth
|
|
409
628
|
* @returns Promise that resolves with the current orderbook state
|
|
629
|
+
*
|
|
630
|
+
* @example-ts Stream order book
|
|
631
|
+
* while (true) {
|
|
632
|
+
* const book = await exchange.watchOrderBook(outcome.outcomeId);
|
|
633
|
+
* console.log(`Bid: ${book.bids[0]?.price} Ask: ${book.asks[0]?.price}`);
|
|
634
|
+
* }
|
|
635
|
+
*
|
|
636
|
+
* @example-python Stream order book
|
|
637
|
+
* while True:
|
|
638
|
+
* book = exchange.watch_order_book(outcome.outcome_id)
|
|
639
|
+
* print(f"Bid: {book.bids[0].price} Ask: {book.asks[0].price}")
|
|
410
640
|
*/
|
|
411
641
|
async watchOrderBook(id, limit) {
|
|
412
642
|
throw new Error(`watchOrderBook() is not supported by ${this.name}`);
|
|
413
643
|
}
|
|
414
644
|
/**
|
|
415
645
|
* Watch trade executions in real-time via WebSocket.
|
|
416
|
-
* Returns a promise that resolves with
|
|
417
|
-
*
|
|
418
|
-
* Usage (async iterator pattern):
|
|
419
|
-
* ```typescript
|
|
420
|
-
* while (true) {
|
|
421
|
-
* const trades = await exchange.watchTrades(outcomeId);
|
|
422
|
-
* console.log(trades);
|
|
423
|
-
* }
|
|
424
|
-
* ```
|
|
646
|
+
* Returns a promise that resolves with the next trade(s). Call repeatedly in a loop to stream updates (CCXT Pro pattern).
|
|
425
647
|
*
|
|
426
648
|
* @param id - The Outcome ID to watch
|
|
427
649
|
* @param since - Optional timestamp to filter trades from
|
|
428
650
|
* @param limit - Optional limit for number of trades
|
|
429
651
|
* @returns Promise that resolves with recent trades
|
|
652
|
+
*
|
|
653
|
+
* @example-ts Stream trades
|
|
654
|
+
* while (true) {
|
|
655
|
+
* const trades = await exchange.watchTrades(outcome.outcomeId);
|
|
656
|
+
* for (const trade of trades) {
|
|
657
|
+
* console.log(`${trade.side} ${trade.amount} @ ${trade.price}`);
|
|
658
|
+
* }
|
|
659
|
+
* }
|
|
660
|
+
*
|
|
661
|
+
* @example-python Stream trades
|
|
662
|
+
* while True:
|
|
663
|
+
* trades = exchange.watch_trades(outcome.outcome_id)
|
|
664
|
+
* for trade in trades:
|
|
665
|
+
* print(f"{trade.side} {trade.amount} @ {trade.price}")
|
|
430
666
|
*/
|
|
431
667
|
async watchTrades(id, since, limit) {
|
|
432
668
|
throw new Error(`watchTrades() is not supported by ${this.name}`);
|
|
433
669
|
}
|
|
434
670
|
/**
|
|
435
671
|
* Close all WebSocket connections and clean up resources.
|
|
436
|
-
*
|
|
672
|
+
* Call this when you're done streaming to properly release connections.
|
|
437
673
|
*
|
|
438
|
-
*
|
|
439
|
-
* ```typescript
|
|
674
|
+
* @example-ts Close connections
|
|
440
675
|
* await exchange.close();
|
|
441
|
-
*
|
|
676
|
+
*
|
|
677
|
+
* @example-python Close connections
|
|
678
|
+
* exchange.close()
|
|
442
679
|
*/
|
|
443
680
|
async close() {
|
|
444
681
|
// Default implementation: no-op
|
|
@@ -36,22 +36,49 @@ export declare class LimitlessExchange extends PredictionMarketExchange {
|
|
|
36
36
|
watchOrderBook(id: string, limit?: number): Promise<OrderBook>;
|
|
37
37
|
watchTrades(id: string, since?: number, limit?: number): Promise<Trade[]>;
|
|
38
38
|
/**
|
|
39
|
-
* Watch AMM price updates for a market address.
|
|
39
|
+
* Watch AMM price updates for a market address (Limitless only).
|
|
40
40
|
* Requires WebSocket connection.
|
|
41
|
+
*
|
|
41
42
|
* @param marketAddress - Market contract address
|
|
42
43
|
* @param callback - Callback for price updates
|
|
44
|
+
*
|
|
45
|
+
* @example-ts Watch prices
|
|
46
|
+
* await exchange.watchPrices(marketAddress, (data) => {
|
|
47
|
+
* console.log('Price update:', data);
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* @example-python Watch prices
|
|
51
|
+
* exchange.watch_prices(market_address, callback=lambda data: print('Price update:', data))
|
|
43
52
|
*/
|
|
44
53
|
watchPrices(marketAddress: string, callback: (data: any) => void): Promise<void>;
|
|
45
54
|
/**
|
|
46
|
-
* Watch user positions in real-time.
|
|
55
|
+
* Watch user positions in real-time (Limitless only).
|
|
47
56
|
* Requires API key authentication.
|
|
57
|
+
*
|
|
48
58
|
* @param callback - Callback for position updates
|
|
59
|
+
*
|
|
60
|
+
* @example-ts Watch positions
|
|
61
|
+
* await exchange.watchUserPositions((data) => {
|
|
62
|
+
* console.log('Position update:', data);
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* @example-python Watch positions
|
|
66
|
+
* exchange.watch_user_positions(callback=lambda data: print('Position update:', data))
|
|
49
67
|
*/
|
|
50
68
|
watchUserPositions(callback: (data: any) => void): Promise<void>;
|
|
51
69
|
/**
|
|
52
|
-
* Watch user transactions in real-time.
|
|
70
|
+
* Watch user transactions in real-time (Limitless only).
|
|
53
71
|
* Requires API key authentication.
|
|
72
|
+
*
|
|
54
73
|
* @param callback - Callback for transaction updates
|
|
74
|
+
*
|
|
75
|
+
* @example-ts Watch transactions
|
|
76
|
+
* await exchange.watchUserTransactions((data) => {
|
|
77
|
+
* console.log('Transaction:', data);
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* @example-python Watch transactions
|
|
81
|
+
* exchange.watch_user_transactions(callback=lambda data: print('Transaction:', data))
|
|
55
82
|
*/
|
|
56
83
|
watchUserTransactions(callback: (data: any) => void): Promise<void>;
|
|
57
84
|
close(): Promise<void>;
|
|
@@ -255,19 +255,37 @@ class LimitlessExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
255
255
|
return ws.watchTrades(id);
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
258
|
-
* Watch AMM price updates for a market address.
|
|
258
|
+
* Watch AMM price updates for a market address (Limitless only).
|
|
259
259
|
* Requires WebSocket connection.
|
|
260
|
+
*
|
|
260
261
|
* @param marketAddress - Market contract address
|
|
261
262
|
* @param callback - Callback for price updates
|
|
263
|
+
*
|
|
264
|
+
* @example-ts Watch prices
|
|
265
|
+
* await exchange.watchPrices(marketAddress, (data) => {
|
|
266
|
+
* console.log('Price update:', data);
|
|
267
|
+
* });
|
|
268
|
+
*
|
|
269
|
+
* @example-python Watch prices
|
|
270
|
+
* exchange.watch_prices(market_address, callback=lambda data: print('Price update:', data))
|
|
262
271
|
*/
|
|
263
272
|
async watchPrices(marketAddress, callback) {
|
|
264
273
|
const ws = this.initWebSocket();
|
|
265
274
|
return ws.watchPrices(marketAddress, callback);
|
|
266
275
|
}
|
|
267
276
|
/**
|
|
268
|
-
* Watch user positions in real-time.
|
|
277
|
+
* Watch user positions in real-time (Limitless only).
|
|
269
278
|
* Requires API key authentication.
|
|
279
|
+
*
|
|
270
280
|
* @param callback - Callback for position updates
|
|
281
|
+
*
|
|
282
|
+
* @example-ts Watch positions
|
|
283
|
+
* await exchange.watchUserPositions((data) => {
|
|
284
|
+
* console.log('Position update:', data);
|
|
285
|
+
* });
|
|
286
|
+
*
|
|
287
|
+
* @example-python Watch positions
|
|
288
|
+
* exchange.watch_user_positions(callback=lambda data: print('Position update:', data))
|
|
271
289
|
*/
|
|
272
290
|
async watchUserPositions(callback) {
|
|
273
291
|
this.ensureAuth(); // Ensure API key is available
|
|
@@ -275,9 +293,18 @@ class LimitlessExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
275
293
|
return ws.watchUserPositions(callback);
|
|
276
294
|
}
|
|
277
295
|
/**
|
|
278
|
-
* Watch user transactions in real-time.
|
|
296
|
+
* Watch user transactions in real-time (Limitless only).
|
|
279
297
|
* Requires API key authentication.
|
|
298
|
+
*
|
|
280
299
|
* @param callback - Callback for transaction updates
|
|
300
|
+
*
|
|
301
|
+
* @example-ts Watch transactions
|
|
302
|
+
* await exchange.watchUserTransactions((data) => {
|
|
303
|
+
* console.log('Transaction:', data);
|
|
304
|
+
* });
|
|
305
|
+
*
|
|
306
|
+
* @example-python Watch transactions
|
|
307
|
+
* exchange.watch_user_transactions(callback=lambda data: print('Transaction:', data))
|
|
281
308
|
*/
|
|
282
309
|
async watchUserTransactions(callback) {
|
|
283
310
|
this.ensureAuth(); // Ensure API key is available
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmxt-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
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,9 +29,10 @@
|
|
|
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.0.
|
|
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.0.
|
|
34
|
-
"
|
|
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.0.8,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.0.8,supportsES6=true,typescriptThreePlus=true && node ../sdks/typescript/scripts/fix-generated.js",
|
|
34
|
+
"extract:jsdoc": "node ../scripts/extract-jsdoc.js",
|
|
35
|
+
"generate:docs": "npm run extract:jsdoc && node ../scripts/generate-api-docs.js",
|
|
35
36
|
"generate:sdk:all": "npm run generate:sdk:python && npm run generate:sdk:typescript && npm run generate:docs"
|
|
36
37
|
},
|
|
37
38
|
"keywords": [],
|