pmxt-core 2.38.0 → 2.39.1
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 +14 -14
- package/dist/BaseExchange.js +19 -19
- package/dist/exchanges/baozi/index.d.ts +2 -2
- package/dist/exchanges/baozi/index.js +5 -5
- package/dist/exchanges/kalshi/api.d.ts +1 -1
- package/dist/exchanges/kalshi/api.js +1 -1
- package/dist/exchanges/kalshi/index.d.ts +6 -6
- package/dist/exchanges/kalshi/index.js +14 -14
- package/dist/exchanges/limitless/api.d.ts +1 -1
- package/dist/exchanges/limitless/api.js +1 -1
- package/dist/exchanges/limitless/index.d.ts +5 -5
- package/dist/exchanges/limitless/index.js +15 -12
- package/dist/exchanges/myriad/api.d.ts +1 -1
- package/dist/exchanges/myriad/api.js +1 -1
- package/dist/exchanges/myriad/index.d.ts +5 -5
- package/dist/exchanges/myriad/index.js +14 -14
- package/dist/exchanges/myriad/websocket.d.ts +2 -2
- package/dist/exchanges/myriad/websocket.js +12 -12
- package/dist/exchanges/opinion/api.d.ts +1 -1
- package/dist/exchanges/opinion/api.js +1 -1
- package/dist/exchanges/opinion/index.d.ts +4 -4
- package/dist/exchanges/opinion/index.js +9 -9
- 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/index.d.ts +8 -8
- package/dist/exchanges/polymarket/index.js +19 -19
- package/dist/exchanges/polymarket/websocket.d.ts +54 -3
- package/dist/exchanges/polymarket/websocket.js +146 -21
- package/dist/exchanges/polymarket_us/index.d.ts +3 -3
- package/dist/exchanges/polymarket_us/index.js +7 -7
- package/dist/exchanges/polymarket_us/websocket.d.ts +2 -2
- package/dist/exchanges/polymarket_us/websocket.js +6 -6
- package/dist/exchanges/probable/api.d.ts +1 -1
- package/dist/exchanges/probable/api.js +1 -1
- package/dist/exchanges/probable/index.d.ts +4 -4
- package/dist/exchanges/probable/index.js +9 -9
- package/dist/exchanges/smarkets/index.d.ts +2 -2
- package/dist/exchanges/smarkets/index.js +5 -5
- package/dist/router/Router.d.ts +1 -1
- package/dist/router/Router.js +3 -3
- package/dist/server/method-verbs.json +7 -7
- package/dist/server/openapi.yaml +3 -3
- package/package.json +3 -3
|
@@ -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-08T20:51:55.548Z
|
|
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-08T20:51:55.548Z
|
|
7
7
|
* Do not edit manually -- run "npm run fetch:openapi" to regenerate.
|
|
8
8
|
*/
|
|
9
9
|
exports.opinionApiSpec = {
|
|
@@ -21,8 +21,8 @@ export declare class OpinionExchange extends PredictionMarketExchange {
|
|
|
21
21
|
protected mapImplicitApiError(error: any): any;
|
|
22
22
|
protected fetchMarketsImpl(params?: MarketFilterParams): Promise<UnifiedMarket[]>;
|
|
23
23
|
protected fetchEventsImpl(params: EventFetchParams): Promise<UnifiedEvent[]>;
|
|
24
|
-
fetchOHLCV(
|
|
25
|
-
fetchOrderBook(
|
|
24
|
+
fetchOHLCV(outcomeId: string, params: OHLCVParams): Promise<PriceCandle[]>;
|
|
25
|
+
fetchOrderBook(outcomeId: string): Promise<OrderBook>;
|
|
26
26
|
fetchMyTrades(params?: MyTradesParams): Promise<UserTrade[]>;
|
|
27
27
|
fetchPositions(): Promise<Position[]>;
|
|
28
28
|
fetchOrder(orderId: string): Promise<Order>;
|
|
@@ -33,8 +33,8 @@ export declare class OpinionExchange extends PredictionMarketExchange {
|
|
|
33
33
|
submitOrder(built: BuiltOrder): Promise<Order>;
|
|
34
34
|
createOrder(params: CreateOrderParams): Promise<Order>;
|
|
35
35
|
cancelOrder(orderId: string): Promise<Order>;
|
|
36
|
-
watchOrderBook(
|
|
37
|
-
watchTrades(
|
|
36
|
+
watchOrderBook(outcomeId: string): Promise<OrderBook>;
|
|
37
|
+
watchTrades(outcomeId: string): Promise<Trade[]>;
|
|
38
38
|
close(): Promise<void>;
|
|
39
39
|
/**
|
|
40
40
|
* Resolve an ID (which may be a token/outcome ID or a numeric market ID string)
|
|
@@ -165,13 +165,13 @@ class OpinionExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
165
165
|
await this.enrichPrices(allMarkets);
|
|
166
166
|
return events;
|
|
167
167
|
}
|
|
168
|
-
async fetchOHLCV(
|
|
169
|
-
const rawPoints = await this.fetcher.fetchRawOHLCV(
|
|
168
|
+
async fetchOHLCV(outcomeId, params) {
|
|
169
|
+
const rawPoints = await this.fetcher.fetchRawOHLCV(outcomeId, params);
|
|
170
170
|
return this.normalizer.normalizeOHLCV({ history: rawPoints }, params);
|
|
171
171
|
}
|
|
172
|
-
async fetchOrderBook(
|
|
173
|
-
const raw = await this.fetcher.fetchRawOrderBook(
|
|
174
|
-
return this.normalizer.normalizeOrderBook(raw,
|
|
172
|
+
async fetchOrderBook(outcomeId) {
|
|
173
|
+
const raw = await this.fetcher.fetchRawOrderBook(outcomeId);
|
|
174
|
+
return this.normalizer.normalizeOrderBook(raw, outcomeId);
|
|
175
175
|
}
|
|
176
176
|
// -------------------------------------------------------------------------
|
|
177
177
|
// User Data (fetcher -> normalizer)
|
|
@@ -323,14 +323,14 @@ class OpinionExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
323
323
|
// -------------------------------------------------------------------------
|
|
324
324
|
// WebSocket
|
|
325
325
|
// -------------------------------------------------------------------------
|
|
326
|
-
async watchOrderBook(
|
|
326
|
+
async watchOrderBook(outcomeId) {
|
|
327
327
|
const ws = this.ensureWebSocket();
|
|
328
|
-
const marketId = this.resolveMarketId(
|
|
328
|
+
const marketId = this.resolveMarketId(outcomeId);
|
|
329
329
|
return ws.watchOrderBook(marketId);
|
|
330
330
|
}
|
|
331
|
-
async watchTrades(
|
|
331
|
+
async watchTrades(outcomeId) {
|
|
332
332
|
const ws = this.ensureWebSocket();
|
|
333
|
-
const marketId = this.resolveMarketId(
|
|
333
|
+
const marketId = this.resolveMarketId(outcomeId);
|
|
334
334
|
return ws.watchTrades(marketId);
|
|
335
335
|
}
|
|
336
336
|
async close() {
|
|
@@ -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-08T20:51:55.496Z
|
|
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-08T20:51:55.496Z
|
|
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-08T20:51:55.511Z
|
|
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-08T20:51:55.511Z
|
|
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-08T20:51:55.508Z
|
|
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-08T20:51:55.508Z
|
|
7
7
|
* Do not edit manually -- run "npm run fetch:openapi" to regenerate.
|
|
8
8
|
*/
|
|
9
9
|
exports.polymarketGammaSpec = {
|
|
@@ -3,8 +3,8 @@ import { SubscribedAddressSnapshot, SubscriptionOption } from '../../subscriber/
|
|
|
3
3
|
import { buildPolymarketTradesActivity, POLYMARKET_DEFAULT_SUBSCRIPTION } from '../../subscriber/external/goldsky';
|
|
4
4
|
import { WatcherConfig } from '../../subscriber/watcher';
|
|
5
5
|
import { Balance, BuiltOrder, CreateOrderParams, Order, OrderBook, Position, PriceCandle, Trade, UnifiedEvent, UnifiedMarket, UserTrade } from '../../types';
|
|
6
|
-
import { PolymarketWebSocketConfig } from './websocket';
|
|
7
|
-
export type { PolymarketWebSocketConfig, WatcherConfig };
|
|
6
|
+
import { PolymarketWebSocketConfig, UserChannelCallback, UserChannelEvent, PolymarketUserChannelCreds } from './websocket';
|
|
7
|
+
export type { PolymarketWebSocketConfig, WatcherConfig, UserChannelCallback, UserChannelEvent, PolymarketUserChannelCreds };
|
|
8
8
|
export { POLYMARKET_DEFAULT_SUBSCRIPTION, buildPolymarketTradesActivity };
|
|
9
9
|
export interface PolymarketExchangeOptions {
|
|
10
10
|
credentials?: ExchangeCredentials;
|
|
@@ -26,9 +26,9 @@ export declare class PolymarketExchange extends PredictionMarketExchange {
|
|
|
26
26
|
* a privateKey was provided (not apiKey/apiSecret/passphrase).
|
|
27
27
|
*/
|
|
28
28
|
initAuth(): Promise<void>;
|
|
29
|
-
fetchOHLCV(
|
|
30
|
-
fetchOrderBook(
|
|
31
|
-
fetchTrades(
|
|
29
|
+
fetchOHLCV(outcomeId: string, params: OHLCVParams): Promise<PriceCandle[]>;
|
|
30
|
+
fetchOrderBook(outcomeId: string): Promise<OrderBook>;
|
|
31
|
+
fetchTrades(outcomeId: string, params: TradesParams | HistoryFilterParams): Promise<Trade[]>;
|
|
32
32
|
/**
|
|
33
33
|
* Pre-warm the SDK's internal caches for a market outcome.
|
|
34
34
|
*
|
|
@@ -49,9 +49,9 @@ export declare class PolymarketExchange extends PredictionMarketExchange {
|
|
|
49
49
|
fetchMyTrades(params?: MyTradesParams): Promise<UserTrade[]>;
|
|
50
50
|
fetchPositions(address?: string): Promise<Position[]>;
|
|
51
51
|
fetchBalance(address?: string): Promise<Balance[]>;
|
|
52
|
-
watchOrderBook(
|
|
53
|
-
unwatchOrderBook(
|
|
54
|
-
watchTrades(
|
|
52
|
+
watchOrderBook(outcomeId: string, limit?: number): Promise<OrderBook>;
|
|
53
|
+
unwatchOrderBook(outcomeId: string): Promise<void>;
|
|
54
|
+
watchTrades(outcomeId: string, address?: string, since?: number, limit?: number): Promise<Trade[]>;
|
|
55
55
|
watchAddress(address: string, types?: SubscriptionOption[]): Promise<SubscribedAddressSnapshot>;
|
|
56
56
|
unwatchAddress(address: string): Promise<void>;
|
|
57
57
|
close(): Promise<void>;
|
|
@@ -101,29 +101,29 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
101
101
|
};
|
|
102
102
|
this.cachedAddress = auth.getFunderAddress();
|
|
103
103
|
}
|
|
104
|
-
async fetchOHLCV(
|
|
105
|
-
(0, validation_1.validateIdFormat)(
|
|
106
|
-
(0, validation_1.validateOutcomeId)(
|
|
104
|
+
async fetchOHLCV(outcomeId, params) {
|
|
105
|
+
(0, validation_1.validateIdFormat)(outcomeId, 'OHLCV');
|
|
106
|
+
(0, validation_1.validateOutcomeId)(outcomeId, 'OHLCV');
|
|
107
107
|
if (!params.resolution) {
|
|
108
108
|
throw new Error('fetchOHLCV requires a resolution parameter. Use OHLCVParams with resolution specified.');
|
|
109
109
|
}
|
|
110
|
-
const raw = await this.fetcher.fetchRawOHLCV(
|
|
110
|
+
const raw = await this.fetcher.fetchRawOHLCV(outcomeId, params);
|
|
111
111
|
return this.normalizer.normalizeOHLCV(raw, params);
|
|
112
112
|
}
|
|
113
|
-
async fetchOrderBook(
|
|
114
|
-
(0, validation_1.validateIdFormat)(
|
|
115
|
-
(0, validation_1.validateOutcomeId)(
|
|
116
|
-
const raw = await this.fetcher.fetchRawOrderBook(
|
|
117
|
-
return this.normalizer.normalizeOrderBook(raw,
|
|
113
|
+
async fetchOrderBook(outcomeId) {
|
|
114
|
+
(0, validation_1.validateIdFormat)(outcomeId, 'OrderBook');
|
|
115
|
+
(0, validation_1.validateOutcomeId)(outcomeId, 'OrderBook');
|
|
116
|
+
const raw = await this.fetcher.fetchRawOrderBook(outcomeId);
|
|
117
|
+
return this.normalizer.normalizeOrderBook(raw, outcomeId);
|
|
118
118
|
}
|
|
119
|
-
async fetchTrades(
|
|
120
|
-
(0, validation_1.validateIdFormat)(
|
|
121
|
-
(0, validation_1.validateOutcomeId)(
|
|
119
|
+
async fetchTrades(outcomeId, params) {
|
|
120
|
+
(0, validation_1.validateIdFormat)(outcomeId, 'Trades');
|
|
121
|
+
(0, validation_1.validateOutcomeId)(outcomeId, 'Trades');
|
|
122
122
|
if ('resolution' in params && params.resolution !== undefined) {
|
|
123
123
|
console.warn('[pmxt] Warning: The "resolution" parameter is deprecated for fetchTrades() and will be ignored. ' +
|
|
124
124
|
'It will be removed in v3.0.0. Please remove it from your code.');
|
|
125
125
|
}
|
|
126
|
-
const rawTrades = await this.fetcher.fetchRawTrades(
|
|
126
|
+
const rawTrades = await this.fetcher.fetchRawTrades(outcomeId, params);
|
|
127
127
|
const mappedTrades = rawTrades.map((raw, i) => this.normalizer.normalizeTrade(raw, i));
|
|
128
128
|
if (params.limit && mappedTrades.length > params.limit) {
|
|
129
129
|
return mappedTrades.slice(0, params.limit);
|
|
@@ -411,14 +411,14 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
411
411
|
// ----------------------------------------------------------------------------
|
|
412
412
|
// WebSocket Methods
|
|
413
413
|
// ----------------------------------------------------------------------------
|
|
414
|
-
async watchOrderBook(
|
|
415
|
-
return this.ensureWs().watchOrderBook(
|
|
414
|
+
async watchOrderBook(outcomeId, limit) {
|
|
415
|
+
return this.ensureWs().watchOrderBook(outcomeId);
|
|
416
416
|
}
|
|
417
|
-
async unwatchOrderBook(
|
|
418
|
-
return this.ensureWs().unwatchOrderBook(
|
|
417
|
+
async unwatchOrderBook(outcomeId) {
|
|
418
|
+
return this.ensureWs().unwatchOrderBook(outcomeId);
|
|
419
419
|
}
|
|
420
|
-
async watchTrades(
|
|
421
|
-
return this.ensureWs().watchTrades(
|
|
420
|
+
async watchTrades(outcomeId, address, since, limit) {
|
|
421
|
+
return this.ensureWs().watchTrades(outcomeId, address);
|
|
422
422
|
}
|
|
423
423
|
async watchAddress(address, types = ['trades', 'positions', 'balances']) {
|
|
424
424
|
return this.ensureWs().watchAddress(address, types);
|
|
@@ -8,6 +8,34 @@
|
|
|
8
8
|
import { SubscribedAddressSnapshot, SubscriptionOption } from '../../subscriber/base';
|
|
9
9
|
import { WatcherConfig } from '../../subscriber/watcher';
|
|
10
10
|
import { OrderBook, Trade } from '../../types';
|
|
11
|
+
export interface PolymarketUserChannelCreds {
|
|
12
|
+
apiKey: string;
|
|
13
|
+
secret: string;
|
|
14
|
+
passphrase: string;
|
|
15
|
+
}
|
|
16
|
+
export interface UserTradeEvent {
|
|
17
|
+
asset_id: string;
|
|
18
|
+
event_type: 'trade';
|
|
19
|
+
price: string;
|
|
20
|
+
size: string;
|
|
21
|
+
side: string;
|
|
22
|
+
status: string;
|
|
23
|
+
maker_orders?: any[];
|
|
24
|
+
timestamp?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface UserOrderEvent {
|
|
27
|
+
asset_id: string;
|
|
28
|
+
event_type: 'order';
|
|
29
|
+
order_id: string;
|
|
30
|
+
price: string;
|
|
31
|
+
original_size: string;
|
|
32
|
+
matched_size?: string;
|
|
33
|
+
side: string;
|
|
34
|
+
type: string;
|
|
35
|
+
timestamp?: string;
|
|
36
|
+
}
|
|
37
|
+
export type UserChannelEvent = UserTradeEvent | UserOrderEvent;
|
|
38
|
+
export type UserChannelCallback = (event: UserChannelEvent) => void;
|
|
11
39
|
export interface PolymarketWebSocketConfig {
|
|
12
40
|
/** Reconnection check interval in milliseconds (default: 5000) */
|
|
13
41
|
reconnectIntervalMs?: number;
|
|
@@ -17,6 +45,8 @@ export interface PolymarketWebSocketConfig {
|
|
|
17
45
|
watcherConfig?: WatcherConfig;
|
|
18
46
|
/** Timeout in ms for watch methods to receive data (default: 30000). 0 = no timeout. */
|
|
19
47
|
watchTimeoutMs?: number;
|
|
48
|
+
/** API credentials for the authenticated user channel (fills/orders). */
|
|
49
|
+
userChannelCreds?: PolymarketUserChannelCreds;
|
|
20
50
|
}
|
|
21
51
|
/**
|
|
22
52
|
* Wrapper around @nevuamarkets/poly-websockets that provides CCXT Pro-style
|
|
@@ -31,11 +61,32 @@ export declare class PolymarketWebSocket {
|
|
|
31
61
|
private config;
|
|
32
62
|
private initializationPromise?;
|
|
33
63
|
constructor(callApi: (operationId: string, params?: Record<string, any>) => Promise<any>, config?: PolymarketWebSocketConfig);
|
|
34
|
-
watchOrderBook(
|
|
35
|
-
unwatchOrderBook(
|
|
36
|
-
watchTrades(
|
|
64
|
+
watchOrderBook(outcomeId: string): Promise<OrderBook>;
|
|
65
|
+
unwatchOrderBook(outcomeId: string): Promise<void>;
|
|
66
|
+
watchTrades(outcomeId: string, address?: string): Promise<Trade[]>;
|
|
37
67
|
watchAddress(address: string, types: SubscriptionOption[]): Promise<SubscribedAddressSnapshot>;
|
|
38
68
|
unwatchAddress(address: string): Promise<void>;
|
|
69
|
+
private userWs;
|
|
70
|
+
private userCallbacks;
|
|
71
|
+
private userPingInterval;
|
|
72
|
+
private userReconnectTimer;
|
|
73
|
+
private userConditionIds;
|
|
74
|
+
/**
|
|
75
|
+
* Subscribe to authenticated fill/order events via Polymarket's user channel.
|
|
76
|
+
* Requires `userChannelCreds` in the config.
|
|
77
|
+
*
|
|
78
|
+
* @param conditionIds - Market condition IDs to monitor
|
|
79
|
+
* @param callback - Called for each trade or order event
|
|
80
|
+
*/
|
|
81
|
+
watchUserFills(conditionIds: string[], callback: UserChannelCallback): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Stop watching user fills and close the user channel WebSocket.
|
|
84
|
+
*/
|
|
85
|
+
unwatchUserFills(): Promise<void>;
|
|
86
|
+
private connectUserChannel;
|
|
87
|
+
private sendUserSubscription;
|
|
88
|
+
private scheduleUserReconnect;
|
|
89
|
+
private closeUserChannel;
|
|
39
90
|
close(): Promise<void>;
|
|
40
91
|
private ensureInitialized;
|
|
41
92
|
private handleBookSnapshot;
|
|
@@ -68,55 +68,55 @@ class PolymarketWebSocket {
|
|
|
68
68
|
buildActivity: goldsky_1.buildPolymarketActivity,
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
async watchOrderBook(
|
|
71
|
+
async watchOrderBook(outcomeId) {
|
|
72
72
|
await this.ensureInitialized();
|
|
73
73
|
// Subscribe to the asset if not already subscribed
|
|
74
74
|
const currentAssets = this.manager.getAssetIds();
|
|
75
|
-
if (!currentAssets.includes(
|
|
76
|
-
await this.manager.addSubscriptions([
|
|
75
|
+
if (!currentAssets.includes(outcomeId)) {
|
|
76
|
+
await this.manager.addSubscriptions([outcomeId]);
|
|
77
77
|
}
|
|
78
78
|
// Return a promise that resolves on the next orderbook update
|
|
79
79
|
const dataPromise = new Promise((resolve, reject) => {
|
|
80
|
-
if (!this.orderBookResolvers.has(
|
|
81
|
-
this.orderBookResolvers.set(
|
|
80
|
+
if (!this.orderBookResolvers.has(outcomeId)) {
|
|
81
|
+
this.orderBookResolvers.set(outcomeId, []);
|
|
82
82
|
}
|
|
83
|
-
this.orderBookResolvers.get(
|
|
83
|
+
this.orderBookResolvers.get(outcomeId).push({ resolve, reject });
|
|
84
84
|
});
|
|
85
|
-
return (0, watch_timeout_1.withWatchTimeout)(dataPromise, this.config.watchTimeoutMs ?? watch_timeout_1.DEFAULT_WATCH_TIMEOUT_MS, `watchOrderBook('${
|
|
85
|
+
return (0, watch_timeout_1.withWatchTimeout)(dataPromise, this.config.watchTimeoutMs ?? watch_timeout_1.DEFAULT_WATCH_TIMEOUT_MS, `watchOrderBook('${outcomeId}')`);
|
|
86
86
|
}
|
|
87
|
-
async unwatchOrderBook(
|
|
87
|
+
async unwatchOrderBook(outcomeId) {
|
|
88
88
|
if (!this.manager) {
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
|
-
await this.manager.removeSubscriptions([
|
|
91
|
+
await this.manager.removeSubscriptions([outcomeId]);
|
|
92
92
|
// Clear any pending resolvers for this asset
|
|
93
|
-
const resolvers = this.orderBookResolvers.get(
|
|
93
|
+
const resolvers = this.orderBookResolvers.get(outcomeId);
|
|
94
94
|
if (resolvers) {
|
|
95
|
-
this.orderBookResolvers = new Map([...this.orderBookResolvers].filter(([key]) => key !==
|
|
95
|
+
this.orderBookResolvers = new Map([...this.orderBookResolvers].filter(([key]) => key !== outcomeId));
|
|
96
96
|
}
|
|
97
97
|
// Remove the cached orderbook for this asset
|
|
98
|
-
if (this.orderBooks.has(
|
|
99
|
-
this.orderBooks = new Map([...this.orderBooks].filter(([key]) => key !==
|
|
98
|
+
if (this.orderBooks.has(outcomeId)) {
|
|
99
|
+
this.orderBooks = new Map([...this.orderBooks].filter(([key]) => key !== outcomeId));
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
async watchTrades(
|
|
102
|
+
async watchTrades(outcomeId, address) {
|
|
103
103
|
if (address) {
|
|
104
|
-
return this.watcher.watch(address, ['trades'],
|
|
104
|
+
return this.watcher.watch(address, ['trades'], outcomeId);
|
|
105
105
|
}
|
|
106
106
|
await this.ensureInitialized();
|
|
107
107
|
// Subscribe to the asset if not already subscribed
|
|
108
108
|
const currentAssets = this.manager.getAssetIds();
|
|
109
|
-
if (!currentAssets.includes(
|
|
110
|
-
await this.manager.addSubscriptions([
|
|
109
|
+
if (!currentAssets.includes(outcomeId)) {
|
|
110
|
+
await this.manager.addSubscriptions([outcomeId]);
|
|
111
111
|
}
|
|
112
112
|
// Return a promise that resolves on the next trade
|
|
113
113
|
const dataPromise = new Promise((resolve, reject) => {
|
|
114
|
-
if (!this.tradeResolvers.has(
|
|
115
|
-
this.tradeResolvers.set(
|
|
114
|
+
if (!this.tradeResolvers.has(outcomeId)) {
|
|
115
|
+
this.tradeResolvers.set(outcomeId, []);
|
|
116
116
|
}
|
|
117
|
-
this.tradeResolvers.get(
|
|
117
|
+
this.tradeResolvers.get(outcomeId).push({ resolve, reject });
|
|
118
118
|
});
|
|
119
|
-
return (0, watch_timeout_1.withWatchTimeout)(dataPromise, this.config.watchTimeoutMs ?? watch_timeout_1.DEFAULT_WATCH_TIMEOUT_MS, `watchTrades('${
|
|
119
|
+
return (0, watch_timeout_1.withWatchTimeout)(dataPromise, this.config.watchTimeoutMs ?? watch_timeout_1.DEFAULT_WATCH_TIMEOUT_MS, `watchTrades('${outcomeId}')`);
|
|
120
120
|
}
|
|
121
121
|
async watchAddress(address, types) {
|
|
122
122
|
return this.watcher.watch(address, types);
|
|
@@ -124,10 +124,135 @@ class PolymarketWebSocket {
|
|
|
124
124
|
async unwatchAddress(address) {
|
|
125
125
|
return this.watcher.unwatch(address);
|
|
126
126
|
}
|
|
127
|
+
// -----------------------------------------------------------------
|
|
128
|
+
// Authenticated User Channel (fills + order updates)
|
|
129
|
+
// -----------------------------------------------------------------
|
|
130
|
+
userWs = null;
|
|
131
|
+
userCallbacks = [];
|
|
132
|
+
userPingInterval = null;
|
|
133
|
+
userReconnectTimer = null;
|
|
134
|
+
userConditionIds = [];
|
|
135
|
+
/**
|
|
136
|
+
* Subscribe to authenticated fill/order events via Polymarket's user channel.
|
|
137
|
+
* Requires `userChannelCreds` in the config.
|
|
138
|
+
*
|
|
139
|
+
* @param conditionIds - Market condition IDs to monitor
|
|
140
|
+
* @param callback - Called for each trade or order event
|
|
141
|
+
*/
|
|
142
|
+
async watchUserFills(conditionIds, callback) {
|
|
143
|
+
const creds = this.config.userChannelCreds;
|
|
144
|
+
if (!creds) {
|
|
145
|
+
throw new Error('User channel requires API credentials. Pass userChannelCreds in PolymarketWebSocketConfig.');
|
|
146
|
+
}
|
|
147
|
+
this.userCallbacks.push(callback);
|
|
148
|
+
this.userConditionIds = [...new Set([...this.userConditionIds, ...conditionIds])];
|
|
149
|
+
if (this.userWs) {
|
|
150
|
+
// Already connected — just re-subscribe with updated condition IDs.
|
|
151
|
+
this.sendUserSubscription(creds);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
await this.connectUserChannel(creds);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Stop watching user fills and close the user channel WebSocket.
|
|
158
|
+
*/
|
|
159
|
+
async unwatchUserFills() {
|
|
160
|
+
this.userCallbacks = [];
|
|
161
|
+
this.userConditionIds = [];
|
|
162
|
+
this.closeUserChannel();
|
|
163
|
+
}
|
|
164
|
+
async connectUserChannel(creds) {
|
|
165
|
+
const WebSocket = (await Promise.resolve().then(() => __importStar(require('ws')))).default;
|
|
166
|
+
const url = 'wss://ws-subscriptions-clob.polymarket.com/ws/user';
|
|
167
|
+
this.userWs = new WebSocket(url);
|
|
168
|
+
this.userWs.on('open', () => {
|
|
169
|
+
console.log('[polymarket-ws] user channel connected');
|
|
170
|
+
this.sendUserSubscription(creds);
|
|
171
|
+
// Ping every 10 seconds to keep the connection alive.
|
|
172
|
+
if (this.userPingInterval)
|
|
173
|
+
clearInterval(this.userPingInterval);
|
|
174
|
+
this.userPingInterval = setInterval(() => {
|
|
175
|
+
if (this.userWs?.readyState === WebSocket.OPEN) {
|
|
176
|
+
this.userWs.ping();
|
|
177
|
+
}
|
|
178
|
+
}, 10_000);
|
|
179
|
+
});
|
|
180
|
+
this.userWs.on('message', (raw) => {
|
|
181
|
+
try {
|
|
182
|
+
const events = JSON.parse(raw.toString());
|
|
183
|
+
const arr = Array.isArray(events) ? events : [events];
|
|
184
|
+
for (const event of arr) {
|
|
185
|
+
for (const cb of this.userCallbacks) {
|
|
186
|
+
try {
|
|
187
|
+
cb(event);
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
console.error('[polymarket-ws] user callback error:', e);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
// Non-JSON control message (pong, etc.) — ignore.
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
this.userWs.on('close', () => {
|
|
200
|
+
console.warn('[polymarket-ws] user channel disconnected, reconnecting in 5s');
|
|
201
|
+
this.scheduleUserReconnect(creds);
|
|
202
|
+
});
|
|
203
|
+
this.userWs.on('error', (err) => {
|
|
204
|
+
console.error('[polymarket-ws] user channel error:', err.message);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
sendUserSubscription(creds) {
|
|
208
|
+
if (!this.userWs || this.userWs.readyState !== 1)
|
|
209
|
+
return;
|
|
210
|
+
const msg = JSON.stringify({
|
|
211
|
+
auth: {
|
|
212
|
+
apiKey: creds.apiKey,
|
|
213
|
+
secret: creds.secret,
|
|
214
|
+
passphrase: creds.passphrase,
|
|
215
|
+
},
|
|
216
|
+
markets: this.userConditionIds,
|
|
217
|
+
type: 'user',
|
|
218
|
+
});
|
|
219
|
+
this.userWs.send(msg);
|
|
220
|
+
}
|
|
221
|
+
scheduleUserReconnect(creds) {
|
|
222
|
+
if (this.userReconnectTimer)
|
|
223
|
+
return;
|
|
224
|
+
this.userReconnectTimer = setTimeout(async () => {
|
|
225
|
+
this.userReconnectTimer = null;
|
|
226
|
+
if (this.userCallbacks.length > 0) {
|
|
227
|
+
try {
|
|
228
|
+
await this.connectUserChannel(creds);
|
|
229
|
+
}
|
|
230
|
+
catch (e) {
|
|
231
|
+
console.error('[polymarket-ws] reconnect failed:', e.message);
|
|
232
|
+
this.scheduleUserReconnect(creds);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}, 5000);
|
|
236
|
+
}
|
|
237
|
+
closeUserChannel() {
|
|
238
|
+
if (this.userPingInterval) {
|
|
239
|
+
clearInterval(this.userPingInterval);
|
|
240
|
+
this.userPingInterval = null;
|
|
241
|
+
}
|
|
242
|
+
if (this.userReconnectTimer) {
|
|
243
|
+
clearTimeout(this.userReconnectTimer);
|
|
244
|
+
this.userReconnectTimer = null;
|
|
245
|
+
}
|
|
246
|
+
if (this.userWs) {
|
|
247
|
+
this.userWs.close();
|
|
248
|
+
this.userWs = null;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
127
251
|
async close() {
|
|
128
252
|
if (this.manager) {
|
|
129
253
|
await this.manager.clearState();
|
|
130
254
|
}
|
|
255
|
+
this.closeUserChannel();
|
|
131
256
|
this.watcher.close();
|
|
132
257
|
}
|
|
133
258
|
async ensureInitialized() {
|
|
@@ -46,7 +46,7 @@ export declare class PolymarketUSExchange extends PredictionMarketExchange {
|
|
|
46
46
|
private slugFromId;
|
|
47
47
|
protected fetchMarketsImpl(params?: MarketFetchParams): Promise<UnifiedMarket[]>;
|
|
48
48
|
protected fetchEventsImpl(params: EventFetchParams): Promise<UnifiedEvent[]>;
|
|
49
|
-
fetchOrderBook(
|
|
49
|
+
fetchOrderBook(outcomeId: string): Promise<OrderBook>;
|
|
50
50
|
fetchBalance(_address?: string): Promise<Balance[]>;
|
|
51
51
|
fetchPositions(_address?: string): Promise<Position[]>;
|
|
52
52
|
fetchMyTrades(params?: MyTradesParams): Promise<UserTrade[]>;
|
|
@@ -62,7 +62,7 @@ export declare class PolymarketUSExchange extends PredictionMarketExchange {
|
|
|
62
62
|
* method calls `requireAuth()` up front.
|
|
63
63
|
*/
|
|
64
64
|
private ensureWs;
|
|
65
|
-
watchOrderBook(
|
|
66
|
-
watchTrades(
|
|
65
|
+
watchOrderBook(outcomeId: string, _limit?: number): Promise<OrderBook>;
|
|
66
|
+
watchTrades(outcomeId: string, _address?: string, _since?: number, _limit?: number): Promise<Trade[]>;
|
|
67
67
|
close(): Promise<void>;
|
|
68
68
|
}
|
|
@@ -166,11 +166,11 @@ class PolymarketUSExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
166
166
|
return events;
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
|
-
async fetchOrderBook(
|
|
169
|
+
async fetchOrderBook(outcomeId) {
|
|
170
170
|
return this.run(async () => {
|
|
171
|
-
const slug = this.slugFromId(
|
|
171
|
+
const slug = this.slugFromId(outcomeId);
|
|
172
172
|
const book = await this.client.markets.book(slug);
|
|
173
|
-
return this.normalizer.normalizeOrderBook(book,
|
|
173
|
+
return this.normalizer.normalizeOrderBook(book, outcomeId);
|
|
174
174
|
});
|
|
175
175
|
}
|
|
176
176
|
// -------------------------------------------------------------------------
|
|
@@ -321,11 +321,11 @@ class PolymarketUSExchange extends BaseExchange_1.PredictionMarketExchange {
|
|
|
321
321
|
}
|
|
322
322
|
return this.wsWrapper;
|
|
323
323
|
}
|
|
324
|
-
async watchOrderBook(
|
|
325
|
-
return this.run(() => this.ensureWs().watchOrderBook(
|
|
324
|
+
async watchOrderBook(outcomeId, _limit) {
|
|
325
|
+
return this.run(() => this.ensureWs().watchOrderBook(outcomeId));
|
|
326
326
|
}
|
|
327
|
-
async watchTrades(
|
|
328
|
-
return this.run(() => this.ensureWs().watchTrades(
|
|
327
|
+
async watchTrades(outcomeId, _address, _since, _limit) {
|
|
328
|
+
return this.run(() => this.ensureWs().watchTrades(outcomeId));
|
|
329
329
|
}
|
|
330
330
|
// -------------------------------------------------------------------------
|
|
331
331
|
// Lifecycle
|
|
@@ -31,8 +31,8 @@ export declare class PolymarketUSWebSocket {
|
|
|
31
31
|
private readonly orderBookResolvers;
|
|
32
32
|
private readonly tradeResolvers;
|
|
33
33
|
constructor(client: PolymarketUSClient, normalizer: PolymarketUSNormalizer, config?: PolymarketUSWebSocketConfig);
|
|
34
|
-
watchOrderBook(
|
|
35
|
-
watchTrades(
|
|
34
|
+
watchOrderBook(outcomeId: string): Promise<OrderBook>;
|
|
35
|
+
watchTrades(outcomeId: string): Promise<Trade[]>;
|
|
36
36
|
close(): Promise<void>;
|
|
37
37
|
private ensureInitialized;
|
|
38
38
|
private handleMarketData;
|
|
@@ -57,8 +57,8 @@ class PolymarketUSWebSocket {
|
|
|
57
57
|
this.normalizer = normalizer;
|
|
58
58
|
this.config = config;
|
|
59
59
|
}
|
|
60
|
-
async watchOrderBook(
|
|
61
|
-
const slug = slugFromId(
|
|
60
|
+
async watchOrderBook(outcomeId) {
|
|
61
|
+
const slug = slugFromId(outcomeId);
|
|
62
62
|
await this.ensureInitialized();
|
|
63
63
|
if (!this.bookSubscriptions.has(slug)) {
|
|
64
64
|
this.bookSubscriptions.add(slug);
|
|
@@ -69,10 +69,10 @@ class PolymarketUSWebSocket {
|
|
|
69
69
|
queue.push({ resolve, reject });
|
|
70
70
|
this.orderBookResolvers.set(slug, queue);
|
|
71
71
|
});
|
|
72
|
-
return (0, watch_timeout_1.withWatchTimeout)(dataPromise, this.config.watchTimeoutMs ?? watch_timeout_1.DEFAULT_WATCH_TIMEOUT_MS, `watchOrderBook('${
|
|
72
|
+
return (0, watch_timeout_1.withWatchTimeout)(dataPromise, this.config.watchTimeoutMs ?? watch_timeout_1.DEFAULT_WATCH_TIMEOUT_MS, `watchOrderBook('${outcomeId}')`);
|
|
73
73
|
}
|
|
74
|
-
async watchTrades(
|
|
75
|
-
const slug = slugFromId(
|
|
74
|
+
async watchTrades(outcomeId) {
|
|
75
|
+
const slug = slugFromId(outcomeId);
|
|
76
76
|
await this.ensureInitialized();
|
|
77
77
|
if (!this.tradeSubscriptions.has(slug)) {
|
|
78
78
|
this.tradeSubscriptions.add(slug);
|
|
@@ -83,7 +83,7 @@ class PolymarketUSWebSocket {
|
|
|
83
83
|
queue.push({ resolve, reject });
|
|
84
84
|
this.tradeResolvers.set(slug, queue);
|
|
85
85
|
});
|
|
86
|
-
return (0, watch_timeout_1.withWatchTimeout)(dataPromise, this.config.watchTimeoutMs ?? watch_timeout_1.DEFAULT_WATCH_TIMEOUT_MS, `watchTrades('${
|
|
86
|
+
return (0, watch_timeout_1.withWatchTimeout)(dataPromise, this.config.watchTimeoutMs ?? watch_timeout_1.DEFAULT_WATCH_TIMEOUT_MS, `watchTrades('${outcomeId}')`);
|
|
87
87
|
}
|
|
88
88
|
async close() {
|
|
89
89
|
if (this.socket) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/probable/probable.yaml
|
|
3
|
-
* Generated at: 2026-05-
|
|
3
|
+
* Generated at: 2026-05-08T20:51:55.535Z
|
|
4
4
|
* Do not edit manually -- run "npm run fetch:openapi" to regenerate.
|
|
5
5
|
*/
|
|
6
6
|
export declare const probableApiSpec: {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.probableApiSpec = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Auto-generated from /home/runner/work/pmxt/pmxt/core/specs/probable/probable.yaml
|
|
6
|
-
* Generated at: 2026-05-
|
|
6
|
+
* Generated at: 2026-05-08T20:51:55.535Z
|
|
7
7
|
* Do not edit manually -- run "npm run fetch:openapi" to regenerate.
|
|
8
8
|
*/
|
|
9
9
|
exports.probableApiSpec = {
|