pmxt-core 2.20.0 → 2.20.2
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/baozi/fetcher.d.ts +40 -0
- package/dist/exchanges/baozi/fetcher.js +155 -0
- package/dist/exchanges/baozi/index.d.ts +2 -0
- package/dist/exchanges/baozi/index.js +60 -131
- package/dist/exchanges/baozi/normalizer.d.ts +14 -0
- package/dist/exchanges/baozi/normalizer.js +208 -0
- package/dist/exchanges/interfaces.d.ts +28 -0
- package/dist/exchanges/interfaces.js +2 -0
- package/dist/exchanges/kalshi/api.d.ts +1 -1
- package/dist/exchanges/kalshi/api.js +1 -1
- package/dist/exchanges/kalshi/fetcher.d.ts +126 -0
- package/dist/exchanges/kalshi/fetcher.js +313 -0
- package/dist/exchanges/kalshi/index.d.ts +6 -6
- package/dist/exchanges/kalshi/index.js +119 -202
- package/dist/exchanges/kalshi/normalizer.d.ts +25 -0
- package/dist/exchanges/kalshi/normalizer.js +294 -0
- package/dist/exchanges/limitless/api.d.ts +1 -1
- package/dist/exchanges/limitless/api.js +1 -1
- package/dist/exchanges/limitless/fetcher.d.ts +81 -0
- package/dist/exchanges/limitless/fetcher.js +238 -0
- package/dist/exchanges/limitless/index.d.ts +6 -9
- package/dist/exchanges/limitless/index.js +81 -79
- package/dist/exchanges/limitless/normalizer.d.ts +14 -0
- package/dist/exchanges/limitless/normalizer.js +117 -0
- package/dist/exchanges/limitless/websocket.d.ts +3 -0
- package/dist/exchanges/limitless/websocket.js +5 -4
- package/dist/exchanges/myriad/api.d.ts +1 -1
- package/dist/exchanges/myriad/api.js +1 -1
- package/dist/exchanges/myriad/fetcher.d.ts +73 -0
- package/dist/exchanges/myriad/fetcher.js +217 -0
- package/dist/exchanges/myriad/index.d.ts +2 -0
- package/dist/exchanges/myriad/index.js +40 -97
- package/dist/exchanges/myriad/normalizer.d.ts +14 -0
- package/dist/exchanges/myriad/normalizer.js +167 -0
- package/dist/exchanges/myriad/websocket.d.ts +3 -1
- package/dist/exchanges/myriad/websocket.js +4 -3
- 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/fetcher.d.ts +99 -0
- package/dist/exchanges/polymarket/fetcher.js +335 -0
- package/dist/exchanges/polymarket/index.d.ts +2 -0
- package/dist/exchanges/polymarket/index.js +80 -66
- package/dist/exchanges/polymarket/normalizer.d.ts +18 -0
- package/dist/exchanges/polymarket/normalizer.js +126 -0
- package/dist/exchanges/probable/api.d.ts +1 -1
- package/dist/exchanges/probable/api.js +1 -1
- package/dist/exchanges/probable/fetcher.d.ts +106 -0
- package/dist/exchanges/probable/fetcher.js +357 -0
- package/dist/exchanges/probable/index.d.ts +3 -1
- package/dist/exchanges/probable/index.js +73 -105
- package/dist/exchanges/probable/normalizer.d.ts +14 -0
- package/dist/exchanges/probable/normalizer.js +109 -0
- package/dist/utils/error-mapper.d.ts +8 -0
- package/dist/utils/error-mapper.js +58 -26
- package/package.json +3 -3
- package/dist/exchanges/baozi/fetchEvents.d.ts +0 -8
- package/dist/exchanges/baozi/fetchEvents.js +0 -39
- package/dist/exchanges/baozi/fetchMarkets.d.ts +0 -5
- package/dist/exchanges/baozi/fetchMarkets.js +0 -160
- package/dist/exchanges/baozi/fetchOHLCV.d.ts +0 -6
- package/dist/exchanges/baozi/fetchOHLCV.js +0 -10
- package/dist/exchanges/baozi/fetchOrderBook.d.ts +0 -12
- package/dist/exchanges/baozi/fetchOrderBook.js +0 -36
- package/dist/exchanges/baozi/fetchTrades.d.ts +0 -6
- package/dist/exchanges/baozi/fetchTrades.js +0 -10
- package/dist/exchanges/kalshi/fetchEvents.d.ts +0 -5
- package/dist/exchanges/kalshi/fetchEvents.js +0 -196
- package/dist/exchanges/kalshi/fetchMarkets.d.ts +0 -6
- package/dist/exchanges/kalshi/fetchMarkets.js +0 -247
- package/dist/exchanges/kalshi/fetchOHLCV.d.ts +0 -3
- package/dist/exchanges/kalshi/fetchOHLCV.js +0 -97
- package/dist/exchanges/kalshi/fetchOrderBook.d.ts +0 -2
- package/dist/exchanges/kalshi/fetchOrderBook.js +0 -60
- package/dist/exchanges/kalshi/fetchTrades.d.ts +0 -3
- package/dist/exchanges/kalshi/fetchTrades.js +0 -33
- package/dist/exchanges/limitless/fetchEvents.d.ts +0 -4
- package/dist/exchanges/limitless/fetchEvents.js +0 -173
- package/dist/exchanges/limitless/fetchMarkets.d.ts +0 -3
- package/dist/exchanges/limitless/fetchMarkets.js +0 -152
- package/dist/exchanges/limitless/fetchOHLCV.d.ts +0 -7
- package/dist/exchanges/limitless/fetchOHLCV.js +0 -49
- package/dist/exchanges/limitless/fetchOrderBook.d.ts +0 -6
- package/dist/exchanges/limitless/fetchOrderBook.js +0 -41
- package/dist/exchanges/limitless/fetchTrades.d.ts +0 -8
- package/dist/exchanges/limitless/fetchTrades.js +0 -27
- package/dist/exchanges/myriad/fetchEvents.d.ts +0 -4
- package/dist/exchanges/myriad/fetchEvents.js +0 -48
- package/dist/exchanges/myriad/fetchMarkets.d.ts +0 -4
- package/dist/exchanges/myriad/fetchMarkets.js +0 -102
- package/dist/exchanges/myriad/fetchOHLCV.d.ts +0 -3
- package/dist/exchanges/myriad/fetchOHLCV.js +0 -83
- package/dist/exchanges/myriad/fetchOrderBook.d.ts +0 -2
- package/dist/exchanges/myriad/fetchOrderBook.js +0 -39
- package/dist/exchanges/polymarket/fetchEvents.d.ts +0 -4
- package/dist/exchanges/polymarket/fetchEvents.js +0 -135
- package/dist/exchanges/polymarket/fetchMarkets.d.ts +0 -4
- package/dist/exchanges/polymarket/fetchMarkets.js +0 -214
- package/dist/exchanges/polymarket/fetchOHLCV.d.ts +0 -7
- package/dist/exchanges/polymarket/fetchOHLCV.js +0 -98
- package/dist/exchanges/polymarket/fetchOrderBook.d.ts +0 -6
- package/dist/exchanges/polymarket/fetchOrderBook.js +0 -33
- package/dist/exchanges/polymarket/fetchTrades.d.ts +0 -9
- package/dist/exchanges/polymarket/fetchTrades.js +0 -43
- package/dist/exchanges/probable/fetchEvents.d.ts +0 -6
- package/dist/exchanges/probable/fetchEvents.js +0 -151
- package/dist/exchanges/probable/fetchMarkets.d.ts +0 -4
- package/dist/exchanges/probable/fetchMarkets.js +0 -239
- package/dist/exchanges/probable/fetchTrades.d.ts +0 -10
- package/dist/exchanges/probable/fetchTrades.js +0 -40
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProbableNormalizer = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
function aggregateCandles(candles, intervalMs) {
|
|
6
|
+
if (candles.length === 0)
|
|
7
|
+
return [];
|
|
8
|
+
const buckets = new Map();
|
|
9
|
+
for (const c of candles) {
|
|
10
|
+
const key = Math.floor(c.timestamp / intervalMs) * intervalMs;
|
|
11
|
+
const existing = buckets.get(key);
|
|
12
|
+
if (!existing) {
|
|
13
|
+
buckets.set(key, { ...c, timestamp: key });
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
buckets.set(key, {
|
|
17
|
+
...existing,
|
|
18
|
+
high: Math.max(existing.high, c.high),
|
|
19
|
+
low: Math.min(existing.low, c.low),
|
|
20
|
+
close: c.close,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return Array.from(buckets.values()).sort((a, b) => a.timestamp - b.timestamp);
|
|
25
|
+
}
|
|
26
|
+
class ProbableNormalizer {
|
|
27
|
+
normalizeMarket(raw) {
|
|
28
|
+
// Delegate to the existing utils function for consistency
|
|
29
|
+
const event = raw._parentEvent || raw.event;
|
|
30
|
+
return (0, utils_1.mapMarketToUnified)(raw, event);
|
|
31
|
+
}
|
|
32
|
+
normalizeEvent(raw) {
|
|
33
|
+
return (0, utils_1.mapEventToUnified)(raw);
|
|
34
|
+
}
|
|
35
|
+
normalizeOrderBook(raw, _id) {
|
|
36
|
+
const bids = (raw.bids || [])
|
|
37
|
+
.map((level) => ({ price: parseFloat(level.price), size: parseFloat(level.size) }))
|
|
38
|
+
.sort((a, b) => b.price - a.price);
|
|
39
|
+
const asks = (raw.asks || [])
|
|
40
|
+
.map((level) => ({ price: parseFloat(level.price), size: parseFloat(level.size) }))
|
|
41
|
+
.sort((a, b) => a.price - b.price);
|
|
42
|
+
return {
|
|
43
|
+
bids,
|
|
44
|
+
asks,
|
|
45
|
+
timestamp: raw.timestamp ? new Date(String(raw.timestamp)).getTime() : Date.now(),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
normalizeOHLCV(rawPoints, params) {
|
|
49
|
+
let candles = rawPoints
|
|
50
|
+
.map((p) => {
|
|
51
|
+
const price = Number(p.p);
|
|
52
|
+
const ts = Number(p.t) * 1000;
|
|
53
|
+
return { timestamp: ts, open: price, high: price, low: price, close: price, volume: 0 };
|
|
54
|
+
})
|
|
55
|
+
.sort((a, b) => a.timestamp - b.timestamp);
|
|
56
|
+
if (params.resolution === '5m') {
|
|
57
|
+
candles = aggregateCandles(candles, 5 * 60 * 1000);
|
|
58
|
+
}
|
|
59
|
+
else if (params.resolution === '15m') {
|
|
60
|
+
candles = aggregateCandles(candles, 15 * 60 * 1000);
|
|
61
|
+
}
|
|
62
|
+
if (params.limit) {
|
|
63
|
+
candles = candles.slice(-params.limit);
|
|
64
|
+
}
|
|
65
|
+
return candles;
|
|
66
|
+
}
|
|
67
|
+
normalizeTrade(raw, index) {
|
|
68
|
+
return {
|
|
69
|
+
id: String(raw.id || raw.tradeId || `${raw.time}-${raw.price}`),
|
|
70
|
+
timestamp: typeof raw.time === 'number'
|
|
71
|
+
? (raw.time < 1e12 ? raw.time * 1000 : raw.time)
|
|
72
|
+
: Date.now(),
|
|
73
|
+
price: parseFloat(String(raw.price || '0')),
|
|
74
|
+
amount: parseFloat(String(raw.qty || raw.size || raw.amount || '0')),
|
|
75
|
+
side: raw.side === 'BUY' ? 'buy'
|
|
76
|
+
: raw.side === 'SELL' ? 'sell'
|
|
77
|
+
: 'unknown',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
normalizeUserTrade(raw, index) {
|
|
81
|
+
return {
|
|
82
|
+
id: String(raw.tradeId || raw.id || raw.timestamp),
|
|
83
|
+
timestamp: typeof raw.time === 'number'
|
|
84
|
+
? (raw.time > 1e12 ? raw.time : raw.time * 1000)
|
|
85
|
+
: Date.now(),
|
|
86
|
+
price: parseFloat(String(raw.price || '0')),
|
|
87
|
+
amount: parseFloat(String(raw.qty || raw.size || raw.amount || '0')),
|
|
88
|
+
side: (String(raw.side || '')).toLowerCase() === 'buy' ? 'buy' : 'sell',
|
|
89
|
+
orderId: raw.orderId,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
normalizePosition(raw) {
|
|
93
|
+
return {
|
|
94
|
+
marketId: String(raw.conditionId || raw.condition_id || ''),
|
|
95
|
+
outcomeId: String(raw.asset || raw.token_id || ''),
|
|
96
|
+
outcomeLabel: raw.outcome || raw.title || 'Unknown',
|
|
97
|
+
size: parseFloat(String(raw.size || '0')),
|
|
98
|
+
entryPrice: parseFloat(String(raw.avgPrice || raw.avg_price || '0')),
|
|
99
|
+
currentPrice: parseFloat(String(raw.curPrice || raw.cur_price || '0')),
|
|
100
|
+
unrealizedPnL: parseFloat(String(raw.cashPnl || raw.cash_pnl || '0')),
|
|
101
|
+
realizedPnL: parseFloat(String(raw.realizedPnl || raw.realized_pnl || '0')),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// -- Price enrichment helper (used by SDK class) --
|
|
105
|
+
async enrichMarketsWithPrices(markets, callMidpoint) {
|
|
106
|
+
await (0, utils_1.enrichMarketsWithPrices)(markets, callMidpoint);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.ProbableNormalizer = ProbableNormalizer;
|
|
@@ -17,6 +17,10 @@ export declare class ErrorMapper {
|
|
|
17
17
|
* Maps axios HTTP errors to appropriate error classes
|
|
18
18
|
*/
|
|
19
19
|
protected mapAxiosError(error: AxiosError): BaseError;
|
|
20
|
+
/**
|
|
21
|
+
* Maps an HTTP status code to the appropriate error class
|
|
22
|
+
*/
|
|
23
|
+
protected mapByStatusCode(status: number, message: string, data: any, response?: any): BaseError;
|
|
20
24
|
/**
|
|
21
25
|
* Maps 400 errors to specific bad request subtypes
|
|
22
26
|
*/
|
|
@@ -33,4 +37,8 @@ export declare class ErrorMapper {
|
|
|
33
37
|
* Extracts error message from various error formats
|
|
34
38
|
*/
|
|
35
39
|
protected extractErrorMessage(error: any): string;
|
|
40
|
+
/**
|
|
41
|
+
* Extracts a message string from a response data payload
|
|
42
|
+
*/
|
|
43
|
+
protected extractFromData(data: any): string | undefined;
|
|
36
44
|
}
|
|
@@ -35,36 +35,24 @@ class ErrorMapper {
|
|
|
35
35
|
// Handle plain objects with status/data (e.g., Polymarket clob-client)
|
|
36
36
|
if (error && typeof error === 'object' && !Array.isArray(error) && !(error instanceof Error)) {
|
|
37
37
|
if (error.status && typeof error.status === 'number') {
|
|
38
|
-
// Treat as axios-like error
|
|
39
38
|
const message = this.extractErrorMessage(error);
|
|
40
|
-
|
|
41
|
-
const data = error.data;
|
|
42
|
-
// Map by HTTP status code (same logic as mapAxiosError)
|
|
43
|
-
switch (status) {
|
|
44
|
-
case 400:
|
|
45
|
-
return this.mapBadRequestError(message, data);
|
|
46
|
-
case 401:
|
|
47
|
-
return new errors_1.AuthenticationError(message, this.exchangeName);
|
|
48
|
-
case 403:
|
|
49
|
-
return new errors_1.PermissionDenied(message, this.exchangeName);
|
|
50
|
-
case 404:
|
|
51
|
-
return this.mapNotFoundError(message, data);
|
|
52
|
-
case 429:
|
|
53
|
-
return this.mapRateLimitError(message, error);
|
|
54
|
-
case 500:
|
|
55
|
-
case 502:
|
|
56
|
-
case 503:
|
|
57
|
-
case 504:
|
|
58
|
-
return new errors_1.ExchangeNotAvailable(`Exchange error (${status}): ${message}`, this.exchangeName);
|
|
59
|
-
default:
|
|
60
|
-
return new errors_1.BadRequest(`HTTP ${status}: ${message}`, this.exchangeName);
|
|
61
|
-
}
|
|
39
|
+
return this.mapByStatusCode(error.status, message, error.data, error);
|
|
62
40
|
}
|
|
63
41
|
}
|
|
64
42
|
// Handle network errors
|
|
65
43
|
if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND' || error.code === 'ETIMEDOUT') {
|
|
66
44
|
return new errors_1.NetworkError(`Network error: ${error.message}`, this.exchangeName);
|
|
67
45
|
}
|
|
46
|
+
// Handle Error instances with attached HTTP metadata (common in third-party SDKs)
|
|
47
|
+
if (error instanceof Error) {
|
|
48
|
+
const err = error;
|
|
49
|
+
const status = err.status ?? err.statusCode ?? err.response?.status ?? err.response?.statusCode;
|
|
50
|
+
if (typeof status === 'number') {
|
|
51
|
+
const message = this.extractErrorMessage(error);
|
|
52
|
+
const data = err.data ?? err.response?.data ?? err.response?.body;
|
|
53
|
+
return this.mapByStatusCode(status, message, data, err.response);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
68
56
|
// Generic error fallback
|
|
69
57
|
const message = this.extractErrorMessage(error);
|
|
70
58
|
return new errors_1.BadRequest(message, this.exchangeName);
|
|
@@ -83,7 +71,12 @@ class ErrorMapper {
|
|
|
83
71
|
}
|
|
84
72
|
return new errors_1.ExchangeNotAvailable(`Exchange unreachable: ${message}`, this.exchangeName);
|
|
85
73
|
}
|
|
86
|
-
|
|
74
|
+
return this.mapByStatusCode(status, message, data, error.response);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Maps an HTTP status code to the appropriate error class
|
|
78
|
+
*/
|
|
79
|
+
mapByStatusCode(status, message, data, response) {
|
|
87
80
|
switch (status) {
|
|
88
81
|
case 400:
|
|
89
82
|
return this.mapBadRequestError(message, data);
|
|
@@ -94,7 +87,7 @@ class ErrorMapper {
|
|
|
94
87
|
case 404:
|
|
95
88
|
return this.mapNotFoundError(message, data);
|
|
96
89
|
case 429:
|
|
97
|
-
return this.mapRateLimitError(message,
|
|
90
|
+
return this.mapRateLimitError(message, response);
|
|
98
91
|
case 500:
|
|
99
92
|
case 502:
|
|
100
93
|
case 503:
|
|
@@ -223,8 +216,16 @@ class ErrorMapper {
|
|
|
223
216
|
return error.statusText;
|
|
224
217
|
}
|
|
225
218
|
}
|
|
226
|
-
// Standard Error object
|
|
219
|
+
// Standard Error object - check for attached response data from third-party SDKs
|
|
227
220
|
if (error instanceof Error) {
|
|
221
|
+
const err = error;
|
|
222
|
+
const data = err.response?.data ?? err.data ?? err.body;
|
|
223
|
+
if (data) {
|
|
224
|
+
const extracted = this.extractFromData(data);
|
|
225
|
+
if (extracted) {
|
|
226
|
+
return extracted;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
228
229
|
return error.message;
|
|
229
230
|
}
|
|
230
231
|
// String error
|
|
@@ -242,5 +243,36 @@ class ErrorMapper {
|
|
|
242
243
|
}
|
|
243
244
|
return String(error);
|
|
244
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Extracts a message string from a response data payload
|
|
248
|
+
*/
|
|
249
|
+
extractFromData(data) {
|
|
250
|
+
if (typeof data === 'string') {
|
|
251
|
+
return data;
|
|
252
|
+
}
|
|
253
|
+
if (data && typeof data === 'object') {
|
|
254
|
+
if (data.error) {
|
|
255
|
+
if (typeof data.error === 'string') {
|
|
256
|
+
return data.error;
|
|
257
|
+
}
|
|
258
|
+
if (data.error.message) {
|
|
259
|
+
return data.error.message;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (data.message) {
|
|
263
|
+
return data.message;
|
|
264
|
+
}
|
|
265
|
+
if (data.errorMsg) {
|
|
266
|
+
return data.errorMsg;
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
return JSON.stringify(data);
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
245
277
|
}
|
|
246
278
|
exports.ErrorMapper = ErrorMapper;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmxt-core",
|
|
3
|
-
"version": "2.20.
|
|
3
|
+
"version": "2.20.2",
|
|
4
4
|
"description": "pmxt is a unified prediction market data API. The ccxt for prediction markets.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"test": "jest -c jest.config.js",
|
|
30
30
|
"server": "tsx watch src/server/index.ts",
|
|
31
31
|
"server:prod": "node dist/server/index.js",
|
|
32
|
-
"generate:sdk:python": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g python -o ../sdks/python/generated --package-name pmxt_internal --additional-properties=projectName=pmxt-internal,packageVersion=2.20.
|
|
33
|
-
"generate:sdk:typescript": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g typescript-fetch -o ../sdks/typescript/generated --additional-properties=npmName=pmxtjs,npmVersion=2.20.
|
|
32
|
+
"generate:sdk:python": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g python -o ../sdks/python/generated --package-name pmxt_internal --additional-properties=projectName=pmxt-internal,packageVersion=2.20.2,library=urllib3",
|
|
33
|
+
"generate:sdk:typescript": "npx @openapitools/openapi-generator-cli generate -i src/server/openapi.yaml -g typescript-fetch -o ../sdks/typescript/generated --additional-properties=npmName=pmxtjs,npmVersion=2.20.2,supportsES6=true,typescriptThreePlus=true && node ../sdks/typescript/scripts/fix-generated.js",
|
|
34
34
|
"fetch:openapi": "node scripts/fetch-openapi-specs.js",
|
|
35
35
|
"extract:jsdoc": "node ../scripts/extract-jsdoc.js",
|
|
36
36
|
"generate:docs": "npm run extract:jsdoc && node ../scripts/generate-api-docs.js",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Connection } from '@solana/web3.js';
|
|
2
|
-
import { EventFetchParams } from '../../BaseExchange';
|
|
3
|
-
import { UnifiedEvent } from '../../types';
|
|
4
|
-
/**
|
|
5
|
-
* Baozi doesn't have Kalshi-style "events" (groups of related markets).
|
|
6
|
-
* Each market IS an event. Simple 1:1 mapping.
|
|
7
|
-
*/
|
|
8
|
-
export declare function fetchEvents(connection: Connection, params: EventFetchParams): Promise<UnifiedEvent[]>;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchEvents = fetchEvents;
|
|
4
|
-
const fetchMarkets_1 = require("./fetchMarkets");
|
|
5
|
-
const errors_1 = require("./errors");
|
|
6
|
-
/**
|
|
7
|
-
* Baozi doesn't have Kalshi-style "events" (groups of related markets).
|
|
8
|
-
* Each market IS an event. Simple 1:1 mapping.
|
|
9
|
-
*/
|
|
10
|
-
async function fetchEvents(connection, params) {
|
|
11
|
-
try {
|
|
12
|
-
const markets = await (0, fetchMarkets_1.fetchMarkets)(connection, {
|
|
13
|
-
query: params.query,
|
|
14
|
-
limit: params.limit,
|
|
15
|
-
offset: params.offset,
|
|
16
|
-
status: params.status,
|
|
17
|
-
searchIn: params.searchIn,
|
|
18
|
-
});
|
|
19
|
-
return markets.map(m => {
|
|
20
|
-
const unifiedEvent = {
|
|
21
|
-
id: m.marketId,
|
|
22
|
-
title: m.title,
|
|
23
|
-
description: m.description,
|
|
24
|
-
slug: m.marketId,
|
|
25
|
-
markets: [m],
|
|
26
|
-
volume24h: m.volume24h,
|
|
27
|
-
volume: m.volume,
|
|
28
|
-
url: m.url,
|
|
29
|
-
image: m.image,
|
|
30
|
-
category: m.category,
|
|
31
|
-
tags: m.tags,
|
|
32
|
-
};
|
|
33
|
-
return unifiedEvent;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
throw errors_1.baoziErrorMapper.mapError(error);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Connection } from '@solana/web3.js';
|
|
2
|
-
import { MarketFetchParams } from '../../BaseExchange';
|
|
3
|
-
import { UnifiedMarket } from '../../types';
|
|
4
|
-
export declare function fetchMarkets(connection: Connection, params?: MarketFetchParams): Promise<UnifiedMarket[]>;
|
|
5
|
-
export declare function fetchSingleMarket(connection: Connection, pubkey: string): Promise<UnifiedMarket | null>;
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.fetchMarkets = fetchMarkets;
|
|
37
|
-
exports.fetchSingleMarket = fetchSingleMarket;
|
|
38
|
-
const utils_1 = require("./utils");
|
|
39
|
-
const errors_1 = require("./errors");
|
|
40
|
-
const marketsCache = new utils_1.Cache(30_000); // 30s TTL
|
|
41
|
-
async function fetchMarkets(connection, params) {
|
|
42
|
-
try {
|
|
43
|
-
// Use cache for default (no-filter) fetches
|
|
44
|
-
if (!params?.query && !params?.slug) {
|
|
45
|
-
const cached = marketsCache.get();
|
|
46
|
-
if (cached) {
|
|
47
|
-
return applyFilters(cached, params);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// Fetch boolean and race markets in parallel
|
|
51
|
-
const [booleanAccounts, raceAccounts] = await Promise.all([
|
|
52
|
-
connection.getProgramAccounts(utils_1.PROGRAM_ID, {
|
|
53
|
-
filters: [{ memcmp: { offset: 0, bytes: utils_1.MARKET_DISCRIMINATOR_BS58 } }],
|
|
54
|
-
}),
|
|
55
|
-
connection.getProgramAccounts(utils_1.PROGRAM_ID, {
|
|
56
|
-
filters: [{ memcmp: { offset: 0, bytes: utils_1.RACE_MARKET_DISCRIMINATOR_BS58 } }],
|
|
57
|
-
}),
|
|
58
|
-
]);
|
|
59
|
-
const markets = [];
|
|
60
|
-
// Parse boolean markets
|
|
61
|
-
for (const account of booleanAccounts) {
|
|
62
|
-
try {
|
|
63
|
-
const parsed = (0, utils_1.parseMarket)(account.account.data);
|
|
64
|
-
markets.push((0, utils_1.mapBooleanToUnified)(parsed, account.pubkey.toString()));
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
// Skip malformed accounts
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// Parse race markets
|
|
71
|
-
for (const account of raceAccounts) {
|
|
72
|
-
try {
|
|
73
|
-
const parsed = (0, utils_1.parseRaceMarket)(account.account.data);
|
|
74
|
-
markets.push((0, utils_1.mapRaceToUnified)(parsed, account.pubkey.toString()));
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
// Skip malformed accounts
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// Cache results
|
|
81
|
-
marketsCache.set(markets);
|
|
82
|
-
return applyFilters(markets, params);
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
throw errors_1.baoziErrorMapper.mapError(error);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
async function fetchSingleMarket(connection, pubkey) {
|
|
89
|
-
try {
|
|
90
|
-
const { PublicKey } = await Promise.resolve().then(() => __importStar(require('@solana/web3.js')));
|
|
91
|
-
const pk = new PublicKey(pubkey);
|
|
92
|
-
const accountInfo = await connection.getAccountInfo(pk);
|
|
93
|
-
if (!accountInfo)
|
|
94
|
-
return null;
|
|
95
|
-
const data = accountInfo.data;
|
|
96
|
-
const discriminator = data.subarray(0, 8);
|
|
97
|
-
// Check if it's a boolean market
|
|
98
|
-
if (Buffer.from(discriminator).equals(Buffer.from([219, 190, 213, 55, 0, 227, 198, 154]))) {
|
|
99
|
-
const parsed = (0, utils_1.parseMarket)(data);
|
|
100
|
-
return (0, utils_1.mapBooleanToUnified)(parsed, pubkey);
|
|
101
|
-
}
|
|
102
|
-
// Check if it's a race market
|
|
103
|
-
if (Buffer.from(discriminator).equals(Buffer.from([235, 196, 111, 75, 230, 113, 118, 238]))) {
|
|
104
|
-
const parsed = (0, utils_1.parseRaceMarket)(data);
|
|
105
|
-
return (0, utils_1.mapRaceToUnified)(parsed, pubkey);
|
|
106
|
-
}
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
function applyFilters(markets, params) {
|
|
114
|
-
let result = [...markets];
|
|
115
|
-
// Status filter
|
|
116
|
-
const status = params?.status || 'active';
|
|
117
|
-
if (status !== 'all') {
|
|
118
|
-
const now = Date.now();
|
|
119
|
-
if (status === 'active') {
|
|
120
|
-
result = result.filter(m => m.resolutionDate.getTime() > now);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
// 'inactive' / 'closed'
|
|
124
|
-
result = result.filter(m => m.resolutionDate.getTime() <= now);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
// Text search
|
|
128
|
-
if (params?.query) {
|
|
129
|
-
const lowerQuery = params.query.toLowerCase();
|
|
130
|
-
const searchIn = params.searchIn || 'title';
|
|
131
|
-
result = result.filter(m => {
|
|
132
|
-
const titleMatch = m.title.toLowerCase().includes(lowerQuery);
|
|
133
|
-
const descMatch = (m.description || '').toLowerCase().includes(lowerQuery);
|
|
134
|
-
if (searchIn === 'title')
|
|
135
|
-
return titleMatch;
|
|
136
|
-
if (searchIn === 'description')
|
|
137
|
-
return descMatch;
|
|
138
|
-
return titleMatch || descMatch; // 'both'
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
// Sort
|
|
142
|
-
if (params?.sort === 'volume') {
|
|
143
|
-
result.sort((a, b) => (b.volume || 0) - (a.volume || 0));
|
|
144
|
-
}
|
|
145
|
-
else if (params?.sort === 'liquidity') {
|
|
146
|
-
result.sort((a, b) => b.liquidity - a.liquidity);
|
|
147
|
-
}
|
|
148
|
-
else if (params?.sort === 'newest') {
|
|
149
|
-
result.sort((a, b) => b.resolutionDate.getTime() - a.resolutionDate.getTime());
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
// Default: sort by volume
|
|
153
|
-
result.sort((a, b) => (b.volume || 0) - (a.volume || 0));
|
|
154
|
-
}
|
|
155
|
-
// Pagination
|
|
156
|
-
const offset = params?.offset || 0;
|
|
157
|
-
const limit = params?.limit || 10000;
|
|
158
|
-
result = result.slice(offset, offset + limit);
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchOHLCV = fetchOHLCV;
|
|
4
|
-
/**
|
|
5
|
-
* Baozi has no historical price/trade API without a custom indexer.
|
|
6
|
-
* Returns an empty array.
|
|
7
|
-
*/
|
|
8
|
-
async function fetchOHLCV() {
|
|
9
|
-
return [];
|
|
10
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Connection } from '@solana/web3.js';
|
|
2
|
-
import { OrderBook } from '../../types';
|
|
3
|
-
/**
|
|
4
|
-
* Pari-mutuel markets don't have a real order book.
|
|
5
|
-
* We synthesize one that represents the current pool state:
|
|
6
|
-
* - bid = ask = implied probability from pool ratios
|
|
7
|
-
* - size = total pool in SOL
|
|
8
|
-
*
|
|
9
|
-
* This honestly represents pari-mutuel: there's one "price"
|
|
10
|
-
* (the implied probability) and you can bet any amount into it.
|
|
11
|
-
*/
|
|
12
|
-
export declare function fetchOrderBook(connection: Connection, outcomeId: string): Promise<OrderBook>;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchOrderBook = fetchOrderBook;
|
|
4
|
-
const fetchMarkets_1 = require("./fetchMarkets");
|
|
5
|
-
const errors_1 = require("./errors");
|
|
6
|
-
/**
|
|
7
|
-
* Pari-mutuel markets don't have a real order book.
|
|
8
|
-
* We synthesize one that represents the current pool state:
|
|
9
|
-
* - bid = ask = implied probability from pool ratios
|
|
10
|
-
* - size = total pool in SOL
|
|
11
|
-
*
|
|
12
|
-
* This honestly represents pari-mutuel: there's one "price"
|
|
13
|
-
* (the implied probability) and you can bet any amount into it.
|
|
14
|
-
*/
|
|
15
|
-
async function fetchOrderBook(connection, outcomeId) {
|
|
16
|
-
try {
|
|
17
|
-
const marketPubkey = outcomeId.replace(/-YES$|-NO$|-\d+$/, '');
|
|
18
|
-
const market = await (0, fetchMarkets_1.fetchSingleMarket)(connection, marketPubkey);
|
|
19
|
-
if (!market) {
|
|
20
|
-
throw new Error(`Market not found: ${marketPubkey}`);
|
|
21
|
-
}
|
|
22
|
-
// Find the outcome matching the requested ID
|
|
23
|
-
const outcome = market.outcomes.find(o => o.outcomeId === outcomeId);
|
|
24
|
-
const price = outcome?.price ?? 0.5;
|
|
25
|
-
const totalLiquidity = market.liquidity;
|
|
26
|
-
// Single price level representing the entire pool
|
|
27
|
-
return {
|
|
28
|
-
bids: [{ price, size: totalLiquidity }],
|
|
29
|
-
asks: [{ price, size: totalLiquidity }],
|
|
30
|
-
timestamp: Date.now(),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
throw errors_1.baoziErrorMapper.mapError(error);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchTrades = fetchTrades;
|
|
4
|
-
/**
|
|
5
|
-
* Baozi has no trade history API without a custom indexer.
|
|
6
|
-
* Returns an empty array.
|
|
7
|
-
*/
|
|
8
|
-
async function fetchTrades() {
|
|
9
|
-
return [];
|
|
10
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { EventFetchParams } from "../../BaseExchange";
|
|
2
|
-
import { UnifiedEvent } from "../../types";
|
|
3
|
-
type CallApi = (operationId: string, params?: Record<string, any>) => Promise<any>;
|
|
4
|
-
export declare function fetchEvents(params: EventFetchParams, callApi: CallApi): Promise<UnifiedEvent[]>;
|
|
5
|
-
export {};
|