pmxtjs 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/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/pmxt/client.d.ts +20 -4
- package/dist/esm/pmxt/client.js +114 -115
- package/dist/esm/pmxt/router.js +12 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -1
- package/dist/pmxt/client.d.ts +20 -4
- package/dist/pmxt/client.js +116 -116
- package/dist/pmxt/router.js +12 -6
- package/generated/package.json +1 -1
- package/index.ts +2 -1
- package/package.json +4 -4
- package/pmxt/client.ts +153 -119
- package/pmxt/router.ts +10 -4
package/dist/esm/index.d.ts
CHANGED
|
@@ -22,9 +22,10 @@ import { Router } from "./pmxt/router.js";
|
|
|
22
22
|
import { ServerManager } from "./pmxt/server-manager.js";
|
|
23
23
|
import * as models from "./pmxt/models.js";
|
|
24
24
|
import * as errors from "./pmxt/errors.js";
|
|
25
|
-
export { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi, Opinion, Metaculus, Smarkets, PolymarketUS, GeminiTitan, Hyperliquid, Mock, PolymarketOptions } from "./pmxt/client.js";
|
|
25
|
+
export { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi, Opinion, Metaculus, Smarkets, PolymarketUS, GeminiTitan, Hyperliquid, SuiBets, Mock, PolymarketOptions } from "./pmxt/client.js";
|
|
26
26
|
export { Router } from "./pmxt/router.js";
|
|
27
27
|
export { ServerManager } from "./pmxt/server-manager.js";
|
|
28
|
+
export { HOSTED_URL, LOCAL_URL, ENV, resolvePmxtBaseUrl } from "./pmxt/constants.js";
|
|
28
29
|
export { MarketList } from "./pmxt/models.js";
|
|
29
30
|
export type * from "./pmxt/models.js";
|
|
30
31
|
export * from "./pmxt/errors.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -22,9 +22,10 @@ import { Router } from "./pmxt/router.js";
|
|
|
22
22
|
import { ServerManager } from "./pmxt/server-manager.js";
|
|
23
23
|
import * as models from "./pmxt/models.js";
|
|
24
24
|
import * as errors from "./pmxt/errors.js";
|
|
25
|
-
export { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi, Opinion, Metaculus, Smarkets, PolymarketUS, GeminiTitan, Hyperliquid, Mock } from "./pmxt/client.js";
|
|
25
|
+
export { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi, Opinion, Metaculus, Smarkets, PolymarketUS, GeminiTitan, Hyperliquid, SuiBets, Mock } from "./pmxt/client.js";
|
|
26
26
|
export { Router } from "./pmxt/router.js";
|
|
27
27
|
export { ServerManager } from "./pmxt/server-manager.js";
|
|
28
|
+
export { HOSTED_URL, LOCAL_URL, ENV, resolvePmxtBaseUrl } from "./pmxt/constants.js";
|
|
28
29
|
export { MarketList } from "./pmxt/models.js";
|
|
29
30
|
export * from "./pmxt/errors.js";
|
|
30
31
|
const defaultManager = new ServerManager();
|
|
@@ -106,7 +106,7 @@ export declare abstract class Exchange {
|
|
|
106
106
|
* Return the shared WebSocket client, creating it on first use.
|
|
107
107
|
*
|
|
108
108
|
* Returns `null` if the sidecar /ws endpoint was previously found
|
|
109
|
-
* to be unavailable
|
|
109
|
+
* to be unavailable.
|
|
110
110
|
*/
|
|
111
111
|
private getOrCreateWs;
|
|
112
112
|
/**
|
|
@@ -114,6 +114,13 @@ export declare abstract class Exchange {
|
|
|
114
114
|
* Returns the raw data on success, or `null` if WS is unavailable.
|
|
115
115
|
*/
|
|
116
116
|
private watchViaWs;
|
|
117
|
+
private wsTransportUnavailableError;
|
|
118
|
+
private isWsTransportUnavailableError;
|
|
119
|
+
private getWsInternals;
|
|
120
|
+
private wsSubscriptionKey;
|
|
121
|
+
private getWsSubscriptionId;
|
|
122
|
+
private clearWsSubscription;
|
|
123
|
+
private sendWsMessage;
|
|
117
124
|
/**
|
|
118
125
|
* Call an exchange-specific REST endpoint by its operationId.
|
|
119
126
|
* This provides direct access to all implicit API methods defined in
|
|
@@ -251,9 +258,6 @@ export declare abstract class Exchange {
|
|
|
251
258
|
* order book snapshot. Call repeatedly in a loop to stream updates
|
|
252
259
|
* (CCXT Pro pattern).
|
|
253
260
|
*
|
|
254
|
-
* Prefers the sidecar WebSocket transport when available, falling
|
|
255
|
-
* back to HTTP POST for older sidecars.
|
|
256
|
-
*
|
|
257
261
|
* @param outcomeIds - Array of outcome IDs (or MarketOutcome objects)
|
|
258
262
|
* @param limit - Optional depth limit for each order book
|
|
259
263
|
* @param params - Optional exchange-specific parameters
|
|
@@ -713,6 +717,18 @@ export declare class GeminiTitan extends Exchange {
|
|
|
713
717
|
export declare class Hyperliquid extends Exchange {
|
|
714
718
|
constructor(options?: ExchangeOptions);
|
|
715
719
|
}
|
|
720
|
+
/**
|
|
721
|
+
* SuiBets exchange client.
|
|
722
|
+
*
|
|
723
|
+
* @example
|
|
724
|
+
* ```typescript
|
|
725
|
+
* const suibets = new SuiBets();
|
|
726
|
+
* const markets = await suibets.fetchMarkets();
|
|
727
|
+
* ```
|
|
728
|
+
*/
|
|
729
|
+
export declare class SuiBets extends Exchange {
|
|
730
|
+
constructor(options?: ExchangeOptions);
|
|
731
|
+
}
|
|
716
732
|
/**
|
|
717
733
|
* Mock exchange client.
|
|
718
734
|
*
|
package/dist/esm/pmxt/client.js
CHANGED
|
@@ -297,7 +297,7 @@ export class Exchange {
|
|
|
297
297
|
* Return the shared WebSocket client, creating it on first use.
|
|
298
298
|
*
|
|
299
299
|
* Returns `null` if the sidecar /ws endpoint was previously found
|
|
300
|
-
* to be unavailable
|
|
300
|
+
* to be unavailable.
|
|
301
301
|
*/
|
|
302
302
|
async getOrCreateWs() {
|
|
303
303
|
if (this._wsUnsupported)
|
|
@@ -345,13 +345,65 @@ export class Exchange {
|
|
|
345
345
|
return await ws.subscribe(this.exchangeName, method, args, this.getCredentials());
|
|
346
346
|
}
|
|
347
347
|
catch (error) {
|
|
348
|
-
|
|
349
|
-
if (error instanceof PmxtError && /connection failed|no websocket/i.test(error.message)) {
|
|
348
|
+
if (this.isWsTransportUnavailableError(error)) {
|
|
350
349
|
return null;
|
|
351
350
|
}
|
|
352
351
|
throw error;
|
|
353
352
|
}
|
|
354
353
|
}
|
|
354
|
+
wsTransportUnavailableError(method) {
|
|
355
|
+
return new PmxtError(`${method}() requires WebSocket transport — connection failed`);
|
|
356
|
+
}
|
|
357
|
+
isWsTransportUnavailableError(error) {
|
|
358
|
+
return error instanceof PmxtError
|
|
359
|
+
&& /connection failed|no websocket|websocket.*not connected/i.test(error.message);
|
|
360
|
+
}
|
|
361
|
+
getWsInternals(ws) {
|
|
362
|
+
return ws;
|
|
363
|
+
}
|
|
364
|
+
wsSubscriptionKey(method, args) {
|
|
365
|
+
const firstArg = args[0] ?? "";
|
|
366
|
+
return Array.isArray(firstArg)
|
|
367
|
+
? `${method}:${[...firstArg].sort().join(",")}`
|
|
368
|
+
: `${method}:${firstArg}`;
|
|
369
|
+
}
|
|
370
|
+
getWsSubscriptionId(ws, method, args) {
|
|
371
|
+
const internals = this.getWsInternals(ws);
|
|
372
|
+
const subKey = this.wsSubscriptionKey(method, args);
|
|
373
|
+
return internals.activeSubs.get(subKey);
|
|
374
|
+
}
|
|
375
|
+
clearWsSubscription(ws, method, args) {
|
|
376
|
+
const internals = this.getWsInternals(ws);
|
|
377
|
+
const subKey = this.wsSubscriptionKey(method, args);
|
|
378
|
+
const requestId = internals.activeSubs.get(subKey);
|
|
379
|
+
if (!requestId)
|
|
380
|
+
return;
|
|
381
|
+
const sub = internals.subscriptions.get(requestId);
|
|
382
|
+
if (sub?.reject) {
|
|
383
|
+
sub.reject(new PmxtError(`${method} subscription cancelled`));
|
|
384
|
+
}
|
|
385
|
+
internals.activeSubs.delete(subKey);
|
|
386
|
+
internals.subscriptions.delete(requestId);
|
|
387
|
+
internals.dataStore.delete(requestId);
|
|
388
|
+
const firstArg = args[0] ?? "";
|
|
389
|
+
const symbols = Array.isArray(firstArg)
|
|
390
|
+
? firstArg.map(String)
|
|
391
|
+
: firstArg
|
|
392
|
+
? [String(firstArg)]
|
|
393
|
+
: [];
|
|
394
|
+
for (const symbol of symbols) {
|
|
395
|
+
internals.dataStore.delete(`${requestId}:${symbol}`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
async sendWsMessage(ws, message) {
|
|
399
|
+
const internals = this.getWsInternals(ws);
|
|
400
|
+
await internals.ensureConnected();
|
|
401
|
+
const socket = internals.ws;
|
|
402
|
+
if (!socket) {
|
|
403
|
+
throw new PmxtError('[ws-client] Cannot send: WebSocket not connected');
|
|
404
|
+
}
|
|
405
|
+
socket.send(JSON.stringify(message));
|
|
406
|
+
}
|
|
355
407
|
// Low-Level API Access
|
|
356
408
|
/**
|
|
357
409
|
* Call an exchange-specific REST endpoint by its operationId.
|
|
@@ -1002,25 +1054,28 @@ export class Exchange {
|
|
|
1002
1054
|
}
|
|
1003
1055
|
async unwatchOrderBook(outcomeId) {
|
|
1004
1056
|
await this.initPromise;
|
|
1057
|
+
const resolvedOutcomeId = resolveOutcomeId(outcomeId);
|
|
1058
|
+
const args = [resolvedOutcomeId];
|
|
1005
1059
|
try {
|
|
1006
|
-
const
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1060
|
+
const ws = await this.getOrCreateWs();
|
|
1061
|
+
if (!ws) {
|
|
1062
|
+
throw this.wsTransportUnavailableError("unwatchOrderBook");
|
|
1063
|
+
}
|
|
1064
|
+
const requestId = this.getWsSubscriptionId(ws, "watchOrderBook", args)
|
|
1065
|
+
?? `req-${Math.random().toString(36).slice(2, 14)}`;
|
|
1066
|
+
await this.sendWsMessage(ws, {
|
|
1067
|
+
id: requestId,
|
|
1068
|
+
action: "unsubscribe",
|
|
1069
|
+
exchange: this.exchangeName,
|
|
1070
|
+
method: "unwatchOrderBook",
|
|
1071
|
+
args,
|
|
1012
1072
|
});
|
|
1013
|
-
|
|
1014
|
-
const body = await response.json().catch(() => ({}));
|
|
1015
|
-
if (body.error && typeof body.error === "object") {
|
|
1016
|
-
throw fromServerError(body.error);
|
|
1017
|
-
}
|
|
1018
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
1019
|
-
}
|
|
1020
|
-
const json = await response.json();
|
|
1021
|
-
this.handleResponse(json);
|
|
1073
|
+
this.clearWsSubscription(ws, "watchOrderBook", args);
|
|
1022
1074
|
}
|
|
1023
1075
|
catch (error) {
|
|
1076
|
+
if (this.isWsTransportUnavailableError(error)) {
|
|
1077
|
+
throw this.wsTransportUnavailableError("unwatchOrderBook");
|
|
1078
|
+
}
|
|
1024
1079
|
if (error instanceof PmxtError)
|
|
1025
1080
|
throw error;
|
|
1026
1081
|
throw new PmxtError(`Failed to unwatchOrderBook: ${error}`);
|
|
@@ -1433,34 +1488,11 @@ export class Exchange {
|
|
|
1433
1488
|
}
|
|
1434
1489
|
args.push(params);
|
|
1435
1490
|
}
|
|
1436
|
-
// Try WebSocket transport first
|
|
1437
1491
|
const wsData = await this.watchViaWs("watchOrderBook", args);
|
|
1438
1492
|
if (wsData !== null) {
|
|
1439
1493
|
return convertOrderBook(wsData);
|
|
1440
1494
|
}
|
|
1441
|
-
|
|
1442
|
-
try {
|
|
1443
|
-
const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/watchOrderBook`, {
|
|
1444
|
-
method: 'POST',
|
|
1445
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
1446
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
1447
|
-
});
|
|
1448
|
-
if (!response.ok) {
|
|
1449
|
-
const body = await response.json().catch(() => ({}));
|
|
1450
|
-
if (body.error && typeof body.error === "object") {
|
|
1451
|
-
throw fromServerError(body.error);
|
|
1452
|
-
}
|
|
1453
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
1454
|
-
}
|
|
1455
|
-
const json = await response.json();
|
|
1456
|
-
const data = this.handleResponse(json);
|
|
1457
|
-
return convertOrderBook(data);
|
|
1458
|
-
}
|
|
1459
|
-
catch (error) {
|
|
1460
|
-
if (error instanceof PmxtError)
|
|
1461
|
-
throw error;
|
|
1462
|
-
throw new PmxtError(`Failed to watch order book: ${error}`);
|
|
1463
|
-
}
|
|
1495
|
+
throw this.wsTransportUnavailableError("watchOrderBook");
|
|
1464
1496
|
}
|
|
1465
1497
|
/**
|
|
1466
1498
|
* Watch real-time order book updates for multiple outcomes at once.
|
|
@@ -1469,9 +1501,6 @@ export class Exchange {
|
|
|
1469
1501
|
* order book snapshot. Call repeatedly in a loop to stream updates
|
|
1470
1502
|
* (CCXT Pro pattern).
|
|
1471
1503
|
*
|
|
1472
|
-
* Prefers the sidecar WebSocket transport when available, falling
|
|
1473
|
-
* back to HTTP POST for older sidecars.
|
|
1474
|
-
*
|
|
1475
1504
|
* @param outcomeIds - Array of outcome IDs (or MarketOutcome objects)
|
|
1476
1505
|
* @param limit - Optional depth limit for each order book
|
|
1477
1506
|
* @param params - Optional exchange-specific parameters
|
|
@@ -1501,54 +1530,27 @@ export class Exchange {
|
|
|
1501
1530
|
}
|
|
1502
1531
|
args.push(params);
|
|
1503
1532
|
}
|
|
1504
|
-
// Try WebSocket transport first
|
|
1505
|
-
const ws = await this.getOrCreateWs();
|
|
1506
|
-
if (ws) {
|
|
1507
|
-
try {
|
|
1508
|
-
const rawResult = await ws.subscribeBatch(this.exchangeName, "watchOrderBooks", args, this.getCredentials());
|
|
1509
|
-
if (rawResult && typeof rawResult === "object") {
|
|
1510
|
-
const result = {};
|
|
1511
|
-
for (const [k, v] of Object.entries(rawResult)) {
|
|
1512
|
-
if (v && typeof v === "object") {
|
|
1513
|
-
result[k] = convertOrderBook(v);
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
return result;
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
catch (error) {
|
|
1520
|
-
// Only fall through to HTTP for transport-level WS failures
|
|
1521
|
-
if (!(error instanceof PmxtError) || !/connection failed|no websocket/i.test(error.message)) {
|
|
1522
|
-
throw error;
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
// HTTP fallback
|
|
1527
1533
|
try {
|
|
1528
|
-
const
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
1532
|
-
});
|
|
1533
|
-
if (!response.ok) {
|
|
1534
|
-
const body = await response.json().catch(() => ({}));
|
|
1535
|
-
if (body.error && typeof body.error === "object") {
|
|
1536
|
-
throw fromServerError(body.error);
|
|
1537
|
-
}
|
|
1538
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
1534
|
+
const ws = await this.getOrCreateWs();
|
|
1535
|
+
if (!ws) {
|
|
1536
|
+
throw this.wsTransportUnavailableError("watchOrderBooks");
|
|
1539
1537
|
}
|
|
1540
|
-
const
|
|
1541
|
-
|
|
1542
|
-
if (data && typeof data === "object") {
|
|
1538
|
+
const rawResult = await ws.subscribeBatch(this.exchangeName, "watchOrderBooks", args, this.getCredentials());
|
|
1539
|
+
if (rawResult && typeof rawResult === "object") {
|
|
1543
1540
|
const result = {};
|
|
1544
|
-
for (const [k, v] of Object.entries(
|
|
1545
|
-
|
|
1541
|
+
for (const [k, v] of Object.entries(rawResult)) {
|
|
1542
|
+
if (v && typeof v === "object") {
|
|
1543
|
+
result[k] = convertOrderBook(v);
|
|
1544
|
+
}
|
|
1546
1545
|
}
|
|
1547
1546
|
return result;
|
|
1548
1547
|
}
|
|
1549
1548
|
throw new PmxtError("watchOrderBooks: unexpected response shape from server");
|
|
1550
1549
|
}
|
|
1551
1550
|
catch (error) {
|
|
1551
|
+
if (this.isWsTransportUnavailableError(error)) {
|
|
1552
|
+
throw this.wsTransportUnavailableError("watchOrderBooks");
|
|
1553
|
+
}
|
|
1552
1554
|
if (error instanceof PmxtError)
|
|
1553
1555
|
throw error;
|
|
1554
1556
|
throw new PmxtError(`Failed to watch order books: ${error}`);
|
|
@@ -1587,7 +1589,7 @@ export class Exchange {
|
|
|
1587
1589
|
orderbook: convertOrderBook(wsData),
|
|
1588
1590
|
};
|
|
1589
1591
|
}
|
|
1590
|
-
throw
|
|
1592
|
+
throw this.wsTransportUnavailableError("watchAllOrderBooks");
|
|
1591
1593
|
}
|
|
1592
1594
|
/** @deprecated Use {@link watchAllOrderBooks} instead. */
|
|
1593
1595
|
async firehose(venues) {
|
|
@@ -1619,38 +1621,21 @@ export class Exchange {
|
|
|
1619
1621
|
async watchTrades(outcomeId, address, since, limit) {
|
|
1620
1622
|
await this.initPromise;
|
|
1621
1623
|
const resolvedOutcomeId = resolveOutcomeId(outcomeId);
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
args.push(address);
|
|
1626
|
-
}
|
|
1627
|
-
if (since !== undefined) {
|
|
1628
|
-
args.push(since);
|
|
1629
|
-
}
|
|
1630
|
-
if (limit !== undefined) {
|
|
1631
|
-
args.push(limit);
|
|
1632
|
-
}
|
|
1633
|
-
const response = await this.fetchWithRetry(`${this.resolveBaseUrl()}/api/${this.exchangeName}/watchTrades`, {
|
|
1634
|
-
method: 'POST',
|
|
1635
|
-
headers: { 'Content-Type': 'application/json', ...this.getAuthHeaders() },
|
|
1636
|
-
body: JSON.stringify({ args, credentials: this.getCredentials() }),
|
|
1637
|
-
});
|
|
1638
|
-
if (!response.ok) {
|
|
1639
|
-
const body = await response.json().catch(() => ({}));
|
|
1640
|
-
if (body.error && typeof body.error === "object") {
|
|
1641
|
-
throw fromServerError(body.error);
|
|
1642
|
-
}
|
|
1643
|
-
throw new PmxtError(body.error?.message || response.statusText);
|
|
1644
|
-
}
|
|
1645
|
-
const json = await response.json();
|
|
1646
|
-
const data = this.handleResponse(json);
|
|
1647
|
-
return data.map(convertTrade);
|
|
1624
|
+
const args = [resolvedOutcomeId];
|
|
1625
|
+
if (address !== undefined) {
|
|
1626
|
+
args.push(address);
|
|
1648
1627
|
}
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1628
|
+
if (since !== undefined) {
|
|
1629
|
+
args.push(since);
|
|
1630
|
+
}
|
|
1631
|
+
if (limit !== undefined) {
|
|
1632
|
+
args.push(limit);
|
|
1633
|
+
}
|
|
1634
|
+
const wsData = await this.watchViaWs("watchTrades", args);
|
|
1635
|
+
if (wsData !== null) {
|
|
1636
|
+
return wsData.map(convertTrade);
|
|
1653
1637
|
}
|
|
1638
|
+
throw this.wsTransportUnavailableError("watchTrades");
|
|
1654
1639
|
}
|
|
1655
1640
|
/**
|
|
1656
1641
|
* Watch real-time updates of a public wallet via WebSocket.
|
|
@@ -2516,6 +2501,20 @@ export class Hyperliquid extends Exchange {
|
|
|
2516
2501
|
super("hyperliquid", options);
|
|
2517
2502
|
}
|
|
2518
2503
|
}
|
|
2504
|
+
/**
|
|
2505
|
+
* SuiBets exchange client.
|
|
2506
|
+
*
|
|
2507
|
+
* @example
|
|
2508
|
+
* ```typescript
|
|
2509
|
+
* const suibets = new SuiBets();
|
|
2510
|
+
* const markets = await suibets.fetchMarkets();
|
|
2511
|
+
* ```
|
|
2512
|
+
*/
|
|
2513
|
+
export class SuiBets extends Exchange {
|
|
2514
|
+
constructor(options = {}) {
|
|
2515
|
+
super("suibets", options);
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2519
2518
|
/**
|
|
2520
2519
|
* Mock exchange client.
|
|
2521
2520
|
*
|
package/dist/esm/pmxt/router.js
CHANGED
|
@@ -159,11 +159,11 @@ export class Router extends Exchange {
|
|
|
159
159
|
const params = 'title' in marketOrParams ? { market: marketOrParams } : marketOrParams;
|
|
160
160
|
await this.initPromise;
|
|
161
161
|
const query = {};
|
|
162
|
-
const marketId = params.marketId ?? params.market?.marketId;
|
|
162
|
+
const marketId = params.marketId ?? (!params.market?.slug ? params.market?.marketId : undefined);
|
|
163
163
|
if (marketId)
|
|
164
164
|
query.marketId = marketId;
|
|
165
|
-
if (params.slug)
|
|
166
|
-
query.slug = params.slug;
|
|
165
|
+
if (params.slug ?? params.market?.slug)
|
|
166
|
+
query.slug = params.slug ?? params.market?.slug;
|
|
167
167
|
if (params.url)
|
|
168
168
|
query.url = params.url;
|
|
169
169
|
if (params.relation)
|
|
@@ -179,6 +179,9 @@ export class Router extends Exchange {
|
|
|
179
179
|
const data = this.handleResponse(json);
|
|
180
180
|
if (!data)
|
|
181
181
|
return [];
|
|
182
|
+
if (!Array.isArray(data)) {
|
|
183
|
+
throw new Error('fetchMarketMatches returned an unexpected response shape: expected an array');
|
|
184
|
+
}
|
|
182
185
|
return data.map(parseMatchResult);
|
|
183
186
|
}
|
|
184
187
|
catch (error) {
|
|
@@ -195,11 +198,11 @@ export class Router extends Exchange {
|
|
|
195
198
|
const params = 'title' in eventOrParams && 'markets' in eventOrParams ? { event: eventOrParams } : eventOrParams;
|
|
196
199
|
await this.initPromise;
|
|
197
200
|
const query = {};
|
|
198
|
-
const eventId = params.eventId ?? params.event?.id;
|
|
201
|
+
const eventId = params.eventId ?? (!params.event?.slug ? params.event?.id : undefined);
|
|
199
202
|
if (eventId)
|
|
200
203
|
query.eventId = eventId;
|
|
201
|
-
if (params.slug)
|
|
202
|
-
query.slug = params.slug;
|
|
204
|
+
if (params.slug ?? params.event?.slug)
|
|
205
|
+
query.slug = params.slug ?? params.event?.slug;
|
|
203
206
|
if (params.relation)
|
|
204
207
|
query.relation = params.relation;
|
|
205
208
|
if (params.minConfidence !== undefined)
|
|
@@ -213,6 +216,9 @@ export class Router extends Exchange {
|
|
|
213
216
|
const data = this.handleResponse(json);
|
|
214
217
|
if (!data)
|
|
215
218
|
return [];
|
|
219
|
+
if (!Array.isArray(data)) {
|
|
220
|
+
throw new Error('fetchEventMatches returned an unexpected response shape: expected an array');
|
|
221
|
+
}
|
|
216
222
|
return data.map((entry) => {
|
|
217
223
|
const event = convertEvent(entry.event || {});
|
|
218
224
|
return {
|
package/dist/index.d.ts
CHANGED
|
@@ -22,9 +22,10 @@ import { Router } from "./pmxt/router.js";
|
|
|
22
22
|
import { ServerManager } from "./pmxt/server-manager.js";
|
|
23
23
|
import * as models from "./pmxt/models.js";
|
|
24
24
|
import * as errors from "./pmxt/errors.js";
|
|
25
|
-
export { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi, Opinion, Metaculus, Smarkets, PolymarketUS, GeminiTitan, Hyperliquid, Mock, PolymarketOptions } from "./pmxt/client.js";
|
|
25
|
+
export { Exchange, Polymarket, Kalshi, KalshiDemo, Limitless, Myriad, Probable, Baozi, Opinion, Metaculus, Smarkets, PolymarketUS, GeminiTitan, Hyperliquid, SuiBets, Mock, PolymarketOptions } from "./pmxt/client.js";
|
|
26
26
|
export { Router } from "./pmxt/router.js";
|
|
27
27
|
export { ServerManager } from "./pmxt/server-manager.js";
|
|
28
|
+
export { HOSTED_URL, LOCAL_URL, ENV, resolvePmxtBaseUrl } from "./pmxt/constants.js";
|
|
28
29
|
export { MarketList } from "./pmxt/models.js";
|
|
29
30
|
export type * from "./pmxt/models.js";
|
|
30
31
|
export * from "./pmxt/errors.js";
|
package/dist/index.js
CHANGED
|
@@ -55,7 +55,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
55
55
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
56
56
|
};
|
|
57
57
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
-
exports.server = exports.MarketList = exports.ServerManager = exports.Router = exports.Mock = exports.Hyperliquid = exports.GeminiTitan = exports.PolymarketUS = exports.Smarkets = exports.Metaculus = exports.Opinion = exports.Baozi = exports.Probable = exports.Myriad = exports.Limitless = exports.KalshiDemo = exports.Kalshi = exports.Polymarket = exports.Exchange = void 0;
|
|
58
|
+
exports.server = exports.MarketList = exports.resolvePmxtBaseUrl = exports.ENV = exports.LOCAL_URL = exports.HOSTED_URL = exports.ServerManager = exports.Router = exports.Mock = exports.SuiBets = exports.Hyperliquid = exports.GeminiTitan = exports.PolymarketUS = exports.Smarkets = exports.Metaculus = exports.Opinion = exports.Baozi = exports.Probable = exports.Myriad = exports.Limitless = exports.KalshiDemo = exports.Kalshi = exports.Polymarket = exports.Exchange = void 0;
|
|
59
59
|
const client_js_1 = require("./pmxt/client.js");
|
|
60
60
|
const router_js_1 = require("./pmxt/router.js");
|
|
61
61
|
const server_manager_js_1 = require("./pmxt/server-manager.js");
|
|
@@ -76,11 +76,17 @@ Object.defineProperty(exports, "Smarkets", { enumerable: true, get: function ()
|
|
|
76
76
|
Object.defineProperty(exports, "PolymarketUS", { enumerable: true, get: function () { return client_js_2.PolymarketUS; } });
|
|
77
77
|
Object.defineProperty(exports, "GeminiTitan", { enumerable: true, get: function () { return client_js_2.GeminiTitan; } });
|
|
78
78
|
Object.defineProperty(exports, "Hyperliquid", { enumerable: true, get: function () { return client_js_2.Hyperliquid; } });
|
|
79
|
+
Object.defineProperty(exports, "SuiBets", { enumerable: true, get: function () { return client_js_2.SuiBets; } });
|
|
79
80
|
Object.defineProperty(exports, "Mock", { enumerable: true, get: function () { return client_js_2.Mock; } });
|
|
80
81
|
var router_js_2 = require("./pmxt/router.js");
|
|
81
82
|
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_js_2.Router; } });
|
|
82
83
|
var server_manager_js_2 = require("./pmxt/server-manager.js");
|
|
83
84
|
Object.defineProperty(exports, "ServerManager", { enumerable: true, get: function () { return server_manager_js_2.ServerManager; } });
|
|
85
|
+
var constants_js_1 = require("./pmxt/constants.js");
|
|
86
|
+
Object.defineProperty(exports, "HOSTED_URL", { enumerable: true, get: function () { return constants_js_1.HOSTED_URL; } });
|
|
87
|
+
Object.defineProperty(exports, "LOCAL_URL", { enumerable: true, get: function () { return constants_js_1.LOCAL_URL; } });
|
|
88
|
+
Object.defineProperty(exports, "ENV", { enumerable: true, get: function () { return constants_js_1.ENV; } });
|
|
89
|
+
Object.defineProperty(exports, "resolvePmxtBaseUrl", { enumerable: true, get: function () { return constants_js_1.resolvePmxtBaseUrl; } });
|
|
84
90
|
var models_js_1 = require("./pmxt/models.js");
|
|
85
91
|
Object.defineProperty(exports, "MarketList", { enumerable: true, get: function () { return models_js_1.MarketList; } });
|
|
86
92
|
__exportStar(require("./pmxt/errors.js"), exports);
|
package/dist/pmxt/client.d.ts
CHANGED
|
@@ -106,7 +106,7 @@ export declare abstract class Exchange {
|
|
|
106
106
|
* Return the shared WebSocket client, creating it on first use.
|
|
107
107
|
*
|
|
108
108
|
* Returns `null` if the sidecar /ws endpoint was previously found
|
|
109
|
-
* to be unavailable
|
|
109
|
+
* to be unavailable.
|
|
110
110
|
*/
|
|
111
111
|
private getOrCreateWs;
|
|
112
112
|
/**
|
|
@@ -114,6 +114,13 @@ export declare abstract class Exchange {
|
|
|
114
114
|
* Returns the raw data on success, or `null` if WS is unavailable.
|
|
115
115
|
*/
|
|
116
116
|
private watchViaWs;
|
|
117
|
+
private wsTransportUnavailableError;
|
|
118
|
+
private isWsTransportUnavailableError;
|
|
119
|
+
private getWsInternals;
|
|
120
|
+
private wsSubscriptionKey;
|
|
121
|
+
private getWsSubscriptionId;
|
|
122
|
+
private clearWsSubscription;
|
|
123
|
+
private sendWsMessage;
|
|
117
124
|
/**
|
|
118
125
|
* Call an exchange-specific REST endpoint by its operationId.
|
|
119
126
|
* This provides direct access to all implicit API methods defined in
|
|
@@ -251,9 +258,6 @@ export declare abstract class Exchange {
|
|
|
251
258
|
* order book snapshot. Call repeatedly in a loop to stream updates
|
|
252
259
|
* (CCXT Pro pattern).
|
|
253
260
|
*
|
|
254
|
-
* Prefers the sidecar WebSocket transport when available, falling
|
|
255
|
-
* back to HTTP POST for older sidecars.
|
|
256
|
-
*
|
|
257
261
|
* @param outcomeIds - Array of outcome IDs (or MarketOutcome objects)
|
|
258
262
|
* @param limit - Optional depth limit for each order book
|
|
259
263
|
* @param params - Optional exchange-specific parameters
|
|
@@ -713,6 +717,18 @@ export declare class GeminiTitan extends Exchange {
|
|
|
713
717
|
export declare class Hyperliquid extends Exchange {
|
|
714
718
|
constructor(options?: ExchangeOptions);
|
|
715
719
|
}
|
|
720
|
+
/**
|
|
721
|
+
* SuiBets exchange client.
|
|
722
|
+
*
|
|
723
|
+
* @example
|
|
724
|
+
* ```typescript
|
|
725
|
+
* const suibets = new SuiBets();
|
|
726
|
+
* const markets = await suibets.fetchMarkets();
|
|
727
|
+
* ```
|
|
728
|
+
*/
|
|
729
|
+
export declare class SuiBets extends Exchange {
|
|
730
|
+
constructor(options?: ExchangeOptions);
|
|
731
|
+
}
|
|
716
732
|
/**
|
|
717
733
|
* Mock exchange client.
|
|
718
734
|
*
|