pmxt-core 2.5.0 → 2.7.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.
Files changed (69) hide show
  1. package/dist/BaseExchange.d.ts +20 -0
  2. package/dist/BaseExchange.js +52 -0
  3. package/dist/exchanges/baozi/index.d.ts +15 -0
  4. package/dist/exchanges/baozi/index.js +15 -0
  5. package/dist/exchanges/kalshi/fetchEvents.d.ts +2 -1
  6. package/dist/exchanges/kalshi/fetchEvents.js +6 -6
  7. package/dist/exchanges/kalshi/fetchMarkets.d.ts +2 -1
  8. package/dist/exchanges/kalshi/fetchMarkets.js +19 -21
  9. package/dist/exchanges/kalshi/fetchOHLCV.d.ts +2 -1
  10. package/dist/exchanges/kalshi/fetchOHLCV.js +2 -2
  11. package/dist/exchanges/kalshi/fetchOrderBook.d.ts +2 -1
  12. package/dist/exchanges/kalshi/fetchOrderBook.js +2 -2
  13. package/dist/exchanges/kalshi/fetchTrades.d.ts +2 -1
  14. package/dist/exchanges/kalshi/fetchTrades.js +2 -2
  15. package/dist/exchanges/kalshi/index.d.ts +15 -0
  16. package/dist/exchanges/kalshi/index.js +26 -15
  17. package/dist/exchanges/kalshi/kalshi.test.js +47 -18
  18. package/dist/exchanges/limitless/fetchEvents.d.ts +2 -1
  19. package/dist/exchanges/limitless/fetchEvents.js +6 -4
  20. package/dist/exchanges/limitless/fetchMarkets.d.ts +2 -1
  21. package/dist/exchanges/limitless/fetchMarkets.js +4 -4
  22. package/dist/exchanges/limitless/fetchOHLCV.d.ts +2 -1
  23. package/dist/exchanges/limitless/fetchOHLCV.js +2 -2
  24. package/dist/exchanges/limitless/fetchOrderBook.d.ts +2 -1
  25. package/dist/exchanges/limitless/fetchOrderBook.js +2 -2
  26. package/dist/exchanges/limitless/fetchTrades.d.ts +2 -1
  27. package/dist/exchanges/limitless/fetchTrades.js +5 -1
  28. package/dist/exchanges/limitless/index.d.ts +15 -0
  29. package/dist/exchanges/limitless/index.js +20 -5
  30. package/dist/exchanges/myriad/fetchEvents.d.ts +2 -1
  31. package/dist/exchanges/myriad/fetchEvents.js +6 -6
  32. package/dist/exchanges/myriad/fetchMarkets.d.ts +2 -1
  33. package/dist/exchanges/myriad/fetchMarkets.js +10 -10
  34. package/dist/exchanges/myriad/fetchOHLCV.d.ts +2 -1
  35. package/dist/exchanges/myriad/fetchOHLCV.js +2 -2
  36. package/dist/exchanges/myriad/fetchOrderBook.d.ts +2 -1
  37. package/dist/exchanges/myriad/fetchOrderBook.js +2 -2
  38. package/dist/exchanges/myriad/fetchTrades.d.ts +2 -1
  39. package/dist/exchanges/myriad/fetchTrades.js +2 -2
  40. package/dist/exchanges/myriad/index.d.ts +15 -0
  41. package/dist/exchanges/myriad/index.js +23 -12
  42. package/dist/exchanges/polymarket/fetchEvents.d.ts +2 -1
  43. package/dist/exchanges/polymarket/fetchEvents.js +8 -8
  44. package/dist/exchanges/polymarket/fetchMarkets.d.ts +2 -1
  45. package/dist/exchanges/polymarket/fetchMarkets.js +17 -17
  46. package/dist/exchanges/polymarket/fetchOHLCV.d.ts +2 -1
  47. package/dist/exchanges/polymarket/fetchOHLCV.js +2 -2
  48. package/dist/exchanges/polymarket/fetchOrderBook.d.ts +2 -1
  49. package/dist/exchanges/polymarket/fetchOrderBook.js +2 -2
  50. package/dist/exchanges/polymarket/fetchTrades.d.ts +2 -1
  51. package/dist/exchanges/polymarket/fetchTrades.js +2 -2
  52. package/dist/exchanges/polymarket/index.d.ts +15 -0
  53. package/dist/exchanges/polymarket/index.js +20 -5
  54. package/dist/exchanges/polymarket/utils.d.ts +2 -2
  55. package/dist/exchanges/polymarket/utils.js +7 -42
  56. package/dist/exchanges/probable/fetchEvents.d.ts +4 -3
  57. package/dist/exchanges/probable/fetchEvents.js +13 -13
  58. package/dist/exchanges/probable/fetchMarkets.d.ts +2 -1
  59. package/dist/exchanges/probable/fetchMarkets.js +16 -16
  60. package/dist/exchanges/probable/fetchOHLCV.d.ts +2 -1
  61. package/dist/exchanges/probable/fetchOHLCV.js +2 -2
  62. package/dist/exchanges/probable/fetchOrderBook.d.ts +2 -1
  63. package/dist/exchanges/probable/fetchOrderBook.js +2 -2
  64. package/dist/exchanges/probable/fetchTrades.d.ts +2 -2
  65. package/dist/exchanges/probable/fetchTrades.js +5 -1
  66. package/dist/exchanges/probable/index.d.ts +15 -0
  67. package/dist/exchanges/probable/index.js +22 -7
  68. package/dist/server/app.js +23 -0
  69. package/package.json +4 -4
@@ -7,37 +7,37 @@ exports.fetchMarkets = fetchMarkets;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const utils_1 = require("./utils");
9
9
  const errors_1 = require("./errors");
10
- async function fetchMarkets(params) {
10
+ async function fetchMarkets(params, http = axios_1.default) {
11
11
  try {
12
12
  // Handle marketId lookup (numeric ID or slug)
13
13
  if (params?.marketId) {
14
- return await fetchMarketByIdOrSlug(params.marketId);
14
+ return await fetchMarketByIdOrSlug(params.marketId, http);
15
15
  }
16
16
  // Slug-based lookup: try market ID or slug via dedicated endpoint
17
17
  if (params?.slug) {
18
- return await fetchMarketByIdOrSlug(params.slug);
18
+ return await fetchMarketByIdOrSlug(params.slug, http);
19
19
  }
20
20
  // Handle outcomeId lookup (no direct API, fetch and filter client-side)
21
21
  if (params?.outcomeId) {
22
- const markets = await fetchMarketsList(params);
22
+ const markets = await fetchMarketsList(params, http);
23
23
  return markets.filter(m => m.outcomes.some(o => o.outcomeId === params.outcomeId));
24
24
  }
25
25
  // Handle eventId lookup (use markets list with eventId param)
26
26
  if (params?.eventId) {
27
- return await fetchMarketsList(params);
27
+ return await fetchMarketsList(params, http);
28
28
  }
29
29
  // Query-based search: use the search endpoint (only endpoint with text search)
30
30
  if (params?.query) {
31
- return await searchAndExtractMarkets(params.query, params);
31
+ return await searchAndExtractMarkets(params.query, params, http);
32
32
  }
33
33
  // Default: use the dedicated markets API for listing
34
- return await fetchMarketsList(params);
34
+ return await fetchMarketsList(params, http);
35
35
  }
36
36
  catch (error) {
37
37
  throw errors_1.probableErrorMapper.mapError(error);
38
38
  }
39
39
  }
40
- async function fetchMarketByIdOrSlug(slug) {
40
+ async function fetchMarketByIdOrSlug(slug, http) {
41
41
  let cleanSlug = slug;
42
42
  let marketIdFromQuery = null;
43
43
  // Handle URLs or partial URLs with query params (e.g., opinion-...-launch?market=584)
@@ -50,7 +50,7 @@ async function fetchMarketByIdOrSlug(slug) {
50
50
  marketIdFromQuery = params.get('market');
51
51
  // If we have a market ID from the query, try that first
52
52
  if (marketIdFromQuery) {
53
- const result = await fetchMarketByIdOrSlug(marketIdFromQuery);
53
+ const result = await fetchMarketByIdOrSlug(marketIdFromQuery, http);
54
54
  if (result.length > 0)
55
55
  return result;
56
56
  }
@@ -63,7 +63,7 @@ async function fetchMarketByIdOrSlug(slug) {
63
63
  const numericId = Number(cleanSlug);
64
64
  if (!isNaN(numericId) && String(numericId) === cleanSlug) {
65
65
  try {
66
- const response = await axios_1.default.get(`${utils_1.BASE_URL}${utils_1.MARKETS_PATH}${numericId}`);
66
+ const response = await http.get(`${utils_1.BASE_URL}${utils_1.MARKETS_PATH}${numericId}`);
67
67
  const mapped = (0, utils_1.mapMarketToUnified)(response.data, response.data?.event);
68
68
  const results = mapped ? [mapped] : [];
69
69
  await (0, utils_1.enrichMarketsWithPrices)(results);
@@ -72,7 +72,7 @@ async function fetchMarketByIdOrSlug(slug) {
72
72
  catch (error) {
73
73
  if (isMarketNotFoundError(error)) {
74
74
  // Individual market endpoint returned 500/404; fall back to list and filter
75
- const allMarkets = await fetchMarketsList({ limit: 100 });
75
+ const allMarkets = await fetchMarketsList({ limit: 100 }, http);
76
76
  const match = allMarkets.filter(m => m.marketId === cleanSlug);
77
77
  if (match.length > 0)
78
78
  return match;
@@ -83,9 +83,9 @@ async function fetchMarketByIdOrSlug(slug) {
83
83
  }
84
84
  }
85
85
  // Fall back to search for slug-based matching
86
- return await searchAndExtractMarkets(cleanSlug, { slug: cleanSlug });
86
+ return await searchAndExtractMarkets(cleanSlug, { slug: cleanSlug }, http);
87
87
  }
88
- async function fetchMarketsList(params) {
88
+ async function fetchMarketsList(params, http) {
89
89
  const limit = params?.limit || 20;
90
90
  const page = params?.offset ? Math.floor(params.offset / limit) + 1 : 1;
91
91
  const queryParams = {
@@ -114,7 +114,7 @@ async function fetchMarketsList(params) {
114
114
  if (params?.eventId) {
115
115
  queryParams.event_id = params.eventId;
116
116
  }
117
- const response = await axios_1.default.get(`${utils_1.BASE_URL}${utils_1.MARKETS_PATH}`, {
117
+ const response = await http.get(`${utils_1.BASE_URL}${utils_1.MARKETS_PATH}`, {
118
118
  params: queryParams,
119
119
  });
120
120
  const markets = response.data?.markets || [];
@@ -127,7 +127,7 @@ async function fetchMarketsList(params) {
127
127
  await (0, utils_1.enrichMarketsWithPrices)(allMarkets);
128
128
  return allMarkets;
129
129
  }
130
- async function searchAndExtractMarkets(query, params) {
130
+ async function searchAndExtractMarkets(query, params, http) {
131
131
  const limit = params?.limit || 20;
132
132
  const page = params?.offset ? Math.floor(params.offset / limit) + 1 : 1;
133
133
  // Improve search for slugs: if the query looks like a slug (has dashes),
@@ -184,7 +184,7 @@ async function searchAndExtractMarkets(query, params) {
184
184
  break;
185
185
  }
186
186
  }
187
- const response = await axios_1.default.get(`${utils_1.BASE_URL}${utils_1.SEARCH_PATH}`, {
187
+ const response = await http.get(`${utils_1.BASE_URL}${utils_1.SEARCH_PATH}`, {
188
188
  params: queryParams,
189
189
  });
190
190
  const events = response.data?.events || [];
@@ -1,3 +1,4 @@
1
+ import { AxiosInstance } from 'axios';
1
2
  import { OHLCVParams, HistoryFilterParams } from '../../BaseExchange';
2
3
  import { PriceCandle } from '../../types';
3
- export declare function fetchOHLCV(id: string, params: OHLCVParams | HistoryFilterParams): Promise<PriceCandle[]>;
4
+ export declare function fetchOHLCV(id: string, params: OHLCVParams | HistoryFilterParams, http?: AxiosInstance): Promise<PriceCandle[]>;
@@ -33,7 +33,7 @@ function aggregateCandles(candles, intervalMs) {
33
33
  }
34
34
  return Array.from(buckets.values()).sort((a, b) => a.timestamp - b.timestamp);
35
35
  }
36
- async function fetchOHLCV(id, params) {
36
+ async function fetchOHLCV(id, params, http = axios_1.default) {
37
37
  if (!params.resolution) {
38
38
  throw new Error('fetchOHLCV requires a resolution parameter.');
39
39
  }
@@ -47,7 +47,7 @@ async function fetchOHLCV(id, params) {
47
47
  queryParams.startTs = Math.floor(params.start.getTime() / 1000);
48
48
  if (params.end)
49
49
  queryParams.endTs = Math.floor(params.end.getTime() / 1000);
50
- const response = await axios_1.default.get(`${utils_1.CLOB_BASE_URL}/prices-history`, {
50
+ const response = await http.get(`${utils_1.CLOB_BASE_URL}/prices-history`, {
51
51
  params: queryParams,
52
52
  });
53
53
  const points = response.data?.history || response.data || [];
@@ -1,2 +1,3 @@
1
+ import { AxiosInstance } from 'axios';
1
2
  import { OrderBook } from '../../types';
2
- export declare function fetchOrderBook(id: string): Promise<OrderBook>;
3
+ export declare function fetchOrderBook(id: string, http?: AxiosInstance): Promise<OrderBook>;
@@ -7,9 +7,9 @@ exports.fetchOrderBook = fetchOrderBook;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const utils_1 = require("./utils");
9
9
  const errors_1 = require("./errors");
10
- async function fetchOrderBook(id) {
10
+ async function fetchOrderBook(id, http = axios_1.default) {
11
11
  try {
12
- const response = await axios_1.default.get(`${utils_1.CLOB_BASE_URL}/book`, {
12
+ const response = await http.get(`${utils_1.CLOB_BASE_URL}/book`, {
13
13
  params: { token_id: id },
14
14
  });
15
15
  const data = response.data;
@@ -1,4 +1,4 @@
1
- import { createClobClient } from '@prob/clob';
1
+ import { AxiosInstance } from 'axios';
2
2
  import { TradesParams, HistoryFilterParams } from '../../BaseExchange';
3
3
  import { Trade } from '../../types';
4
4
  /**
@@ -7,4 +7,4 @@ import { Trade } from '../../types';
7
7
  * @param params - Trade query parameters
8
8
  * @param client - Authenticated ClobClient instance
9
9
  */
10
- export declare function fetchTrades(id: string, params: TradesParams | HistoryFilterParams, client: ReturnType<typeof createClobClient>): Promise<Trade[]>;
10
+ export declare function fetchTrades(id: string, params: TradesParams | HistoryFilterParams, client: any, http?: AxiosInstance): Promise<Trade[]>;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchTrades = fetchTrades;
7
+ const axios_1 = __importDefault(require("axios"));
4
8
  const errors_1 = require("./errors");
5
9
  /**
6
10
  * Fetch trade history for a specific token using the @prob/clob SDK.
@@ -8,7 +12,7 @@ const errors_1 = require("./errors");
8
12
  * @param params - Trade query parameters
9
13
  * @param client - Authenticated ClobClient instance
10
14
  */
11
- async function fetchTrades(id, params, client) {
15
+ async function fetchTrades(id, params, client, http = axios_1.default) {
12
16
  try {
13
17
  const queryParams = {
14
18
  tokenId: id,
@@ -2,6 +2,21 @@ import { PredictionMarketExchange, MarketFetchParams, EventFetchParams, Exchange
2
2
  import { UnifiedMarket, UnifiedEvent, OrderBook, PriceCandle, Trade, Order, Position, Balance, CreateOrderParams } from '../../types';
3
3
  import { ProbableWebSocketConfig } from './websocket';
4
4
  export declare class ProbableExchange extends PredictionMarketExchange {
5
+ readonly has: {
6
+ fetchMarkets: true;
7
+ fetchEvents: true;
8
+ fetchOHLCV: true;
9
+ fetchOrderBook: true;
10
+ fetchTrades: true;
11
+ createOrder: true;
12
+ cancelOrder: true;
13
+ fetchOrder: true;
14
+ fetchOpenOrders: true;
15
+ fetchPositions: true;
16
+ fetchBalance: true;
17
+ watchOrderBook: true;
18
+ watchTrades: false;
19
+ };
5
20
  private auth?;
6
21
  private ws?;
7
22
  private wsConfig?;
@@ -15,6 +15,21 @@ const errors_2 = require("../../errors");
15
15
  const clob_1 = require("@prob/clob");
16
16
  const BSC_USDT_ADDRESS = '0x55d398326f99059fF775485246999027B3197955';
17
17
  class ProbableExchange extends BaseExchange_1.PredictionMarketExchange {
18
+ has = {
19
+ fetchMarkets: true,
20
+ fetchEvents: true,
21
+ fetchOHLCV: true,
22
+ fetchOrderBook: true,
23
+ fetchTrades: true,
24
+ createOrder: true,
25
+ cancelOrder: true,
26
+ fetchOrder: true,
27
+ fetchOpenOrders: true,
28
+ fetchPositions: true,
29
+ fetchBalance: true,
30
+ watchOrderBook: true,
31
+ watchTrades: false,
32
+ };
18
33
  auth;
19
34
  ws;
20
35
  wsConfig;
@@ -39,22 +54,22 @@ class ProbableExchange extends BaseExchange_1.PredictionMarketExchange {
39
54
  // Market Data (read-only, no auth needed)
40
55
  // --------------------------------------------------------------------------
41
56
  async fetchMarketsImpl(params) {
42
- return (0, fetchMarkets_1.fetchMarkets)(params);
57
+ return (0, fetchMarkets_1.fetchMarkets)(params, this.http);
43
58
  }
44
59
  async fetchEventsImpl(params) {
45
- return (0, fetchEvents_1.fetchEvents)(params);
60
+ return (0, fetchEvents_1.fetchEvents)(params, this.http);
46
61
  }
47
62
  async getEventById(id) {
48
- return (0, fetchEvents_1.fetchEventById)(id);
63
+ return (0, fetchEvents_1.fetchEventById)(id, this.http);
49
64
  }
50
65
  async getEventBySlug(slug) {
51
- return (0, fetchEvents_1.fetchEventBySlug)(slug);
66
+ return (0, fetchEvents_1.fetchEventBySlug)(slug, this.http);
52
67
  }
53
68
  async fetchOrderBook(id) {
54
- return (0, fetchOrderBook_1.fetchOrderBook)(id);
69
+ return (0, fetchOrderBook_1.fetchOrderBook)(id, this.http);
55
70
  }
56
71
  async fetchOHLCV(id, params) {
57
- return (0, fetchOHLCV_1.fetchOHLCV)(id, params);
72
+ return (0, fetchOHLCV_1.fetchOHLCV)(id, params, this.http);
58
73
  }
59
74
  // --------------------------------------------------------------------------
60
75
  // Trading Methods
@@ -271,7 +286,7 @@ class ProbableExchange extends BaseExchange_1.PredictionMarketExchange {
271
286
  async fetchTrades(id, params) {
272
287
  const auth = this.ensureAuth();
273
288
  const client = auth.getClobClient();
274
- return (0, fetchTrades_1.fetchTrades)(id, params, client);
289
+ return (0, fetchTrades_1.fetchTrades)(id, params, client, this.http);
275
290
  }
276
291
  // --------------------------------------------------------------------------
277
292
  // WebSocket Streaming (public, no auth needed)
@@ -39,6 +39,20 @@ async function startServer(port, accessToken) {
39
39
  }
40
40
  next();
41
41
  });
42
+ // Capability map endpoint: GET /api/:exchange/has
43
+ app.get('/api/:exchange/has', (req, res, next) => {
44
+ try {
45
+ const exchangeName = req.params.exchange.toLowerCase();
46
+ if (!defaultExchanges[exchangeName]) {
47
+ defaultExchanges[exchangeName] = createExchange(exchangeName);
48
+ }
49
+ const exchange = defaultExchanges[exchangeName];
50
+ res.json({ success: true, data: exchange.has });
51
+ }
52
+ catch (error) {
53
+ next(error);
54
+ }
55
+ });
42
56
  // API endpoint: POST /api/:exchange/:method
43
57
  // Body: { args: any[], credentials?: ExchangeCredentials }
44
58
  app.post('/api/:exchange/:method', async (req, res, next) => {
@@ -60,6 +74,15 @@ async function startServer(port, accessToken) {
60
74
  }
61
75
  exchange = defaultExchanges[exchangeName];
62
76
  }
77
+ // Set verbose flag if present in request
78
+ if (req.body.verbose === true) {
79
+ exchange.verbose = true;
80
+ }
81
+ else {
82
+ // Reset to false for singleton instances to avoid leaking state between requests
83
+ // For new instances it defaults to false anyway
84
+ exchange.verbose = false;
85
+ }
63
86
  // 2. Validate Method
64
87
  if (typeof exchange[methodName] !== 'function') {
65
88
  res.status(404).json({ success: false, error: `Method '${methodName}' not found on ${exchangeName}` });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmxt-core",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
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.5.0,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.5.0,supportsES6=true,typescriptThreePlus=true && node ../sdks/typescript/scripts/fix-generated.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.7.0,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.7.0,supportsES6=true,typescriptThreePlus=true && node ../sdks/typescript/scripts/fix-generated.js",
34
34
  "extract:jsdoc": "node ../scripts/extract-jsdoc.js",
35
35
  "generate:docs": "npm run extract:jsdoc && node ../scripts/generate-api-docs.js",
36
36
  "generate:sdk:all": "npm run generate:sdk:python && npm run generate:sdk:typescript && npm run generate:docs"
@@ -45,7 +45,7 @@
45
45
  "@prob/clob": "0.5.0",
46
46
  "@solana/web3.js": "^1.98.4",
47
47
  "@types/express": "^5.0.6",
48
- "axios": "^1.7.9",
48
+ "axios": "^1.13.2",
49
49
  "bs58": "^6.0.0",
50
50
  "cors": "^2.8.5",
51
51
  "dotenv": "^17.2.3",