pmxt-core 2.7.0 → 2.9.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 (85) hide show
  1. package/dist/BaseExchange.d.ts +59 -0
  2. package/dist/BaseExchange.js +155 -0
  3. package/dist/exchanges/kalshi/api.d.ts +1763 -0
  4. package/dist/exchanges/kalshi/api.js +2554 -0
  5. package/dist/exchanges/kalshi/fetchEvents.d.ts +3 -2
  6. package/dist/exchanges/kalshi/fetchEvents.js +9 -16
  7. package/dist/exchanges/kalshi/fetchMarkets.d.ts +3 -2
  8. package/dist/exchanges/kalshi/fetchMarkets.js +27 -35
  9. package/dist/exchanges/kalshi/fetchOHLCV.d.ts +1 -2
  10. package/dist/exchanges/kalshi/fetchOHLCV.js +9 -11
  11. package/dist/exchanges/kalshi/index.d.ts +2 -1
  12. package/dist/exchanges/kalshi/index.js +161 -183
  13. package/dist/exchanges/kalshi/kalshi.test.js +51 -31
  14. package/dist/exchanges/limitless/api.d.ts +555 -0
  15. package/dist/exchanges/limitless/api.js +863 -0
  16. package/dist/exchanges/limitless/fetchEvents.d.ts +1 -2
  17. package/dist/exchanges/limitless/fetchEvents.js +9 -15
  18. package/dist/exchanges/limitless/fetchMarkets.d.ts +1 -2
  19. package/dist/exchanges/limitless/fetchMarkets.js +11 -18
  20. package/dist/exchanges/limitless/fetchOHLCV.d.ts +1 -2
  21. package/dist/exchanges/limitless/fetchOHLCV.js +2 -11
  22. package/dist/exchanges/limitless/fetchOrderBook.d.ts +1 -2
  23. package/dist/exchanges/limitless/fetchOrderBook.js +2 -11
  24. package/dist/exchanges/limitless/index.d.ts +1 -0
  25. package/dist/exchanges/limitless/index.js +28 -7
  26. package/dist/exchanges/limitless/websocket.d.ts +2 -1
  27. package/dist/exchanges/limitless/websocket.js +6 -4
  28. package/dist/exchanges/myriad/api.d.ts +294 -0
  29. package/dist/exchanges/myriad/api.js +690 -0
  30. package/dist/exchanges/myriad/fetchOHLCV.d.ts +1 -2
  31. package/dist/exchanges/myriad/fetchOHLCV.js +3 -11
  32. package/dist/exchanges/myriad/fetchOrderBook.d.ts +1 -2
  33. package/dist/exchanges/myriad/fetchOrderBook.js +3 -11
  34. package/dist/exchanges/myriad/index.d.ts +2 -0
  35. package/dist/exchanges/myriad/index.js +116 -103
  36. package/dist/exchanges/myriad/websocket.d.ts +2 -2
  37. package/dist/exchanges/myriad/websocket.js +28 -6
  38. package/dist/exchanges/polymarket/api-clob.d.ts +346 -0
  39. package/dist/exchanges/polymarket/api-clob.js +517 -0
  40. package/dist/exchanges/polymarket/api-data.d.ts +789 -0
  41. package/dist/exchanges/polymarket/api-data.js +860 -0
  42. package/dist/exchanges/polymarket/api-gamma.d.ts +556 -0
  43. package/dist/exchanges/polymarket/api-gamma.js +1161 -0
  44. package/dist/exchanges/polymarket/fetchEvents.js +0 -68
  45. package/dist/exchanges/polymarket/fetchMarkets.js +2 -2
  46. package/dist/exchanges/polymarket/fetchOHLCV.d.ts +1 -2
  47. package/dist/exchanges/polymarket/fetchOHLCV.js +4 -10
  48. package/dist/exchanges/polymarket/fetchOrderBook.d.ts +1 -2
  49. package/dist/exchanges/polymarket/fetchOrderBook.js +2 -10
  50. package/dist/exchanges/polymarket/fetchTrades.d.ts +1 -2
  51. package/dist/exchanges/polymarket/fetchTrades.js +2 -11
  52. package/dist/exchanges/polymarket/index.d.ts +10 -0
  53. package/dist/exchanges/polymarket/index.js +110 -5
  54. package/dist/exchanges/probable/api.d.ts +605 -0
  55. package/dist/exchanges/probable/api.js +887 -0
  56. package/dist/exchanges/probable/fetchEvents.d.ts +3 -3
  57. package/dist/exchanges/probable/fetchEvents.js +28 -25
  58. package/dist/exchanges/probable/fetchMarkets.d.ts +1 -1
  59. package/dist/exchanges/probable/fetchMarkets.js +25 -21
  60. package/dist/exchanges/probable/index.d.ts +1 -0
  61. package/dist/exchanges/probable/index.js +92 -10
  62. package/dist/exchanges/probable/utils.d.ts +1 -2
  63. package/dist/exchanges/probable/utils.js +4 -11
  64. package/dist/index.d.ts +1 -0
  65. package/dist/index.js +3 -1
  66. package/dist/types.d.ts +1 -0
  67. package/dist/utils/openapi.d.ts +9 -0
  68. package/dist/utils/openapi.js +59 -0
  69. package/package.json +4 -3
  70. package/dist/exchanges/kalshi/fetchOrderBook.d.ts +0 -3
  71. package/dist/exchanges/kalshi/fetchOrderBook.js +0 -59
  72. package/dist/exchanges/kalshi/fetchTrades.d.ts +0 -4
  73. package/dist/exchanges/kalshi/fetchTrades.js +0 -31
  74. package/dist/exchanges/limitless/fetchPositions.d.ts +0 -2
  75. package/dist/exchanges/limitless/fetchPositions.js +0 -34
  76. package/dist/exchanges/myriad/fetchTrades.d.ts +0 -4
  77. package/dist/exchanges/myriad/fetchTrades.js +0 -62
  78. package/dist/exchanges/polymarket/fetchPositions.d.ts +0 -2
  79. package/dist/exchanges/polymarket/fetchPositions.js +0 -34
  80. package/dist/exchanges/probable/fetchOHLCV.d.ts +0 -4
  81. package/dist/exchanges/probable/fetchOHLCV.js +0 -83
  82. package/dist/exchanges/probable/fetchOrderBook.d.ts +0 -3
  83. package/dist/exchanges/probable/fetchOrderBook.js +0 -37
  84. package/dist/exchanges/probable/fetchPositions.d.ts +0 -2
  85. package/dist/exchanges/probable/fetchPositions.js +0 -33
@@ -7,76 +7,8 @@ exports.fetchEvents = fetchEvents;
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 fetchEventByGammaId(id, http) {
11
- const response = await http.get(utils_1.GAMMA_API_URL, {
12
- params: { id }
13
- });
14
- const events = response.data;
15
- if (!events || events.length === 0)
16
- return [];
17
- return events.map((event) => {
18
- const markets = [];
19
- if (event.markets && Array.isArray(event.markets)) {
20
- for (const market of event.markets) {
21
- const unifiedMarket = (0, utils_1.mapMarketToUnified)(event, market, { useQuestionAsCandidateFallback: true });
22
- if (unifiedMarket) {
23
- markets.push(unifiedMarket);
24
- }
25
- }
26
- }
27
- return {
28
- id: event.id || event.slug,
29
- title: event.title,
30
- description: event.description || '',
31
- slug: event.slug,
32
- markets,
33
- url: `https://polymarket.com/event/${event.slug}`,
34
- image: event.image || `https://polymarket.com/api/og?slug=${event.slug}`,
35
- category: event.category || event.tags?.[0]?.label,
36
- tags: event.tags?.map((t) => t.label) || []
37
- };
38
- });
39
- }
40
- async function fetchEventBySlug(slug, http) {
41
- const response = await http.get(utils_1.GAMMA_API_URL, {
42
- params: { slug }
43
- });
44
- const events = response.data;
45
- if (!events || events.length === 0)
46
- return [];
47
- return events.map((event) => {
48
- const markets = [];
49
- if (event.markets && Array.isArray(event.markets)) {
50
- for (const market of event.markets) {
51
- const unifiedMarket = (0, utils_1.mapMarketToUnified)(event, market, { useQuestionAsCandidateFallback: true });
52
- if (unifiedMarket) {
53
- markets.push(unifiedMarket);
54
- }
55
- }
56
- }
57
- return {
58
- id: event.id || event.slug,
59
- title: event.title,
60
- description: event.description || '',
61
- slug: event.slug,
62
- markets,
63
- url: `https://polymarket.com/event/${event.slug}`,
64
- image: event.image || `https://polymarket.com/api/og?slug=${event.slug}`,
65
- category: event.category || event.tags?.[0]?.label,
66
- tags: event.tags?.map((t) => t.label) || []
67
- };
68
- });
69
- }
70
10
  async function fetchEvents(params, http = axios_1.default) {
71
11
  try {
72
- // Handle eventId lookup (Gamma event ID)
73
- if (params.eventId) {
74
- return await fetchEventByGammaId(params.eventId, http);
75
- }
76
- // Handle slug lookup
77
- if (params.slug) {
78
- return await fetchEventBySlug(params.slug, http);
79
- }
80
12
  if (!params.query) {
81
13
  throw new Error("Query is required for Polymarket event search");
82
14
  }
@@ -97,7 +97,7 @@ async function fetchMarketsBySlug(slug, http) {
97
97
  return unifiedMarkets;
98
98
  }
99
99
  async function searchMarkets(query, params, http) {
100
- const limit = params?.limit || 10000;
100
+ const limit = params?.limit || 250000;
101
101
  // Use parallel pagination to fetch all matching events
102
102
  // Each event can contain multiple markets, so we need a larger pool
103
103
  const queryParams = {
@@ -138,7 +138,7 @@ async function searchMarkets(query, params, http) {
138
138
  return unifiedMarkets.slice(0, limit);
139
139
  }
140
140
  async function fetchMarketsDefault(params, http) {
141
- const limit = params?.limit || 10000; // Higher default for better coverage
141
+ const limit = params?.limit || 250000; // Higher default for better coverage
142
142
  const offset = params?.offset || 0;
143
143
  // Map generic sort params to Polymarket Gamma API params
144
144
  let queryParams = {
@@ -1,8 +1,7 @@
1
- import { AxiosInstance } from 'axios';
2
1
  import { HistoryFilterParams, OHLCVParams } from '../../BaseExchange';
3
2
  import { PriceCandle } from '../../types';
4
3
  /**
5
4
  * Fetch historical price data (OHLCV candles) for a specific token.
6
5
  * @param id - The CLOB token ID (e.g., outcome token ID)
7
6
  */
8
- export declare function fetchOHLCV(id: string, params: OHLCVParams | HistoryFilterParams, http?: AxiosInstance): Promise<PriceCandle[]>;
7
+ export declare function fetchOHLCV(id: string, params: OHLCVParams | HistoryFilterParams, callApi: (operationId: string, params?: Record<string, any>) => Promise<any>): Promise<PriceCandle[]>;
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchOHLCV = fetchOHLCV;
7
- const axios_1 = __importDefault(require("axios"));
8
4
  const utils_1 = require("./utils");
9
5
  const validation_1 = require("../../utils/validation");
10
6
  const errors_1 = require("./errors");
@@ -12,7 +8,7 @@ const errors_1 = require("./errors");
12
8
  * Fetch historical price data (OHLCV candles) for a specific token.
13
9
  * @param id - The CLOB token ID (e.g., outcome token ID)
14
10
  */
15
- async function fetchOHLCV(id, params, http = axios_1.default) {
11
+ async function fetchOHLCV(id, params, callApi) {
16
12
  (0, validation_1.validateIdFormat)(id, 'OHLCV');
17
13
  (0, validation_1.validateOutcomeId)(id, 'OHLCV');
18
14
  // Validate resolution is provided
@@ -45,7 +41,7 @@ async function fetchOHLCV(id, params, http = axios_1.default) {
45
41
  // Default limit is usually 20 in the example, but safety margin is good.
46
42
  // If limit is not set, we default to 100 candles.
47
43
  const count = params.limit || 100;
48
- // fidelity is in minutes.
44
+ // fidelity is in minutes.
49
45
  const durationSeconds = count * fidelity * 60;
50
46
  startTs = endTs - durationSeconds;
51
47
  }
@@ -55,10 +51,8 @@ async function fetchOHLCV(id, params, http = axios_1.default) {
55
51
  startTs: startTs,
56
52
  endTs: endTs
57
53
  };
58
- const response = await http.get(`${utils_1.CLOB_API_URL}/prices-history`, {
59
- params: queryParams
60
- });
61
- const history = response.data.history || [];
54
+ const data = await callApi('getPricesHistory', queryParams);
55
+ const history = data.history || [];
62
56
  // 2. Align Timestamps (Snap to Grid)
63
57
  // Polymarket returns random tick timestamps (e.g. 1:00:21).
64
58
  // We want to normalize this to the start of the bucket (1:00:00).
@@ -1,7 +1,6 @@
1
- import { AxiosInstance } from 'axios';
2
1
  import { OrderBook } from '../../types';
3
2
  /**
4
3
  * Fetch the current order book for a specific token.
5
4
  * @param id - The CLOB token ID
6
5
  */
7
- export declare function fetchOrderBook(id: string, http?: AxiosInstance): Promise<OrderBook>;
6
+ export declare function fetchOrderBook(id: string, callApi: (operationId: string, params?: Record<string, any>) => Promise<any>): Promise<OrderBook>;
@@ -1,25 +1,17 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchOrderBook = fetchOrderBook;
7
- const axios_1 = __importDefault(require("axios"));
8
- const utils_1 = require("./utils");
9
4
  const validation_1 = require("../../utils/validation");
10
5
  const errors_1 = require("./errors");
11
6
  /**
12
7
  * Fetch the current order book for a specific token.
13
8
  * @param id - The CLOB token ID
14
9
  */
15
- async function fetchOrderBook(id, http = axios_1.default) {
10
+ async function fetchOrderBook(id, callApi) {
16
11
  (0, validation_1.validateIdFormat)(id, 'OrderBook');
17
12
  (0, validation_1.validateOutcomeId)(id, 'OrderBook');
18
13
  try {
19
- const response = await http.get(`${utils_1.CLOB_API_URL}/book`, {
20
- params: { token_id: id }
21
- });
22
- const data = response.data;
14
+ const data = await callApi('getBook', { token_id: id });
23
15
  // Response format: { bids: [{price: "0.52", size: "100"}], asks: [...] }
24
16
  const bids = (data.bids || []).map((level) => ({
25
17
  price: parseFloat(level.price),
@@ -1,4 +1,3 @@
1
- import { AxiosInstance } from 'axios';
2
1
  import { HistoryFilterParams, TradesParams } from '../../BaseExchange';
3
2
  import { Trade } from '../../types';
4
3
  /**
@@ -7,4 +6,4 @@ import { Trade } from '../../types';
7
6
  *
8
7
  * NOTE: Uses Polymarket Data API (public) to fetch trades.
9
8
  */
10
- export declare function fetchTrades(id: string, params: TradesParams | HistoryFilterParams, http?: AxiosInstance): Promise<Trade[]>;
9
+ export declare function fetchTrades(id: string, params: TradesParams | HistoryFilterParams, callApi: (operationId: string, params?: Record<string, any>) => Promise<any>): Promise<Trade[]>;
@@ -1,11 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.fetchTrades = fetchTrades;
7
- const axios_1 = __importDefault(require("axios"));
8
- const utils_1 = require("./utils");
9
4
  const validation_1 = require("../../utils/validation");
10
5
  const errors_1 = require("./errors");
11
6
  /**
@@ -14,7 +9,7 @@ const errors_1 = require("./errors");
14
9
  *
15
10
  * NOTE: Uses Polymarket Data API (public) to fetch trades.
16
11
  */
17
- async function fetchTrades(id, params, http = axios_1.default) {
12
+ async function fetchTrades(id, params, callApi) {
18
13
  (0, validation_1.validateIdFormat)(id, 'Trades');
19
14
  (0, validation_1.validateOutcomeId)(id, 'Trades');
20
15
  try {
@@ -28,11 +23,7 @@ async function fetchTrades(id, params, http = axios_1.default) {
28
23
  if (params.end) {
29
24
  queryParams.before = Math.floor(params.end.getTime() / 1000);
30
25
  }
31
- const response = await http.get(`${utils_1.DATA_API_URL}/trades`, {
32
- params: queryParams
33
- });
34
- // Response is an array of trade objects
35
- const trades = response.data || [];
26
+ const trades = await callApi('getTrades', queryParams) || [];
36
27
  const mappedTrades = trades.map((trade) => ({
37
28
  id: trade.id || `${trade.timestamp}-${trade.price}`,
38
29
  timestamp: trade.timestamp * 1000, // Convert to milliseconds
@@ -24,8 +24,18 @@ export declare class PolymarketExchange extends PredictionMarketExchange {
24
24
  };
25
25
  private auth?;
26
26
  private wsConfig?;
27
+ private cachedApiCreds?;
28
+ private cachedAddress?;
27
29
  constructor(options?: ExchangeCredentials | PolymarketExchangeOptions);
28
30
  get name(): string;
31
+ /**
32
+ * Initialize L2 API credentials for implicit API signing.
33
+ * Must be called before using private implicit API endpoints if only
34
+ * a privateKey was provided (not apiKey/apiSecret/passphrase).
35
+ */
36
+ initAuth(): Promise<void>;
37
+ protected sign(method: string, path: string, _params: Record<string, any>): Record<string, string>;
38
+ protected mapImplicitApiError(error: any): any;
29
39
  protected fetchMarketsImpl(params?: MarketFilterParams): Promise<UnifiedMarket[]>;
30
40
  protected fetchEventsImpl(params: EventFetchParams): Promise<UnifiedEvent[]>;
31
41
  fetchOHLCV(id: string, params: OHLCVParams | HistoryFilterParams): Promise<PriceCandle[]>;
@@ -1,18 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PolymarketExchange = void 0;
4
+ const crypto_1 = require("crypto");
4
5
  const BaseExchange_1 = require("../../BaseExchange");
6
+ const openapi_1 = require("../../utils/openapi");
5
7
  const fetchMarkets_1 = require("./fetchMarkets");
6
8
  const fetchEvents_1 = require("./fetchEvents");
9
+ const utils_1 = require("./utils");
7
10
  const fetchOHLCV_1 = require("./fetchOHLCV");
8
11
  const fetchOrderBook_1 = require("./fetchOrderBook");
9
12
  const fetchTrades_1 = require("./fetchTrades");
10
- const fetchPositions_1 = require("./fetchPositions");
11
13
  const auth_1 = require("./auth");
12
14
  const clob_client_1 = require("@polymarket/clob-client");
13
15
  const websocket_1 = require("./websocket");
14
16
  const errors_1 = require("./errors");
15
17
  const errors_2 = require("../../errors");
18
+ const api_clob_1 = require("./api-clob");
19
+ const api_gamma_1 = require("./api-gamma");
20
+ const api_data_1 = require("./api-data");
16
21
  class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
17
22
  has = {
18
23
  fetchMarkets: true,
@@ -31,6 +36,8 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
31
36
  };
32
37
  auth;
33
38
  wsConfig;
39
+ cachedApiCreds;
40
+ cachedAddress;
34
41
  constructor(options) {
35
42
  // Support both old signature (credentials only) and new signature (options object)
36
43
  let credentials;
@@ -50,24 +57,111 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
50
57
  if (credentials?.privateKey) {
51
58
  this.auth = new auth_1.PolymarketAuth(credentials);
52
59
  }
60
+ // If L2 API creds are provided directly, cache them for sync sign()
61
+ if (credentials?.apiKey && credentials?.apiSecret && credentials?.passphrase) {
62
+ this.cachedApiCreds = {
63
+ key: credentials.apiKey,
64
+ secret: credentials.apiSecret,
65
+ passphrase: credentials.passphrase,
66
+ };
67
+ }
68
+ // Register implicit APIs for all 3 Polymarket services
69
+ const clobDescriptor = (0, openapi_1.parseOpenApiSpec)(api_clob_1.polymarketClobSpec);
70
+ this.defineImplicitApi(clobDescriptor);
71
+ const gammaDescriptor = (0, openapi_1.parseOpenApiSpec)(api_gamma_1.polymarketGammaSpec);
72
+ this.defineImplicitApi(gammaDescriptor);
73
+ const dataDescriptor = (0, openapi_1.parseOpenApiSpec)(api_data_1.polymarketDataSpec);
74
+ this.defineImplicitApi(dataDescriptor);
53
75
  }
54
76
  get name() {
55
77
  return 'Polymarket';
56
78
  }
57
79
  // ----------------------------------------------------------------------------
80
+ // Implicit API Auth & Error Mapping
81
+ // ----------------------------------------------------------------------------
82
+ /**
83
+ * Initialize L2 API credentials for implicit API signing.
84
+ * Must be called before using private implicit API endpoints if only
85
+ * a privateKey was provided (not apiKey/apiSecret/passphrase).
86
+ */
87
+ async initAuth() {
88
+ const auth = this.ensureAuth();
89
+ const creds = await auth.getApiCredentials();
90
+ this.cachedApiCreds = {
91
+ key: creds.key,
92
+ secret: creds.secret,
93
+ passphrase: creds.passphrase,
94
+ };
95
+ this.cachedAddress = auth.getFunderAddress();
96
+ }
97
+ sign(method, path, _params) {
98
+ if (!this.cachedApiCreds) {
99
+ throw new errors_2.AuthenticationError('API credentials not initialized. Either provide apiKey/apiSecret/passphrase ' +
100
+ 'in credentials, or call initAuth() before using private implicit API endpoints.', 'Polymarket');
101
+ }
102
+ const timestamp = Math.floor(Date.now() / 1000).toString();
103
+ const message = timestamp + method.toUpperCase() + path;
104
+ // Decode the base64url secret
105
+ const secretB64 = this.cachedApiCreds.secret
106
+ .replace(/-/g, '+')
107
+ .replace(/_/g, '/');
108
+ const secretBuffer = Buffer.from(secretB64, 'base64');
109
+ // HMAC-SHA256 -> base64url
110
+ const hmac = (0, crypto_1.createHmac)('sha256', secretBuffer);
111
+ hmac.update(message);
112
+ const signature = hmac.digest('base64')
113
+ .replace(/\+/g, '-')
114
+ .replace(/\//g, '_');
115
+ return {
116
+ 'POLY_ADDRESS': this.cachedAddress || (this.auth ? this.auth.getFunderAddress() : ''),
117
+ 'POLY_SIGNATURE': signature,
118
+ 'POLY_TIMESTAMP': timestamp,
119
+ 'POLY_API_KEY': this.cachedApiCreds.key,
120
+ 'POLY_PASSPHRASE': this.cachedApiCreds.passphrase,
121
+ };
122
+ }
123
+ mapImplicitApiError(error) {
124
+ throw errors_1.polymarketErrorMapper.mapError(error);
125
+ }
126
+ // ----------------------------------------------------------------------------
58
127
  // Implementation methods for CCXT-style API
59
128
  // ----------------------------------------------------------------------------
60
129
  async fetchMarketsImpl(params) {
61
130
  return (0, fetchMarkets_1.fetchMarkets)(params, this.http);
62
131
  }
63
132
  async fetchEventsImpl(params) {
133
+ if (params.eventId || params.slug) {
134
+ const queryParams = params.eventId ? { id: params.eventId } : { slug: params.slug };
135
+ const events = await this.callApi('listEvents', queryParams);
136
+ return (events || []).map((event) => {
137
+ const markets = [];
138
+ if (event.markets && Array.isArray(event.markets)) {
139
+ for (const market of event.markets) {
140
+ const unified = (0, utils_1.mapMarketToUnified)(event, market, { useQuestionAsCandidateFallback: true });
141
+ if (unified)
142
+ markets.push(unified);
143
+ }
144
+ }
145
+ return {
146
+ id: event.id || event.slug,
147
+ title: event.title,
148
+ description: event.description || '',
149
+ slug: event.slug,
150
+ markets,
151
+ url: `https://polymarket.com/event/${event.slug}`,
152
+ image: event.image || `https://polymarket.com/api/og?slug=${event.slug}`,
153
+ category: event.category || event.tags?.[0]?.label,
154
+ tags: event.tags?.map((t) => t.label) || [],
155
+ };
156
+ });
157
+ }
64
158
  return (0, fetchEvents_1.fetchEvents)(params, this.http);
65
159
  }
66
160
  async fetchOHLCV(id, params) {
67
- return (0, fetchOHLCV_1.fetchOHLCV)(id, params, this.http);
161
+ return (0, fetchOHLCV_1.fetchOHLCV)(id, params, this.callApi.bind(this));
68
162
  }
69
163
  async fetchOrderBook(id) {
70
- return (0, fetchOrderBook_1.fetchOrderBook)(id, this.http);
164
+ return (0, fetchOrderBook_1.fetchOrderBook)(id, this.callApi.bind(this));
71
165
  }
72
166
  async fetchTrades(id, params) {
73
167
  // Deprecation warning (also in base class, but adding here for consistency)
@@ -75,7 +169,7 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
75
169
  console.warn('[pmxt] Warning: The "resolution" parameter is deprecated for fetchTrades() and will be ignored. ' +
76
170
  'It will be removed in v3.0.0. Please remove it from your code.');
77
171
  }
78
- return (0, fetchTrades_1.fetchTrades)(id, params, this.http);
172
+ return (0, fetchTrades_1.fetchTrades)(id, params, this.callApi.bind(this));
79
173
  }
80
174
  // ----------------------------------------------------------------------------
81
175
  // Trading Methods
@@ -235,7 +329,18 @@ class PolymarketExchange extends BaseExchange_1.PredictionMarketExchange {
235
329
  try {
236
330
  const auth = this.ensureAuth();
237
331
  const address = await auth.getEffectiveFunderAddress();
238
- return (0, fetchPositions_1.fetchPositions)(address);
332
+ const result = await this.callApi('getPositions', { user: address, limit: 100 });
333
+ const data = Array.isArray(result) ? result : [];
334
+ return data.map((p) => ({
335
+ marketId: p.conditionId,
336
+ outcomeId: p.asset,
337
+ outcomeLabel: p.outcome || 'Unknown',
338
+ size: parseFloat(p.size),
339
+ entryPrice: parseFloat(p.avgPrice),
340
+ currentPrice: parseFloat(p.curPrice || '0'),
341
+ unrealizedPnL: parseFloat(p.cashPnl || '0'),
342
+ realizedPnL: parseFloat(p.realizedPnl || '0'),
343
+ }));
239
344
  }
240
345
  catch (error) {
241
346
  throw errors_1.polymarketErrorMapper.mapError(error);