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.
Files changed (113) hide show
  1. package/dist/exchanges/baozi/fetcher.d.ts +40 -0
  2. package/dist/exchanges/baozi/fetcher.js +155 -0
  3. package/dist/exchanges/baozi/index.d.ts +2 -0
  4. package/dist/exchanges/baozi/index.js +60 -131
  5. package/dist/exchanges/baozi/normalizer.d.ts +14 -0
  6. package/dist/exchanges/baozi/normalizer.js +208 -0
  7. package/dist/exchanges/interfaces.d.ts +28 -0
  8. package/dist/exchanges/interfaces.js +2 -0
  9. package/dist/exchanges/kalshi/api.d.ts +1 -1
  10. package/dist/exchanges/kalshi/api.js +1 -1
  11. package/dist/exchanges/kalshi/fetcher.d.ts +126 -0
  12. package/dist/exchanges/kalshi/fetcher.js +313 -0
  13. package/dist/exchanges/kalshi/index.d.ts +6 -6
  14. package/dist/exchanges/kalshi/index.js +119 -202
  15. package/dist/exchanges/kalshi/normalizer.d.ts +25 -0
  16. package/dist/exchanges/kalshi/normalizer.js +294 -0
  17. package/dist/exchanges/limitless/api.d.ts +1 -1
  18. package/dist/exchanges/limitless/api.js +1 -1
  19. package/dist/exchanges/limitless/fetcher.d.ts +81 -0
  20. package/dist/exchanges/limitless/fetcher.js +238 -0
  21. package/dist/exchanges/limitless/index.d.ts +6 -9
  22. package/dist/exchanges/limitless/index.js +81 -79
  23. package/dist/exchanges/limitless/normalizer.d.ts +14 -0
  24. package/dist/exchanges/limitless/normalizer.js +117 -0
  25. package/dist/exchanges/limitless/websocket.d.ts +3 -0
  26. package/dist/exchanges/limitless/websocket.js +5 -4
  27. package/dist/exchanges/myriad/api.d.ts +1 -1
  28. package/dist/exchanges/myriad/api.js +1 -1
  29. package/dist/exchanges/myriad/fetcher.d.ts +73 -0
  30. package/dist/exchanges/myriad/fetcher.js +217 -0
  31. package/dist/exchanges/myriad/index.d.ts +2 -0
  32. package/dist/exchanges/myriad/index.js +40 -97
  33. package/dist/exchanges/myriad/normalizer.d.ts +14 -0
  34. package/dist/exchanges/myriad/normalizer.js +167 -0
  35. package/dist/exchanges/myriad/websocket.d.ts +3 -1
  36. package/dist/exchanges/myriad/websocket.js +4 -3
  37. package/dist/exchanges/polymarket/api-clob.d.ts +1 -1
  38. package/dist/exchanges/polymarket/api-clob.js +1 -1
  39. package/dist/exchanges/polymarket/api-data.d.ts +1 -1
  40. package/dist/exchanges/polymarket/api-data.js +1 -1
  41. package/dist/exchanges/polymarket/api-gamma.d.ts +1 -1
  42. package/dist/exchanges/polymarket/api-gamma.js +1 -1
  43. package/dist/exchanges/polymarket/fetcher.d.ts +99 -0
  44. package/dist/exchanges/polymarket/fetcher.js +335 -0
  45. package/dist/exchanges/polymarket/index.d.ts +2 -0
  46. package/dist/exchanges/polymarket/index.js +80 -66
  47. package/dist/exchanges/polymarket/normalizer.d.ts +18 -0
  48. package/dist/exchanges/polymarket/normalizer.js +126 -0
  49. package/dist/exchanges/probable/api.d.ts +1 -1
  50. package/dist/exchanges/probable/api.js +1 -1
  51. package/dist/exchanges/probable/fetcher.d.ts +106 -0
  52. package/dist/exchanges/probable/fetcher.js +357 -0
  53. package/dist/exchanges/probable/index.d.ts +3 -1
  54. package/dist/exchanges/probable/index.js +73 -105
  55. package/dist/exchanges/probable/normalizer.d.ts +14 -0
  56. package/dist/exchanges/probable/normalizer.js +109 -0
  57. package/dist/utils/error-mapper.d.ts +8 -0
  58. package/dist/utils/error-mapper.js +58 -26
  59. package/package.json +3 -3
  60. package/dist/exchanges/baozi/fetchEvents.d.ts +0 -8
  61. package/dist/exchanges/baozi/fetchEvents.js +0 -39
  62. package/dist/exchanges/baozi/fetchMarkets.d.ts +0 -5
  63. package/dist/exchanges/baozi/fetchMarkets.js +0 -160
  64. package/dist/exchanges/baozi/fetchOHLCV.d.ts +0 -6
  65. package/dist/exchanges/baozi/fetchOHLCV.js +0 -10
  66. package/dist/exchanges/baozi/fetchOrderBook.d.ts +0 -12
  67. package/dist/exchanges/baozi/fetchOrderBook.js +0 -36
  68. package/dist/exchanges/baozi/fetchTrades.d.ts +0 -6
  69. package/dist/exchanges/baozi/fetchTrades.js +0 -10
  70. package/dist/exchanges/kalshi/fetchEvents.d.ts +0 -5
  71. package/dist/exchanges/kalshi/fetchEvents.js +0 -196
  72. package/dist/exchanges/kalshi/fetchMarkets.d.ts +0 -6
  73. package/dist/exchanges/kalshi/fetchMarkets.js +0 -247
  74. package/dist/exchanges/kalshi/fetchOHLCV.d.ts +0 -3
  75. package/dist/exchanges/kalshi/fetchOHLCV.js +0 -97
  76. package/dist/exchanges/kalshi/fetchOrderBook.d.ts +0 -2
  77. package/dist/exchanges/kalshi/fetchOrderBook.js +0 -60
  78. package/dist/exchanges/kalshi/fetchTrades.d.ts +0 -3
  79. package/dist/exchanges/kalshi/fetchTrades.js +0 -33
  80. package/dist/exchanges/limitless/fetchEvents.d.ts +0 -4
  81. package/dist/exchanges/limitless/fetchEvents.js +0 -173
  82. package/dist/exchanges/limitless/fetchMarkets.d.ts +0 -3
  83. package/dist/exchanges/limitless/fetchMarkets.js +0 -152
  84. package/dist/exchanges/limitless/fetchOHLCV.d.ts +0 -7
  85. package/dist/exchanges/limitless/fetchOHLCV.js +0 -49
  86. package/dist/exchanges/limitless/fetchOrderBook.d.ts +0 -6
  87. package/dist/exchanges/limitless/fetchOrderBook.js +0 -41
  88. package/dist/exchanges/limitless/fetchTrades.d.ts +0 -8
  89. package/dist/exchanges/limitless/fetchTrades.js +0 -27
  90. package/dist/exchanges/myriad/fetchEvents.d.ts +0 -4
  91. package/dist/exchanges/myriad/fetchEvents.js +0 -48
  92. package/dist/exchanges/myriad/fetchMarkets.d.ts +0 -4
  93. package/dist/exchanges/myriad/fetchMarkets.js +0 -102
  94. package/dist/exchanges/myriad/fetchOHLCV.d.ts +0 -3
  95. package/dist/exchanges/myriad/fetchOHLCV.js +0 -83
  96. package/dist/exchanges/myriad/fetchOrderBook.d.ts +0 -2
  97. package/dist/exchanges/myriad/fetchOrderBook.js +0 -39
  98. package/dist/exchanges/polymarket/fetchEvents.d.ts +0 -4
  99. package/dist/exchanges/polymarket/fetchEvents.js +0 -135
  100. package/dist/exchanges/polymarket/fetchMarkets.d.ts +0 -4
  101. package/dist/exchanges/polymarket/fetchMarkets.js +0 -214
  102. package/dist/exchanges/polymarket/fetchOHLCV.d.ts +0 -7
  103. package/dist/exchanges/polymarket/fetchOHLCV.js +0 -98
  104. package/dist/exchanges/polymarket/fetchOrderBook.d.ts +0 -6
  105. package/dist/exchanges/polymarket/fetchOrderBook.js +0 -33
  106. package/dist/exchanges/polymarket/fetchTrades.d.ts +0 -9
  107. package/dist/exchanges/polymarket/fetchTrades.js +0 -43
  108. package/dist/exchanges/probable/fetchEvents.d.ts +0 -6
  109. package/dist/exchanges/probable/fetchEvents.js +0 -151
  110. package/dist/exchanges/probable/fetchMarkets.d.ts +0 -4
  111. package/dist/exchanges/probable/fetchMarkets.js +0 -239
  112. package/dist/exchanges/probable/fetchTrades.d.ts +0 -10
  113. package/dist/exchanges/probable/fetchTrades.js +0 -40
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MyriadWebSocket = void 0;
4
- const fetchOrderBook_1 = require("./fetchOrderBook");
5
4
  // Myriad API v2 does not expose a WebSocket endpoint.
6
5
  // We implement a poll-based fallback that resolves promises
7
6
  // on each polling interval, matching the CCXT Pro async pattern.
8
7
  const DEFAULT_POLL_INTERVAL = 5000; // 5 seconds
9
8
  class MyriadWebSocket {
10
9
  callApi;
10
+ fetchOrderBook;
11
11
  pollInterval;
12
12
  orderBookTimers = new Map();
13
13
  tradeTimers = new Map();
@@ -15,8 +15,9 @@ class MyriadWebSocket {
15
15
  tradeResolvers = new Map();
16
16
  lastTradeTimestamp = new Map();
17
17
  closed = false;
18
- constructor(callApi, pollInterval) {
18
+ constructor(callApi, fetchOrderBook, pollInterval) {
19
19
  this.callApi = callApi;
20
+ this.fetchOrderBook = fetchOrderBook;
20
21
  this.pollInterval = pollInterval || DEFAULT_POLL_INTERVAL;
21
22
  }
22
23
  async watchOrderBook(id) {
@@ -61,7 +62,7 @@ class MyriadWebSocket {
61
62
  startOrderBookPolling(id) {
62
63
  const poll = async () => {
63
64
  try {
64
- const book = await (0, fetchOrderBook_1.fetchOrderBook)(id, this.callApi);
65
+ const book = await this.fetchOrderBook(id);
65
66
  const resolvers = this.orderBookResolvers.get(id) || [];
66
67
  this.orderBookResolvers.set(id, []);
67
68
  for (const resolve of resolvers) {
@@ -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-03-14T16:22:11.391Z
3
+ * Generated at: 2026-03-14T21:28:31.838Z
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-03-14T16:22:11.391Z
6
+ * Generated at: 2026-03-14T21:28:31.838Z
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-03-14T16:22:11.405Z
3
+ * Generated at: 2026-03-14T21:28:31.859Z
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-03-14T16:22:11.405Z
6
+ * Generated at: 2026-03-14T21:28:31.859Z
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-03-14T16:22:11.402Z
3
+ * Generated at: 2026-03-14T21:28:31.854Z
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-03-14T16:22:11.402Z
6
+ * Generated at: 2026-03-14T21:28:31.854Z
7
7
  * Do not edit manually -- run "npm run fetch:openapi" to regenerate.
8
8
  */
9
9
  exports.polymarketGammaSpec = {
@@ -0,0 +1,99 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { MarketFilterParams, EventFetchParams, OHLCVParams, TradesParams, MyTradesParams } from '../../BaseExchange';
3
+ import { IExchangeFetcher, FetcherContext } from '../interfaces';
4
+ export interface PolymarketRawEvent {
5
+ id?: string;
6
+ slug?: string;
7
+ title?: string;
8
+ description?: string;
9
+ image?: string;
10
+ category?: string;
11
+ active?: boolean;
12
+ closed?: boolean;
13
+ tags?: Array<{
14
+ label: string;
15
+ }>;
16
+ markets?: PolymarketRawMarket[];
17
+ [key: string]: unknown;
18
+ }
19
+ export interface PolymarketRawMarket {
20
+ id?: string;
21
+ question?: string;
22
+ description?: string;
23
+ outcomes?: string | string[];
24
+ outcomePrices?: string | string[];
25
+ clobTokenIds?: string | string[];
26
+ groupItemTitle?: string;
27
+ endDate?: string;
28
+ end_date_iso?: string;
29
+ volume24hr?: number | string;
30
+ volume_24h?: number | string;
31
+ volume?: number | string;
32
+ liquidity?: number | string;
33
+ openInterest?: number | string;
34
+ open_interest?: number | string;
35
+ oneDayPriceChange?: number | string;
36
+ image?: string;
37
+ rewards?: {
38
+ liquidity?: number;
39
+ };
40
+ events?: PolymarketRawEvent[];
41
+ [key: string]: unknown;
42
+ }
43
+ export interface PolymarketRawOHLCVPoint {
44
+ t: number;
45
+ p: number;
46
+ s?: number;
47
+ v?: number;
48
+ }
49
+ export interface PolymarketRawOrderBookLevel {
50
+ price: string;
51
+ size: string;
52
+ }
53
+ export interface PolymarketRawOrderBook {
54
+ bids?: PolymarketRawOrderBookLevel[];
55
+ asks?: PolymarketRawOrderBookLevel[];
56
+ timestamp?: string | number;
57
+ }
58
+ export interface PolymarketRawTrade {
59
+ id?: string;
60
+ transactionHash?: string;
61
+ timestamp: number;
62
+ price: string;
63
+ size?: string;
64
+ amount?: string;
65
+ side?: string;
66
+ orderId?: string;
67
+ asset?: string;
68
+ }
69
+ export interface PolymarketRawPosition {
70
+ conditionId?: string;
71
+ asset?: string;
72
+ outcome?: string;
73
+ size: string;
74
+ avgPrice: string;
75
+ curPrice?: string;
76
+ cashPnl?: string;
77
+ realizedPnl?: string;
78
+ }
79
+ export declare class PolymarketFetcher implements IExchangeFetcher<PolymarketRawEvent, PolymarketRawEvent> {
80
+ private readonly ctx;
81
+ private readonly http;
82
+ constructor(ctx: FetcherContext, http: AxiosInstance);
83
+ fetchRawMarkets(params?: MarketFilterParams): Promise<PolymarketRawEvent[]>;
84
+ fetchRawEvents(params: EventFetchParams): Promise<PolymarketRawEvent[]>;
85
+ fetchRawOHLCV(id: string, params: OHLCVParams): Promise<{
86
+ history: PolymarketRawOHLCVPoint[];
87
+ }>;
88
+ fetchRawOrderBook(id: string): Promise<PolymarketRawOrderBook>;
89
+ fetchRawTrades(id: string, params: TradesParams): Promise<PolymarketRawTrade[]>;
90
+ fetchRawMyTrades(params: MyTradesParams, walletAddress: string): Promise<PolymarketRawTrade[]>;
91
+ fetchRawPositions(walletAddress: string): Promise<PolymarketRawPosition[]>;
92
+ private fetchRawMarketById;
93
+ private fetchRawMarketsByEventId;
94
+ private fetchRawMarketsBySlug;
95
+ private fetchRawMarketsSearch;
96
+ private fetchRawMarketsDefault;
97
+ private fetchRawEventsSearch;
98
+ private fetchRawEventsDefault;
99
+ }
@@ -0,0 +1,335 @@
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.PolymarketFetcher = void 0;
37
+ const utils_1 = require("./utils");
38
+ const errors_1 = require("./errors");
39
+ const GAMMA_MARKETS_URL = 'https://gamma-api.polymarket.com/markets';
40
+ class PolymarketFetcher {
41
+ ctx;
42
+ http;
43
+ constructor(ctx, http) {
44
+ this.ctx = ctx;
45
+ this.http = http;
46
+ }
47
+ // ------------------------------------------------------------------------
48
+ // Markets
49
+ // ------------------------------------------------------------------------
50
+ async fetchRawMarkets(params) {
51
+ try {
52
+ if (params?.marketId) {
53
+ return this.fetchRawMarketById(params.marketId);
54
+ }
55
+ if (params?.slug) {
56
+ return this.fetchRawMarketsBySlug(params.slug);
57
+ }
58
+ if (params?.eventId) {
59
+ return this.fetchRawMarketsByEventId(params.eventId);
60
+ }
61
+ if (params?.query) {
62
+ return this.fetchRawMarketsSearch(params);
63
+ }
64
+ return this.fetchRawMarketsDefault(params);
65
+ }
66
+ catch (error) {
67
+ throw errors_1.polymarketErrorMapper.mapError(error);
68
+ }
69
+ }
70
+ // ------------------------------------------------------------------------
71
+ // Events
72
+ // ------------------------------------------------------------------------
73
+ async fetchRawEvents(params) {
74
+ try {
75
+ if (params.eventId || params.slug) {
76
+ const queryParams = params.eventId ? { id: params.eventId } : { slug: params.slug };
77
+ const response = await this.http.get(utils_1.GAMMA_API_URL, { params: queryParams });
78
+ const events = response.data;
79
+ if (!events || events.length === 0)
80
+ return [];
81
+ return events.slice(0, params.limit || 10000);
82
+ }
83
+ if (params.query) {
84
+ return this.fetchRawEventsSearch(params);
85
+ }
86
+ return this.fetchRawEventsDefault(params);
87
+ }
88
+ catch (error) {
89
+ throw errors_1.polymarketErrorMapper.mapError(error);
90
+ }
91
+ }
92
+ // ------------------------------------------------------------------------
93
+ // OHLCV
94
+ // ------------------------------------------------------------------------
95
+ async fetchRawOHLCV(id, params) {
96
+ try {
97
+ const { mapIntervalToFidelity } = await Promise.resolve().then(() => __importStar(require('./utils')));
98
+ const fidelity = mapIntervalToFidelity(params.resolution);
99
+ const nowTs = Math.floor(Date.now() / 1000);
100
+ const ensureDate = (d) => {
101
+ if (typeof d === 'string') {
102
+ if (!d.endsWith('Z') && !d.match(/[+-]\d{2}:\d{2}$/)) {
103
+ return new Date(d + 'Z');
104
+ }
105
+ return new Date(d);
106
+ }
107
+ return d;
108
+ };
109
+ const pStart = params.start ? ensureDate(params.start) : undefined;
110
+ const pEnd = params.end ? ensureDate(params.end) : undefined;
111
+ let startTs = pStart ? Math.floor(pStart.getTime() / 1000) : 0;
112
+ const endTs = pEnd ? Math.floor(pEnd.getTime() / 1000) : nowTs;
113
+ if (!pStart) {
114
+ const count = params.limit || 100;
115
+ const durationSeconds = count * fidelity * 60;
116
+ startTs = endTs - durationSeconds;
117
+ }
118
+ const queryParams = {
119
+ market: id,
120
+ fidelity: fidelity,
121
+ startTs: startTs,
122
+ endTs: endTs,
123
+ };
124
+ const data = await this.ctx.callApi('getPricesHistory', queryParams);
125
+ return { history: data.history || [] };
126
+ }
127
+ catch (error) {
128
+ throw errors_1.polymarketErrorMapper.mapError(error);
129
+ }
130
+ }
131
+ // ------------------------------------------------------------------------
132
+ // Order Book
133
+ // ------------------------------------------------------------------------
134
+ async fetchRawOrderBook(id) {
135
+ try {
136
+ const data = await this.ctx.callApi('getBook', { token_id: id });
137
+ return data;
138
+ }
139
+ catch (error) {
140
+ throw errors_1.polymarketErrorMapper.mapError(error);
141
+ }
142
+ }
143
+ // ------------------------------------------------------------------------
144
+ // Trades
145
+ // ------------------------------------------------------------------------
146
+ async fetchRawTrades(id, params) {
147
+ try {
148
+ const queryParams = {
149
+ asset_id: id,
150
+ };
151
+ if (params.start) {
152
+ queryParams.after = Math.floor(params.start.getTime() / 1000);
153
+ }
154
+ if (params.end) {
155
+ queryParams.before = Math.floor(params.end.getTime() / 1000);
156
+ }
157
+ const trades = await this.ctx.callApi('getTrades', queryParams) || [];
158
+ return trades;
159
+ }
160
+ catch (error) {
161
+ throw errors_1.polymarketErrorMapper.mapError(error);
162
+ }
163
+ }
164
+ async fetchRawMyTrades(params, walletAddress) {
165
+ const queryParams = { user: walletAddress };
166
+ if (params?.marketId)
167
+ queryParams.market = params.marketId;
168
+ if (params?.limit)
169
+ queryParams.limit = params.limit;
170
+ if (params?.since)
171
+ queryParams.start = Math.floor(params.since.getTime() / 1000);
172
+ if (params?.until)
173
+ queryParams.end = Math.floor(params.until.getTime() / 1000);
174
+ const data = await this.ctx.callApi('getTrades', queryParams);
175
+ const trades = Array.isArray(data) ? data : (data.data || []);
176
+ return trades;
177
+ }
178
+ // ------------------------------------------------------------------------
179
+ // Positions
180
+ // ------------------------------------------------------------------------
181
+ async fetchRawPositions(walletAddress) {
182
+ const result = await this.ctx.callApi('getPositions', { user: walletAddress, limit: 100 });
183
+ return Array.isArray(result) ? result : [];
184
+ }
185
+ // ------------------------------------------------------------------------
186
+ // Private helpers -- Markets
187
+ // ------------------------------------------------------------------------
188
+ async fetchRawMarketById(marketId) {
189
+ const response = await this.http.get(GAMMA_MARKETS_URL, {
190
+ params: { id: marketId },
191
+ });
192
+ const markets = response.data;
193
+ if (!markets || markets.length === 0)
194
+ return [];
195
+ // Wrap each market in an event-like shape for consistent normalizer input
196
+ return markets.map((market) => {
197
+ const event = market.events?.[0] || market;
198
+ return { ...event, markets: [market] };
199
+ });
200
+ }
201
+ async fetchRawMarketsByEventId(eventId) {
202
+ const response = await this.http.get(utils_1.GAMMA_API_URL, {
203
+ params: { id: eventId },
204
+ });
205
+ return response.data || [];
206
+ }
207
+ async fetchRawMarketsBySlug(slug) {
208
+ const response = await this.http.get(utils_1.GAMMA_API_URL, {
209
+ params: { slug },
210
+ });
211
+ return response.data || [];
212
+ }
213
+ async fetchRawMarketsSearch(params) {
214
+ const limit = params?.limit || 250000;
215
+ const queryParams = {
216
+ q: params.query,
217
+ limit_per_type: 50,
218
+ events_status: params?.status === 'all' ? undefined : (params?.status === 'inactive' || params?.status === 'closed' ? 'closed' : 'active'),
219
+ sort: 'volume',
220
+ ascending: false,
221
+ };
222
+ return (0, utils_1.paginateSearchParallel)(utils_1.GAMMA_SEARCH_URL, queryParams, limit * 5, this.http);
223
+ }
224
+ async fetchRawMarketsDefault(params) {
225
+ const limit = params?.limit || 250000;
226
+ const offset = params?.offset || 0;
227
+ const queryParams = {
228
+ limit: limit,
229
+ offset: offset,
230
+ };
231
+ const status = params?.status || 'active';
232
+ if (status === 'active') {
233
+ queryParams.active = 'true';
234
+ queryParams.closed = 'false';
235
+ }
236
+ else if (status === 'closed' || status === 'inactive') {
237
+ queryParams.active = 'false';
238
+ queryParams.closed = 'true';
239
+ }
240
+ if (params?.sort === 'volume') {
241
+ queryParams.order = 'volume';
242
+ queryParams.ascending = 'false';
243
+ }
244
+ else if (params?.sort === 'newest') {
245
+ queryParams.order = 'startDate';
246
+ queryParams.ascending = 'false';
247
+ }
248
+ else {
249
+ queryParams.order = 'volume';
250
+ queryParams.ascending = 'false';
251
+ }
252
+ return (0, utils_1.paginateParallel)(utils_1.GAMMA_API_URL, queryParams, this.http);
253
+ }
254
+ // ------------------------------------------------------------------------
255
+ // Private helpers -- Events
256
+ // ------------------------------------------------------------------------
257
+ async fetchRawEventsSearch(params) {
258
+ const limit = params.limit || 10000;
259
+ let sortParam = 'volume';
260
+ if (params.sort === 'newest')
261
+ sortParam = 'startDate';
262
+ if (params.sort === 'liquidity')
263
+ sortParam = 'liquidity';
264
+ const queryParams = {
265
+ q: params.query,
266
+ limit_per_type: 50,
267
+ sort: sortParam,
268
+ ascending: false,
269
+ };
270
+ const status = params.status || 'active';
271
+ const fetchWithStatus = async (eventStatus) => {
272
+ const currentParams = { ...queryParams, events_status: eventStatus };
273
+ return (0, utils_1.paginateSearchParallel)(utils_1.GAMMA_SEARCH_URL, currentParams, limit * 10, this.http);
274
+ };
275
+ const filterActive = (e) => e.active === true;
276
+ const filterClosed = (e) => e.closed === true;
277
+ let events = [];
278
+ if (status === 'all') {
279
+ const [activeEvents, closedEvents] = await Promise.all([
280
+ fetchWithStatus('active'),
281
+ fetchWithStatus('closed'),
282
+ ]);
283
+ const seenIds = new Set();
284
+ events = [...activeEvents, ...closedEvents].filter(event => {
285
+ const id = event.id || event.slug;
286
+ if (seenIds.has(id))
287
+ return false;
288
+ seenIds.add(id);
289
+ return true;
290
+ });
291
+ }
292
+ else if (status === 'active') {
293
+ const rawEvents = await fetchWithStatus('active');
294
+ events = rawEvents.filter(filterActive);
295
+ }
296
+ else if (status === 'inactive' || status === 'closed') {
297
+ const rawEvents = await fetchWithStatus('closed');
298
+ events = rawEvents.filter(filterClosed);
299
+ }
300
+ const lowerQuery = params.query.toLowerCase();
301
+ const searchIn = params.searchIn || 'title';
302
+ return events.filter((event) => {
303
+ const titleMatch = (event.title || '').toLowerCase().includes(lowerQuery);
304
+ const descMatch = (event.description || '').toLowerCase().includes(lowerQuery);
305
+ if (searchIn === 'title')
306
+ return titleMatch;
307
+ if (searchIn === 'description')
308
+ return descMatch;
309
+ return titleMatch || descMatch;
310
+ }).slice(0, limit);
311
+ }
312
+ async fetchRawEventsDefault(params) {
313
+ const limit = params.limit || 10000;
314
+ const status = params.status || 'active';
315
+ let sortParam = 'volume';
316
+ if (params.sort === 'newest')
317
+ sortParam = 'startDate';
318
+ else if (params.sort === 'liquidity')
319
+ sortParam = 'liquidity';
320
+ const queryParams = {
321
+ order: sortParam,
322
+ ascending: false,
323
+ };
324
+ if (status === 'active') {
325
+ queryParams.active = 'true';
326
+ queryParams.closed = 'false';
327
+ }
328
+ else if (status === 'closed' || status === 'inactive') {
329
+ queryParams.active = 'false';
330
+ queryParams.closed = 'true';
331
+ }
332
+ return (0, utils_1.paginateParallel)(utils_1.GAMMA_API_URL, queryParams, this.http, limit);
333
+ }
334
+ }
335
+ exports.PolymarketFetcher = PolymarketFetcher;
@@ -38,6 +38,8 @@ export declare class PolymarketExchange extends PredictionMarketExchange {
38
38
  private cachedApiCreds?;
39
39
  private cachedAddress?;
40
40
  private ws?;
41
+ private readonly fetcher;
42
+ private readonly normalizer;
41
43
  constructor(options?: ExchangeCredentials | PolymarketExchangeOptions);
42
44
  get name(): string;
43
45
  /**