pmxt-core 2.20.1 → 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 (111) 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/package.json +3 -3
  58. package/dist/exchanges/baozi/fetchEvents.d.ts +0 -8
  59. package/dist/exchanges/baozi/fetchEvents.js +0 -39
  60. package/dist/exchanges/baozi/fetchMarkets.d.ts +0 -5
  61. package/dist/exchanges/baozi/fetchMarkets.js +0 -160
  62. package/dist/exchanges/baozi/fetchOHLCV.d.ts +0 -6
  63. package/dist/exchanges/baozi/fetchOHLCV.js +0 -10
  64. package/dist/exchanges/baozi/fetchOrderBook.d.ts +0 -12
  65. package/dist/exchanges/baozi/fetchOrderBook.js +0 -36
  66. package/dist/exchanges/baozi/fetchTrades.d.ts +0 -6
  67. package/dist/exchanges/baozi/fetchTrades.js +0 -10
  68. package/dist/exchanges/kalshi/fetchEvents.d.ts +0 -5
  69. package/dist/exchanges/kalshi/fetchEvents.js +0 -196
  70. package/dist/exchanges/kalshi/fetchMarkets.d.ts +0 -6
  71. package/dist/exchanges/kalshi/fetchMarkets.js +0 -247
  72. package/dist/exchanges/kalshi/fetchOHLCV.d.ts +0 -3
  73. package/dist/exchanges/kalshi/fetchOHLCV.js +0 -97
  74. package/dist/exchanges/kalshi/fetchOrderBook.d.ts +0 -2
  75. package/dist/exchanges/kalshi/fetchOrderBook.js +0 -60
  76. package/dist/exchanges/kalshi/fetchTrades.d.ts +0 -3
  77. package/dist/exchanges/kalshi/fetchTrades.js +0 -33
  78. package/dist/exchanges/limitless/fetchEvents.d.ts +0 -4
  79. package/dist/exchanges/limitless/fetchEvents.js +0 -173
  80. package/dist/exchanges/limitless/fetchMarkets.d.ts +0 -3
  81. package/dist/exchanges/limitless/fetchMarkets.js +0 -152
  82. package/dist/exchanges/limitless/fetchOHLCV.d.ts +0 -7
  83. package/dist/exchanges/limitless/fetchOHLCV.js +0 -49
  84. package/dist/exchanges/limitless/fetchOrderBook.d.ts +0 -6
  85. package/dist/exchanges/limitless/fetchOrderBook.js +0 -41
  86. package/dist/exchanges/limitless/fetchTrades.d.ts +0 -8
  87. package/dist/exchanges/limitless/fetchTrades.js +0 -27
  88. package/dist/exchanges/myriad/fetchEvents.d.ts +0 -4
  89. package/dist/exchanges/myriad/fetchEvents.js +0 -48
  90. package/dist/exchanges/myriad/fetchMarkets.d.ts +0 -4
  91. package/dist/exchanges/myriad/fetchMarkets.js +0 -102
  92. package/dist/exchanges/myriad/fetchOHLCV.d.ts +0 -3
  93. package/dist/exchanges/myriad/fetchOHLCV.js +0 -83
  94. package/dist/exchanges/myriad/fetchOrderBook.d.ts +0 -2
  95. package/dist/exchanges/myriad/fetchOrderBook.js +0 -39
  96. package/dist/exchanges/polymarket/fetchEvents.d.ts +0 -4
  97. package/dist/exchanges/polymarket/fetchEvents.js +0 -135
  98. package/dist/exchanges/polymarket/fetchMarkets.d.ts +0 -4
  99. package/dist/exchanges/polymarket/fetchMarkets.js +0 -214
  100. package/dist/exchanges/polymarket/fetchOHLCV.d.ts +0 -7
  101. package/dist/exchanges/polymarket/fetchOHLCV.js +0 -98
  102. package/dist/exchanges/polymarket/fetchOrderBook.d.ts +0 -6
  103. package/dist/exchanges/polymarket/fetchOrderBook.js +0 -33
  104. package/dist/exchanges/polymarket/fetchTrades.d.ts +0 -9
  105. package/dist/exchanges/polymarket/fetchTrades.js +0 -43
  106. package/dist/exchanges/probable/fetchEvents.d.ts +0 -6
  107. package/dist/exchanges/probable/fetchEvents.js +0 -151
  108. package/dist/exchanges/probable/fetchMarkets.d.ts +0 -4
  109. package/dist/exchanges/probable/fetchMarkets.js +0 -239
  110. package/dist/exchanges/probable/fetchTrades.d.ts +0 -10
  111. package/dist/exchanges/probable/fetchTrades.js +0 -40
@@ -1,151 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fetchEvents = fetchEvents;
7
- exports.fetchEventById = fetchEventById;
8
- exports.fetchEventBySlug = fetchEventBySlug;
9
- const axios_1 = __importDefault(require("axios"));
10
- const utils_1 = require("./utils");
11
- const errors_1 = require("./errors");
12
- async function fetchEvents(params, http = axios_1.default, callMidpoint, callSearch) {
13
- try {
14
- // Handle eventId lookup
15
- if (params.eventId) {
16
- const event = await fetchEventById(params.eventId, http, callMidpoint);
17
- return event ? [event] : [];
18
- }
19
- // Handle slug lookup
20
- if (params.slug) {
21
- const event = await fetchEventBySlug(params.slug, http, callMidpoint);
22
- return event ? [event] : [];
23
- }
24
- // Query-based search: use the search endpoint (only endpoint with text search)
25
- if (params.query) {
26
- return await searchEvents(params, http, callMidpoint, callSearch);
27
- }
28
- // Default: use the dedicated events API for listing
29
- return await fetchEventsList(params, http, callMidpoint);
30
- }
31
- catch (error) {
32
- throw errors_1.probableErrorMapper.mapError(error);
33
- }
34
- }
35
- async function fetchEventById(id, http = axios_1.default, callMidpoint) {
36
- try {
37
- const numericId = Number(id);
38
- if (isNaN(numericId))
39
- return null;
40
- const response = await http.get(`${utils_1.BASE_URL}${utils_1.EVENTS_PATH}${numericId}`);
41
- const event = (0, utils_1.mapEventToUnified)(response.data);
42
- if (event && callMidpoint)
43
- await (0, utils_1.enrichMarketsWithPrices)(event.markets, callMidpoint);
44
- return event;
45
- }
46
- catch (error) {
47
- if (isNotFoundError(error))
48
- return null;
49
- throw errors_1.probableErrorMapper.mapError(error);
50
- }
51
- }
52
- async function fetchEventBySlug(slug, http = axios_1.default, callMidpoint) {
53
- try {
54
- const response = await http.get(`${utils_1.BASE_URL}${utils_1.EVENTS_PATH}slug/${slug}`);
55
- const event = (0, utils_1.mapEventToUnified)(response.data);
56
- if (event && callMidpoint)
57
- await (0, utils_1.enrichMarketsWithPrices)(event.markets, callMidpoint);
58
- return event;
59
- }
60
- catch (error) {
61
- if (isNotFoundError(error))
62
- return null;
63
- throw errors_1.probableErrorMapper.mapError(error);
64
- }
65
- }
66
- async function fetchEventsList(params, http, callMidpoint) {
67
- const limit = params.limit || 20;
68
- const page = params.offset ? Math.floor(params.offset / limit) + 1 : 1;
69
- const queryParams = {
70
- page,
71
- limit,
72
- };
73
- // Map status
74
- if (params.status) {
75
- switch (params.status) {
76
- case 'active':
77
- queryParams.status = 'active';
78
- break;
79
- case 'inactive':
80
- case 'closed':
81
- queryParams.status = 'closed';
82
- break;
83
- case 'all':
84
- queryParams.status = 'all';
85
- break;
86
- }
87
- }
88
- else {
89
- queryParams.status = 'active';
90
- }
91
- // Default sort by volume
92
- queryParams.sort = 'volume';
93
- queryParams.ascending = false;
94
- const response = await http.get(`${utils_1.BASE_URL}${utils_1.EVENTS_PATH}`, {
95
- params: queryParams,
96
- });
97
- const events = response.data?.events || [];
98
- const result = events
99
- .map((event) => (0, utils_1.mapEventToUnified)(event))
100
- .filter((e) => e !== null);
101
- const allMarkets = result.flatMap((e) => e.markets);
102
- if (callMidpoint)
103
- await (0, utils_1.enrichMarketsWithPrices)(allMarkets, callMidpoint);
104
- return result;
105
- }
106
- async function searchEvents(params, http, callMidpoint, callSearch) {
107
- const limit = params.limit || 20;
108
- const page = params.offset ? Math.floor(params.offset / limit) + 1 : 1;
109
- const queryParams = {
110
- q: params.query,
111
- page,
112
- limit,
113
- events_status: mapStatus(params.status),
114
- keep_closed_markets: params.status === 'all' || params.status === 'inactive' || params.status === 'closed' ? 1 : 0,
115
- };
116
- const searchData = callSearch
117
- ? await callSearch(queryParams)
118
- : (await http.get(`${utils_1.BASE_URL}${utils_1.SEARCH_PATH}`, { params: queryParams })).data;
119
- const events = searchData?.events || [];
120
- const result = events
121
- .map((event) => (0, utils_1.mapEventToUnified)(event))
122
- .filter((e) => e !== null);
123
- const allMarkets = result.flatMap((e) => e.markets);
124
- if (callMidpoint)
125
- await (0, utils_1.enrichMarketsWithPrices)(allMarkets, callMidpoint);
126
- return result;
127
- }
128
- function isNotFoundError(error) {
129
- const status = error.response?.status;
130
- if (status === 404 || status === 400)
131
- return true;
132
- // API returns 500 with plain-text "not found" message for missing resources
133
- if (status === 500) {
134
- const data = error.response?.data;
135
- const msg = typeof data === 'string' ? data : (data?.detail || data?.message || '');
136
- return /not found/i.test(String(msg));
137
- }
138
- return false;
139
- }
140
- function mapStatus(status) {
141
- switch (status) {
142
- case 'inactive':
143
- case 'closed':
144
- return 'closed';
145
- case 'all':
146
- return 'all';
147
- case 'active':
148
- default:
149
- return 'active';
150
- }
151
- }
@@ -1,4 +0,0 @@
1
- import { MarketFetchParams } from '../../BaseExchange';
2
- import { UnifiedMarket } from '../../types';
3
- import { AxiosInstance } from 'axios';
4
- export declare function fetchMarkets(params?: MarketFetchParams, http?: AxiosInstance, callMidpoint?: (tokenId: string) => Promise<any>, callSearch?: (params: any) => Promise<any>): Promise<UnifiedMarket[]>;
@@ -1,239 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fetchMarkets = fetchMarkets;
7
- const axios_1 = __importDefault(require("axios"));
8
- const utils_1 = require("./utils");
9
- const errors_1 = require("./errors");
10
- async function fetchMarkets(params, http = axios_1.default, callMidpoint, callSearch) {
11
- try {
12
- // Handle marketId lookup (numeric ID or slug)
13
- if (params?.marketId) {
14
- return await fetchMarketByIdOrSlug(params.marketId, http, callMidpoint, callSearch);
15
- }
16
- // Slug-based lookup: try market ID or slug via dedicated endpoint
17
- if (params?.slug) {
18
- return await fetchMarketByIdOrSlug(params.slug, http, callMidpoint, callSearch);
19
- }
20
- // Handle outcomeId lookup (no direct API, fetch and filter client-side)
21
- if (params?.outcomeId) {
22
- const markets = await fetchMarketsList(params, http, callMidpoint);
23
- return markets.filter(m => m.outcomes.some(o => o.outcomeId === params.outcomeId));
24
- }
25
- // Handle eventId lookup (use markets list with eventId param)
26
- if (params?.eventId) {
27
- return await fetchMarketsList(params, http, callMidpoint);
28
- }
29
- // Query-based search: use the search endpoint (only endpoint with text search)
30
- if (params?.query) {
31
- return await searchAndExtractMarkets(params.query, params, http, callMidpoint, callSearch);
32
- }
33
- // Default: use the dedicated markets API for listing
34
- return await fetchMarketsList(params, http, callMidpoint);
35
- }
36
- catch (error) {
37
- throw errors_1.probableErrorMapper.mapError(error);
38
- }
39
- }
40
- async function fetchMarketByIdOrSlug(slug, http, callMidpoint, callSearch) {
41
- let cleanSlug = slug;
42
- let marketIdFromQuery = null;
43
- // Handle URLs or partial URLs with query params (e.g., opinion-...-launch?market=584)
44
- if (slug.includes('?')) {
45
- try {
46
- const urlParts = slug.split('?');
47
- cleanSlug = urlParts[0];
48
- const query = urlParts[1];
49
- const params = new URLSearchParams(query);
50
- marketIdFromQuery = params.get('market');
51
- // If we have a market ID from the query, try that first
52
- if (marketIdFromQuery) {
53
- const result = await fetchMarketByIdOrSlug(marketIdFromQuery, http, callMidpoint);
54
- if (result.length > 0)
55
- return result;
56
- }
57
- }
58
- catch (e) {
59
- // Fall back to original slug if parsing fails
60
- }
61
- }
62
- // Try numeric ID lookup first
63
- const numericId = Number(cleanSlug);
64
- if (!isNaN(numericId) && String(numericId) === cleanSlug) {
65
- try {
66
- const response = await http.get(`${utils_1.BASE_URL}${utils_1.MARKETS_PATH}${numericId}`);
67
- const mapped = (0, utils_1.mapMarketToUnified)(response.data, response.data?.event);
68
- const results = mapped ? [mapped] : [];
69
- if (callMidpoint)
70
- await (0, utils_1.enrichMarketsWithPrices)(results, callMidpoint);
71
- return results;
72
- }
73
- catch (error) {
74
- if (isMarketNotFoundError(error)) {
75
- // Individual market endpoint returned 500/404; fall back to list and filter
76
- const allMarkets = await fetchMarketsList({ limit: 100 }, http, callMidpoint);
77
- const match = allMarkets.filter(m => m.marketId === cleanSlug);
78
- if (match.length > 0)
79
- return match;
80
- }
81
- else {
82
- throw error;
83
- }
84
- }
85
- }
86
- // Fall back to search for slug-based matching
87
- return await searchAndExtractMarkets(cleanSlug, { slug: cleanSlug }, http, callMidpoint, callSearch);
88
- }
89
- async function fetchMarketsList(params, http, callMidpoint) {
90
- const limit = params?.limit || 20;
91
- const page = params?.offset ? Math.floor(params.offset / limit) + 1 : 1;
92
- const queryParams = {
93
- page,
94
- limit,
95
- };
96
- // Map status filters
97
- if (params?.status) {
98
- switch (params.status) {
99
- case 'active':
100
- queryParams.active = true;
101
- break;
102
- case 'inactive':
103
- case 'closed':
104
- queryParams.closed = true;
105
- break;
106
- case 'all':
107
- // No filter
108
- break;
109
- }
110
- }
111
- else {
112
- queryParams.active = true;
113
- }
114
- // Map event_id if provided
115
- if (params?.eventId) {
116
- queryParams.event_id = params.eventId;
117
- }
118
- const response = await http.get(`${utils_1.BASE_URL}${utils_1.MARKETS_PATH}`, {
119
- params: queryParams,
120
- });
121
- const markets = response.data?.markets || [];
122
- const allMarkets = [];
123
- for (const market of markets) {
124
- const mapped = (0, utils_1.mapMarketToUnified)(market, market.event);
125
- if (mapped)
126
- allMarkets.push(mapped);
127
- }
128
- if (callMidpoint)
129
- await (0, utils_1.enrichMarketsWithPrices)(allMarkets, callMidpoint);
130
- return allMarkets;
131
- }
132
- async function searchAndExtractMarkets(query, params, http, callMidpoint, callSearch) {
133
- const limit = params?.limit || 20;
134
- const page = params?.offset ? Math.floor(params.offset / limit) + 1 : 1;
135
- // Improve search for slugs: if the query looks like a slug (has dashes),
136
- // try searching with the first few words as keywords.
137
- // The Probable search engine often fails with long, exact slug-like queries.
138
- let searchQuery = query;
139
- if (query.includes('-')) {
140
- const tokens = query.split('-');
141
- // Use first 3 tokens for search to cast a wider but relevant net
142
- searchQuery = tokens.slice(0, 3).join(' ');
143
- }
144
- const queryParams = {
145
- q: searchQuery,
146
- page,
147
- limit,
148
- };
149
- // Map status
150
- if (params?.status) {
151
- switch (params.status) {
152
- case 'inactive':
153
- case 'closed':
154
- queryParams.events_status = 'closed';
155
- queryParams.keep_closed_markets = 1;
156
- break;
157
- case 'all':
158
- queryParams.events_status = 'all';
159
- queryParams.keep_closed_markets = 1;
160
- break;
161
- case 'active':
162
- default:
163
- queryParams.events_status = 'active';
164
- queryParams.keep_closed_markets = 0;
165
- break;
166
- }
167
- }
168
- else if (params?.slug) {
169
- // For slug lookups, default to 'all' status to be safe
170
- queryParams.events_status = 'all';
171
- queryParams.keep_closed_markets = 1;
172
- }
173
- else {
174
- queryParams.events_status = 'active';
175
- queryParams.keep_closed_markets = 0;
176
- }
177
- // Map sort
178
- if (params?.sort) {
179
- switch (params.sort) {
180
- case 'volume':
181
- queryParams.sort = 'volume';
182
- break;
183
- case 'newest':
184
- queryParams.sort = 'created_at';
185
- queryParams.ascending = false;
186
- break;
187
- }
188
- }
189
- const searchData = callSearch
190
- ? await callSearch(queryParams)
191
- : (await http.get(`${utils_1.BASE_URL}${utils_1.SEARCH_PATH}`, { params: queryParams })).data;
192
- const events = searchData?.events || [];
193
- const allMarkets = [];
194
- for (const event of events) {
195
- if (event.markets && Array.isArray(event.markets)) {
196
- for (const market of event.markets) {
197
- const mapped = (0, utils_1.mapMarketToUnified)(market, event);
198
- if (mapped) {
199
- // Inject a temporary field for slug matching
200
- mapped._eventSlug = event.slug;
201
- allMarkets.push(mapped);
202
- }
203
- }
204
- }
205
- }
206
- // If slug lookup, try to find exact match
207
- if (params?.slug) {
208
- const exact = allMarkets.filter(m => m.marketId === params.slug ||
209
- m.url.includes(params.slug) ||
210
- m._eventSlug === params.slug);
211
- // Remove temporary fields before returning
212
- for (const m of exact) {
213
- delete m._eventSlug;
214
- }
215
- if (exact.length > 0) {
216
- if (callMidpoint)
217
- await (0, utils_1.enrichMarketsWithPrices)(exact, callMidpoint);
218
- return exact;
219
- }
220
- }
221
- // Clean up temporary fields for all markets if no exact match found
222
- for (const m of allMarkets) {
223
- delete m._eventSlug;
224
- }
225
- if (callMidpoint)
226
- await (0, utils_1.enrichMarketsWithPrices)(allMarkets, callMidpoint);
227
- return allMarkets;
228
- }
229
- function isMarketNotFoundError(error) {
230
- const status = error.response?.status;
231
- if (status === 404 || status === 400)
232
- return true;
233
- if (status === 500) {
234
- const data = error.response?.data;
235
- const msg = typeof data === 'string' ? data : (data?.detail || data?.message || '');
236
- return /not found|failed to retrieve/i.test(String(msg));
237
- }
238
- return false;
239
- }
@@ -1,10 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- import { TradesParams, HistoryFilterParams } from '../../BaseExchange';
3
- import { Trade } from '../../types';
4
- /**
5
- * Fetch trade history for a specific token using the @prob/clob SDK.
6
- * @param id - The token ID (outcomeId)
7
- * @param params - Trade query parameters
8
- * @param client - Authenticated ClobClient instance
9
- */
10
- export declare function fetchTrades(id: string, params: TradesParams | HistoryFilterParams, client: any, http?: AxiosInstance): Promise<Trade[]>;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fetchTrades = fetchTrades;
7
- const axios_1 = __importDefault(require("axios"));
8
- const errors_1 = require("./errors");
9
- /**
10
- * Fetch trade history for a specific token using the @prob/clob SDK.
11
- * @param id - The token ID (outcomeId)
12
- * @param params - Trade query parameters
13
- * @param client - Authenticated ClobClient instance
14
- */
15
- async function fetchTrades(id, params, client, http = axios_1.default) {
16
- try {
17
- const queryParams = {
18
- tokenId: id,
19
- };
20
- if (params.limit) {
21
- queryParams.limit = params.limit;
22
- }
23
- const response = await client.getTrades(queryParams);
24
- const trades = Array.isArray(response) ? response : response?.data || [];
25
- return trades.map((trade) => ({
26
- id: String(trade.id || trade.tradeId || `${trade.time}-${trade.price}`),
27
- timestamp: typeof trade.time === 'number'
28
- ? (trade.time < 1e12 ? trade.time * 1000 : trade.time)
29
- : Date.now(),
30
- price: parseFloat(String(trade.price || '0')),
31
- amount: parseFloat(String(trade.qty || trade.size || trade.amount || '0')),
32
- side: trade.side === 'BUY' ? 'buy'
33
- : trade.side === 'SELL' ? 'sell'
34
- : 'unknown',
35
- }));
36
- }
37
- catch (error) {
38
- throw errors_1.probableErrorMapper.mapError(error);
39
- }
40
- }