pmxt-core 2.44.5 → 2.45.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/dist/exchanges/kalshi/api.d.ts +1 -1
- package/dist/exchanges/kalshi/api.js +1 -1
- package/dist/exchanges/kalshi/fetcher.d.ts +11 -1
- package/dist/exchanges/kalshi/fetcher.js +49 -17
- package/dist/exchanges/kalshi/normalizer.d.ts +12 -0
- package/dist/exchanges/kalshi/normalizer.js +125 -1
- package/dist/exchanges/limitless/api.d.ts +1 -1
- package/dist/exchanges/limitless/api.js +1 -1
- package/dist/exchanges/mock/index.js +13 -2
- package/dist/exchanges/myriad/api.d.ts +1 -1
- package/dist/exchanges/myriad/api.js +1 -1
- package/dist/exchanges/opinion/api.d.ts +1 -1
- package/dist/exchanges/opinion/api.js +1 -1
- package/dist/exchanges/polymarket/api-clob.d.ts +1 -1
- package/dist/exchanges/polymarket/api-clob.js +1 -1
- package/dist/exchanges/polymarket/api-data.d.ts +1 -1
- package/dist/exchanges/polymarket/api-data.js +1 -1
- package/dist/exchanges/polymarket/api-gamma.d.ts +1 -1
- package/dist/exchanges/polymarket/api-gamma.js +1 -1
- package/dist/exchanges/polymarket/websocket.d.ts +12 -0
- package/dist/exchanges/polymarket/websocket.js +120 -14
- package/dist/exchanges/probable/api.d.ts +1 -1
- package/dist/exchanges/probable/api.js +1 -1
- package/dist/exchanges/suibets/api.d.ts +15 -0
- package/dist/exchanges/suibets/api.js +17 -0
- package/dist/exchanges/suibets/config.d.ts +16 -0
- package/dist/exchanges/suibets/config.js +34 -0
- package/dist/exchanges/suibets/errors.d.ts +16 -0
- package/dist/exchanges/suibets/errors.js +71 -0
- package/dist/exchanges/suibets/fetcher.d.ts +64 -0
- package/dist/exchanges/suibets/fetcher.js +128 -0
- package/dist/exchanges/suibets/index.d.ts +54 -0
- package/dist/exchanges/suibets/index.js +114 -0
- package/dist/exchanges/suibets/normalizer.d.ts +8 -0
- package/dist/exchanges/suibets/normalizer.js +102 -0
- package/dist/exchanges/suibets/utils.d.ts +63 -0
- package/dist/exchanges/suibets/utils.js +124 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -1
- package/dist/router/Router.js +12 -3
- package/dist/server/app.js +76 -1
- package/dist/server/exchange-factory.js +6 -0
- package/dist/server/openapi.yaml +7 -0
- package/dist/server/ws-handler.js +196 -23
- package/package.json +6 -6
|
@@ -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-05-
|
|
3
|
+
* Generated at: 2026-05-25T15:44:11.679Z
|
|
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-05-
|
|
6
|
+
* Generated at: 2026-05-25T15:44:11.679Z
|
|
7
7
|
* Do not edit manually -- run "npm run fetch:openapi" to regenerate.
|
|
8
8
|
*/
|
|
9
9
|
exports.kalshiApiSpec = {
|
|
@@ -30,13 +30,20 @@ export interface KalshiRawMarket {
|
|
|
30
30
|
export interface KalshiRawEvent {
|
|
31
31
|
event_ticker: string;
|
|
32
32
|
title: string;
|
|
33
|
+
sub_title?: string;
|
|
33
34
|
image_url?: string;
|
|
34
35
|
category?: string;
|
|
35
36
|
tags?: string[];
|
|
36
37
|
series_ticker?: string;
|
|
38
|
+
series_title?: string;
|
|
39
|
+
mutually_exclusive?: boolean;
|
|
37
40
|
markets?: KalshiRawMarket[];
|
|
38
41
|
[key: string]: unknown;
|
|
39
42
|
}
|
|
43
|
+
interface KalshiSeriesInfo {
|
|
44
|
+
title?: string;
|
|
45
|
+
tags?: string[];
|
|
46
|
+
}
|
|
40
47
|
export interface KalshiRawEventPage {
|
|
41
48
|
events: KalshiRawEvent[];
|
|
42
49
|
cursor?: string | null;
|
|
@@ -146,10 +153,13 @@ export declare class KalshiFetcher implements IExchangeFetcher<KalshiRawEvent, K
|
|
|
146
153
|
}>;
|
|
147
154
|
fetchRawOrders(queryParams: Record<string, any>): Promise<KalshiRawOrder[]>;
|
|
148
155
|
fetchRawHistoricalOrders(queryParams: Record<string, any>): Promise<KalshiRawOrder[]>;
|
|
149
|
-
fetchRawSeriesMap(): Promise<Map<string,
|
|
156
|
+
fetchRawSeriesMap(): Promise<Map<string, KalshiSeriesInfo>>;
|
|
150
157
|
fetchRawEventByTicker(eventTicker: string): Promise<KalshiRawEvent[]>;
|
|
151
158
|
private fetchRawEventsDefault;
|
|
159
|
+
private enrichEventsWithSeriesList;
|
|
160
|
+
private enrichEventsWithSeriesMap;
|
|
152
161
|
private fetchActiveEvents;
|
|
153
162
|
private fetchAllWithStatus;
|
|
154
163
|
private fetchPageWithStatus;
|
|
155
164
|
}
|
|
165
|
+
export {};
|
|
@@ -65,16 +65,16 @@ class KalshiFetcher {
|
|
|
65
65
|
this.fetchAllWithStatus('closed'),
|
|
66
66
|
this.fetchAllWithStatus('settled'),
|
|
67
67
|
]);
|
|
68
|
-
return [...openEvents, ...closedEvents, ...settledEvents];
|
|
68
|
+
return this.enrichEventsWithSeriesList([...openEvents, ...closedEvents, ...settledEvents]);
|
|
69
69
|
}
|
|
70
70
|
else if (status === 'closed' || status === 'inactive') {
|
|
71
71
|
const [closedEvents, settledEvents] = await Promise.all([
|
|
72
72
|
this.fetchAllWithStatus('closed'),
|
|
73
73
|
this.fetchAllWithStatus('settled'),
|
|
74
74
|
]);
|
|
75
|
-
return [...closedEvents, ...settledEvents];
|
|
75
|
+
return this.enrichEventsWithSeriesList([...closedEvents, ...settledEvents]);
|
|
76
76
|
}
|
|
77
|
-
return this.fetchAllWithStatus('open');
|
|
77
|
+
return this.enrichEventsWithSeriesList(await this.fetchAllWithStatus('open'));
|
|
78
78
|
}
|
|
79
79
|
catch (error) {
|
|
80
80
|
throw errors_1.kalshiErrorMapper.mapError(error);
|
|
@@ -92,7 +92,9 @@ class KalshiFetcher {
|
|
|
92
92
|
if (status === 'settled')
|
|
93
93
|
apiStatus = 'settled';
|
|
94
94
|
const limit = Math.max(1, Math.floor(params.limit || BATCH_SIZE));
|
|
95
|
-
|
|
95
|
+
const page = await this.fetchPageWithStatus(apiStatus, limit, params.cursor);
|
|
96
|
+
await this.enrichEventsWithSeriesList(page.events);
|
|
97
|
+
return page;
|
|
96
98
|
}
|
|
97
99
|
catch (error) {
|
|
98
100
|
throw errors_1.kalshiErrorMapper.mapError(error);
|
|
@@ -217,8 +219,11 @@ class KalshiFetcher {
|
|
|
217
219
|
const seriesList = data.series || [];
|
|
218
220
|
const map = new Map();
|
|
219
221
|
for (const series of seriesList) {
|
|
220
|
-
if (series.
|
|
221
|
-
map.set(series.ticker,
|
|
222
|
+
if (series.ticker) {
|
|
223
|
+
map.set(series.ticker, {
|
|
224
|
+
title: typeof series.title === 'string' ? series.title : undefined,
|
|
225
|
+
tags: Array.isArray(series.tags) ? series.tags : undefined,
|
|
226
|
+
});
|
|
222
227
|
}
|
|
223
228
|
}
|
|
224
229
|
return map;
|
|
@@ -237,20 +242,24 @@ class KalshiFetcher {
|
|
|
237
242
|
const event = data.event;
|
|
238
243
|
if (!event)
|
|
239
244
|
return [];
|
|
240
|
-
// Enrich with series
|
|
245
|
+
// Enrich with series metadata. The series title helps the normalizer
|
|
246
|
+
// avoid polluted event titles on multi-market futures.
|
|
241
247
|
if (event.series_ticker) {
|
|
242
248
|
try {
|
|
243
249
|
const seriesData = await this.ctx.callApi('GetSeries', {
|
|
244
250
|
series_ticker: event.series_ticker,
|
|
245
251
|
});
|
|
246
252
|
const series = seriesData.series;
|
|
253
|
+
if (typeof series?.title === 'string' && series.title.trim()) {
|
|
254
|
+
event.series_title = series.title.trim();
|
|
255
|
+
}
|
|
247
256
|
if (series?.tags?.length > 0 && (!event.tags || event.tags.length === 0)) {
|
|
248
257
|
event.tags = series.tags;
|
|
249
258
|
}
|
|
250
259
|
}
|
|
251
260
|
catch (err) {
|
|
252
|
-
// Non-critical —
|
|
253
|
-
logger_1.logger.warn('kalshi: series
|
|
261
|
+
// Non-critical — series metadata is enrichment only.
|
|
262
|
+
logger_1.logger.warn('kalshi: series metadata fetch failed', {
|
|
254
263
|
series_ticker: event.series_ticker,
|
|
255
264
|
error: err instanceof Error ? err.message : String(err),
|
|
256
265
|
});
|
|
@@ -275,14 +284,7 @@ class KalshiFetcher {
|
|
|
275
284
|
this.fetchActiveEvents(fetchLimit, apiStatus),
|
|
276
285
|
this.fetchRawSeriesMap(),
|
|
277
286
|
]);
|
|
278
|
-
|
|
279
|
-
for (const event of allEvents) {
|
|
280
|
-
if (event.series_ticker && fetchedSeriesMap.has(event.series_ticker)) {
|
|
281
|
-
if (!event.tags || event.tags.length === 0) {
|
|
282
|
-
event.tags = fetchedSeriesMap.get(event.series_ticker);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
287
|
+
this.enrichEventsWithSeriesMap(allEvents, fetchedSeriesMap);
|
|
286
288
|
if (fetchLimit >= 1000 && useCache) {
|
|
287
289
|
this.cachedEvents = allEvents;
|
|
288
290
|
this.cachedSeriesMap = fetchedSeriesMap;
|
|
@@ -290,6 +292,36 @@ class KalshiFetcher {
|
|
|
290
292
|
}
|
|
291
293
|
return allEvents;
|
|
292
294
|
}
|
|
295
|
+
async enrichEventsWithSeriesList(events) {
|
|
296
|
+
if (events.length === 0)
|
|
297
|
+
return events;
|
|
298
|
+
try {
|
|
299
|
+
const seriesMap = await this.fetchRawSeriesMap();
|
|
300
|
+
this.enrichEventsWithSeriesMap(events, seriesMap);
|
|
301
|
+
}
|
|
302
|
+
catch (err) {
|
|
303
|
+
// Non-critical — callers can still normalize the venue-native title.
|
|
304
|
+
logger_1.logger.warn('kalshi: series list enrichment failed', {
|
|
305
|
+
error: err instanceof Error ? err.message : String(err),
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
return events;
|
|
309
|
+
}
|
|
310
|
+
enrichEventsWithSeriesMap(events, seriesMap) {
|
|
311
|
+
for (const event of events) {
|
|
312
|
+
if (!event.series_ticker)
|
|
313
|
+
continue;
|
|
314
|
+
const seriesInfo = seriesMap.get(event.series_ticker);
|
|
315
|
+
if (!seriesInfo)
|
|
316
|
+
continue;
|
|
317
|
+
if (seriesInfo.title) {
|
|
318
|
+
event.series_title = seriesInfo.title;
|
|
319
|
+
}
|
|
320
|
+
if (seriesInfo.tags?.length && (!event.tags || event.tags.length === 0)) {
|
|
321
|
+
event.tags = seriesInfo.tags;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
293
325
|
async fetchActiveEvents(targetMarketCount, status = 'open') {
|
|
294
326
|
let allEvents = [];
|
|
295
327
|
let totalMarketCount = 0;
|
|
@@ -21,6 +21,18 @@ export declare class KalshiNormalizer implements IExchangeNormalizer<KalshiRawEv
|
|
|
21
21
|
}): Balance[];
|
|
22
22
|
private mapOrderStatus;
|
|
23
23
|
private deriveEventDescription;
|
|
24
|
+
private deriveEventTitle;
|
|
25
|
+
private shouldUseSeriesTitle;
|
|
26
|
+
private deriveCommonEventTitle;
|
|
27
|
+
private extractEventTitleFromMarketTitle;
|
|
28
|
+
private composeSeriesTitle;
|
|
29
|
+
private ensureWinnerTitle;
|
|
30
|
+
private hasResolutionTerm;
|
|
31
|
+
private extractEventTitlePrefix;
|
|
32
|
+
private extractResolutionTerm;
|
|
33
|
+
private hasWinVerb;
|
|
34
|
+
private normalizeTitleText;
|
|
35
|
+
private escapeRegExp;
|
|
24
36
|
private deriveOutcomeLabel;
|
|
25
37
|
private cleanLabel;
|
|
26
38
|
private templateRule;
|
|
@@ -102,7 +102,7 @@ class KalshiNormalizer {
|
|
|
102
102
|
const markets = this.normalizeMarketsFromEvent(raw);
|
|
103
103
|
return {
|
|
104
104
|
id: raw.event_ticker,
|
|
105
|
-
title: raw
|
|
105
|
+
title: this.deriveEventTitle(raw),
|
|
106
106
|
description: this.deriveEventDescription(raw.markets || []),
|
|
107
107
|
slug: raw.event_ticker,
|
|
108
108
|
markets,
|
|
@@ -299,6 +299,130 @@ class KalshiNormalizer {
|
|
|
299
299
|
}
|
|
300
300
|
return texts[0];
|
|
301
301
|
}
|
|
302
|
+
deriveEventTitle(event) {
|
|
303
|
+
const rawTitle = this.cleanLabel(event.title) || event.event_ticker;
|
|
304
|
+
const seriesTitle = this.cleanLabel(event.series_title);
|
|
305
|
+
const markets = event.markets || [];
|
|
306
|
+
if (!seriesTitle || !this.shouldUseSeriesTitle(event, markets)) {
|
|
307
|
+
return rawTitle;
|
|
308
|
+
}
|
|
309
|
+
return this.composeSeriesTitle(seriesTitle, this.deriveCommonEventTitle(event, markets));
|
|
310
|
+
}
|
|
311
|
+
shouldUseSeriesTitle(event, markets) {
|
|
312
|
+
if (event.mutually_exclusive !== true)
|
|
313
|
+
return false;
|
|
314
|
+
if (markets.length < 4)
|
|
315
|
+
return false;
|
|
316
|
+
const rawTitle = this.cleanLabel(event.title);
|
|
317
|
+
if (!rawTitle)
|
|
318
|
+
return false;
|
|
319
|
+
const titleLooksScoped = /(?:\bvs\.?\b|\bversus\b|:)/i.test(rawTitle);
|
|
320
|
+
if (!titleLooksScoped)
|
|
321
|
+
return false;
|
|
322
|
+
const candidateLabels = markets
|
|
323
|
+
.map((market) => this.deriveOutcomeLabel(market))
|
|
324
|
+
.filter((label) => label != null && label.length >= 3);
|
|
325
|
+
if (candidateLabels.length < 4)
|
|
326
|
+
return false;
|
|
327
|
+
const normalizedTitle = this.normalizeTitleText(rawTitle);
|
|
328
|
+
const containedLabels = new Set();
|
|
329
|
+
for (const label of candidateLabels) {
|
|
330
|
+
const normalizedLabel = this.normalizeTitleText(label);
|
|
331
|
+
if (normalizedLabel && normalizedTitle.includes(normalizedLabel)) {
|
|
332
|
+
containedLabels.add(normalizedLabel);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return containedLabels.size >= 2;
|
|
336
|
+
}
|
|
337
|
+
deriveCommonEventTitle(event, markets) {
|
|
338
|
+
const eventTitlePrefix = this.extractEventTitlePrefix(event.title);
|
|
339
|
+
if (eventTitlePrefix) {
|
|
340
|
+
if (this.hasWinVerb(eventTitlePrefix))
|
|
341
|
+
return 'Winner';
|
|
342
|
+
if (this.hasResolutionTerm(eventTitlePrefix))
|
|
343
|
+
return eventTitlePrefix;
|
|
344
|
+
}
|
|
345
|
+
const candidates = new Map();
|
|
346
|
+
for (const market of markets) {
|
|
347
|
+
const marketTitle = this.cleanLabel(market.title);
|
|
348
|
+
if (!marketTitle)
|
|
349
|
+
continue;
|
|
350
|
+
const outcomeLabel = this.deriveOutcomeLabel(market);
|
|
351
|
+
const candidate = this.extractEventTitleFromMarketTitle(marketTitle, outcomeLabel);
|
|
352
|
+
if (!candidate)
|
|
353
|
+
continue;
|
|
354
|
+
candidates.set(candidate, (candidates.get(candidate) ?? 0) + 1);
|
|
355
|
+
}
|
|
356
|
+
let best = null;
|
|
357
|
+
let bestCount = 0;
|
|
358
|
+
for (const [candidate, count] of candidates.entries()) {
|
|
359
|
+
if (count > bestCount) {
|
|
360
|
+
best = candidate;
|
|
361
|
+
bestCount = count;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return best;
|
|
365
|
+
}
|
|
366
|
+
extractEventTitleFromMarketTitle(title, outcomeLabel) {
|
|
367
|
+
const escapedOutcome = outcomeLabel ? this.escapeRegExp(outcomeLabel) : '[^?]+?';
|
|
368
|
+
const winPattern = new RegExp(`^Will (?:the )?${escapedOutcome} win (?:the )?(.+?)\\??$`, 'i');
|
|
369
|
+
const winMatch = title.match(winPattern);
|
|
370
|
+
if (winMatch?.[1]) {
|
|
371
|
+
return this.ensureWinnerTitle(winMatch[1].trim());
|
|
372
|
+
}
|
|
373
|
+
const plainWinnerMatch = title.match(/^(.+? Winner)\??$/i);
|
|
374
|
+
if (plainWinnerMatch?.[1])
|
|
375
|
+
return plainWinnerMatch[1].trim();
|
|
376
|
+
const championMatch = title.match(/^(.+? Champion(?:ship)?)\??$/i);
|
|
377
|
+
if (championMatch?.[1])
|
|
378
|
+
return championMatch[1].trim();
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
composeSeriesTitle(seriesTitle, commonTitle) {
|
|
382
|
+
if (!commonTitle)
|
|
383
|
+
return seriesTitle;
|
|
384
|
+
let title = seriesTitle;
|
|
385
|
+
const year = commonTitle.match(/^\s*(20\d{2})\b/)?.[1];
|
|
386
|
+
if (year && !new RegExp(`\\b${year}\\b`).test(title)) {
|
|
387
|
+
title = `${year} ${title}`;
|
|
388
|
+
}
|
|
389
|
+
if (this.hasResolutionTerm(title)) {
|
|
390
|
+
return title;
|
|
391
|
+
}
|
|
392
|
+
const resolutionTerm = this.extractResolutionTerm(commonTitle);
|
|
393
|
+
if (resolutionTerm) {
|
|
394
|
+
return `${title} ${resolutionTerm}`;
|
|
395
|
+
}
|
|
396
|
+
return title;
|
|
397
|
+
}
|
|
398
|
+
ensureWinnerTitle(title) {
|
|
399
|
+
if (this.hasResolutionTerm(title))
|
|
400
|
+
return title;
|
|
401
|
+
return `${title} Winner`;
|
|
402
|
+
}
|
|
403
|
+
hasResolutionTerm(title) {
|
|
404
|
+
return /\b(winner|champion|championship|nominee|nomination|election|finals?|cup|award)\b/i.test(title);
|
|
405
|
+
}
|
|
406
|
+
extractEventTitlePrefix(title) {
|
|
407
|
+
const match = title.match(/^(.+?)(?:\s*:\s*|\s+[-\u2013\u2014]\s+)(.+)$/u);
|
|
408
|
+
const prefix = match?.[1]?.trim();
|
|
409
|
+
if (prefix && this.normalizeTitleText(prefix) === 'series winner')
|
|
410
|
+
return null;
|
|
411
|
+
return prefix || null;
|
|
412
|
+
}
|
|
413
|
+
extractResolutionTerm(title) {
|
|
414
|
+
const match = title.match(/\b(Winner|Champion|Championship|Nominee|Nomination|Election|Finals?|Cup|Award)\b\s*$/i);
|
|
415
|
+
return match?.[1] || null;
|
|
416
|
+
}
|
|
417
|
+
hasWinVerb(title) {
|
|
418
|
+
return /\bwin(?:s|ning)?\b/i.test(title);
|
|
419
|
+
}
|
|
420
|
+
normalizeTitleText(value) {
|
|
421
|
+
return value.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, ' ').trim();
|
|
422
|
+
}
|
|
423
|
+
escapeRegExp(value) {
|
|
424
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
425
|
+
}
|
|
302
426
|
deriveOutcomeLabel(market) {
|
|
303
427
|
const yesSubtitle = this.cleanLabel(market.yes_sub_title);
|
|
304
428
|
if (yesSubtitle)
|
|
@@ -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-05-
|
|
3
|
+
* Generated at: 2026-05-25T15:44:11.717Z
|
|
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-05-
|
|
6
|
+
* Generated at: 2026-05-25T15:44:11.717Z
|
|
7
7
|
* Do not edit manually -- run "npm run fetch:openapi" to regenerate.
|
|
8
8
|
*/
|
|
9
9
|
exports.limitlessApiSpec = {
|
|
@@ -5,6 +5,17 @@ const BaseExchange_1 = require("../../BaseExchange");
|
|
|
5
5
|
const seededRng_1 = require("./seededRng");
|
|
6
6
|
const clamp = (n, lo, hi) => Math.min(hi, Math.max(lo, n));
|
|
7
7
|
const round = (n, decimals = 3) => parseFloat(n.toFixed(decimals));
|
|
8
|
+
const toTimestamp = (value) => {
|
|
9
|
+
if (value === undefined)
|
|
10
|
+
return undefined;
|
|
11
|
+
if (value instanceof Date)
|
|
12
|
+
return value.getTime();
|
|
13
|
+
const parsed = typeof value === 'number' ? value : new Date(value).getTime();
|
|
14
|
+
if (!Number.isFinite(parsed)) {
|
|
15
|
+
throw new Error(`Invalid date value: ${String(value)}`);
|
|
16
|
+
}
|
|
17
|
+
return parsed;
|
|
18
|
+
};
|
|
8
19
|
const CATEGORIES = ['Politics', 'Sports', 'Crypto', 'Finance', 'Science', 'Entertainment', 'Tech', 'World'];
|
|
9
20
|
const LOREM = `lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor
|
|
10
21
|
incididunt ut labore et dolore magna aliqua enim ad minim veniam quis nostrud
|
|
@@ -333,8 +344,8 @@ class MockExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
333
344
|
};
|
|
334
345
|
const step = resolutionMs[params.resolution] ?? 3_600_000;
|
|
335
346
|
const limit = params.limit ?? 100;
|
|
336
|
-
const end = params.end
|
|
337
|
-
const start = params.start
|
|
347
|
+
const end = toTimestamp(params.end) ?? Date.now();
|
|
348
|
+
const start = toTimestamp(params.start) ?? end - step * limit;
|
|
338
349
|
const candles = [];
|
|
339
350
|
let price = round(f.float(0.2, 0.8), 3);
|
|
340
351
|
let t = start;
|
|
@@ -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-05-
|
|
3
|
+
* Generated at: 2026-05-25T15:44:11.728Z
|
|
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-05-
|
|
6
|
+
* Generated at: 2026-05-25T15:44:11.728Z
|
|
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/opinion/opinion-openapi.yaml
|
|
3
|
-
* Generated at: 2026-05-
|
|
3
|
+
* Generated at: 2026-05-25T15:44:11.734Z
|
|
4
4
|
* Do not edit manually -- run "npm run fetch:openapi" to regenerate.
|
|
5
5
|
*/
|
|
6
6
|
export declare const opinionApiSpec: {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.opinionApiSpec = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/opinion/opinion-openapi.yaml
|
|
6
|
-
* Generated at: 2026-05-
|
|
6
|
+
* Generated at: 2026-05-25T15:44:11.734Z
|
|
7
7
|
* Do not edit manually -- run "npm run fetch:openapi" to regenerate.
|
|
8
8
|
*/
|
|
9
9
|
exports.opinionApiSpec = {
|
|
@@ -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-05-
|
|
3
|
+
* Generated at: 2026-05-25T15:44:11.685Z
|
|
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-05-
|
|
6
|
+
* Generated at: 2026-05-25T15:44:11.685Z
|
|
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-05-
|
|
3
|
+
* Generated at: 2026-05-25T15:44:11.697Z
|
|
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-05-
|
|
6
|
+
* Generated at: 2026-05-25T15:44:11.697Z
|
|
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-05-
|
|
3
|
+
* Generated at: 2026-05-25T15:44:11.694Z
|
|
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-05-
|
|
6
|
+
* Generated at: 2026-05-25T15:44:11.694Z
|
|
7
7
|
* Do not edit manually -- run "npm run fetch:openapi" to regenerate.
|
|
8
8
|
*/
|
|
9
9
|
exports.polymarketGammaSpec = {
|
|
@@ -49,6 +49,8 @@ export interface PolymarketWebSocketConfig {
|
|
|
49
49
|
userChannelCreds?: PolymarketUserChannelCreds;
|
|
50
50
|
/** Timeout in ms for WebSocket connections to open (default: 30000). */
|
|
51
51
|
connectionTimeoutMs?: number;
|
|
52
|
+
/** Time to wait for an initial market-channel book before using a REST snapshot fallback. */
|
|
53
|
+
snapshotFallbackMs?: number;
|
|
52
54
|
}
|
|
53
55
|
/**
|
|
54
56
|
* Native WebSocket implementation for Polymarket market data.
|
|
@@ -64,6 +66,8 @@ export declare class PolymarketWebSocket {
|
|
|
64
66
|
private orderBooks;
|
|
65
67
|
private config;
|
|
66
68
|
private initializationPromise?;
|
|
69
|
+
private marketPingInterval;
|
|
70
|
+
private readonly callApi;
|
|
67
71
|
constructor(callApi: (operationId: string, params?: Record<string, any>) => Promise<any>, config?: PolymarketWebSocketConfig);
|
|
68
72
|
watchOrderBook(outcomeId: string): Promise<OrderBook>;
|
|
69
73
|
unwatchOrderBook(outcomeId: string): Promise<void>;
|
|
@@ -95,6 +99,14 @@ export declare class PolymarketWebSocket {
|
|
|
95
99
|
private subscribe;
|
|
96
100
|
private ensureInitialized;
|
|
97
101
|
private handleBookSnapshot;
|
|
102
|
+
private withSnapshotFallback;
|
|
103
|
+
private removeOrderBookResolver;
|
|
104
|
+
private fetchOrderBookSnapshot;
|
|
105
|
+
private normalizeRawOrderBook;
|
|
106
|
+
private parseTimestamp;
|
|
107
|
+
private startMarketHeartbeat;
|
|
108
|
+
private stopMarketHeartbeat;
|
|
109
|
+
private rejectPendingMarketResolvers;
|
|
98
110
|
private handlePriceChange;
|
|
99
111
|
private handleTrade;
|
|
100
112
|
private resolveOrderBook;
|