pmxt-core 2.8.0 → 2.9.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.
Files changed (83) hide show
  1. package/dist/BaseExchange.d.ts +48 -0
  2. package/dist/BaseExchange.js +116 -0
  3. package/dist/exchanges/kalshi/api.d.ts +1763 -0
  4. package/dist/exchanges/kalshi/api.js +2554 -0
  5. package/dist/exchanges/kalshi/fetchEvents.d.ts +3 -2
  6. package/dist/exchanges/kalshi/fetchEvents.js +9 -16
  7. package/dist/exchanges/kalshi/fetchMarkets.d.ts +3 -2
  8. package/dist/exchanges/kalshi/fetchMarkets.js +24 -32
  9. package/dist/exchanges/kalshi/fetchOHLCV.d.ts +1 -2
  10. package/dist/exchanges/kalshi/fetchOHLCV.js +9 -11
  11. package/dist/exchanges/kalshi/index.d.ts +2 -1
  12. package/dist/exchanges/kalshi/index.js +161 -183
  13. package/dist/exchanges/kalshi/kalshi.test.js +51 -31
  14. package/dist/exchanges/limitless/api.d.ts +555 -0
  15. package/dist/exchanges/limitless/api.js +863 -0
  16. package/dist/exchanges/limitless/fetchEvents.d.ts +1 -2
  17. package/dist/exchanges/limitless/fetchEvents.js +9 -15
  18. package/dist/exchanges/limitless/fetchMarkets.d.ts +1 -2
  19. package/dist/exchanges/limitless/fetchMarkets.js +9 -16
  20. package/dist/exchanges/limitless/fetchOHLCV.d.ts +1 -2
  21. package/dist/exchanges/limitless/fetchOHLCV.js +2 -11
  22. package/dist/exchanges/limitless/fetchOrderBook.d.ts +1 -2
  23. package/dist/exchanges/limitless/fetchOrderBook.js +2 -11
  24. package/dist/exchanges/limitless/index.d.ts +1 -0
  25. package/dist/exchanges/limitless/index.js +28 -7
  26. package/dist/exchanges/limitless/websocket.d.ts +2 -1
  27. package/dist/exchanges/limitless/websocket.js +6 -4
  28. package/dist/exchanges/myriad/api.d.ts +294 -0
  29. package/dist/exchanges/myriad/api.js +690 -0
  30. package/dist/exchanges/myriad/fetchOHLCV.d.ts +1 -2
  31. package/dist/exchanges/myriad/fetchOHLCV.js +3 -11
  32. package/dist/exchanges/myriad/fetchOrderBook.d.ts +1 -2
  33. package/dist/exchanges/myriad/fetchOrderBook.js +3 -11
  34. package/dist/exchanges/myriad/index.d.ts +2 -0
  35. package/dist/exchanges/myriad/index.js +116 -103
  36. package/dist/exchanges/myriad/websocket.d.ts +2 -2
  37. package/dist/exchanges/myriad/websocket.js +28 -6
  38. package/dist/exchanges/polymarket/api-clob.d.ts +346 -0
  39. package/dist/exchanges/polymarket/api-clob.js +517 -0
  40. package/dist/exchanges/polymarket/api-data.d.ts +789 -0
  41. package/dist/exchanges/polymarket/api-data.js +860 -0
  42. package/dist/exchanges/polymarket/api-gamma.d.ts +556 -0
  43. package/dist/exchanges/polymarket/api-gamma.js +1161 -0
  44. package/dist/exchanges/polymarket/fetchEvents.js +0 -68
  45. package/dist/exchanges/polymarket/fetchOHLCV.d.ts +1 -2
  46. package/dist/exchanges/polymarket/fetchOHLCV.js +4 -10
  47. package/dist/exchanges/polymarket/fetchOrderBook.d.ts +1 -2
  48. package/dist/exchanges/polymarket/fetchOrderBook.js +2 -10
  49. package/dist/exchanges/polymarket/fetchTrades.d.ts +1 -2
  50. package/dist/exchanges/polymarket/fetchTrades.js +2 -11
  51. package/dist/exchanges/polymarket/index.d.ts +10 -0
  52. package/dist/exchanges/polymarket/index.js +110 -5
  53. package/dist/exchanges/probable/api.d.ts +605 -0
  54. package/dist/exchanges/probable/api.js +887 -0
  55. package/dist/exchanges/probable/fetchEvents.d.ts +3 -3
  56. package/dist/exchanges/probable/fetchEvents.js +28 -25
  57. package/dist/exchanges/probable/fetchMarkets.d.ts +1 -1
  58. package/dist/exchanges/probable/fetchMarkets.js +25 -21
  59. package/dist/exchanges/probable/index.d.ts +1 -0
  60. package/dist/exchanges/probable/index.js +92 -10
  61. package/dist/exchanges/probable/utils.d.ts +1 -2
  62. package/dist/exchanges/probable/utils.js +4 -11
  63. package/dist/index.d.ts +1 -0
  64. package/dist/index.js +3 -1
  65. package/dist/utils/openapi.d.ts +9 -0
  66. package/dist/utils/openapi.js +59 -0
  67. package/package.json +4 -3
  68. package/dist/exchanges/kalshi/fetchOrderBook.d.ts +0 -3
  69. package/dist/exchanges/kalshi/fetchOrderBook.js +0 -59
  70. package/dist/exchanges/kalshi/fetchTrades.d.ts +0 -4
  71. package/dist/exchanges/kalshi/fetchTrades.js +0 -31
  72. package/dist/exchanges/limitless/fetchPositions.d.ts +0 -2
  73. package/dist/exchanges/limitless/fetchPositions.js +0 -34
  74. package/dist/exchanges/myriad/fetchTrades.d.ts +0 -4
  75. package/dist/exchanges/myriad/fetchTrades.js +0 -62
  76. package/dist/exchanges/polymarket/fetchPositions.d.ts +0 -2
  77. package/dist/exchanges/polymarket/fetchPositions.js +0 -34
  78. package/dist/exchanges/probable/fetchOHLCV.d.ts +0 -4
  79. package/dist/exchanges/probable/fetchOHLCV.js +0 -83
  80. package/dist/exchanges/probable/fetchOrderBook.d.ts +0 -3
  81. package/dist/exchanges/probable/fetchOrderBook.js +0 -37
  82. package/dist/exchanges/probable/fetchPositions.d.ts +0 -2
  83. package/dist/exchanges/probable/fetchPositions.js +0 -33
@@ -1,4 +1,5 @@
1
1
  import { EventFetchParams } from '../../BaseExchange';
2
2
  import { UnifiedEvent } from '../../types';
3
- import { AxiosInstance } from 'axios';
4
- export declare function fetchEvents(params: EventFetchParams, http?: AxiosInstance): Promise<UnifiedEvent[]>;
3
+ type CallApi = (operationId: string, params?: Record<string, any>) => Promise<any>;
4
+ export declare function fetchEvents(params: EventFetchParams, callApi: CallApi): Promise<UnifiedEvent[]>;
5
+ export {};
@@ -1,19 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchEvents = fetchEvents;
7
- const axios_1 = __importDefault(require("axios"));
8
4
  const utils_1 = require("./utils");
9
5
  const errors_1 = require("./errors");
10
- async function fetchEventByTicker(eventTicker, http) {
6
+ async function fetchEventByTicker(eventTicker, callApi) {
11
7
  const normalizedTicker = eventTicker.toUpperCase();
12
- const url = `https://api.elections.kalshi.com/trade-api/v2/events/${normalizedTicker}`;
13
- const response = await http.get(url, {
14
- params: { with_nested_markets: true }
15
- });
16
- const event = response.data.event;
8
+ const data = await callApi('GetEvent', { event_ticker: normalizedTicker, with_nested_markets: true });
9
+ const event = data.event;
17
10
  if (!event)
18
11
  return [];
19
12
  const markets = [];
@@ -38,15 +31,15 @@ async function fetchEventByTicker(eventTicker, http) {
38
31
  };
39
32
  return [unifiedEvent];
40
33
  }
41
- async function fetchEvents(params, http = axios_1.default) {
34
+ async function fetchEvents(params, callApi) {
42
35
  try {
43
36
  // Handle eventId lookup (direct API call)
44
37
  if (params.eventId) {
45
- return await fetchEventByTicker(params.eventId, http);
38
+ return await fetchEventByTicker(params.eventId, callApi);
46
39
  }
47
40
  // Handle slug lookup (slug IS the event ticker on Kalshi)
48
41
  if (params.slug) {
49
- return await fetchEventByTicker(params.slug, http);
42
+ return await fetchEventByTicker(params.slug, callApi);
50
43
  }
51
44
  const status = params?.status || 'active';
52
45
  const limit = params?.limit || 10000;
@@ -65,12 +58,12 @@ async function fetchEvents(params, http = axios_1.default) {
65
58
  };
66
59
  if (cursor)
67
60
  queryParams.cursor = cursor;
68
- const response = await http.get(utils_1.KALSHI_API_URL, { params: queryParams });
69
- const events = response.data.events || [];
61
+ const data = await callApi('GetEvents', queryParams);
62
+ const events = data.events || [];
70
63
  if (events.length === 0)
71
64
  break;
72
65
  allEvents = allEvents.concat(events);
73
- cursor = response.data.cursor;
66
+ cursor = data.cursor;
74
67
  page++;
75
68
  // If we have no search query and have fetched enough events, we can stop early
76
69
  if (!query && allEvents.length >= limit * 1.5) {
@@ -1,5 +1,6 @@
1
- import { AxiosInstance } from 'axios';
2
1
  import { MarketFetchParams } from '../../BaseExchange';
3
2
  import { UnifiedMarket } from '../../types';
3
+ type CallApi = (operationId: string, params?: Record<string, any>) => Promise<any>;
4
4
  export declare function resetCache(): void;
5
- export declare function fetchMarkets(params?: MarketFetchParams, http?: AxiosInstance): Promise<UnifiedMarket[]>;
5
+ export declare function fetchMarkets(params: MarketFetchParams | undefined, callApi: CallApi): Promise<UnifiedMarket[]>;
6
+ export {};
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.resetCache = resetCache;
7
4
  exports.fetchMarkets = fetchMarkets;
8
- const axios_1 = __importDefault(require("axios"));
9
5
  const utils_1 = require("./utils");
10
6
  const errors_1 = require("./errors");
11
- async function fetchActiveEvents(http, targetMarketCount, status = 'open') {
7
+ async function fetchActiveEvents(callApi, targetMarketCount, status = 'open') {
12
8
  let allEvents = [];
13
9
  let totalMarketCount = 0;
14
10
  let cursor = null;
@@ -27,8 +23,8 @@ async function fetchActiveEvents(http, targetMarketCount, status = 'open') {
27
23
  };
28
24
  if (cursor)
29
25
  queryParams.cursor = cursor;
30
- const response = await http.get(utils_1.KALSHI_API_URL, { params: queryParams });
31
- const events = response.data.events || [];
26
+ const data = await callApi('GetEvents', queryParams);
27
+ const events = data.events || [];
32
28
  if (events.length === 0)
33
29
  break;
34
30
  allEvents = allEvents.concat(events);
@@ -43,7 +39,7 @@ async function fetchActiveEvents(http, targetMarketCount, status = 'open') {
43
39
  break;
44
40
  }
45
41
  }
46
- cursor = response.data.cursor;
42
+ cursor = data.cursor;
47
43
  page++;
48
44
  // Additional safety: if no target specified, limit to reasonable number of pages
49
45
  if (!targetMarketCount && page >= 10) {
@@ -56,10 +52,10 @@ async function fetchActiveEvents(http, targetMarketCount, status = 'open') {
56
52
  } while (cursor && page < MAX_PAGES);
57
53
  return allEvents;
58
54
  }
59
- async function fetchSeriesMap(http) {
55
+ async function fetchSeriesMap(callApi) {
60
56
  try {
61
- const response = await http.get(utils_1.KALSHI_SERIES_URL);
62
- const seriesList = response.data.series || [];
57
+ const data = await callApi('GetSeriesList');
58
+ const seriesList = data.series || [];
63
59
  const map = new Map();
64
60
  for (const series of seriesList) {
65
61
  if (series.tags && series.tags.length > 0) {
@@ -83,52 +79,48 @@ function resetCache() {
83
79
  cachedSeriesMap = null;
84
80
  lastCacheTime = 0;
85
81
  }
86
- async function fetchMarkets(params, http = axios_1.default) {
82
+ async function fetchMarkets(params, callApi) {
87
83
  try {
88
84
  // Handle marketId lookup (Kalshi marketId is the ticker)
89
85
  if (params?.marketId) {
90
- return await fetchMarketsBySlug(params.marketId, http);
86
+ return await fetchMarketsBySlug(params.marketId, callApi);
91
87
  }
92
88
  // Handle slug-based lookup (event ticker)
93
89
  if (params?.slug) {
94
- return await fetchMarketsBySlug(params.slug, http);
90
+ return await fetchMarketsBySlug(params.slug, callApi);
95
91
  }
96
92
  // Handle outcomeId lookup (strip -NO suffix, use as ticker)
97
93
  if (params?.outcomeId) {
98
94
  const ticker = params.outcomeId.replace(/-NO$/, '');
99
- return await fetchMarketsBySlug(ticker, http);
95
+ return await fetchMarketsBySlug(ticker, callApi);
100
96
  }
101
97
  // Handle eventId lookup (event ticker works the same way)
102
98
  if (params?.eventId) {
103
- return await fetchMarketsBySlug(params.eventId, http);
99
+ return await fetchMarketsBySlug(params.eventId, callApi);
104
100
  }
105
101
  // Handle query-based search
106
102
  if (params?.query) {
107
- return await searchMarkets(params.query, params, http);
103
+ return await searchMarkets(params.query, params, callApi);
108
104
  }
109
105
  // Default: fetch markets
110
- return await fetchMarketsDefault(params, http);
106
+ return await fetchMarketsDefault(params, callApi);
111
107
  }
112
108
  catch (error) {
113
109
  throw errors_1.kalshiErrorMapper.mapError(error);
114
110
  }
115
111
  }
116
- async function fetchMarketsBySlug(eventTicker, http) {
112
+ async function fetchMarketsBySlug(eventTicker, callApi) {
117
113
  // Kalshi API expects uppercase tickers, but URLs use lowercase
118
114
  const normalizedTicker = eventTicker.toUpperCase();
119
- const url = `https://api.elections.kalshi.com/trade-api/v2/events/${normalizedTicker}`;
120
- const response = await http.get(url, {
121
- params: { with_nested_markets: true }
122
- });
123
- const event = response.data.event;
115
+ const data = await callApi('GetEvent', { event_ticker: normalizedTicker, with_nested_markets: true });
116
+ const event = data.event;
124
117
  if (!event)
125
118
  return [];
126
119
  // Enrichment: Fetch series tags if they exist
127
120
  if (event.series_ticker) {
128
121
  try {
129
- const seriesUrl = `${utils_1.KALSHI_SERIES_URL}/${event.series_ticker}`;
130
- const seriesResponse = await http.get(seriesUrl);
131
- const series = seriesResponse.data.series;
122
+ const seriesData = await callApi('GetSeries', { series_ticker: event.series_ticker });
123
+ const series = seriesData.series;
132
124
  if (series && series.tags && series.tags.length > 0) {
133
125
  if (!event.tags || event.tags.length === 0) {
134
126
  event.tags = series.tags;
@@ -149,10 +141,10 @@ async function fetchMarketsBySlug(eventTicker, http) {
149
141
  }
150
142
  return unifiedMarkets;
151
143
  }
152
- async function searchMarkets(query, params, http) {
144
+ async function searchMarkets(query, params, callApi) {
153
145
  // We must fetch ALL markets to search them locally since we don't have server-side search
154
146
  const searchLimit = 250000;
155
- const markets = await fetchMarketsDefault({ ...params, limit: searchLimit }, http);
147
+ const markets = await fetchMarketsDefault({ ...params, limit: searchLimit }, callApi);
156
148
  const lowerQuery = query.toLowerCase();
157
149
  const searchIn = params?.searchIn || 'title'; // Default to title-only search
158
150
  const filtered = markets.filter(market => {
@@ -167,7 +159,7 @@ async function searchMarkets(query, params, http) {
167
159
  const limit = params?.limit || 250000;
168
160
  return filtered.slice(0, limit);
169
161
  }
170
- async function fetchMarketsDefault(params, http) {
162
+ async function fetchMarketsDefault(params, callApi) {
171
163
  const limit = params?.limit || 250000;
172
164
  const offset = params?.offset || 0;
173
165
  const now = Date.now();
@@ -196,8 +188,8 @@ async function fetchMarketsDefault(params, http) {
196
188
  const isSorted = params?.sort && (params.sort === 'volume' || params.sort === 'liquidity');
197
189
  const fetchLimit = isSorted ? 1000 : limit;
198
190
  const [allEvents, fetchedSeriesMap] = await Promise.all([
199
- fetchActiveEvents(http, fetchLimit, apiStatus),
200
- fetchSeriesMap(http)
191
+ fetchActiveEvents(callApi, fetchLimit, apiStatus),
192
+ fetchSeriesMap(callApi)
201
193
  ]);
202
194
  events = allEvents;
203
195
  seriesMap = fetchedSeriesMap;
@@ -1,4 +1,3 @@
1
- import { AxiosInstance } from 'axios';
2
1
  import { HistoryFilterParams, OHLCVParams } from '../../BaseExchange';
3
2
  import { PriceCandle } from '../../types';
4
- export declare function fetchOHLCV(id: string, params: OHLCVParams | HistoryFilterParams, http?: AxiosInstance): Promise<PriceCandle[]>;
3
+ export declare function fetchOHLCV(id: string, params: OHLCVParams | HistoryFilterParams, callApi: (operationId: string, params?: Record<string, any>) => Promise<any>): Promise<PriceCandle[]>;
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchOHLCV = fetchOHLCV;
7
- const axios_1 = __importDefault(require("axios"));
8
4
  const utils_1 = require("./utils");
9
5
  const validation_1 = require("../../utils/validation");
10
6
  const errors_1 = require("./errors");
11
- async function fetchOHLCV(id, params, http = axios_1.default) {
7
+ async function fetchOHLCV(id, params, callApi) {
12
8
  (0, validation_1.validateIdFormat)(id, 'OHLCV');
13
9
  // Validate resolution is provided
14
10
  if (!params.resolution) {
@@ -26,8 +22,6 @@ async function fetchOHLCV(id, params, http = axios_1.default) {
26
22
  throw new Error(`Invalid Kalshi Ticker format: "${id}". Expected format like "FED-25JAN29-B4.75".`);
27
23
  }
28
24
  const seriesTicker = parts.slice(0, -1).join('-');
29
- const url = `https://api.elections.kalshi.com/trade-api/v2/series/${seriesTicker}/markets/${normalizedId}/candlesticks`;
30
- const queryParams = { period_interval: interval };
31
25
  const now = Math.floor(Date.now() / 1000);
32
26
  let startTs = now - (24 * 60 * 60);
33
27
  let endTs = now;
@@ -55,10 +49,14 @@ async function fetchOHLCV(id, params, http = axios_1.default) {
55
49
  startTs = endTs - (24 * 60 * 60);
56
50
  }
57
51
  }
58
- queryParams.start_ts = startTs;
59
- queryParams.end_ts = endTs;
60
- const response = await http.get(url, { params: queryParams });
61
- const candles = response.data.candlesticks || [];
52
+ const data = await callApi('GetMarketCandlesticks', {
53
+ series_ticker: seriesTicker,
54
+ ticker: normalizedId,
55
+ period_interval: interval,
56
+ start_ts: startTs,
57
+ end_ts: endTs,
58
+ });
59
+ const candles = data.candlesticks || [];
62
60
  const mappedCandles = candles.map((c) => {
63
61
  // Priority:
64
62
  // 1. Transaction price (close)
@@ -26,7 +26,8 @@ export declare class KalshiExchange extends PredictionMarketExchange {
26
26
  private wsConfig?;
27
27
  constructor(options?: ExchangeCredentials | KalshiExchangeOptions);
28
28
  get name(): string;
29
- private getBaseUrl;
29
+ protected sign(method: string, path: string, _params: Record<string, any>): Record<string, string>;
30
+ protected mapImplicitApiError(error: any): any;
30
31
  private ensureAuth;
31
32
  protected fetchMarketsImpl(params?: MarketFilterParams): Promise<UnifiedMarket[]>;
32
33
  protected fetchEventsImpl(params: EventFetchParams): Promise<UnifiedEvent[]>;