pmxt-core 2.20.1 → 2.20.3
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.
- package/dist/exchanges/baozi/fetcher.d.ts +40 -0
- package/dist/exchanges/baozi/fetcher.js +155 -0
- package/dist/exchanges/baozi/index.d.ts +2 -0
- package/dist/exchanges/baozi/index.js +60 -131
- package/dist/exchanges/baozi/normalizer.d.ts +14 -0
- package/dist/exchanges/baozi/normalizer.js +208 -0
- package/dist/exchanges/interfaces.d.ts +28 -0
- package/dist/exchanges/interfaces.js +2 -0
- package/dist/exchanges/kalshi/api.d.ts +1 -1
- package/dist/exchanges/kalshi/api.js +1 -1
- package/dist/exchanges/kalshi/fetcher.d.ts +136 -0
- package/dist/exchanges/kalshi/fetcher.js +313 -0
- package/dist/exchanges/kalshi/index.d.ts +6 -6
- package/dist/exchanges/kalshi/index.js +119 -202
- package/dist/exchanges/kalshi/normalizer.d.ts +25 -0
- package/dist/exchanges/kalshi/normalizer.js +313 -0
- package/dist/exchanges/limitless/api.d.ts +1 -1
- package/dist/exchanges/limitless/api.js +1 -1
- package/dist/exchanges/limitless/fetcher.d.ts +81 -0
- package/dist/exchanges/limitless/fetcher.js +238 -0
- package/dist/exchanges/limitless/index.d.ts +6 -9
- package/dist/exchanges/limitless/index.js +81 -79
- package/dist/exchanges/limitless/normalizer.d.ts +14 -0
- package/dist/exchanges/limitless/normalizer.js +117 -0
- package/dist/exchanges/limitless/websocket.d.ts +3 -0
- package/dist/exchanges/limitless/websocket.js +5 -4
- package/dist/exchanges/myriad/api.d.ts +1 -1
- package/dist/exchanges/myriad/api.js +1 -1
- package/dist/exchanges/myriad/fetcher.d.ts +73 -0
- package/dist/exchanges/myriad/fetcher.js +217 -0
- package/dist/exchanges/myriad/index.d.ts +2 -0
- package/dist/exchanges/myriad/index.js +40 -97
- package/dist/exchanges/myriad/normalizer.d.ts +14 -0
- package/dist/exchanges/myriad/normalizer.js +167 -0
- package/dist/exchanges/myriad/websocket.d.ts +3 -1
- package/dist/exchanges/myriad/websocket.js +4 -3
- package/dist/exchanges/polymarket/api-clob.d.ts +1 -1
- package/dist/exchanges/polymarket/api-clob.js +1 -1
- package/dist/exchanges/polymarket/api-data.d.ts +1 -1
- package/dist/exchanges/polymarket/api-data.js +1 -1
- package/dist/exchanges/polymarket/api-gamma.d.ts +1 -1
- package/dist/exchanges/polymarket/api-gamma.js +1 -1
- package/dist/exchanges/polymarket/fetcher.d.ts +99 -0
- package/dist/exchanges/polymarket/fetcher.js +335 -0
- package/dist/exchanges/polymarket/index.d.ts +2 -0
- package/dist/exchanges/polymarket/index.js +80 -66
- package/dist/exchanges/polymarket/normalizer.d.ts +18 -0
- package/dist/exchanges/polymarket/normalizer.js +126 -0
- package/dist/exchanges/probable/api.d.ts +1 -1
- package/dist/exchanges/probable/api.js +1 -1
- package/dist/exchanges/probable/fetcher.d.ts +106 -0
- package/dist/exchanges/probable/fetcher.js +357 -0
- package/dist/exchanges/probable/index.d.ts +3 -1
- package/dist/exchanges/probable/index.js +73 -105
- package/dist/exchanges/probable/normalizer.d.ts +14 -0
- package/dist/exchanges/probable/normalizer.js +109 -0
- package/package.json +3 -3
- package/dist/exchanges/baozi/fetchEvents.d.ts +0 -8
- package/dist/exchanges/baozi/fetchEvents.js +0 -39
- package/dist/exchanges/baozi/fetchMarkets.d.ts +0 -5
- package/dist/exchanges/baozi/fetchMarkets.js +0 -160
- package/dist/exchanges/baozi/fetchOHLCV.d.ts +0 -6
- package/dist/exchanges/baozi/fetchOHLCV.js +0 -10
- package/dist/exchanges/baozi/fetchOrderBook.d.ts +0 -12
- package/dist/exchanges/baozi/fetchOrderBook.js +0 -36
- package/dist/exchanges/baozi/fetchTrades.d.ts +0 -6
- package/dist/exchanges/baozi/fetchTrades.js +0 -10
- package/dist/exchanges/kalshi/fetchEvents.d.ts +0 -5
- package/dist/exchanges/kalshi/fetchEvents.js +0 -196
- package/dist/exchanges/kalshi/fetchMarkets.d.ts +0 -6
- package/dist/exchanges/kalshi/fetchMarkets.js +0 -247
- package/dist/exchanges/kalshi/fetchOHLCV.d.ts +0 -3
- package/dist/exchanges/kalshi/fetchOHLCV.js +0 -97
- package/dist/exchanges/kalshi/fetchOrderBook.d.ts +0 -2
- package/dist/exchanges/kalshi/fetchOrderBook.js +0 -60
- package/dist/exchanges/kalshi/fetchTrades.d.ts +0 -3
- package/dist/exchanges/kalshi/fetchTrades.js +0 -33
- package/dist/exchanges/limitless/fetchEvents.d.ts +0 -4
- package/dist/exchanges/limitless/fetchEvents.js +0 -173
- package/dist/exchanges/limitless/fetchMarkets.d.ts +0 -3
- package/dist/exchanges/limitless/fetchMarkets.js +0 -152
- package/dist/exchanges/limitless/fetchOHLCV.d.ts +0 -7
- package/dist/exchanges/limitless/fetchOHLCV.js +0 -49
- package/dist/exchanges/limitless/fetchOrderBook.d.ts +0 -6
- package/dist/exchanges/limitless/fetchOrderBook.js +0 -41
- package/dist/exchanges/limitless/fetchTrades.d.ts +0 -8
- package/dist/exchanges/limitless/fetchTrades.js +0 -27
- package/dist/exchanges/myriad/fetchEvents.d.ts +0 -4
- package/dist/exchanges/myriad/fetchEvents.js +0 -48
- package/dist/exchanges/myriad/fetchMarkets.d.ts +0 -4
- package/dist/exchanges/myriad/fetchMarkets.js +0 -102
- package/dist/exchanges/myriad/fetchOHLCV.d.ts +0 -3
- package/dist/exchanges/myriad/fetchOHLCV.js +0 -83
- package/dist/exchanges/myriad/fetchOrderBook.d.ts +0 -2
- package/dist/exchanges/myriad/fetchOrderBook.js +0 -39
- package/dist/exchanges/polymarket/fetchEvents.d.ts +0 -4
- package/dist/exchanges/polymarket/fetchEvents.js +0 -135
- package/dist/exchanges/polymarket/fetchMarkets.d.ts +0 -4
- package/dist/exchanges/polymarket/fetchMarkets.js +0 -214
- package/dist/exchanges/polymarket/fetchOHLCV.d.ts +0 -7
- package/dist/exchanges/polymarket/fetchOHLCV.js +0 -98
- package/dist/exchanges/polymarket/fetchOrderBook.d.ts +0 -6
- package/dist/exchanges/polymarket/fetchOrderBook.js +0 -33
- package/dist/exchanges/polymarket/fetchTrades.d.ts +0 -9
- package/dist/exchanges/polymarket/fetchTrades.js +0 -43
- package/dist/exchanges/probable/fetchEvents.d.ts +0 -6
- package/dist/exchanges/probable/fetchEvents.js +0 -151
- package/dist/exchanges/probable/fetchMarkets.d.ts +0 -4
- package/dist/exchanges/probable/fetchMarkets.js +0 -239
- package/dist/exchanges/probable/fetchTrades.d.ts +0 -10
- package/dist/exchanges/probable/fetchTrades.js +0 -40
|
@@ -1,135 +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
|
-
function mapRawEventToUnified(event) {
|
|
11
|
-
const markets = [];
|
|
12
|
-
if (event.markets && Array.isArray(event.markets)) {
|
|
13
|
-
for (const market of event.markets) {
|
|
14
|
-
const unifiedMarket = (0, utils_1.mapMarketToUnified)(event, market, { useQuestionAsCandidateFallback: true });
|
|
15
|
-
if (unifiedMarket) {
|
|
16
|
-
markets.push(unifiedMarket);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
const unifiedEvent = {
|
|
21
|
-
id: event.id || event.slug,
|
|
22
|
-
title: event.title,
|
|
23
|
-
description: event.description || '',
|
|
24
|
-
slug: event.slug,
|
|
25
|
-
markets: markets,
|
|
26
|
-
volume24h: markets.reduce((sum, m) => sum + m.volume24h, 0),
|
|
27
|
-
volume: markets.some(m => m.volume !== undefined) ? markets.reduce((sum, m) => sum + (m.volume ?? 0), 0) : undefined,
|
|
28
|
-
url: `https://polymarket.com/event/${event.slug}`,
|
|
29
|
-
image: event.image || `https://polymarket.com/api/og?slug=${event.slug}`,
|
|
30
|
-
category: event.category || event.tags?.[0]?.label,
|
|
31
|
-
tags: event.tags?.map((t) => t.label) || []
|
|
32
|
-
};
|
|
33
|
-
return unifiedEvent;
|
|
34
|
-
}
|
|
35
|
-
async function fetchEvents(params, http = axios_1.default) {
|
|
36
|
-
try {
|
|
37
|
-
const limit = params.limit || 10000;
|
|
38
|
-
// Handle eventId or slug lookup (direct API call)
|
|
39
|
-
if (params.eventId || params.slug) {
|
|
40
|
-
const queryParams = params.eventId ? { id: params.eventId } : { slug: params.slug };
|
|
41
|
-
const response = await http.get(utils_1.GAMMA_API_URL, { params: queryParams });
|
|
42
|
-
const events = response.data;
|
|
43
|
-
if (!events || events.length === 0)
|
|
44
|
-
return [];
|
|
45
|
-
return events.map(mapRawEventToUnified).slice(0, limit);
|
|
46
|
-
}
|
|
47
|
-
// Handle query-based search (uses the /public-search endpoint)
|
|
48
|
-
if (params.query) {
|
|
49
|
-
return await searchEvents(params, limit, http);
|
|
50
|
-
}
|
|
51
|
-
// Default: fetch top events list from the Gamma /events endpoint (no query required)
|
|
52
|
-
return await fetchEventsDefault(params, limit, http);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
throw errors_1.polymarketErrorMapper.mapError(error);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async function searchEvents(params, limit, http) {
|
|
59
|
-
let sortParam = 'volume';
|
|
60
|
-
if (params.sort === 'newest')
|
|
61
|
-
sortParam = 'startDate';
|
|
62
|
-
if (params.sort === 'liquidity')
|
|
63
|
-
sortParam = 'liquidity';
|
|
64
|
-
const queryParams = {
|
|
65
|
-
q: params.query,
|
|
66
|
-
limit_per_type: 50,
|
|
67
|
-
sort: sortParam,
|
|
68
|
-
ascending: false
|
|
69
|
-
};
|
|
70
|
-
const status = params.status || 'active';
|
|
71
|
-
const fetchWithStatus = async (eventStatus) => {
|
|
72
|
-
const currentParams = { ...queryParams, events_status: eventStatus };
|
|
73
|
-
return (0, utils_1.paginateSearchParallel)(utils_1.GAMMA_SEARCH_URL, currentParams, limit * 10, http);
|
|
74
|
-
};
|
|
75
|
-
const filterActive = (e) => e.active === true;
|
|
76
|
-
const filterClosed = (e) => e.closed === true;
|
|
77
|
-
let events = [];
|
|
78
|
-
if (status === 'all') {
|
|
79
|
-
const [activeEvents, closedEvents] = await Promise.all([
|
|
80
|
-
fetchWithStatus('active'),
|
|
81
|
-
fetchWithStatus('closed')
|
|
82
|
-
]);
|
|
83
|
-
const seenIds = new Set();
|
|
84
|
-
events = [...activeEvents, ...closedEvents].filter(event => {
|
|
85
|
-
const id = event.id || event.slug;
|
|
86
|
-
if (seenIds.has(id))
|
|
87
|
-
return false;
|
|
88
|
-
seenIds.add(id);
|
|
89
|
-
return true;
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
else if (status === 'active') {
|
|
93
|
-
const rawEvents = await fetchWithStatus('active');
|
|
94
|
-
events = rawEvents.filter(filterActive);
|
|
95
|
-
}
|
|
96
|
-
else if (status === 'inactive' || status === 'closed') {
|
|
97
|
-
const rawEvents = await fetchWithStatus('closed');
|
|
98
|
-
events = rawEvents.filter(filterClosed);
|
|
99
|
-
}
|
|
100
|
-
const lowerQuery = params.query.toLowerCase();
|
|
101
|
-
const searchIn = params.searchIn || 'title';
|
|
102
|
-
const filteredEvents = events.filter((event) => {
|
|
103
|
-
const titleMatch = (event.title || '').toLowerCase().includes(lowerQuery);
|
|
104
|
-
const descMatch = (event.description || '').toLowerCase().includes(lowerQuery);
|
|
105
|
-
if (searchIn === 'title')
|
|
106
|
-
return titleMatch;
|
|
107
|
-
if (searchIn === 'description')
|
|
108
|
-
return descMatch;
|
|
109
|
-
return titleMatch || descMatch;
|
|
110
|
-
});
|
|
111
|
-
return filteredEvents.map(mapRawEventToUnified).slice(0, limit);
|
|
112
|
-
}
|
|
113
|
-
async function fetchEventsDefault(params, limit, http) {
|
|
114
|
-
const status = params.status || 'active';
|
|
115
|
-
let sortParam = 'volume';
|
|
116
|
-
if (params.sort === 'newest')
|
|
117
|
-
sortParam = 'startDate';
|
|
118
|
-
else if (params.sort === 'liquidity')
|
|
119
|
-
sortParam = 'liquidity';
|
|
120
|
-
const queryParams = {
|
|
121
|
-
order: sortParam,
|
|
122
|
-
ascending: false,
|
|
123
|
-
};
|
|
124
|
-
if (status === 'active') {
|
|
125
|
-
queryParams.active = 'true';
|
|
126
|
-
queryParams.closed = 'false';
|
|
127
|
-
}
|
|
128
|
-
else if (status === 'closed' || status === 'inactive') {
|
|
129
|
-
queryParams.active = 'false';
|
|
130
|
-
queryParams.closed = 'true';
|
|
131
|
-
}
|
|
132
|
-
// 'all' — no status filter applied
|
|
133
|
-
const events = await (0, utils_1.paginateParallel)(utils_1.GAMMA_API_URL, queryParams, http, limit);
|
|
134
|
-
return events.map(mapRawEventToUnified).slice(0, limit);
|
|
135
|
-
}
|
|
@@ -1,214 +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) {
|
|
11
|
-
try {
|
|
12
|
-
// Handle marketId lookup (Gamma market condition ID)
|
|
13
|
-
if (params?.marketId) {
|
|
14
|
-
return await fetchMarketById(params.marketId, http);
|
|
15
|
-
}
|
|
16
|
-
// Handle slug-based lookup
|
|
17
|
-
if (params?.slug) {
|
|
18
|
-
return await fetchMarketsBySlug(params.slug, http);
|
|
19
|
-
}
|
|
20
|
-
// Handle outcomeId lookup (CLOB token ID -- no direct API, fetch and filter)
|
|
21
|
-
if (params?.outcomeId) {
|
|
22
|
-
const markets = await fetchMarketsDefault(params, http);
|
|
23
|
-
return markets.filter(m => m.outcomes.some(o => o.outcomeId === params.outcomeId));
|
|
24
|
-
}
|
|
25
|
-
// Handle eventId lookup (Gamma event ID)
|
|
26
|
-
if (params?.eventId) {
|
|
27
|
-
return await fetchMarketsByEventId(params.eventId, http);
|
|
28
|
-
}
|
|
29
|
-
// Handle query-based search
|
|
30
|
-
if (params?.query) {
|
|
31
|
-
return await searchMarkets(params.query, params, http);
|
|
32
|
-
}
|
|
33
|
-
// Default: fetch markets
|
|
34
|
-
return await fetchMarketsDefault(params, http);
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
throw errors_1.polymarketErrorMapper.mapError(error);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async function fetchMarketById(marketId, http) {
|
|
41
|
-
const GAMMA_MARKETS_URL = 'https://gamma-api.polymarket.com/markets';
|
|
42
|
-
const response = await http.get(GAMMA_MARKETS_URL, {
|
|
43
|
-
params: { id: marketId }
|
|
44
|
-
});
|
|
45
|
-
const markets = response.data;
|
|
46
|
-
if (!markets || markets.length === 0)
|
|
47
|
-
return [];
|
|
48
|
-
const unifiedMarkets = [];
|
|
49
|
-
for (const market of markets) {
|
|
50
|
-
// The /markets endpoint returns markets with an embedded 'events' array
|
|
51
|
-
const event = market.events?.[0] || market;
|
|
52
|
-
const unifiedMarket = (0, utils_1.mapMarketToUnified)(event, market, { useQuestionAsCandidateFallback: true });
|
|
53
|
-
if (unifiedMarket) {
|
|
54
|
-
unifiedMarkets.push(unifiedMarket);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return unifiedMarkets;
|
|
58
|
-
}
|
|
59
|
-
async function fetchMarketsByEventId(eventId, http) {
|
|
60
|
-
const response = await http.get(utils_1.GAMMA_API_URL, {
|
|
61
|
-
params: { id: eventId }
|
|
62
|
-
});
|
|
63
|
-
const events = response.data;
|
|
64
|
-
if (!events || events.length === 0)
|
|
65
|
-
return [];
|
|
66
|
-
const unifiedMarkets = [];
|
|
67
|
-
for (const event of events) {
|
|
68
|
-
if (!event.markets)
|
|
69
|
-
continue;
|
|
70
|
-
for (const market of event.markets) {
|
|
71
|
-
const unifiedMarket = (0, utils_1.mapMarketToUnified)(event, market, { useQuestionAsCandidateFallback: true });
|
|
72
|
-
if (unifiedMarket) {
|
|
73
|
-
unifiedMarkets.push(unifiedMarket);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return unifiedMarkets;
|
|
78
|
-
}
|
|
79
|
-
async function fetchMarketsBySlug(slug, http) {
|
|
80
|
-
const response = await http.get(utils_1.GAMMA_API_URL, {
|
|
81
|
-
params: { slug: slug }
|
|
82
|
-
});
|
|
83
|
-
const events = response.data;
|
|
84
|
-
if (!events || events.length === 0)
|
|
85
|
-
return [];
|
|
86
|
-
const unifiedMarkets = [];
|
|
87
|
-
for (const event of events) {
|
|
88
|
-
if (!event.markets)
|
|
89
|
-
continue;
|
|
90
|
-
for (const market of event.markets) {
|
|
91
|
-
const unifiedMarket = (0, utils_1.mapMarketToUnified)(event, market, { useQuestionAsCandidateFallback: true });
|
|
92
|
-
if (unifiedMarket) {
|
|
93
|
-
unifiedMarkets.push(unifiedMarket);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return unifiedMarkets;
|
|
98
|
-
}
|
|
99
|
-
async function searchMarkets(query, params, http) {
|
|
100
|
-
const limit = params?.limit || 250000;
|
|
101
|
-
// Use parallel pagination to fetch all matching events
|
|
102
|
-
// Each event can contain multiple markets, so we need a larger pool
|
|
103
|
-
const queryParams = {
|
|
104
|
-
q: query,
|
|
105
|
-
limit_per_type: 50, // Fetch 50 events per page
|
|
106
|
-
events_status: params?.status === 'all' ? undefined : (params?.status === 'inactive' || params?.status === 'closed' ? 'closed' : 'active'),
|
|
107
|
-
sort: 'volume',
|
|
108
|
-
ascending: false
|
|
109
|
-
};
|
|
110
|
-
// Fetch events with parallel pagination
|
|
111
|
-
const events = await (0, utils_1.paginateSearchParallel)(utils_1.GAMMA_SEARCH_URL, queryParams, limit * 5, http);
|
|
112
|
-
const unifiedMarkets = [];
|
|
113
|
-
const lowerQuery = query.toLowerCase();
|
|
114
|
-
const searchIn = params?.searchIn || 'title';
|
|
115
|
-
// Flatten events into markets
|
|
116
|
-
for (const event of events) {
|
|
117
|
-
if (!event.markets)
|
|
118
|
-
continue;
|
|
119
|
-
for (const market of event.markets) {
|
|
120
|
-
const unifiedMarket = (0, utils_1.mapMarketToUnified)(event, market, { useQuestionAsCandidateFallback: true });
|
|
121
|
-
if (!unifiedMarket)
|
|
122
|
-
continue;
|
|
123
|
-
// Apply client-side filtering on market title
|
|
124
|
-
const titleMatch = (unifiedMarket.title || '').toLowerCase().includes(lowerQuery);
|
|
125
|
-
const descMatch = (unifiedMarket.description || '').toLowerCase().includes(lowerQuery);
|
|
126
|
-
let matches = false;
|
|
127
|
-
if (searchIn === 'title')
|
|
128
|
-
matches = titleMatch;
|
|
129
|
-
else if (searchIn === 'description')
|
|
130
|
-
matches = descMatch;
|
|
131
|
-
else
|
|
132
|
-
matches = titleMatch || descMatch;
|
|
133
|
-
if (matches) {
|
|
134
|
-
unifiedMarkets.push(unifiedMarket);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return unifiedMarkets.slice(0, limit);
|
|
139
|
-
}
|
|
140
|
-
async function fetchMarketsDefault(params, http) {
|
|
141
|
-
const limit = params?.limit || 250000; // Higher default for better coverage
|
|
142
|
-
const offset = params?.offset || 0;
|
|
143
|
-
// Map generic sort params to Polymarket Gamma API params
|
|
144
|
-
let queryParams = {
|
|
145
|
-
limit: limit,
|
|
146
|
-
offset: offset,
|
|
147
|
-
};
|
|
148
|
-
const status = params?.status || 'active';
|
|
149
|
-
if (status === 'active') {
|
|
150
|
-
queryParams.active = 'true';
|
|
151
|
-
queryParams.closed = 'false';
|
|
152
|
-
}
|
|
153
|
-
else if (status === 'closed' || status === 'inactive') {
|
|
154
|
-
queryParams.active = 'false';
|
|
155
|
-
queryParams.closed = 'true';
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
// 'all' - don't filter by status
|
|
159
|
-
}
|
|
160
|
-
// Gamma API uses 'order' and 'ascending' for sorting
|
|
161
|
-
if (params?.sort === 'volume') {
|
|
162
|
-
queryParams.order = 'volume';
|
|
163
|
-
queryParams.ascending = 'false';
|
|
164
|
-
}
|
|
165
|
-
else if (params?.sort === 'newest') {
|
|
166
|
-
queryParams.order = 'startDate';
|
|
167
|
-
queryParams.ascending = 'false';
|
|
168
|
-
}
|
|
169
|
-
else if (params?.sort === 'liquidity') {
|
|
170
|
-
// queryParams.order = 'liquidity';
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
// Default to volume sort to ensure we get active markets
|
|
174
|
-
queryParams.order = 'volume';
|
|
175
|
-
queryParams.ascending = 'false';
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
// Fetch active events from Gamma using parallel pagination
|
|
179
|
-
const events = await (0, utils_1.paginateParallel)(utils_1.GAMMA_API_URL, queryParams, http);
|
|
180
|
-
const unifiedMarkets = [];
|
|
181
|
-
for (const event of events) {
|
|
182
|
-
// Each event is a container (e.g. "US Election").
|
|
183
|
-
// It contains specific "markets" (e.g. "Winner", "Pop Vote").
|
|
184
|
-
if (!event.markets)
|
|
185
|
-
continue;
|
|
186
|
-
for (const market of event.markets) {
|
|
187
|
-
const unifiedMarket = (0, utils_1.mapMarketToUnified)(event, market);
|
|
188
|
-
if (unifiedMarket) {
|
|
189
|
-
unifiedMarkets.push(unifiedMarket);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
// Client-side Sort capability to ensure contract fulfillment
|
|
194
|
-
// Often API filters are "good effort" or apply to the 'event' but not the 'market'
|
|
195
|
-
if (params?.sort === 'volume') {
|
|
196
|
-
unifiedMarkets.sort((a, b) => b.volume24h - a.volume24h);
|
|
197
|
-
}
|
|
198
|
-
else if (params?.sort === 'newest') {
|
|
199
|
-
// unifiedMarkets.sort((a, b) => b.resolutionDate.getTime() - a.resolutionDate.getTime()); // Not quite 'newest'
|
|
200
|
-
}
|
|
201
|
-
else if (params?.sort === 'liquidity') {
|
|
202
|
-
unifiedMarkets.sort((a, b) => b.liquidity - a.liquidity);
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
// Default volume sort
|
|
206
|
-
unifiedMarkets.sort((a, b) => b.volume24h - a.volume24h);
|
|
207
|
-
}
|
|
208
|
-
// Respect limit strictly after flattening
|
|
209
|
-
return unifiedMarkets.slice(0, limit);
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
throw errors_1.polymarketErrorMapper.mapError(error);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { OHLCVParams } from '../../BaseExchange';
|
|
2
|
-
import { PriceCandle } from '../../types';
|
|
3
|
-
/**
|
|
4
|
-
* Fetch historical price data (OHLCV candles) for a specific token.
|
|
5
|
-
* @param id - The CLOB token ID (e.g., outcome token ID)
|
|
6
|
-
*/
|
|
7
|
-
export declare function fetchOHLCV(id: string, params: OHLCVParams, callApi: (operationId: string, params?: Record<string, any>) => Promise<any>): Promise<PriceCandle[]>;
|
|
@@ -1,98 +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 (OHLCV candles) for a specific token.
|
|
9
|
-
* @param id - The CLOB token ID (e.g., outcome token ID)
|
|
10
|
-
*/
|
|
11
|
-
async function fetchOHLCV(id, params, callApi) {
|
|
12
|
-
(0, validation_1.validateIdFormat)(id, 'OHLCV');
|
|
13
|
-
(0, validation_1.validateOutcomeId)(id, 'OHLCV');
|
|
14
|
-
// Validate resolution is provided
|
|
15
|
-
if (!params.resolution) {
|
|
16
|
-
throw new Error('fetchOHLCV requires a resolution parameter. Use OHLCVParams with resolution specified.');
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
const fidelity = (0, utils_1.mapIntervalToFidelity)(params.resolution);
|
|
20
|
-
const nowTs = Math.floor(Date.now() / 1000);
|
|
21
|
-
// 1. Smart Lookback Calculation
|
|
22
|
-
// If start/end not provided, calculate window based on limit * resolution
|
|
23
|
-
// Helper to handle string dates (from JSON)
|
|
24
|
-
// IMPORTANT: Python sends naive datetimes as ISO strings without 'Z' suffix.
|
|
25
|
-
// We must treat these as UTC, not local time.
|
|
26
|
-
const ensureDate = (d) => {
|
|
27
|
-
if (typeof d === 'string') {
|
|
28
|
-
// If string doesn't end with 'Z' and doesn't have timezone offset, append 'Z'
|
|
29
|
-
if (!d.endsWith('Z') && !d.match(/[+-]\d{2}:\d{2}$/)) {
|
|
30
|
-
return new Date(d + 'Z');
|
|
31
|
-
}
|
|
32
|
-
return new Date(d);
|
|
33
|
-
}
|
|
34
|
-
return d;
|
|
35
|
-
};
|
|
36
|
-
const pStart = params.start ? ensureDate(params.start) : undefined;
|
|
37
|
-
const pEnd = params.end ? ensureDate(params.end) : undefined;
|
|
38
|
-
let startTs = pStart ? Math.floor(pStart.getTime() / 1000) : 0;
|
|
39
|
-
let endTs = pEnd ? Math.floor(pEnd.getTime() / 1000) : nowTs;
|
|
40
|
-
if (!pStart) {
|
|
41
|
-
// Default limit is usually 20 in the example, but safety margin is good.
|
|
42
|
-
// If limit is not set, we default to 100 candles.
|
|
43
|
-
const count = params.limit || 100;
|
|
44
|
-
// fidelity is in minutes.
|
|
45
|
-
const durationSeconds = count * fidelity * 60;
|
|
46
|
-
startTs = endTs - durationSeconds;
|
|
47
|
-
}
|
|
48
|
-
const queryParams = {
|
|
49
|
-
market: id,
|
|
50
|
-
fidelity: fidelity,
|
|
51
|
-
startTs: startTs,
|
|
52
|
-
endTs: endTs
|
|
53
|
-
};
|
|
54
|
-
const data = await callApi('getPricesHistory', queryParams);
|
|
55
|
-
const history = data.history || [];
|
|
56
|
-
// 2. Align Timestamps (Snap to Grid)
|
|
57
|
-
// Polymarket returns random tick timestamps (e.g. 1:00:21).
|
|
58
|
-
// We want to normalize this to the start of the bucket (1:00:00).
|
|
59
|
-
const resolutionMs = fidelity * 60 * 1000;
|
|
60
|
-
// 2. Client-side Aggregation
|
|
61
|
-
// Polymarket returns tick data. We must group by time bucket to create true candles.
|
|
62
|
-
const buckets = new Map();
|
|
63
|
-
history.forEach((item) => {
|
|
64
|
-
const rawMs = item.t * 1000;
|
|
65
|
-
const snappedMs = Math.floor(rawMs / resolutionMs) * resolutionMs;
|
|
66
|
-
const price = Number(item.p);
|
|
67
|
-
const volume = Number(item.s || item.v || 0); // specific field depends on api, usually 's' for size
|
|
68
|
-
if (!buckets.has(snappedMs)) {
|
|
69
|
-
buckets.set(snappedMs, {
|
|
70
|
-
timestamp: snappedMs,
|
|
71
|
-
open: price,
|
|
72
|
-
high: price,
|
|
73
|
-
low: price,
|
|
74
|
-
close: price,
|
|
75
|
-
volume: volume
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
const candle = buckets.get(snappedMs);
|
|
80
|
-
candle.high = Math.max(candle.high, price);
|
|
81
|
-
candle.low = Math.min(candle.low, price);
|
|
82
|
-
candle.close = price; // Assuming history is sorted by time. If not, we need to track timestamps.
|
|
83
|
-
candle.volume = (candle.volume || 0) + volume;
|
|
84
|
-
// If history is not guaranteed sorted, we should track first/last timestamps per bucket.
|
|
85
|
-
// But usually /prices-history is sorted. We'll assume sorted for efficiency.
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
const candles = Array.from(buckets.values()).sort((a, b) => a.timestamp - b.timestamp);
|
|
89
|
-
// Apply limit if specified
|
|
90
|
-
if (params.limit && candles.length > params.limit) {
|
|
91
|
-
return candles.slice(-params.limit);
|
|
92
|
-
}
|
|
93
|
-
return candles;
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
throw errors_1.polymarketErrorMapper.mapError(error);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { OrderBook } from '../../types';
|
|
2
|
-
/**
|
|
3
|
-
* Fetch the current order book for a specific token.
|
|
4
|
-
* @param id - The CLOB token ID
|
|
5
|
-
*/
|
|
6
|
-
export declare function fetchOrderBook(id: string, callApi: (operationId: string, params?: Record<string, any>) => Promise<any>): Promise<OrderBook>;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchOrderBook = fetchOrderBook;
|
|
4
|
-
const validation_1 = require("../../utils/validation");
|
|
5
|
-
const errors_1 = require("./errors");
|
|
6
|
-
/**
|
|
7
|
-
* Fetch the current order book for a specific token.
|
|
8
|
-
* @param id - The CLOB token ID
|
|
9
|
-
*/
|
|
10
|
-
async function fetchOrderBook(id, callApi) {
|
|
11
|
-
(0, validation_1.validateIdFormat)(id, 'OrderBook');
|
|
12
|
-
(0, validation_1.validateOutcomeId)(id, 'OrderBook');
|
|
13
|
-
try {
|
|
14
|
-
const data = await callApi('getBook', { token_id: id });
|
|
15
|
-
// Response format: { bids: [{price: "0.52", size: "100"}], asks: [...] }
|
|
16
|
-
const bids = (data.bids || []).map((level) => ({
|
|
17
|
-
price: parseFloat(level.price),
|
|
18
|
-
size: parseFloat(level.size)
|
|
19
|
-
})).sort((a, b) => b.price - a.price); // Sort Bids Descending (Best/Highest first)
|
|
20
|
-
const asks = (data.asks || []).map((level) => ({
|
|
21
|
-
price: parseFloat(level.price),
|
|
22
|
-
size: parseFloat(level.size)
|
|
23
|
-
})).sort((a, b) => a.price - b.price); // Sort Asks Ascending (Best/Lowest first)
|
|
24
|
-
return {
|
|
25
|
-
bids,
|
|
26
|
-
asks,
|
|
27
|
-
timestamp: data.timestamp ? new Date(data.timestamp).getTime() : Date.now()
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
throw errors_1.polymarketErrorMapper.mapError(error);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { HistoryFilterParams, TradesParams } from '../../BaseExchange';
|
|
2
|
-
import { Trade } from '../../types';
|
|
3
|
-
/**
|
|
4
|
-
* Fetch raw trade history for a specific token.
|
|
5
|
-
* @param id - The CLOB token ID
|
|
6
|
-
*
|
|
7
|
-
* NOTE: Uses Polymarket Data API (public) to fetch trades.
|
|
8
|
-
*/
|
|
9
|
-
export declare function fetchTrades(id: string, params: TradesParams | HistoryFilterParams, callApi: (operationId: string, params?: Record<string, any>) => Promise<any>): Promise<Trade[]>;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchTrades = fetchTrades;
|
|
4
|
-
const validation_1 = require("../../utils/validation");
|
|
5
|
-
const errors_1 = require("./errors");
|
|
6
|
-
/**
|
|
7
|
-
* Fetch raw trade history for a specific token.
|
|
8
|
-
* @param id - The CLOB token ID
|
|
9
|
-
*
|
|
10
|
-
* NOTE: Uses Polymarket Data API (public) to fetch trades.
|
|
11
|
-
*/
|
|
12
|
-
async function fetchTrades(id, params, callApi) {
|
|
13
|
-
(0, validation_1.validateIdFormat)(id, 'Trades');
|
|
14
|
-
(0, validation_1.validateOutcomeId)(id, 'Trades');
|
|
15
|
-
try {
|
|
16
|
-
const queryParams = {
|
|
17
|
-
asset_id: id // Uses asset_id for Token ID on Data API
|
|
18
|
-
};
|
|
19
|
-
// Add time filters if provided
|
|
20
|
-
if (params.start) {
|
|
21
|
-
queryParams.after = Math.floor(params.start.getTime() / 1000);
|
|
22
|
-
}
|
|
23
|
-
if (params.end) {
|
|
24
|
-
queryParams.before = Math.floor(params.end.getTime() / 1000);
|
|
25
|
-
}
|
|
26
|
-
const trades = await callApi('getTrades', queryParams) || [];
|
|
27
|
-
const mappedTrades = trades.map((trade) => ({
|
|
28
|
-
id: trade.id || `${trade.timestamp}-${trade.price}`,
|
|
29
|
-
timestamp: trade.timestamp * 1000, // Convert to milliseconds
|
|
30
|
-
price: parseFloat(trade.price),
|
|
31
|
-
amount: parseFloat(trade.size || trade.amount || 0),
|
|
32
|
-
side: trade.side === 'BUY' ? 'buy' : trade.side === 'SELL' ? 'sell' : 'unknown'
|
|
33
|
-
}));
|
|
34
|
-
// Apply limit if specified
|
|
35
|
-
if (params.limit && mappedTrades.length > params.limit) {
|
|
36
|
-
return mappedTrades.slice(0, params.limit); // Return most recent N trades
|
|
37
|
-
}
|
|
38
|
-
return mappedTrades;
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
throw errors_1.polymarketErrorMapper.mapError(error);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { EventFetchParams } from '../../BaseExchange';
|
|
2
|
-
import { UnifiedEvent } from '../../types';
|
|
3
|
-
import { AxiosInstance } from 'axios';
|
|
4
|
-
export declare function fetchEvents(params: EventFetchParams, http?: AxiosInstance, callMidpoint?: (tokenId: string) => Promise<any>, callSearch?: (params: any) => Promise<any>): Promise<UnifiedEvent[]>;
|
|
5
|
-
export declare function fetchEventById(id: string, http?: AxiosInstance, callMidpoint?: (tokenId: string) => Promise<any>): Promise<UnifiedEvent | null>;
|
|
6
|
-
export declare function fetchEventBySlug(slug: string, http?: AxiosInstance, callMidpoint?: (tokenId: string) => Promise<any>): Promise<UnifiedEvent | null>;
|