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,152 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.fetchMarkets = fetchMarkets;
37
- const utils_1 = require("./utils");
38
- const errors_1 = require("./errors");
39
- async function fetchMarkets(params, apiKey, callApi) {
40
- // Limitless API currently only supports fetching active markets for lists
41
- // Early return to avoid SDK initialization in tests
42
- if (params?.status === 'inactive' || params?.status === 'closed') {
43
- return [];
44
- }
45
- // Lazy import SDK to avoid initialization when not needed
46
- const { HttpClient, MarketFetcher } = await Promise.resolve().then(() => __importStar(require('@limitless-exchange/sdk')));
47
- try {
48
- // Create HTTP client (no auth needed for market data)
49
- const httpClient = new HttpClient({
50
- baseURL: utils_1.LIMITLESS_API_URL,
51
- apiKey: apiKey, // Optional - not required for public market data
52
- });
53
- const marketFetcher = new MarketFetcher(httpClient);
54
- // Handle marketId lookup (Limitless marketId is the slug)
55
- if (params?.marketId) {
56
- return await fetchMarketsBySlug(marketFetcher, params.marketId);
57
- }
58
- // Handle slug-based lookup
59
- if (params?.slug) {
60
- return await fetchMarketsBySlug(marketFetcher, params.slug);
61
- }
62
- // Handle outcomeId lookup (no direct API, fetch and filter client-side)
63
- if (params?.outcomeId) {
64
- const markets = await fetchMarketsDefault(marketFetcher, params);
65
- return markets.filter(m => m.outcomes.some(o => o.outcomeId === params.outcomeId));
66
- }
67
- // Handle eventId lookup (same as slug for Limitless)
68
- if (params?.eventId) {
69
- return await fetchMarketsBySlug(marketFetcher, params.eventId);
70
- }
71
- // Handle query-based search
72
- if (params?.query) {
73
- return await searchMarkets(params.query, params, callApi);
74
- }
75
- // Default: fetch active markets
76
- return await fetchMarketsDefault(marketFetcher, params);
77
- }
78
- catch (error) {
79
- throw errors_1.limitlessErrorMapper.mapError(error);
80
- }
81
- }
82
- async function fetchMarketsBySlug(marketFetcher, slug) {
83
- const market = await marketFetcher.getMarket(slug);
84
- if (!market)
85
- return [];
86
- const unifiedMarket = (0, utils_1.mapMarketToUnified)(market);
87
- return unifiedMarket ? [unifiedMarket] : [];
88
- }
89
- async function searchMarkets(query, params, callApi) {
90
- // NOTE: The Limitless /markets/search endpoint currently only returns active/funded markets.
91
- // It does not include expired or resolved markets in search results.
92
- const data = await callApi('MarketSearchController_search', {
93
- query: query,
94
- limit: params?.limit || 250000,
95
- page: params?.page || 1,
96
- similarityThreshold: params?.similarityThreshold || 0.5,
97
- });
98
- const rawResults = data?.markets || [];
99
- const allMarkets = [];
100
- for (const res of rawResults) {
101
- if (res.markets && Array.isArray(res.markets)) {
102
- // It's a group market, extract individual markets
103
- for (const child of res.markets) {
104
- const mapped = (0, utils_1.mapMarketToUnified)(child);
105
- if (mapped)
106
- allMarkets.push(mapped);
107
- }
108
- }
109
- else {
110
- const mapped = (0, utils_1.mapMarketToUnified)(res);
111
- if (mapped)
112
- allMarkets.push(mapped);
113
- }
114
- }
115
- return allMarkets
116
- .filter((m) => m !== null && m.outcomes.length > 0)
117
- .slice(0, params?.limit || 250000);
118
- }
119
- async function fetchMarketsDefault(marketFetcher, params) {
120
- const limit = params?.limit || 250000;
121
- const offset = params?.offset || 0;
122
- // Map sort parameter to SDK's sortBy
123
- let sortBy = 'lp_rewards';
124
- if (params?.sort === 'volume') {
125
- sortBy = 'high_value';
126
- }
127
- try {
128
- // Use pagination utility to handle limits > 25
129
- // The utility over-fetches to account for markets that get filtered out
130
- const totalToFetch = limit + offset;
131
- const rawMarkets = await (0, utils_1.paginateLimitlessMarkets)(marketFetcher, totalToFetch, sortBy);
132
- // Map and filter markets
133
- const unifiedMarkets = [];
134
- for (const market of rawMarkets) {
135
- const unifiedMarket = (0, utils_1.mapMarketToUnified)(market);
136
- // Only include markets that are valid and have outcomes (compliance requirement)
137
- if (unifiedMarket && unifiedMarket.outcomes.length > 0) {
138
- unifiedMarkets.push(unifiedMarket);
139
- }
140
- }
141
- // If local sorting is needed (SDK already sorts by sortBy parameter)
142
- if (params?.sort === 'volume') {
143
- unifiedMarkets.sort((a, b) => (b.volume ?? 0) - (a.volume ?? 0));
144
- }
145
- // Apply offset and limit to the FILTERED results
146
- const marketsAfterOffset = offset > 0 ? unifiedMarkets.slice(offset) : unifiedMarkets;
147
- return marketsAfterOffset.slice(0, limit);
148
- }
149
- catch (error) {
150
- throw errors_1.limitlessErrorMapper.mapError(error);
151
- }
152
- }
@@ -1,7 +0,0 @@
1
- import { OHLCVParams } from '../../BaseExchange';
2
- import { PriceCandle } from '../../types';
3
- /**
4
- * Fetch historical price data (candles) for a specific market.
5
- * @param id - The market slug
6
- */
7
- export declare function fetchOHLCV(id: string, params: OHLCVParams, callApi: (operationId: string, params?: Record<string, any>) => Promise<any>): Promise<PriceCandle[]>;
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchOHLCV = fetchOHLCV;
4
- const utils_1 = require("./utils");
5
- const validation_1 = require("../../utils/validation");
6
- const errors_1 = require("./errors");
7
- /**
8
- * Fetch historical price data (candles) for a specific market.
9
- * @param id - The market slug
10
- */
11
- async function fetchOHLCV(id, params, callApi) {
12
- (0, validation_1.validateIdFormat)(id, 'OHLCV');
13
- // Validate resolution is provided
14
- if (!params.resolution) {
15
- throw new Error('fetchOHLCV requires a resolution parameter. Use OHLCVParams with resolution specified.');
16
- }
17
- try {
18
- const fidelity = (0, utils_1.mapIntervalToFidelity)(params.resolution);
19
- const data = await callApi('MarketOrderbookController_getHistoricalPrice', { slug: id, fidelity });
20
- const prices = data.prices || [];
21
- // Map price points to pmxt PriceCandle format
22
- // The API returns price points, so we treat each point as a candle
23
- let candles = prices.map((p) => {
24
- const price = Number(p.price);
25
- const ts = Number(p.timestamp);
26
- return {
27
- timestamp: ts,
28
- open: price,
29
- high: price,
30
- low: price,
31
- close: price,
32
- volume: 0 // Volume not provided in this specific endpoint
33
- };
34
- }).sort((a, b) => a.timestamp - b.timestamp);
35
- if (params.start) {
36
- candles = candles.filter((c) => c.timestamp >= params.start.getTime());
37
- }
38
- if (params.end) {
39
- candles = candles.filter((c) => c.timestamp <= params.end.getTime());
40
- }
41
- if (params.limit) {
42
- candles = candles.slice(0, params.limit);
43
- }
44
- return candles;
45
- }
46
- catch (error) {
47
- throw errors_1.limitlessErrorMapper.mapError(error);
48
- }
49
- }
@@ -1,6 +0,0 @@
1
- import { OrderBook } from '../../types';
2
- /**
3
- * Fetch the current order book for a specific market.
4
- * @param id - The market slug (preferred) or CLOB token ID
5
- */
6
- export declare function fetchOrderBook(id: string, callApi: (operationId: string, params?: Record<string, any>) => Promise<any>): Promise<OrderBook>;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchOrderBook = fetchOrderBook;
4
- const validation_1 = require("../../utils/validation");
5
- // Limitless uses USDC with 6 decimals
6
- const USDC_DECIMALS = 6;
7
- const USDC_SCALE = Math.pow(10, USDC_DECIMALS);
8
- /**
9
- * Convert raw orderbook size from smallest unit to human-readable USDC amount.
10
- */
11
- function convertSize(rawSize) {
12
- return rawSize / USDC_SCALE;
13
- }
14
- /**
15
- * Fetch the current order book for a specific market.
16
- * @param id - The market slug (preferred) or CLOB token ID
17
- */
18
- async function fetchOrderBook(id, callApi) {
19
- (0, validation_1.validateIdFormat)(id, 'OrderBook');
20
- try {
21
- const data = await callApi('MarketOrderbookController_getOrderbook', { slug: id });
22
- // Response format: { bids: [{price: 0.52, size: 100000000}], asks: [...] }
23
- // Sizes are in smallest unit (USDC with 6 decimals), convert to human-readable
24
- const bids = (data.bids || []).map((level) => ({
25
- price: parseFloat(level.price),
26
- size: convertSize(parseFloat(level.size))
27
- })).sort((a, b) => b.price - a.price);
28
- const asks = (data.asks || []).map((level) => ({
29
- price: parseFloat(level.price),
30
- size: convertSize(parseFloat(level.size))
31
- })).sort((a, b) => a.price - b.price);
32
- return {
33
- bids,
34
- asks,
35
- timestamp: Date.now() // API doesn't seem to return a specific timestamp in the root anymore
36
- };
37
- }
38
- catch (error) {
39
- return { bids: [], asks: [] };
40
- }
41
- }
@@ -1,8 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- import { HistoryFilterParams, TradesParams } from '../../BaseExchange';
3
- import { Trade } from '../../types';
4
- /**
5
- * Fetch trade history for a specific market or user.
6
- * @param id - The market slug or wallet address
7
- */
8
- export declare function fetchTrades(id: string, params: TradesParams | HistoryFilterParams, http?: AxiosInstance): Promise<Trade[]>;
@@ -1,27 +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 market or user.
11
- * @param id - The market slug or wallet address
12
- */
13
- async function fetchTrades(id, params, http = axios_1.default) {
14
- try {
15
- // Limitless API v1 does not provide a public endpoint to fetch trades for a specific market/outcome.
16
- // The previous implementation used /portfolio/trades which returns the *authenticated user's* trades,
17
- // not the market's trades. This caused compliance tests to fail because they expect public data
18
- // (and a fresh test account has 0 trades).
19
- //
20
- // Until a public /markets/{slug}/trades endpoint exists, we mark this as not implemented
21
- // so compliance tests can correctly skip it.
22
- throw new Error('Limitless fetchTrades not implemented: No public market trades API available.');
23
- }
24
- catch (error) {
25
- throw errors_1.limitlessErrorMapper.mapError(error);
26
- }
27
- }
@@ -1,4 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- import { EventFetchParams } from '../../BaseExchange';
3
- import { UnifiedEvent } from '../../types';
4
- export declare function fetchEvents(params: EventFetchParams, headers?: Record<string, string>, http?: AxiosInstance): Promise<UnifiedEvent[]>;
@@ -1,48 +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
- const axios_1 = __importDefault(require("axios"));
8
- const utils_1 = require("./utils");
9
- const errors_1 = require("./errors");
10
- async function fetchEvents(params, headers, http = axios_1.default) {
11
- try {
12
- if (params.eventId) {
13
- return await fetchQuestionById(params.eventId, headers, http);
14
- }
15
- if (params.slug) {
16
- return await fetchQuestionById(params.slug, headers, http);
17
- }
18
- const limit = params.limit || 100;
19
- const queryParams = {
20
- page: 1,
21
- limit: Math.min(limit, 100),
22
- };
23
- if (params.query) {
24
- queryParams.keyword = params.query;
25
- }
26
- const response = await http.get(`${utils_1.BASE_URL}/questions`, {
27
- params: queryParams,
28
- headers,
29
- });
30
- const questions = response.data.data || response.data.questions || [];
31
- const events = [];
32
- for (const q of questions) {
33
- const event = (0, utils_1.mapQuestionToEvent)(q);
34
- if (event)
35
- events.push(event);
36
- }
37
- return events.slice(0, limit);
38
- }
39
- catch (error) {
40
- throw errors_1.myriadErrorMapper.mapError(error);
41
- }
42
- }
43
- async function fetchQuestionById(id, headers, http) {
44
- const response = await http.get(`${utils_1.BASE_URL}/questions/${id}`, { headers });
45
- const question = response.data.data || response.data;
46
- const event = (0, utils_1.mapQuestionToEvent)(question);
47
- return event ? [event] : [];
48
- }
@@ -1,4 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- import { MarketFetchParams } from '../../BaseExchange';
3
- import { UnifiedMarket } from '../../types';
4
- export declare function fetchMarkets(params?: MarketFetchParams, headers?: Record<string, string>, http?: AxiosInstance): Promise<UnifiedMarket[]>;
@@ -1,102 +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
- const MAX_PAGE_SIZE = 100;
11
- async function fetchMarkets(params, headers, http = axios_1.default) {
12
- try {
13
- if (params?.marketId) {
14
- return await fetchMarketById(params.marketId, headers, http);
15
- }
16
- if (params?.slug) {
17
- return await fetchMarketBySlug(params.slug, headers, http);
18
- }
19
- const limit = params?.limit || 100;
20
- const queryParams = {
21
- page: params?.page || 1,
22
- limit: Math.min(limit, MAX_PAGE_SIZE),
23
- };
24
- if (params?.query) {
25
- queryParams.keyword = params.query;
26
- }
27
- const myriadState = (0, utils_1.mapStatusToMyriad)(params?.status);
28
- if (myriadState) {
29
- queryParams.state = myriadState;
30
- }
31
- if (params?.sort === 'volume') {
32
- queryParams.sort = 'volume';
33
- queryParams.order = 'desc';
34
- }
35
- else if (params?.sort === 'liquidity') {
36
- queryParams.sort = 'liquidity';
37
- queryParams.order = 'desc';
38
- }
39
- else if (params?.sort === 'newest') {
40
- queryParams.sort = 'published_at';
41
- queryParams.order = 'desc';
42
- }
43
- // If we need more than one page, paginate
44
- if (limit <= MAX_PAGE_SIZE) {
45
- const response = await http.get(`${utils_1.BASE_URL}/markets`, {
46
- params: queryParams,
47
- headers,
48
- });
49
- const markets = response.data.data || response.data.markets || [];
50
- return markets.map(utils_1.mapMarketToUnified).filter(Boolean);
51
- }
52
- // Paginate through multiple pages
53
- const allMarkets = [];
54
- let page = 1;
55
- const maxPages = Math.ceil(limit / MAX_PAGE_SIZE);
56
- while (page <= maxPages) {
57
- queryParams.page = page;
58
- queryParams.limit = MAX_PAGE_SIZE;
59
- const response = await http.get(`${utils_1.BASE_URL}/markets`, {
60
- params: queryParams,
61
- headers,
62
- });
63
- const data = response.data;
64
- const markets = data.data || data.markets || [];
65
- for (const m of markets) {
66
- const um = (0, utils_1.mapMarketToUnified)(m);
67
- if (um)
68
- allMarkets.push(um);
69
- }
70
- const pagination = data.pagination;
71
- if (!pagination?.hasNext || markets.length === 0)
72
- break;
73
- page++;
74
- }
75
- return allMarkets.slice(0, limit);
76
- }
77
- catch (error) {
78
- throw errors_1.myriadErrorMapper.mapError(error);
79
- }
80
- }
81
- async function fetchMarketById(marketId, headers, http) {
82
- // marketId format: {networkId}:{id}
83
- const parts = marketId.split(':');
84
- if (parts.length !== 2) {
85
- // Try as slug
86
- return fetchMarketBySlug(marketId, headers, http);
87
- }
88
- const [networkId, id] = parts;
89
- const response = await http.get(`${utils_1.BASE_URL}/markets/${id}`, {
90
- params: { network_id: Number(networkId) },
91
- headers,
92
- });
93
- const market = response.data.data || response.data;
94
- const um = (0, utils_1.mapMarketToUnified)(market);
95
- return um ? [um] : [];
96
- }
97
- async function fetchMarketBySlug(slug, headers, http) {
98
- const response = await http.get(`${utils_1.BASE_URL}/markets/${slug}`, { headers });
99
- const market = response.data.data || response.data;
100
- const um = (0, utils_1.mapMarketToUnified)(market);
101
- return um ? [um] : [];
102
- }
@@ -1,3 +0,0 @@
1
- import { OHLCVParams } from '../../BaseExchange';
2
- import { PriceCandle } from '../../types';
3
- export declare function fetchOHLCV(id: string, params: OHLCVParams, callApi: (operationId: string, params?: Record<string, any>) => Promise<any>): Promise<PriceCandle[]>;
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchOHLCV = fetchOHLCV;
4
- const errors_1 = require("./errors");
5
- // Myriad provides price charts via GET /markets/:id with these timeframes:
6
- // - 24h: 5-minute buckets (max 288)
7
- // - 7d: 30-minute buckets (max 336)
8
- // - 30d: 4-hour buckets (max 180)
9
- // - all: 4-hour buckets
10
- function selectTimeframe(interval) {
11
- switch (interval) {
12
- case '1m':
13
- case '5m':
14
- return '24h';
15
- case '15m':
16
- case '1h':
17
- return '7d';
18
- case '6h':
19
- case '1d':
20
- return '30d';
21
- default:
22
- return '7d';
23
- }
24
- }
25
- async function fetchOHLCV(id, params, callApi) {
26
- if (!params.resolution) {
27
- throw new Error('fetchOHLCV requires a resolution parameter.');
28
- }
29
- try {
30
- // id format: {networkId}:{marketId}:{outcomeId}
31
- // We need the marketId and networkId to fetch the market, then extract the outcome's price_charts
32
- const parts = id.split(':');
33
- if (parts.length < 2) {
34
- throw new Error(`Invalid Myriad outcome ID format: "${id}". Expected "{networkId}:{marketId}:{outcomeId}".`);
35
- }
36
- const networkId = parts[0];
37
- const marketId = parts[1];
38
- const outcomeId = parts.length >= 3 ? parts[2] : undefined;
39
- const response = await callApi('getMarkets', { id: marketId, network_id: Number(networkId) });
40
- const market = response.data || response;
41
- const outcomes = market.outcomes || [];
42
- // Find the target outcome
43
- let targetOutcome = outcomes[0];
44
- if (outcomeId !== undefined) {
45
- const found = outcomes.find((o) => String(o.id) === outcomeId);
46
- if (found)
47
- targetOutcome = found;
48
- }
49
- if (!targetOutcome || !targetOutcome.price_charts) {
50
- return [];
51
- }
52
- // price_charts is an object with numeric keys (0-3), each containing:
53
- // { timeframe: '24h'|'7d'|'30d'|'all', prices: [{value, timestamp, date}] }
54
- const desiredTimeframe = selectTimeframe(params.resolution);
55
- const charts = targetOutcome.price_charts;
56
- let prices = null;
57
- for (const key of Object.keys(charts)) {
58
- const chart = charts[key];
59
- if (chart && chart.timeframe === desiredTimeframe && Array.isArray(chart.prices)) {
60
- prices = chart.prices;
61
- break;
62
- }
63
- }
64
- if (!prices || prices.length === 0) {
65
- return [];
66
- }
67
- const candles = prices.map((point) => ({
68
- timestamp: point.timestamp ? point.timestamp * 1000 : Date.now(),
69
- open: Number(point.value || 0),
70
- high: Number(point.value || 0),
71
- low: Number(point.value || 0),
72
- close: Number(point.value || 0),
73
- volume: undefined,
74
- }));
75
- if (params.limit && candles.length > params.limit) {
76
- return candles.slice(-params.limit);
77
- }
78
- return candles;
79
- }
80
- catch (error) {
81
- throw errors_1.myriadErrorMapper.mapError(error);
82
- }
83
- }
@@ -1,2 +0,0 @@
1
- import { OrderBook } from '../../types';
2
- export declare function fetchOrderBook(id: string, callApi: (operationId: string, params?: Record<string, any>) => Promise<any>): Promise<OrderBook>;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchOrderBook = fetchOrderBook;
4
- const errors_1 = require("./errors");
5
- // Myriad is AMM-based -- there is no native order book.
6
- // We synthesize a minimal order book from the current outcome price
7
- // and quote data to give callers a consistent interface.
8
- async function fetchOrderBook(id, callApi) {
9
- try {
10
- // id format: {networkId}:{marketId}:{outcomeId}
11
- const parts = id.split(':');
12
- if (parts.length < 3) {
13
- throw new Error(`Invalid Myriad outcome ID format: "${id}". Expected "{networkId}:{marketId}:{outcomeId}".`);
14
- }
15
- const [networkId, marketId, outcomeId] = parts;
16
- // Fetch the market to get current prices
17
- const response = await callApi('getMarkets', { id: marketId, network_id: Number(networkId) });
18
- const market = response.data || response;
19
- const outcomes = market.outcomes || [];
20
- const outcome = outcomes.find((o) => String(o.id) === outcomeId) || outcomes[0];
21
- if (!outcome) {
22
- return { bids: [], asks: [], timestamp: Date.now() };
23
- }
24
- const price = Number(outcome.price) || 0.5;
25
- const liquidity = Number(market.liquidity || 0);
26
- // For AMM markets, we represent the current price as a single-level book.
27
- // The spread is zero (AMM provides continuous liquidity at the current price).
28
- // Size is derived from the market's liquidity.
29
- const size = liquidity > 0 ? liquidity : 1;
30
- return {
31
- bids: [{ price, size }],
32
- asks: [{ price, size }],
33
- timestamp: Date.now(),
34
- };
35
- }
36
- catch (error) {
37
- throw errors_1.myriadErrorMapper.mapError(error);
38
- }
39
- }
@@ -1,4 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- import { EventFetchParams } from '../../BaseExchange';
3
- import { UnifiedEvent } from '../../types';
4
- export declare function fetchEvents(params: EventFetchParams, http?: AxiosInstance): Promise<UnifiedEvent[]>;