pmxt-core 2.23.0 → 2.25.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/limitless/api.d.ts +1 -1
- package/dist/exchanges/limitless/api.js +1 -1
- 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/auth.js +42 -8
- package/dist/exchanges/polymarket/index.js +56 -19
- package/dist/exchanges/polymarket_us/config.d.ts +18 -0
- package/dist/exchanges/polymarket_us/config.js +22 -0
- package/dist/exchanges/polymarket_us/errors.d.ts +19 -0
- package/dist/exchanges/polymarket_us/errors.js +123 -0
- package/dist/exchanges/polymarket_us/errors.test.d.ts +1 -0
- package/dist/exchanges/polymarket_us/errors.test.js +54 -0
- package/dist/exchanges/polymarket_us/index.d.ts +90 -0
- package/dist/exchanges/polymarket_us/index.js +366 -0
- package/dist/exchanges/polymarket_us/index.test.d.ts +8 -0
- package/dist/exchanges/polymarket_us/index.test.js +237 -0
- package/dist/exchanges/polymarket_us/normalizer.d.ts +55 -0
- package/dist/exchanges/polymarket_us/normalizer.js +385 -0
- package/dist/exchanges/polymarket_us/normalizer.test.d.ts +1 -0
- package/dist/exchanges/polymarket_us/normalizer.test.js +224 -0
- package/dist/exchanges/polymarket_us/price.d.ts +94 -0
- package/dist/exchanges/polymarket_us/price.js +149 -0
- package/dist/exchanges/polymarket_us/price.test.d.ts +1 -0
- package/dist/exchanges/polymarket_us/price.test.js +131 -0
- package/dist/exchanges/polymarket_us/websocket.d.ts +39 -0
- package/dist/exchanges/polymarket_us/websocket.js +181 -0
- package/dist/exchanges/polymarket_us/websocket.test.d.ts +8 -0
- package/dist/exchanges/polymarket_us/websocket.test.js +162 -0
- package/dist/exchanges/probable/api.d.ts +1 -1
- package/dist/exchanges/probable/api.js +1 -1
- package/dist/exchanges/smarkets/api.d.ts +8067 -0
- package/dist/exchanges/smarkets/api.js +10698 -0
- package/dist/exchanges/smarkets/auth.d.ts +56 -0
- package/dist/exchanges/smarkets/auth.js +105 -0
- package/dist/exchanges/smarkets/config.d.ts +41 -0
- package/dist/exchanges/smarkets/config.js +47 -0
- package/dist/exchanges/smarkets/errors.d.ts +31 -0
- package/dist/exchanges/smarkets/errors.js +186 -0
- package/dist/exchanges/smarkets/fetcher.d.ts +177 -0
- package/dist/exchanges/smarkets/fetcher.js +342 -0
- package/dist/exchanges/smarkets/index.d.ts +54 -0
- package/dist/exchanges/smarkets/index.js +285 -0
- package/dist/exchanges/smarkets/normalizer.d.ts +18 -0
- package/dist/exchanges/smarkets/normalizer.js +267 -0
- package/dist/exchanges/smarkets/price.d.ts +26 -0
- package/dist/exchanges/smarkets/price.js +44 -0
- package/dist/exchanges/smarkets/price.test.d.ts +1 -0
- package/dist/exchanges/smarkets/price.test.js +50 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -1
- package/dist/server/app.js +18 -2
- package/package.json +4 -3
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Unit tests for PolymarketUSWebSocket.
|
|
4
|
+
*
|
|
5
|
+
* The polymarket-us SDK is fully stubbed here so the tests run without
|
|
6
|
+
* touching the network. A fake MarketsWebSocket captures subscriptions
|
|
7
|
+
* and lets each test fire synthetic messages through a listener map.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const websocket_1 = require("./websocket");
|
|
11
|
+
const normalizer_1 = require("./normalizer");
|
|
12
|
+
class FakeMarketsWebSocket {
|
|
13
|
+
listeners = new Map();
|
|
14
|
+
connectCalls = 0;
|
|
15
|
+
closeCalls = 0;
|
|
16
|
+
subscribeMarketDataCalls = [];
|
|
17
|
+
subscribeTradesCalls = [];
|
|
18
|
+
on(event, listener) {
|
|
19
|
+
const arr = this.listeners.get(event) ?? [];
|
|
20
|
+
arr.push(listener);
|
|
21
|
+
this.listeners.set(event, arr);
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
async connect() {
|
|
25
|
+
this.connectCalls += 1;
|
|
26
|
+
}
|
|
27
|
+
close() {
|
|
28
|
+
this.closeCalls += 1;
|
|
29
|
+
}
|
|
30
|
+
subscribeMarketData(requestId, slugs) {
|
|
31
|
+
this.subscribeMarketDataCalls.push({ requestId, slugs });
|
|
32
|
+
}
|
|
33
|
+
subscribeTrades(requestId, slugs) {
|
|
34
|
+
this.subscribeTradesCalls.push({ requestId, slugs });
|
|
35
|
+
}
|
|
36
|
+
emit(event, arg) {
|
|
37
|
+
const arr = this.listeners.get(event) ?? [];
|
|
38
|
+
for (const listener of arr)
|
|
39
|
+
listener(arg);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function makeClient(fakeSocket) {
|
|
43
|
+
return {
|
|
44
|
+
ws: {
|
|
45
|
+
markets: () => fakeSocket,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
describe('PolymarketUSWebSocket', () => {
|
|
50
|
+
let fake;
|
|
51
|
+
let ws;
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
fake = new FakeMarketsWebSocket();
|
|
54
|
+
ws = new websocket_1.PolymarketUSWebSocket(makeClient(fake), new normalizer_1.PolymarketUSNormalizer());
|
|
55
|
+
});
|
|
56
|
+
describe('watchOrderBook', () => {
|
|
57
|
+
it('connects lazily, subscribes once per slug, and resolves on marketData', async () => {
|
|
58
|
+
const pending = ws.watchOrderBook('btc-100k');
|
|
59
|
+
// Let the ensureInitialized microtask run so connect resolves
|
|
60
|
+
await new Promise(r => setImmediate(r));
|
|
61
|
+
expect(fake.connectCalls).toBe(1);
|
|
62
|
+
expect(fake.subscribeMarketDataCalls).toEqual([
|
|
63
|
+
{ requestId: 'book:btc-100k', slugs: ['btc-100k'] },
|
|
64
|
+
]);
|
|
65
|
+
fake.emit('marketData', {
|
|
66
|
+
requestId: 'book:btc-100k',
|
|
67
|
+
subscriptionType: 'SUBSCRIPTION_TYPE_MARKET_DATA',
|
|
68
|
+
marketData: {
|
|
69
|
+
marketSlug: 'btc-100k',
|
|
70
|
+
bids: [{ px: { value: '0.55', currency: 'USD' }, qty: '10' }],
|
|
71
|
+
offers: [{ px: { value: '0.57', currency: 'USD' }, qty: '5' }],
|
|
72
|
+
state: 'MARKET_STATE_OPEN',
|
|
73
|
+
transactTime: '2026-04-06T00:00:00Z',
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const book = await pending;
|
|
77
|
+
expect(book.bids).toEqual([{ price: 0.55, size: 10 }]);
|
|
78
|
+
expect(book.asks).toEqual([{ price: 0.57, size: 5 }]);
|
|
79
|
+
});
|
|
80
|
+
it('strips :long suffix before subscribing', async () => {
|
|
81
|
+
const pending = ws.watchOrderBook('btc-100k:long');
|
|
82
|
+
await new Promise(r => setImmediate(r));
|
|
83
|
+
expect(fake.subscribeMarketDataCalls).toEqual([
|
|
84
|
+
{ requestId: 'book:btc-100k', slugs: ['btc-100k'] },
|
|
85
|
+
]);
|
|
86
|
+
fake.emit('marketData', {
|
|
87
|
+
marketData: {
|
|
88
|
+
marketSlug: 'btc-100k',
|
|
89
|
+
bids: [],
|
|
90
|
+
offers: [],
|
|
91
|
+
state: 'MARKET_STATE_OPEN',
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
await pending;
|
|
95
|
+
});
|
|
96
|
+
it('does not re-subscribe when called twice for the same slug', async () => {
|
|
97
|
+
const p1 = ws.watchOrderBook('btc-100k');
|
|
98
|
+
await new Promise(r => setImmediate(r));
|
|
99
|
+
const p2 = ws.watchOrderBook('btc-100k');
|
|
100
|
+
await new Promise(r => setImmediate(r));
|
|
101
|
+
expect(fake.subscribeMarketDataCalls).toHaveLength(1);
|
|
102
|
+
fake.emit('marketData', {
|
|
103
|
+
marketData: {
|
|
104
|
+
marketSlug: 'btc-100k',
|
|
105
|
+
bids: [],
|
|
106
|
+
offers: [],
|
|
107
|
+
state: 'MARKET_STATE_OPEN',
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
const [b1, b2] = await Promise.all([p1, p2]);
|
|
111
|
+
expect(b1.bids).toEqual([]);
|
|
112
|
+
expect(b2.bids).toEqual([]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe('watchTrades', () => {
|
|
116
|
+
it('resolves with a PMXT Trade on the next trade message', async () => {
|
|
117
|
+
const pending = ws.watchTrades('btc-100k');
|
|
118
|
+
await new Promise(r => setImmediate(r));
|
|
119
|
+
expect(fake.subscribeTradesCalls).toEqual([
|
|
120
|
+
{ requestId: 'trade:btc-100k', slugs: ['btc-100k'] },
|
|
121
|
+
]);
|
|
122
|
+
fake.emit('trade', {
|
|
123
|
+
requestId: 'trade:btc-100k',
|
|
124
|
+
subscriptionType: 'SUBSCRIPTION_TYPE_TRADE',
|
|
125
|
+
trade: {
|
|
126
|
+
marketSlug: 'btc-100k',
|
|
127
|
+
price: { value: '0.55', currency: 'USD' },
|
|
128
|
+
quantity: { value: '10', currency: 'USD' },
|
|
129
|
+
tradeTime: '2026-04-06T00:00:00Z',
|
|
130
|
+
maker: { side: 'ORDER_SIDE_SELL', intent: 'ORDER_INTENT_SELL_LONG' },
|
|
131
|
+
taker: { side: 'ORDER_SIDE_BUY', intent: 'ORDER_INTENT_BUY_LONG' },
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
const trades = await pending;
|
|
135
|
+
expect(trades).toHaveLength(1);
|
|
136
|
+
expect(trades[0].price).toBeCloseTo(0.55);
|
|
137
|
+
expect(trades[0].amount).toBeCloseTo(10);
|
|
138
|
+
expect(trades[0].side).toBe('buy');
|
|
139
|
+
expect(trades[0].timestamp).toBe(new Date('2026-04-06T00:00:00Z').getTime());
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
describe('close', () => {
|
|
143
|
+
it('rejects pending watchers and closes the socket', async () => {
|
|
144
|
+
const pending = ws.watchOrderBook('btc-100k');
|
|
145
|
+
await new Promise(r => setImmediate(r));
|
|
146
|
+
const pendingTrade = ws.watchTrades('btc-100k');
|
|
147
|
+
await new Promise(r => setImmediate(r));
|
|
148
|
+
await ws.close();
|
|
149
|
+
await expect(pending).rejects.toThrow('PolymarketUS WebSocket closed');
|
|
150
|
+
await expect(pendingTrade).rejects.toThrow('PolymarketUS WebSocket closed');
|
|
151
|
+
expect(fake.closeCalls).toBe(1);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
describe('error handling', () => {
|
|
155
|
+
it('rejects pending watchers when the socket emits an error', async () => {
|
|
156
|
+
const pending = ws.watchOrderBook('btc-100k');
|
|
157
|
+
await new Promise(r => setImmediate(r));
|
|
158
|
+
fake.emit('error', new Error('boom'));
|
|
159
|
+
await expect(pending).rejects.toThrow('boom');
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
@@ -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-04-
|
|
3
|
+
* Generated at: 2026-04-06T19:59:33.366Z
|
|
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-04-
|
|
6
|
+
* Generated at: 2026-04-06T19:59:33.366Z
|
|
7
7
|
* Do not edit manually -- run "npm run fetch:openapi" to regenerate.
|
|
8
8
|
*/
|
|
9
9
|
exports.probableApiSpec = {
|