coingecko-pro 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +431 -0
- package/dist/index.cjs +2266 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4308 -0
- package/dist/index.d.ts +4308 -0
- package/dist/index.js +2254 -0
- package/dist/index.js.map +1 -0
- package/package.json +54 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2266 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/cache.ts
|
|
4
|
+
var TTLCache = class {
|
|
5
|
+
store = /* @__PURE__ */ new Map();
|
|
6
|
+
defaultTtl;
|
|
7
|
+
/**
|
|
8
|
+
* @param defaultTtl - Default time-to-live in milliseconds for new entries.
|
|
9
|
+
*/
|
|
10
|
+
constructor(defaultTtl) {
|
|
11
|
+
this.defaultTtl = defaultTtl;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves a value from the cache.
|
|
15
|
+
* Returns `undefined` if the key does not exist or has expired.
|
|
16
|
+
*
|
|
17
|
+
* @param key - Cache key.
|
|
18
|
+
* @returns The cached value, or `undefined` if missing/expired.
|
|
19
|
+
*/
|
|
20
|
+
get(key) {
|
|
21
|
+
const entry = this.store.get(key);
|
|
22
|
+
if (entry === void 0) return void 0;
|
|
23
|
+
if (Date.now() > entry.expiresAt) {
|
|
24
|
+
this.store.delete(key);
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
return entry.value;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Stores a value in the cache with a TTL.
|
|
31
|
+
*
|
|
32
|
+
* @param key - Cache key.
|
|
33
|
+
* @param value - Value to store.
|
|
34
|
+
* @param ttl - Optional TTL in milliseconds. Falls back to the instance default.
|
|
35
|
+
*/
|
|
36
|
+
set(key, value, ttl) {
|
|
37
|
+
const expiresAt = Date.now() + (ttl ?? this.defaultTtl);
|
|
38
|
+
this.store.set(key, { value, expiresAt });
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Removes a single entry from the cache.
|
|
42
|
+
*
|
|
43
|
+
* @param key - Cache key to remove.
|
|
44
|
+
* @returns `true` if the key existed, `false` otherwise.
|
|
45
|
+
*/
|
|
46
|
+
delete(key) {
|
|
47
|
+
return this.store.delete(key);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Removes all entries from the cache.
|
|
51
|
+
*/
|
|
52
|
+
clear() {
|
|
53
|
+
this.store.clear();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns the number of entries currently in the cache, including expired
|
|
57
|
+
* entries that have not yet been lazily evicted.
|
|
58
|
+
*/
|
|
59
|
+
get size() {
|
|
60
|
+
return this.store.size;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/utils/rate-limiter.ts
|
|
65
|
+
var RateLimiter = class {
|
|
66
|
+
maxTokens;
|
|
67
|
+
/** Milliseconds between individual token refills. */
|
|
68
|
+
refillIntervalMs;
|
|
69
|
+
tokens;
|
|
70
|
+
lastRefillTime;
|
|
71
|
+
/**
|
|
72
|
+
* @param maxPerMinute - Maximum number of requests allowed per minute.
|
|
73
|
+
*/
|
|
74
|
+
constructor(maxPerMinute) {
|
|
75
|
+
this.maxTokens = maxPerMinute;
|
|
76
|
+
this.refillIntervalMs = 6e4 / maxPerMinute;
|
|
77
|
+
this.tokens = maxPerMinute;
|
|
78
|
+
this.lastRefillTime = Date.now();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Refills tokens based on elapsed time since the last refill.
|
|
82
|
+
*/
|
|
83
|
+
refill() {
|
|
84
|
+
const now = Date.now();
|
|
85
|
+
const elapsed = now - this.lastRefillTime;
|
|
86
|
+
const tokensToAdd = Math.floor(elapsed / this.refillIntervalMs);
|
|
87
|
+
if (tokensToAdd > 0) {
|
|
88
|
+
this.tokens = Math.min(this.maxTokens, this.tokens + tokensToAdd);
|
|
89
|
+
this.lastRefillTime += tokensToAdd * this.refillIntervalMs;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Acquires a single token, waiting asynchronously if none are available.
|
|
94
|
+
*
|
|
95
|
+
* When the bucket is empty the method calculates exactly how long until the
|
|
96
|
+
* next token is available and waits that duration before retrying, avoiding
|
|
97
|
+
* busy-polling.
|
|
98
|
+
*
|
|
99
|
+
* @returns A promise that resolves when a token has been consumed.
|
|
100
|
+
*/
|
|
101
|
+
async acquire() {
|
|
102
|
+
this.refill();
|
|
103
|
+
if (this.tokens > 0) {
|
|
104
|
+
this.tokens -= 1;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const waitMs = this.refillIntervalMs - (Date.now() - this.lastRefillTime);
|
|
108
|
+
await new Promise((resolve) => setTimeout(resolve, Math.max(0, waitMs)));
|
|
109
|
+
return this.acquire();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// src/utils/helpers.ts
|
|
114
|
+
function formatArrayParam(value) {
|
|
115
|
+
if (Array.isArray(value)) {
|
|
116
|
+
return value.join(",");
|
|
117
|
+
}
|
|
118
|
+
return String(value);
|
|
119
|
+
}
|
|
120
|
+
function buildUrl(base, path, params) {
|
|
121
|
+
const normalised = base.replace(/\/+$/, "") + "/" + path.replace(/^\/+/, "");
|
|
122
|
+
const url = new URL(normalised);
|
|
123
|
+
if (params) {
|
|
124
|
+
for (const [key, value] of Object.entries(params)) {
|
|
125
|
+
if (value === void 0 || value === null) continue;
|
|
126
|
+
url.searchParams.set(key, formatArrayParam(value));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return url.toString();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/errors.ts
|
|
133
|
+
var CoinGeckoError = class extends Error {
|
|
134
|
+
/**
|
|
135
|
+
* The HTTP status code returned by the API, or `0` for network-level
|
|
136
|
+
* failures (e.g. timeout, DNS error).
|
|
137
|
+
*/
|
|
138
|
+
status;
|
|
139
|
+
/**
|
|
140
|
+
* The full URL that was requested when the error occurred.
|
|
141
|
+
*/
|
|
142
|
+
url;
|
|
143
|
+
/**
|
|
144
|
+
* The response body parsed as JSON if possible, otherwise the raw text.
|
|
145
|
+
* `undefined` when the error is network-level and no response was received.
|
|
146
|
+
*/
|
|
147
|
+
data;
|
|
148
|
+
/**
|
|
149
|
+
* @param message - Human-readable error description.
|
|
150
|
+
* @param status - HTTP status code (use `0` for network errors).
|
|
151
|
+
* @param url - URL that triggered the error.
|
|
152
|
+
* @param data - Parsed response body, if available.
|
|
153
|
+
*/
|
|
154
|
+
constructor(message, status, url, data) {
|
|
155
|
+
super(message);
|
|
156
|
+
this.name = "CoinGeckoError";
|
|
157
|
+
this.status = status;
|
|
158
|
+
this.url = url;
|
|
159
|
+
this.data = data;
|
|
160
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/client.ts
|
|
165
|
+
var PRO_BASE_URL = "https://pro-api.coingecko.com/api/v3";
|
|
166
|
+
var FREE_BASE_URL = "https://api.coingecko.com/api/v3";
|
|
167
|
+
var DEFAULT_CACHE_TTL = 3e4;
|
|
168
|
+
var DEFAULT_MAX_RETRIES = 3;
|
|
169
|
+
var DEFAULT_RETRY_DELAY = 1e3;
|
|
170
|
+
var DEFAULT_TIMEOUT = 15e3;
|
|
171
|
+
var DEFAULT_RATE_LIMIT_PRO = 500;
|
|
172
|
+
var DEFAULT_RATE_LIMIT_FREE = 30;
|
|
173
|
+
var RETRYABLE_STATUSES = /* @__PURE__ */ new Set([429, 503]);
|
|
174
|
+
var CoinGeckoClient = class {
|
|
175
|
+
baseUrl;
|
|
176
|
+
apiKey;
|
|
177
|
+
cacheTtl;
|
|
178
|
+
maxRetries;
|
|
179
|
+
retryDelay;
|
|
180
|
+
timeout;
|
|
181
|
+
onRequest;
|
|
182
|
+
onResponse;
|
|
183
|
+
onError;
|
|
184
|
+
cache;
|
|
185
|
+
rateLimiter;
|
|
186
|
+
/**
|
|
187
|
+
* @param config - Optional configuration. See {@link CoinGeckoClientConfig}.
|
|
188
|
+
*/
|
|
189
|
+
constructor(config) {
|
|
190
|
+
this.apiKey = config?.apiKey;
|
|
191
|
+
this.baseUrl = config?.baseUrl ?? (this.apiKey ? PRO_BASE_URL : FREE_BASE_URL);
|
|
192
|
+
this.cacheTtl = config?.cacheTtl ?? DEFAULT_CACHE_TTL;
|
|
193
|
+
this.maxRetries = config?.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
194
|
+
this.retryDelay = config?.retryDelay ?? DEFAULT_RETRY_DELAY;
|
|
195
|
+
this.timeout = config?.timeout ?? DEFAULT_TIMEOUT;
|
|
196
|
+
this.onRequest = config?.onRequest;
|
|
197
|
+
this.onResponse = config?.onResponse;
|
|
198
|
+
this.onError = config?.onError;
|
|
199
|
+
const rateLimit = config?.rateLimit ?? (this.apiKey ? DEFAULT_RATE_LIMIT_PRO : DEFAULT_RATE_LIMIT_FREE);
|
|
200
|
+
this.cache = new TTLCache(this.cacheTtl);
|
|
201
|
+
this.rateLimiter = new RateLimiter(rateLimit);
|
|
202
|
+
}
|
|
203
|
+
// -------------------------------------------------------------------------
|
|
204
|
+
// Public API
|
|
205
|
+
// -------------------------------------------------------------------------
|
|
206
|
+
/**
|
|
207
|
+
* Performs a GET request to the given API path.
|
|
208
|
+
*
|
|
209
|
+
* Results are cached by default. Pass `options.cacheTtl = 0` to bypass
|
|
210
|
+
* caching for a specific call.
|
|
211
|
+
*
|
|
212
|
+
* @template T - Expected shape of the response body.
|
|
213
|
+
* @param path - API endpoint path, e.g. `/coins/markets`.
|
|
214
|
+
* @param params - Query parameters. `undefined`/`null` values are omitted.
|
|
215
|
+
* @param options - Per-call overrides.
|
|
216
|
+
* @returns Parsed JSON response body cast to `T`.
|
|
217
|
+
* @throws {@link CoinGeckoError} on non-2xx responses or network failures.
|
|
218
|
+
*/
|
|
219
|
+
async get(path, params, options) {
|
|
220
|
+
const url = buildUrl(this.baseUrl, path, params);
|
|
221
|
+
const ttl = options?.cacheTtl ?? this.cacheTtl;
|
|
222
|
+
if (ttl > 0) {
|
|
223
|
+
const cached = this.cache.get(url);
|
|
224
|
+
if (cached !== void 0) {
|
|
225
|
+
return cached;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
await this.rateLimiter.acquire();
|
|
229
|
+
this.onRequest?.(url);
|
|
230
|
+
let lastError;
|
|
231
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
232
|
+
if (attempt > 0) {
|
|
233
|
+
const backoff = this.retryDelay * Math.pow(2, attempt - 1);
|
|
234
|
+
await new Promise((resolve) => setTimeout(resolve, backoff));
|
|
235
|
+
await this.rateLimiter.acquire();
|
|
236
|
+
}
|
|
237
|
+
const startMs = Date.now();
|
|
238
|
+
try {
|
|
239
|
+
const result = await this.fetchWithTimeout(url, startMs, ttl);
|
|
240
|
+
return result;
|
|
241
|
+
} catch (err) {
|
|
242
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
243
|
+
lastError = error;
|
|
244
|
+
if (err instanceof CoinGeckoError && !RETRYABLE_STATUSES.has(err.status) && err.status !== 0) {
|
|
245
|
+
this.onError?.(url, error);
|
|
246
|
+
throw err;
|
|
247
|
+
}
|
|
248
|
+
if (attempt === this.maxRetries) {
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const finalError = lastError ?? new CoinGeckoError("Unknown error", 0, url);
|
|
254
|
+
this.onError?.(url, finalError);
|
|
255
|
+
throw finalError;
|
|
256
|
+
}
|
|
257
|
+
// -------------------------------------------------------------------------
|
|
258
|
+
// Private helpers
|
|
259
|
+
// -------------------------------------------------------------------------
|
|
260
|
+
/**
|
|
261
|
+
* Performs a single fetch with an AbortController timeout, then handles
|
|
262
|
+
* caching and lifecycle hooks.
|
|
263
|
+
*/
|
|
264
|
+
async fetchWithTimeout(url, startMs, ttl) {
|
|
265
|
+
const controller = new AbortController();
|
|
266
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
267
|
+
let response;
|
|
268
|
+
try {
|
|
269
|
+
const headers = {
|
|
270
|
+
"Accept": "application/json"
|
|
271
|
+
};
|
|
272
|
+
if (this.apiKey) {
|
|
273
|
+
headers["x-cg-pro-api-key"] = this.apiKey;
|
|
274
|
+
}
|
|
275
|
+
response = await fetch(url, {
|
|
276
|
+
method: "GET",
|
|
277
|
+
headers,
|
|
278
|
+
signal: controller.signal
|
|
279
|
+
});
|
|
280
|
+
} catch (err) {
|
|
281
|
+
clearTimeout(timer);
|
|
282
|
+
const elapsed2 = Date.now() - startMs;
|
|
283
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
284
|
+
const timeoutError = new CoinGeckoError(
|
|
285
|
+
`Request timed out after ${this.timeout}ms`,
|
|
286
|
+
0,
|
|
287
|
+
url
|
|
288
|
+
);
|
|
289
|
+
this.onError?.(url, timeoutError);
|
|
290
|
+
throw timeoutError;
|
|
291
|
+
}
|
|
292
|
+
const networkError = new CoinGeckoError(
|
|
293
|
+
err instanceof Error ? err.message : String(err),
|
|
294
|
+
0,
|
|
295
|
+
url
|
|
296
|
+
);
|
|
297
|
+
this.onResponse?.(url, 0, elapsed2);
|
|
298
|
+
throw networkError;
|
|
299
|
+
}
|
|
300
|
+
clearTimeout(timer);
|
|
301
|
+
const elapsed = Date.now() - startMs;
|
|
302
|
+
this.onResponse?.(url, response.status, elapsed);
|
|
303
|
+
if (!response.ok) {
|
|
304
|
+
let data;
|
|
305
|
+
let message = `HTTP ${response.status}`;
|
|
306
|
+
try {
|
|
307
|
+
data = await response.json();
|
|
308
|
+
if (data !== null && typeof data === "object" && "error" in data && typeof data["error"] === "string") {
|
|
309
|
+
message = data["error"];
|
|
310
|
+
}
|
|
311
|
+
} catch {
|
|
312
|
+
try {
|
|
313
|
+
data = await response.text();
|
|
314
|
+
} catch {
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
throw new CoinGeckoError(message, response.status, url, data);
|
|
318
|
+
}
|
|
319
|
+
const json = await response.json();
|
|
320
|
+
if (ttl > 0) {
|
|
321
|
+
this.cache.set(url, json, ttl);
|
|
322
|
+
}
|
|
323
|
+
return json;
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// src/endpoints/coins.ts
|
|
328
|
+
var CoinsEndpoints = class {
|
|
329
|
+
constructor(client) {
|
|
330
|
+
this.client = client;
|
|
331
|
+
}
|
|
332
|
+
// -------------------------------------------------------------------------
|
|
333
|
+
// Simple price
|
|
334
|
+
// -------------------------------------------------------------------------
|
|
335
|
+
/**
|
|
336
|
+
* @description Get the current price of one or more coins in the requested
|
|
337
|
+
* vs-currencies. Optionally include market cap, 24h volume, 24h change, and
|
|
338
|
+
* last-updated timestamp in the response.
|
|
339
|
+
*
|
|
340
|
+
* @param params - Query parameters including required `ids` and
|
|
341
|
+
* `vs_currencies` plus optional data flags.
|
|
342
|
+
* @returns A map of coin ID → currency code → numeric value.
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```ts
|
|
346
|
+
* const prices = await coins.price({
|
|
347
|
+
* ids: 'bitcoin,ethereum',
|
|
348
|
+
* vs_currencies: 'usd,eur',
|
|
349
|
+
* include_market_cap: true,
|
|
350
|
+
* });
|
|
351
|
+
* // { bitcoin: { usd: 69840, usd_market_cap: 1.38e12 }, ethereum: { usd: 3700 } }
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
async price(params) {
|
|
355
|
+
return this.client.get("/simple/price", params);
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* @description Get the current price of one or more ERC-20/token contract
|
|
359
|
+
* addresses on a given asset platform (e.g. `ethereum`).
|
|
360
|
+
*
|
|
361
|
+
* @param platformId - Asset platform ID (e.g. `'ethereum'`, `'polygon-pos'`).
|
|
362
|
+
* @param params - Query parameters including required `contract_addresses` and
|
|
363
|
+
* `vs_currencies`.
|
|
364
|
+
* @returns A map of contract address → currency code → numeric value.
|
|
365
|
+
*
|
|
366
|
+
* @remarks Requires Analyst+ plan for more than one address per request.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* const tokenPrices = await coins.tokenPrice('ethereum', {
|
|
371
|
+
* contract_addresses: '0xdac17f958d2ee523a2206206994597c13d831ec7',
|
|
372
|
+
* vs_currencies: 'usd',
|
|
373
|
+
* });
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
async tokenPrice(platformId, params) {
|
|
377
|
+
return this.client.get(
|
|
378
|
+
`/simple/token_price/${platformId}`,
|
|
379
|
+
params
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* @description Get the full list of vs-currency codes supported by CoinGecko
|
|
384
|
+
* (e.g. `'usd'`, `'eur'`, `'btc'`).
|
|
385
|
+
*
|
|
386
|
+
* @returns An array of currency code strings.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* const currencies = await coins.supportedVsCurrencies();
|
|
391
|
+
* // ['btc', 'eth', 'usd', 'eur', ...]
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
async supportedVsCurrencies() {
|
|
395
|
+
return this.client.get("/simple/supported_vs_currencies");
|
|
396
|
+
}
|
|
397
|
+
// -------------------------------------------------------------------------
|
|
398
|
+
// Coin list & markets
|
|
399
|
+
// -------------------------------------------------------------------------
|
|
400
|
+
/**
|
|
401
|
+
* @description Get the full list of coins available on CoinGecko, including
|
|
402
|
+
* their IDs, symbols, and names. Optionally include contract addresses per
|
|
403
|
+
* platform.
|
|
404
|
+
*
|
|
405
|
+
* @param params - Optional query parameters.
|
|
406
|
+
* @returns An array of minimal coin entries.
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```ts
|
|
410
|
+
* const coins = await coins.list({ include_platform: true });
|
|
411
|
+
* // [{ id: 'bitcoin', symbol: 'btc', name: 'Bitcoin', platforms: {} }, ...]
|
|
412
|
+
* ```
|
|
413
|
+
*/
|
|
414
|
+
async list(params) {
|
|
415
|
+
return this.client.get("/coins/list", params);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* @description Get coin market data (price, market cap, volume, etc.) for
|
|
419
|
+
* all or a filtered set of coins ordered by market cap.
|
|
420
|
+
*
|
|
421
|
+
* @param params - Query parameters including required `vs_currency`.
|
|
422
|
+
* @returns An array of `MarketCoin` objects with full market statistics.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```ts
|
|
426
|
+
* const top10 = await coins.markets({ vs_currency: 'usd', per_page: 10 });
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
async markets(params) {
|
|
430
|
+
return this.client.get("/coins/markets", params);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* @description Get the top 30 gaining and top 30 losing coins over a given
|
|
434
|
+
* time duration, filtered by the requested vs-currency.
|
|
435
|
+
*
|
|
436
|
+
* @param params - Optional query parameters including `vs_currency`,
|
|
437
|
+
* `duration`, and `top_coins` filter.
|
|
438
|
+
* @returns An object with `top_gainers` and `top_losers` arrays.
|
|
439
|
+
*
|
|
440
|
+
* @remarks Requires Analyst+ plan.
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```ts
|
|
444
|
+
* const movers = await coins.topGainersLosers({ vs_currency: 'usd', duration: '24h' });
|
|
445
|
+
* console.log(movers.top_gainers[0]);
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
async topGainersLosers(params) {
|
|
449
|
+
return this.client.get(
|
|
450
|
+
"/coins/top_gainers_losers",
|
|
451
|
+
params
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* @description Get a list of the 200 most recently listed coins on CoinGecko,
|
|
456
|
+
* ordered by listing date descending.
|
|
457
|
+
*
|
|
458
|
+
* @returns An array of `NewCoin` entries with activation timestamps.
|
|
459
|
+
*
|
|
460
|
+
* @remarks Requires Analyst+ plan.
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ```ts
|
|
464
|
+
* const newCoins = await coins.listNew();
|
|
465
|
+
* console.log(newCoins[0].activated_at);
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
async listNew() {
|
|
469
|
+
return this.client.get("/coins/list/new");
|
|
470
|
+
}
|
|
471
|
+
// -------------------------------------------------------------------------
|
|
472
|
+
// Coin by ID
|
|
473
|
+
// -------------------------------------------------------------------------
|
|
474
|
+
/**
|
|
475
|
+
* @description Get comprehensive data for a specific coin by its CoinGecko
|
|
476
|
+
* ID, including market data, links, community stats, developer activity, and
|
|
477
|
+
* more.
|
|
478
|
+
*
|
|
479
|
+
* @param id - CoinGecko coin ID (e.g. `'bitcoin'`).
|
|
480
|
+
* @param params - Optional flags controlling which data blocks to include.
|
|
481
|
+
* @returns A `CoinDetail` object with all available metadata.
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* ```ts
|
|
485
|
+
* const bitcoin = await coins.getById('bitcoin', { market_data: true, tickers: false });
|
|
486
|
+
* console.log(bitcoin.market_data?.current_price?.usd);
|
|
487
|
+
* ```
|
|
488
|
+
*/
|
|
489
|
+
async getById(id, params) {
|
|
490
|
+
return this.client.get(`/coins/${id}`, params);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* @description Get the exchange tickers for a specific coin, optionally
|
|
494
|
+
* filtered by exchange.
|
|
495
|
+
*
|
|
496
|
+
* @param id - CoinGecko coin ID (e.g. `'bitcoin'`).
|
|
497
|
+
* @param params - Optional pagination, exchange filter, and sort params.
|
|
498
|
+
* @returns A `CoinTickersResponse` wrapping the coin name and ticker array.
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```ts
|
|
502
|
+
* const { tickers } = await coins.tickers('bitcoin', { exchange_ids: 'binance' });
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
async tickers(id, params) {
|
|
506
|
+
return this.client.get(
|
|
507
|
+
`/coins/${id}/tickers`,
|
|
508
|
+
params
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* @description Get historical snapshot data for a coin on a specific past
|
|
513
|
+
* date, including price, market cap, and volume.
|
|
514
|
+
*
|
|
515
|
+
* @param id - CoinGecko coin ID (e.g. `'bitcoin'`).
|
|
516
|
+
* @param params - Query parameters including required `date` (`dd-mm-yyyy`).
|
|
517
|
+
* @returns A `CoinHistoricalData` snapshot object.
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```ts
|
|
521
|
+
* const snapshot = await coins.history('bitcoin', { date: '30-12-2022' });
|
|
522
|
+
* console.log(snapshot.market_data?.current_price?.usd);
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
async history(id, params) {
|
|
526
|
+
return this.client.get(`/coins/${id}/history`, params);
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* @description Get historical market chart data (price, market cap, and
|
|
530
|
+
* volume) for a coin over a given number of days. Data granularity is
|
|
531
|
+
* automatically selected unless `interval` is specified.
|
|
532
|
+
*
|
|
533
|
+
* @param id - CoinGecko coin ID (e.g. `'ethereum'`).
|
|
534
|
+
* @param params - Query parameters including required `vs_currency` and
|
|
535
|
+
* `days`.
|
|
536
|
+
* @returns A `MarketChartResponse` containing price, market cap, and volume
|
|
537
|
+
* time series.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```ts
|
|
541
|
+
* const chart = await coins.marketChart('ethereum', { vs_currency: 'usd', days: 30 });
|
|
542
|
+
* const [ts, price] = chart.prices[0];
|
|
543
|
+
* ```
|
|
544
|
+
*/
|
|
545
|
+
async marketChart(id, params) {
|
|
546
|
+
return this.client.get(
|
|
547
|
+
`/coins/${id}/market_chart`,
|
|
548
|
+
params
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* @description Get historical market chart data (price, market cap, and
|
|
553
|
+
* volume) for a coin within a UNIX timestamp range.
|
|
554
|
+
*
|
|
555
|
+
* @param id - CoinGecko coin ID.
|
|
556
|
+
* @param params - Query parameters including `vs_currency`, `from`, and `to`
|
|
557
|
+
* UNIX timestamps (seconds).
|
|
558
|
+
* @returns A `MarketChartResponse` containing price, market cap, and volume
|
|
559
|
+
* time series.
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* ```ts
|
|
563
|
+
* const chart = await coins.marketChartRange('bitcoin', {
|
|
564
|
+
* vs_currency: 'usd',
|
|
565
|
+
* from: 1640995200,
|
|
566
|
+
* to: 1672531200,
|
|
567
|
+
* });
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
async marketChartRange(id, params) {
|
|
571
|
+
return this.client.get(
|
|
572
|
+
`/coins/${id}/market_chart/range`,
|
|
573
|
+
params
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* @description Get OHLC (open, high, low, close) candlestick data for a coin
|
|
578
|
+
* over a given number of days.
|
|
579
|
+
*
|
|
580
|
+
* @param id - CoinGecko coin ID.
|
|
581
|
+
* @param params - Query parameters including required `vs_currency` and
|
|
582
|
+
* `days`.
|
|
583
|
+
* @returns An array of OHLC data points, each formatted as
|
|
584
|
+
* `[timestamp_ms, open, high, low, close]`.
|
|
585
|
+
*
|
|
586
|
+
* @remarks Requires Analyst+ plan.
|
|
587
|
+
*
|
|
588
|
+
* @example
|
|
589
|
+
* ```ts
|
|
590
|
+
* const candles = await coins.ohlc('bitcoin', { vs_currency: 'usd', days: 7 });
|
|
591
|
+
* const [ts, open, high, low, close] = candles[0];
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
async ohlc(id, params) {
|
|
595
|
+
return this.client.get(`/coins/${id}/ohlc`, params);
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* @description Get OHLC (open, high, low, close) candlestick data for a coin
|
|
599
|
+
* within a UNIX timestamp range.
|
|
600
|
+
*
|
|
601
|
+
* @param id - CoinGecko coin ID.
|
|
602
|
+
* @param params - Query parameters including required `vs_currency`, `from`,
|
|
603
|
+
* and `to` UNIX timestamps (seconds).
|
|
604
|
+
* @returns An array of OHLC data points, each formatted as
|
|
605
|
+
* `[timestamp_ms, open, high, low, close]`.
|
|
606
|
+
*
|
|
607
|
+
* @remarks Requires Analyst+ plan.
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```ts
|
|
611
|
+
* const candles = await coins.ohlcRange('bitcoin', {
|
|
612
|
+
* vs_currency: 'usd',
|
|
613
|
+
* from: 1640995200,
|
|
614
|
+
* to: 1672531200,
|
|
615
|
+
* });
|
|
616
|
+
* ```
|
|
617
|
+
*/
|
|
618
|
+
async ohlcRange(id, params) {
|
|
619
|
+
return this.client.get(
|
|
620
|
+
`/coins/${id}/ohlc/range`,
|
|
621
|
+
params
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
// -------------------------------------------------------------------------
|
|
625
|
+
// Supply charts (Enterprise)
|
|
626
|
+
// -------------------------------------------------------------------------
|
|
627
|
+
/**
|
|
628
|
+
* @description Get the historical circulating supply chart for a coin over a
|
|
629
|
+
* given number of days.
|
|
630
|
+
*
|
|
631
|
+
* @param id - CoinGecko coin ID.
|
|
632
|
+
* @param params - Query parameters including required `days`.
|
|
633
|
+
* @returns An array of `[timestamp_ms, supply_value]` data points.
|
|
634
|
+
*
|
|
635
|
+
* @remarks Requires Enterprise plan.
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```ts
|
|
639
|
+
* const supply = await coins.circulatingSupplyChart('bitcoin', { days: 365 });
|
|
640
|
+
* const [ts, value] = supply[0];
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
async circulatingSupplyChart(id, params) {
|
|
644
|
+
return this.client.get(
|
|
645
|
+
`/coins/${id}/circulating_supply_chart`,
|
|
646
|
+
params
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* @description Get the historical circulating supply chart for a coin within
|
|
651
|
+
* a UNIX timestamp range.
|
|
652
|
+
*
|
|
653
|
+
* @param id - CoinGecko coin ID.
|
|
654
|
+
* @param params - Query parameters including required `from` and `to` UNIX
|
|
655
|
+
* timestamps (seconds).
|
|
656
|
+
* @returns An array of `[timestamp_ms, supply_value]` data points.
|
|
657
|
+
*
|
|
658
|
+
* @remarks Requires Enterprise plan.
|
|
659
|
+
*
|
|
660
|
+
* @example
|
|
661
|
+
* ```ts
|
|
662
|
+
* const supply = await coins.circulatingSupplyChartRange('bitcoin', {
|
|
663
|
+
* from: 1640995200,
|
|
664
|
+
* to: 1672531200,
|
|
665
|
+
* });
|
|
666
|
+
* ```
|
|
667
|
+
*/
|
|
668
|
+
async circulatingSupplyChartRange(id, params) {
|
|
669
|
+
return this.client.get(
|
|
670
|
+
`/coins/${id}/circulating_supply_chart/range`,
|
|
671
|
+
params
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* @description Get the historical total supply chart for a coin over a given
|
|
676
|
+
* number of days.
|
|
677
|
+
*
|
|
678
|
+
* @param id - CoinGecko coin ID.
|
|
679
|
+
* @param params - Query parameters including required `days`.
|
|
680
|
+
* @returns An array of `[timestamp_ms, supply_value]` data points.
|
|
681
|
+
*
|
|
682
|
+
* @remarks Requires Enterprise plan.
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* ```ts
|
|
686
|
+
* const supply = await coins.totalSupplyChart('ethereum', { days: 90 });
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
async totalSupplyChart(id, params) {
|
|
690
|
+
return this.client.get(
|
|
691
|
+
`/coins/${id}/total_supply_chart`,
|
|
692
|
+
params
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* @description Get the historical total supply chart for a coin within a
|
|
697
|
+
* UNIX timestamp range.
|
|
698
|
+
*
|
|
699
|
+
* @param id - CoinGecko coin ID.
|
|
700
|
+
* @param params - Query parameters including required `from` and `to` UNIX
|
|
701
|
+
* timestamps (seconds).
|
|
702
|
+
* @returns An array of `[timestamp_ms, supply_value]` data points.
|
|
703
|
+
*
|
|
704
|
+
* @remarks Requires Enterprise plan.
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* ```ts
|
|
708
|
+
* const supply = await coins.totalSupplyChartRange('ethereum', {
|
|
709
|
+
* from: 1640995200,
|
|
710
|
+
* to: 1672531200,
|
|
711
|
+
* });
|
|
712
|
+
* ```
|
|
713
|
+
*/
|
|
714
|
+
async totalSupplyChartRange(id, params) {
|
|
715
|
+
return this.client.get(
|
|
716
|
+
`/coins/${id}/total_supply_chart/range`,
|
|
717
|
+
params
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
// -------------------------------------------------------------------------
|
|
721
|
+
// Contract address
|
|
722
|
+
// -------------------------------------------------------------------------
|
|
723
|
+
/**
|
|
724
|
+
* @description Get full coin data for a token by its smart contract address
|
|
725
|
+
* on a given asset platform.
|
|
726
|
+
*
|
|
727
|
+
* @param platformId - Asset platform ID (e.g. `'ethereum'`, `'binance-smart-chain'`).
|
|
728
|
+
* @param contractAddress - Token contract address (e.g. `'0xdac17f…'`).
|
|
729
|
+
* @returns A `CoinDetail` object equivalent to `/coins/{id}`.
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* ```ts
|
|
733
|
+
* const usdt = await coins.getByContract(
|
|
734
|
+
* 'ethereum',
|
|
735
|
+
* '0xdac17f958d2ee523a2206206994597c13d831ec7',
|
|
736
|
+
* );
|
|
737
|
+
* console.log(usdt.name); // 'Tether'
|
|
738
|
+
* ```
|
|
739
|
+
*/
|
|
740
|
+
async getByContract(platformId, contractAddress) {
|
|
741
|
+
return this.client.get(`/coins/${platformId}/contract/${contractAddress}`);
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* @description Get historical market chart data (price, market cap, volume)
|
|
745
|
+
* for a token identified by its contract address on a given asset platform.
|
|
746
|
+
*
|
|
747
|
+
* @param platformId - Asset platform ID (e.g. `'ethereum'`).
|
|
748
|
+
* @param contractAddress - Token contract address.
|
|
749
|
+
* @param params - Query parameters including required `vs_currency` and
|
|
750
|
+
* `days`.
|
|
751
|
+
* @returns A `MarketChartResponse` with price, market cap, and volume time
|
|
752
|
+
* series.
|
|
753
|
+
*
|
|
754
|
+
* @example
|
|
755
|
+
* ```ts
|
|
756
|
+
* const chart = await coins.contractMarketChart(
|
|
757
|
+
* 'ethereum',
|
|
758
|
+
* '0xdac17f958d2ee523a2206206994597c13d831ec7',
|
|
759
|
+
* { vs_currency: 'usd', days: 30 },
|
|
760
|
+
* );
|
|
761
|
+
* ```
|
|
762
|
+
*/
|
|
763
|
+
async contractMarketChart(platformId, contractAddress, params) {
|
|
764
|
+
return this.client.get(
|
|
765
|
+
`/coins/${platformId}/contract/${contractAddress}/market_chart`,
|
|
766
|
+
params
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* @description Get historical market chart data for a token identified by
|
|
771
|
+
* its contract address, within a UNIX timestamp range.
|
|
772
|
+
*
|
|
773
|
+
* @param platformId - Asset platform ID (e.g. `'ethereum'`).
|
|
774
|
+
* @param contractAddress - Token contract address.
|
|
775
|
+
* @param params - Query parameters including required `vs_currency`, `from`,
|
|
776
|
+
* and `to` UNIX timestamps (seconds).
|
|
777
|
+
* @returns A `MarketChartResponse` with price, market cap, and volume time
|
|
778
|
+
* series.
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* ```ts
|
|
782
|
+
* const chart = await coins.contractMarketChartRange(
|
|
783
|
+
* 'ethereum',
|
|
784
|
+
* '0xdac17f958d2ee523a2206206994597c13d831ec7',
|
|
785
|
+
* { vs_currency: 'usd', from: 1640995200, to: 1672531200 },
|
|
786
|
+
* );
|
|
787
|
+
* ```
|
|
788
|
+
*/
|
|
789
|
+
async contractMarketChartRange(platformId, contractAddress, params) {
|
|
790
|
+
return this.client.get(
|
|
791
|
+
`/coins/${platformId}/contract/${contractAddress}/market_chart/range`,
|
|
792
|
+
params
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
// -------------------------------------------------------------------------
|
|
796
|
+
// Categories
|
|
797
|
+
// -------------------------------------------------------------------------
|
|
798
|
+
/**
|
|
799
|
+
* @description Get a flat list of all coin categories available on
|
|
800
|
+
* CoinGecko, returning only the category ID and name.
|
|
801
|
+
*
|
|
802
|
+
* @returns An array of `CategoryListEntry` items with `category_id` and
|
|
803
|
+
* `name`.
|
|
804
|
+
*
|
|
805
|
+
* @example
|
|
806
|
+
* ```ts
|
|
807
|
+
* const list = await coins.categoriesList();
|
|
808
|
+
* // [{ category_id: 'decentralized-finance-defi', name: 'DeFi' }, ...]
|
|
809
|
+
* ```
|
|
810
|
+
*/
|
|
811
|
+
async categoriesList() {
|
|
812
|
+
return this.client.get("/coins/categories/list");
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* @description Get all coin categories with market data (market cap, 24h
|
|
816
|
+
* change, volume, top coins), optionally sorted.
|
|
817
|
+
*
|
|
818
|
+
* @param params - Optional query parameters for sort order.
|
|
819
|
+
* @returns An array of `Category` objects with market statistics.
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* ```ts
|
|
823
|
+
* const categories = await coins.categories({ order: 'market_cap_desc' });
|
|
824
|
+
* console.log(categories[0].name, categories[0].market_cap);
|
|
825
|
+
* ```
|
|
826
|
+
*/
|
|
827
|
+
async categories(params) {
|
|
828
|
+
return this.client.get(
|
|
829
|
+
"/coins/categories",
|
|
830
|
+
params
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
// src/endpoints/exchanges.ts
|
|
836
|
+
var ExchangesEndpoints = class {
|
|
837
|
+
constructor(client) {
|
|
838
|
+
this.client = client;
|
|
839
|
+
}
|
|
840
|
+
// ---------------------------------------------------------------------------
|
|
841
|
+
// /exchanges
|
|
842
|
+
// ---------------------------------------------------------------------------
|
|
843
|
+
/**
|
|
844
|
+
* Returns a paginated list of all active exchanges with market data.
|
|
845
|
+
*
|
|
846
|
+
* @param params - Optional pagination parameters (`per_page`, `page`).
|
|
847
|
+
* @returns Array of {@link Exchange} objects ordered by trust score rank.
|
|
848
|
+
*
|
|
849
|
+
* @example
|
|
850
|
+
* ```ts
|
|
851
|
+
* const page1 = await exchanges.list({ per_page: 50, page: 1 });
|
|
852
|
+
* ```
|
|
853
|
+
*/
|
|
854
|
+
async list(params) {
|
|
855
|
+
return this.client.get("/exchanges", params);
|
|
856
|
+
}
|
|
857
|
+
// ---------------------------------------------------------------------------
|
|
858
|
+
// /exchanges/list
|
|
859
|
+
// ---------------------------------------------------------------------------
|
|
860
|
+
/**
|
|
861
|
+
* Returns a lightweight list of all exchange IDs and names.
|
|
862
|
+
*
|
|
863
|
+
* Use this endpoint to resolve exchange API IDs for subsequent calls
|
|
864
|
+
* rather than fetching full exchange data.
|
|
865
|
+
*
|
|
866
|
+
* @returns Array of {@link ExchangeListEntry} objects (`id` + `name` only).
|
|
867
|
+
*
|
|
868
|
+
* @example
|
|
869
|
+
* ```ts
|
|
870
|
+
* const ids = await exchanges.listAll();
|
|
871
|
+
* // [{ id: 'binance', name: 'Binance' }, ...]
|
|
872
|
+
* ```
|
|
873
|
+
*/
|
|
874
|
+
async listAll() {
|
|
875
|
+
return this.client.get("/exchanges/list");
|
|
876
|
+
}
|
|
877
|
+
// ---------------------------------------------------------------------------
|
|
878
|
+
// /exchanges/{id}
|
|
879
|
+
// ---------------------------------------------------------------------------
|
|
880
|
+
/**
|
|
881
|
+
* Returns full details for a single exchange by its API ID.
|
|
882
|
+
*
|
|
883
|
+
* @param id - Exchange API ID (e.g. `"binance"`). Use {@link listAll} to
|
|
884
|
+
* discover valid IDs.
|
|
885
|
+
* @returns {@link ExchangeDetail} including social links, trust score, and
|
|
886
|
+
* top 100 tickers.
|
|
887
|
+
*
|
|
888
|
+
* @example
|
|
889
|
+
* ```ts
|
|
890
|
+
* const binance = await exchanges.getById('binance');
|
|
891
|
+
* console.log(binance.trust_score); // 10
|
|
892
|
+
* ```
|
|
893
|
+
*/
|
|
894
|
+
async getById(id) {
|
|
895
|
+
return this.client.get(`/exchanges/${encodeURIComponent(id)}`);
|
|
896
|
+
}
|
|
897
|
+
// ---------------------------------------------------------------------------
|
|
898
|
+
// /exchanges/{id}/tickers
|
|
899
|
+
// ---------------------------------------------------------------------------
|
|
900
|
+
/**
|
|
901
|
+
* Returns paginated tickers for a specific exchange.
|
|
902
|
+
*
|
|
903
|
+
* @param id - Exchange API ID (e.g. `"binance"`).
|
|
904
|
+
* @param params - Optional filter/sort/pagination parameters.
|
|
905
|
+
* @returns {@link ExchangeTickersResponse} containing the exchange name and
|
|
906
|
+
* an array of tickers.
|
|
907
|
+
*
|
|
908
|
+
* @example
|
|
909
|
+
* ```ts
|
|
910
|
+
* const result = await exchanges.tickers('binance', {
|
|
911
|
+
* coin_ids: 'bitcoin,ethereum',
|
|
912
|
+
* order: 'trust_score_desc',
|
|
913
|
+
* });
|
|
914
|
+
* console.log(result.tickers.length);
|
|
915
|
+
* ```
|
|
916
|
+
*/
|
|
917
|
+
async tickers(id, params) {
|
|
918
|
+
return this.client.get(
|
|
919
|
+
`/exchanges/${encodeURIComponent(id)}/tickers`,
|
|
920
|
+
params
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
// ---------------------------------------------------------------------------
|
|
924
|
+
// /exchanges/{id}/volume_chart
|
|
925
|
+
// ---------------------------------------------------------------------------
|
|
926
|
+
/**
|
|
927
|
+
* Returns BTC-denominated volume chart data for a specific exchange.
|
|
928
|
+
*
|
|
929
|
+
* @param id - Exchange API ID (e.g. `"binance"`).
|
|
930
|
+
* @param params - Required query parameters, including `days`.
|
|
931
|
+
* @returns {@link VolumeChartResponse} — array of `[timestamp_ms, volume_btc]`
|
|
932
|
+
* tuples. Volume is returned as a string to preserve precision.
|
|
933
|
+
*
|
|
934
|
+
* @example
|
|
935
|
+
* ```ts
|
|
936
|
+
* const chart = await exchanges.volumeChart('binance', { days: '30' });
|
|
937
|
+
* // [[1711792200000, '306800.051794'], ...]
|
|
938
|
+
* ```
|
|
939
|
+
*/
|
|
940
|
+
async volumeChart(id, params) {
|
|
941
|
+
return this.client.get(
|
|
942
|
+
`/exchanges/${encodeURIComponent(id)}/volume_chart`,
|
|
943
|
+
params
|
|
944
|
+
);
|
|
945
|
+
}
|
|
946
|
+
// ---------------------------------------------------------------------------
|
|
947
|
+
// /exchanges/{id}/volume_chart/range (Analyst+)
|
|
948
|
+
// ---------------------------------------------------------------------------
|
|
949
|
+
/**
|
|
950
|
+
* Returns BTC-denominated volume chart data for an exchange over a custom
|
|
951
|
+
* Unix timestamp range.
|
|
952
|
+
*
|
|
953
|
+
* @param id - Exchange API ID (e.g. `"binance"`).
|
|
954
|
+
* @param params - Required `from` and `to` Unix timestamps (seconds).
|
|
955
|
+
* @returns {@link VolumeChartResponse} — array of `[timestamp_ms, volume_btc]`
|
|
956
|
+
* tuples.
|
|
957
|
+
*
|
|
958
|
+
* @remarks Requires **Analyst+** plan.
|
|
959
|
+
*
|
|
960
|
+
* @example
|
|
961
|
+
* ```ts
|
|
962
|
+
* const chart = await exchanges.volumeChartRange('binance', {
|
|
963
|
+
* from: 1711670400,
|
|
964
|
+
* to: 1712275200,
|
|
965
|
+
* });
|
|
966
|
+
* ```
|
|
967
|
+
*/
|
|
968
|
+
async volumeChartRange(id, params) {
|
|
969
|
+
return this.client.get(
|
|
970
|
+
`/exchanges/${encodeURIComponent(id)}/volume_chart/range`,
|
|
971
|
+
params
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
// src/endpoints/derivatives.ts
|
|
977
|
+
var DerivativesEndpoints = class {
|
|
978
|
+
constructor(client) {
|
|
979
|
+
this.client = client;
|
|
980
|
+
}
|
|
981
|
+
// ---------------------------------------------------------------------------
|
|
982
|
+
// /derivatives
|
|
983
|
+
// ---------------------------------------------------------------------------
|
|
984
|
+
/**
|
|
985
|
+
* Returns a list of all derivative tickers across all derivatives exchanges.
|
|
986
|
+
*
|
|
987
|
+
* @param params - Optional filter parameters.
|
|
988
|
+
* @param params.include_tickers - Whether to include tickers.
|
|
989
|
+
* `"all"` returns all tickers; `"unexpired"` excludes expired contracts.
|
|
990
|
+
* @returns Array of {@link DerivativeTicker} objects.
|
|
991
|
+
*
|
|
992
|
+
* @example
|
|
993
|
+
* ```ts
|
|
994
|
+
* const allTickers = await deriv.tickers({ include_tickers: 'unexpired' });
|
|
995
|
+
* ```
|
|
996
|
+
*/
|
|
997
|
+
async tickers(params) {
|
|
998
|
+
return this.client.get("/derivatives", params);
|
|
999
|
+
}
|
|
1000
|
+
// ---------------------------------------------------------------------------
|
|
1001
|
+
// /derivatives/exchanges
|
|
1002
|
+
// ---------------------------------------------------------------------------
|
|
1003
|
+
/**
|
|
1004
|
+
* Returns a paginated list of all derivatives exchanges.
|
|
1005
|
+
*
|
|
1006
|
+
* @param params - Optional sort and pagination parameters.
|
|
1007
|
+
* @returns Array of {@link DerivativeExchange} objects.
|
|
1008
|
+
*
|
|
1009
|
+
* @example
|
|
1010
|
+
* ```ts
|
|
1011
|
+
* const top = await deriv.exchanges({
|
|
1012
|
+
* order: 'open_interest_btc_desc',
|
|
1013
|
+
* per_page: 10,
|
|
1014
|
+
* });
|
|
1015
|
+
* ```
|
|
1016
|
+
*/
|
|
1017
|
+
async exchanges(params) {
|
|
1018
|
+
return this.client.get(
|
|
1019
|
+
"/derivatives/exchanges",
|
|
1020
|
+
params
|
|
1021
|
+
);
|
|
1022
|
+
}
|
|
1023
|
+
// ---------------------------------------------------------------------------
|
|
1024
|
+
// /derivatives/exchanges/{id}
|
|
1025
|
+
// ---------------------------------------------------------------------------
|
|
1026
|
+
/**
|
|
1027
|
+
* Returns detailed data for a single derivatives exchange by its API ID.
|
|
1028
|
+
*
|
|
1029
|
+
* @param id - Derivatives exchange API ID (e.g. `"binance_futures"`).
|
|
1030
|
+
* @param params - Optional parameters to include ticker data.
|
|
1031
|
+
* @returns {@link DerivativeExchangeDetail} with optional tickers array.
|
|
1032
|
+
*
|
|
1033
|
+
* @example
|
|
1034
|
+
* ```ts
|
|
1035
|
+
* const detail = await deriv.exchangeById('binance_futures', {
|
|
1036
|
+
* include_tickers: 'unexpired',
|
|
1037
|
+
* });
|
|
1038
|
+
* console.log(detail.open_interest_btc);
|
|
1039
|
+
* ```
|
|
1040
|
+
*/
|
|
1041
|
+
async exchangeById(id, params) {
|
|
1042
|
+
return this.client.get(
|
|
1043
|
+
`/derivatives/exchanges/${encodeURIComponent(id)}`,
|
|
1044
|
+
params
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
// ---------------------------------------------------------------------------
|
|
1048
|
+
// /derivatives/exchanges/list
|
|
1049
|
+
// ---------------------------------------------------------------------------
|
|
1050
|
+
/**
|
|
1051
|
+
* Returns a lightweight list of all derivatives exchange IDs and names.
|
|
1052
|
+
*
|
|
1053
|
+
* Use this to resolve exchange API IDs for subsequent calls.
|
|
1054
|
+
*
|
|
1055
|
+
* @returns Array of {@link ExchangeListEntry} objects (`id` + `name` only).
|
|
1056
|
+
*
|
|
1057
|
+
* @example
|
|
1058
|
+
* ```ts
|
|
1059
|
+
* const ids = await deriv.exchangesList();
|
|
1060
|
+
* // [{ id: 'binance_futures', name: 'Binance (Futures)' }, ...]
|
|
1061
|
+
* ```
|
|
1062
|
+
*/
|
|
1063
|
+
async exchangesList() {
|
|
1064
|
+
return this.client.get("/derivatives/exchanges/list");
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
// src/endpoints/nfts.ts
|
|
1069
|
+
var NftsEndpoints = class {
|
|
1070
|
+
constructor(client) {
|
|
1071
|
+
this.client = client;
|
|
1072
|
+
}
|
|
1073
|
+
// ---------------------------------------------------------------------------
|
|
1074
|
+
// /nfts/list
|
|
1075
|
+
// ---------------------------------------------------------------------------
|
|
1076
|
+
/**
|
|
1077
|
+
* Returns a paginated list of all NFT collections supported by CoinGecko.
|
|
1078
|
+
*
|
|
1079
|
+
* @param params - Optional pagination parameters (`per_page`, `page`).
|
|
1080
|
+
* @returns Array of {@link NftListEntry} objects with minimal metadata.
|
|
1081
|
+
*
|
|
1082
|
+
* @example
|
|
1083
|
+
* ```ts
|
|
1084
|
+
* const collections = await nfts.list({ per_page: 100, page: 1 });
|
|
1085
|
+
* ```
|
|
1086
|
+
*/
|
|
1087
|
+
async list(params) {
|
|
1088
|
+
return this.client.get("/nfts/list", params);
|
|
1089
|
+
}
|
|
1090
|
+
// ---------------------------------------------------------------------------
|
|
1091
|
+
// /nfts/{id}
|
|
1092
|
+
// ---------------------------------------------------------------------------
|
|
1093
|
+
/**
|
|
1094
|
+
* Returns full data for a single NFT collection by its CoinGecko API ID.
|
|
1095
|
+
*
|
|
1096
|
+
* @param id - NFT collection API ID (e.g. `"pudgy-penguins"`). Use
|
|
1097
|
+
* {@link list} to discover valid IDs.
|
|
1098
|
+
* @returns {@link NftCollection} with floor price, market cap, volume, and
|
|
1099
|
+
* other collection metadata.
|
|
1100
|
+
*
|
|
1101
|
+
* @example
|
|
1102
|
+
* ```ts
|
|
1103
|
+
* const penguins = await nfts.getById('pudgy-penguins');
|
|
1104
|
+
* console.log(penguins.floor_price?.usd);
|
|
1105
|
+
* ```
|
|
1106
|
+
*/
|
|
1107
|
+
async getById(id) {
|
|
1108
|
+
return this.client.get(`/nfts/${encodeURIComponent(id)}`);
|
|
1109
|
+
}
|
|
1110
|
+
// ---------------------------------------------------------------------------
|
|
1111
|
+
// /nfts/{platformId}/contract/{address}
|
|
1112
|
+
// ---------------------------------------------------------------------------
|
|
1113
|
+
/**
|
|
1114
|
+
* Returns full data for a single NFT collection identified by its contract
|
|
1115
|
+
* address on a specific asset platform.
|
|
1116
|
+
*
|
|
1117
|
+
* @param platformId - Asset platform ID (e.g. `"ethereum"`).
|
|
1118
|
+
* @param address - Token contract address (e.g. `"0xBd3531..."`).
|
|
1119
|
+
* @returns {@link NftCollection} with the same fields as {@link getById}.
|
|
1120
|
+
*
|
|
1121
|
+
* @example
|
|
1122
|
+
* ```ts
|
|
1123
|
+
* const collection = await nfts.getByContract(
|
|
1124
|
+
* 'ethereum',
|
|
1125
|
+
* '0xBd3531dA5CF5857e7CfAA92426877b022e612cf8',
|
|
1126
|
+
* );
|
|
1127
|
+
* ```
|
|
1128
|
+
*/
|
|
1129
|
+
async getByContract(platformId, address) {
|
|
1130
|
+
return this.client.get(
|
|
1131
|
+
`/nfts/${encodeURIComponent(platformId)}/contract/${encodeURIComponent(address)}`
|
|
1132
|
+
);
|
|
1133
|
+
}
|
|
1134
|
+
// ---------------------------------------------------------------------------
|
|
1135
|
+
// /nfts/markets (Analyst+)
|
|
1136
|
+
// ---------------------------------------------------------------------------
|
|
1137
|
+
/**
|
|
1138
|
+
* Returns a paginated list of NFT collections with market data.
|
|
1139
|
+
*
|
|
1140
|
+
* @param params - Optional filter and sort parameters.
|
|
1141
|
+
* @returns Array of {@link NftCollection} objects with market data.
|
|
1142
|
+
*
|
|
1143
|
+
* @remarks Requires **Analyst+** plan.
|
|
1144
|
+
*
|
|
1145
|
+
* @example
|
|
1146
|
+
* ```ts
|
|
1147
|
+
* const markets = await nfts.markets({
|
|
1148
|
+
* asset_platform_id: 'ethereum',
|
|
1149
|
+
* order: 'market_cap_usd_desc',
|
|
1150
|
+
* per_page: 50,
|
|
1151
|
+
* });
|
|
1152
|
+
* ```
|
|
1153
|
+
*/
|
|
1154
|
+
async markets(params) {
|
|
1155
|
+
return this.client.get("/nfts/markets", params);
|
|
1156
|
+
}
|
|
1157
|
+
// ---------------------------------------------------------------------------
|
|
1158
|
+
// /nfts/{id}/market_chart (Analyst+)
|
|
1159
|
+
// ---------------------------------------------------------------------------
|
|
1160
|
+
/**
|
|
1161
|
+
* Returns historical market chart data for a single NFT collection.
|
|
1162
|
+
*
|
|
1163
|
+
* @param id - NFT collection API ID (e.g. `"pudgy-penguins"`).
|
|
1164
|
+
* @param params - Optional query parameters, including `days`.
|
|
1165
|
+
* @returns {@link NftMarketChart} with floor price, market cap, and volume
|
|
1166
|
+
* time series.
|
|
1167
|
+
*
|
|
1168
|
+
* @remarks Requires **Analyst+** plan.
|
|
1169
|
+
*
|
|
1170
|
+
* @example
|
|
1171
|
+
* ```ts
|
|
1172
|
+
* const chart = await nfts.marketChart('pudgy-penguins', { days: 30 });
|
|
1173
|
+
* console.log(chart.floor_price_usd);
|
|
1174
|
+
* ```
|
|
1175
|
+
*/
|
|
1176
|
+
async marketChart(id, params) {
|
|
1177
|
+
return this.client.get(
|
|
1178
|
+
`/nfts/${encodeURIComponent(id)}/market_chart`,
|
|
1179
|
+
params
|
|
1180
|
+
);
|
|
1181
|
+
}
|
|
1182
|
+
// ---------------------------------------------------------------------------
|
|
1183
|
+
// /nfts/{platformId}/contract/{address}/market_chart (Analyst+)
|
|
1184
|
+
// ---------------------------------------------------------------------------
|
|
1185
|
+
/**
|
|
1186
|
+
* Returns historical market chart data for an NFT collection identified by
|
|
1187
|
+
* its contract address on a specific asset platform.
|
|
1188
|
+
*
|
|
1189
|
+
* @param platformId - Asset platform ID (e.g. `"ethereum"`).
|
|
1190
|
+
* @param address - Token contract address.
|
|
1191
|
+
* @param params - Optional query parameters, including `days`.
|
|
1192
|
+
* @returns {@link NftMarketChart} with floor price, market cap, and volume
|
|
1193
|
+
* time series.
|
|
1194
|
+
*
|
|
1195
|
+
* @remarks Requires **Analyst+** plan.
|
|
1196
|
+
*
|
|
1197
|
+
* @example
|
|
1198
|
+
* ```ts
|
|
1199
|
+
* const chart = await nfts.contractMarketChart(
|
|
1200
|
+
* 'ethereum',
|
|
1201
|
+
* '0xBd3531dA5CF5857e7CfAA92426877b022e612cf8',
|
|
1202
|
+
* { days: 14 },
|
|
1203
|
+
* );
|
|
1204
|
+
* ```
|
|
1205
|
+
*/
|
|
1206
|
+
async contractMarketChart(platformId, address, params) {
|
|
1207
|
+
return this.client.get(
|
|
1208
|
+
`/nfts/${encodeURIComponent(platformId)}/contract/${encodeURIComponent(address)}/market_chart`,
|
|
1209
|
+
params
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
1212
|
+
// ---------------------------------------------------------------------------
|
|
1213
|
+
// /nfts/{id}/tickers (Analyst+)
|
|
1214
|
+
// ---------------------------------------------------------------------------
|
|
1215
|
+
/**
|
|
1216
|
+
* Returns marketplace tickers (floor price, volume) for a single NFT
|
|
1217
|
+
* collection across all supported NFT marketplaces.
|
|
1218
|
+
*
|
|
1219
|
+
* @param id - NFT collection API ID (e.g. `"pudgy-penguins"`).
|
|
1220
|
+
* @returns {@link NftTickersResponse} with an array of marketplace tickers.
|
|
1221
|
+
*
|
|
1222
|
+
* @remarks Requires **Analyst+** plan.
|
|
1223
|
+
*
|
|
1224
|
+
* @example
|
|
1225
|
+
* ```ts
|
|
1226
|
+
* const result = await nfts.tickers('pudgy-penguins');
|
|
1227
|
+
* result.tickers.forEach(t => console.log(t.name, t.floor_price_in_native_currency));
|
|
1228
|
+
* ```
|
|
1229
|
+
*/
|
|
1230
|
+
async tickers(id) {
|
|
1231
|
+
return this.client.get(`/nfts/${encodeURIComponent(id)}/tickers`);
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
|
|
1235
|
+
// src/endpoints/onchain.ts
|
|
1236
|
+
var OnchainEndpoints = class {
|
|
1237
|
+
constructor(client) {
|
|
1238
|
+
this.client = client;
|
|
1239
|
+
}
|
|
1240
|
+
// -------------------------------------------------------------------------
|
|
1241
|
+
// Simple
|
|
1242
|
+
// -------------------------------------------------------------------------
|
|
1243
|
+
/**
|
|
1244
|
+
* Returns the current USD (or other currency) price of one or more tokens
|
|
1245
|
+
* on a given network.
|
|
1246
|
+
*
|
|
1247
|
+
* @param network - Network ID (e.g. `"eth"`, `"bsc"`).
|
|
1248
|
+
* @param addresses - Token contract address or array of addresses.
|
|
1249
|
+
* @returns A map of address → { usd: "price" } (or whichever currencies were requested).
|
|
1250
|
+
*
|
|
1251
|
+
* @example
|
|
1252
|
+
* ```ts
|
|
1253
|
+
* const prices = await onchain.tokenPrice('eth', [
|
|
1254
|
+
* '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1255
|
+
* '0xdac17f958d2ee523a2206206994597c13d831ec7',
|
|
1256
|
+
* ]);
|
|
1257
|
+
* // { '0xa0b8...': { usd: '1.001' }, '0xdac1...': { usd: '0.9998' } }
|
|
1258
|
+
* ```
|
|
1259
|
+
*/
|
|
1260
|
+
tokenPrice(network, addresses) {
|
|
1261
|
+
const addressParam = Array.isArray(addresses) ? addresses.join(",") : addresses;
|
|
1262
|
+
return this.client.get(
|
|
1263
|
+
`/onchain/simple/networks/${network}/token_price/${addressParam}`
|
|
1264
|
+
);
|
|
1265
|
+
}
|
|
1266
|
+
// -------------------------------------------------------------------------
|
|
1267
|
+
// Networks & DEXes
|
|
1268
|
+
// -------------------------------------------------------------------------
|
|
1269
|
+
/**
|
|
1270
|
+
* Returns the list of all supported networks (blockchains) on GeckoTerminal.
|
|
1271
|
+
*
|
|
1272
|
+
* @param params - Optional pagination parameters.
|
|
1273
|
+
* @returns Paginated list of network resources.
|
|
1274
|
+
*
|
|
1275
|
+
* @example
|
|
1276
|
+
* ```ts
|
|
1277
|
+
* const { data } = await onchain.networks();
|
|
1278
|
+
* data.forEach(n => console.log(n.id, n.attributes.name));
|
|
1279
|
+
* ```
|
|
1280
|
+
*/
|
|
1281
|
+
networks(params) {
|
|
1282
|
+
return this.client.get("/onchain/networks", params);
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Returns the list of DEXes available on a given network.
|
|
1286
|
+
*
|
|
1287
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1288
|
+
* @param params - Optional pagination parameters.
|
|
1289
|
+
* @returns Paginated list of DEX resources.
|
|
1290
|
+
*
|
|
1291
|
+
* @example
|
|
1292
|
+
* ```ts
|
|
1293
|
+
* const { data } = await onchain.dexes('eth');
|
|
1294
|
+
* data.forEach(d => console.log(d.id, d.attributes.name));
|
|
1295
|
+
* ```
|
|
1296
|
+
*/
|
|
1297
|
+
dexes(network, params) {
|
|
1298
|
+
return this.client.get(
|
|
1299
|
+
`/onchain/networks/${network}/dexes`,
|
|
1300
|
+
params
|
|
1301
|
+
);
|
|
1302
|
+
}
|
|
1303
|
+
// -------------------------------------------------------------------------
|
|
1304
|
+
// Pools
|
|
1305
|
+
// -------------------------------------------------------------------------
|
|
1306
|
+
/**
|
|
1307
|
+
* Returns detailed data for a single pool by contract address.
|
|
1308
|
+
*
|
|
1309
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1310
|
+
* @param address - Pool contract address.
|
|
1311
|
+
* @returns Single pool resource (JSON:API envelope).
|
|
1312
|
+
*
|
|
1313
|
+
* @example
|
|
1314
|
+
* ```ts
|
|
1315
|
+
* const { data } = await onchain.pool('eth', '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640');
|
|
1316
|
+
* console.log(data.attributes.name, data.attributes.reserve_in_usd);
|
|
1317
|
+
* ```
|
|
1318
|
+
*/
|
|
1319
|
+
pool(network, address) {
|
|
1320
|
+
return this.client.get(
|
|
1321
|
+
`/onchain/networks/${network}/pools/${address}`
|
|
1322
|
+
);
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Returns data for multiple pools by contract addresses in one request.
|
|
1326
|
+
*
|
|
1327
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1328
|
+
* @param addresses - Array of pool contract addresses (joined as comma-separated path segment).
|
|
1329
|
+
* @returns List of pool resources (JSON:API envelope).
|
|
1330
|
+
*
|
|
1331
|
+
* @example
|
|
1332
|
+
* ```ts
|
|
1333
|
+
* const { data } = await onchain.pools('eth', [
|
|
1334
|
+
* '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640',
|
|
1335
|
+
* '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8',
|
|
1336
|
+
* ]);
|
|
1337
|
+
* ```
|
|
1338
|
+
*/
|
|
1339
|
+
pools(network, addresses) {
|
|
1340
|
+
return this.client.get(
|
|
1341
|
+
`/onchain/networks/${network}/pools/multi/${addresses.join(",")}`
|
|
1342
|
+
);
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Returns the top pools on a given network ranked by volume or liquidity.
|
|
1346
|
+
*
|
|
1347
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1348
|
+
* @param params - Optional pagination parameters.
|
|
1349
|
+
* @returns Paginated list of pool resources.
|
|
1350
|
+
*
|
|
1351
|
+
* @example
|
|
1352
|
+
* ```ts
|
|
1353
|
+
* const { data } = await onchain.topPools('eth', { page: 1 });
|
|
1354
|
+
* ```
|
|
1355
|
+
*/
|
|
1356
|
+
topPools(network, params) {
|
|
1357
|
+
return this.client.get(
|
|
1358
|
+
`/onchain/networks/${network}/pools`,
|
|
1359
|
+
params
|
|
1360
|
+
);
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Returns the top pools for a specific DEX on a given network.
|
|
1364
|
+
*
|
|
1365
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1366
|
+
* @param dex - DEX ID (e.g. `"uniswap_v3"`).
|
|
1367
|
+
* @param params - Optional pagination parameters.
|
|
1368
|
+
* @returns Paginated list of pool resources.
|
|
1369
|
+
*
|
|
1370
|
+
* @example
|
|
1371
|
+
* ```ts
|
|
1372
|
+
* const { data } = await onchain.topPoolsByDex('eth', 'uniswap_v3');
|
|
1373
|
+
* ```
|
|
1374
|
+
*/
|
|
1375
|
+
topPoolsByDex(network, dex, params) {
|
|
1376
|
+
return this.client.get(
|
|
1377
|
+
`/onchain/networks/${network}/dexes/${dex}/pools`,
|
|
1378
|
+
params
|
|
1379
|
+
);
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Returns trending pools, either globally or filtered to a specific network.
|
|
1383
|
+
*
|
|
1384
|
+
* When `network` is omitted, the global trending pools endpoint is used:
|
|
1385
|
+
* `GET /onchain/networks/trending_pools`.
|
|
1386
|
+
* When `network` is provided: `GET /onchain/networks/{network}/trending_pools`.
|
|
1387
|
+
*
|
|
1388
|
+
* @param network - Optional network ID to scope results.
|
|
1389
|
+
* @param params - Optional pagination parameters.
|
|
1390
|
+
* @returns Paginated list of trending pool resources.
|
|
1391
|
+
*
|
|
1392
|
+
* @example
|
|
1393
|
+
* ```ts
|
|
1394
|
+
* // Global trending
|
|
1395
|
+
* const { data } = await onchain.trendingPools();
|
|
1396
|
+
*
|
|
1397
|
+
* // Network-scoped trending
|
|
1398
|
+
* const { data: ethTrending } = await onchain.trendingPools('eth');
|
|
1399
|
+
* ```
|
|
1400
|
+
*/
|
|
1401
|
+
trendingPools(network, params) {
|
|
1402
|
+
const path = network ? `/onchain/networks/${network}/trending_pools` : "/onchain/networks/trending_pools";
|
|
1403
|
+
return this.client.get(path, params);
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Returns newly created pools, either globally or filtered to a specific network.
|
|
1407
|
+
*
|
|
1408
|
+
* When `network` is omitted, the global new pools endpoint is used:
|
|
1409
|
+
* `GET /onchain/networks/new_pools`.
|
|
1410
|
+
* When `network` is provided: `GET /onchain/networks/{network}/new_pools`.
|
|
1411
|
+
*
|
|
1412
|
+
* @param network - Optional network ID to scope results.
|
|
1413
|
+
* @param params - Optional pagination parameters.
|
|
1414
|
+
* @returns Paginated list of new pool resources.
|
|
1415
|
+
*
|
|
1416
|
+
* @example
|
|
1417
|
+
* ```ts
|
|
1418
|
+
* // All new pools across all networks
|
|
1419
|
+
* const { data } = await onchain.newPools();
|
|
1420
|
+
*
|
|
1421
|
+
* // New pools on Solana only
|
|
1422
|
+
* const { data: solNew } = await onchain.newPools('solana');
|
|
1423
|
+
* ```
|
|
1424
|
+
*/
|
|
1425
|
+
newPools(network, params) {
|
|
1426
|
+
const path = network ? `/onchain/networks/${network}/new_pools` : "/onchain/networks/new_pools";
|
|
1427
|
+
return this.client.get(path, params);
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Returns pools matching advanced filter criteria (megafilter).
|
|
1431
|
+
*
|
|
1432
|
+
* @remarks
|
|
1433
|
+
* **Requires Analyst+ (💼) plan.** Calls are rejected with HTTP 403 on
|
|
1434
|
+
* lower-tier keys.
|
|
1435
|
+
*
|
|
1436
|
+
* @param params - Filter, sort, and pagination parameters.
|
|
1437
|
+
* @returns Paginated list of pool resources matching the criteria.
|
|
1438
|
+
*
|
|
1439
|
+
* @example
|
|
1440
|
+
* ```ts
|
|
1441
|
+
* const { data } = await onchain.megafilter({
|
|
1442
|
+
* network: 'eth',
|
|
1443
|
+
* reserve_in_usd_gte: 100_000,
|
|
1444
|
+
* sort: 'h24_volume_usd',
|
|
1445
|
+
* page: 1,
|
|
1446
|
+
* });
|
|
1447
|
+
* ```
|
|
1448
|
+
*/
|
|
1449
|
+
megafilter(params) {
|
|
1450
|
+
return this.client.get(
|
|
1451
|
+
"/onchain/pools/megafilter",
|
|
1452
|
+
params
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
/**
|
|
1456
|
+
* Searches for pools matching a text query across all networks or a
|
|
1457
|
+
* specific network.
|
|
1458
|
+
*
|
|
1459
|
+
* @param query - Search query string (token name, symbol, or pool address).
|
|
1460
|
+
* @param params - Optional network filter and pagination parameters.
|
|
1461
|
+
* @returns Paginated list of matching pool resources.
|
|
1462
|
+
*
|
|
1463
|
+
* @example
|
|
1464
|
+
* ```ts
|
|
1465
|
+
* const { data } = await onchain.searchPools('PEPE');
|
|
1466
|
+
* const { data: ethPepe } = await onchain.searchPools('PEPE', { network: 'eth' });
|
|
1467
|
+
* ```
|
|
1468
|
+
*/
|
|
1469
|
+
searchPools(query, params) {
|
|
1470
|
+
return this.client.get(
|
|
1471
|
+
"/onchain/search/pools",
|
|
1472
|
+
{ query, ...params }
|
|
1473
|
+
);
|
|
1474
|
+
}
|
|
1475
|
+
/**
|
|
1476
|
+
* Returns pools that are currently trending in search on GeckoTerminal.
|
|
1477
|
+
*
|
|
1478
|
+
* @remarks
|
|
1479
|
+
* **Requires Analyst+ (💼) plan.** Calls are rejected with HTTP 403 on
|
|
1480
|
+
* lower-tier keys.
|
|
1481
|
+
*
|
|
1482
|
+
* @returns List of trending-search pool resources.
|
|
1483
|
+
*
|
|
1484
|
+
* @example
|
|
1485
|
+
* ```ts
|
|
1486
|
+
* const { data } = await onchain.trendingSearchPools();
|
|
1487
|
+
* ```
|
|
1488
|
+
*/
|
|
1489
|
+
trendingSearchPools() {
|
|
1490
|
+
return this.client.get(
|
|
1491
|
+
"/onchain/pools/trending_search"
|
|
1492
|
+
);
|
|
1493
|
+
}
|
|
1494
|
+
/**
|
|
1495
|
+
* Returns rich metadata / info for a single pool.
|
|
1496
|
+
*
|
|
1497
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1498
|
+
* @param poolAddress - Pool contract address.
|
|
1499
|
+
* @returns Single pool info resource (JSON:API envelope).
|
|
1500
|
+
*
|
|
1501
|
+
* @example
|
|
1502
|
+
* ```ts
|
|
1503
|
+
* const { data } = await onchain.poolInfo('eth', '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640');
|
|
1504
|
+
* ```
|
|
1505
|
+
*/
|
|
1506
|
+
poolInfo(network, poolAddress) {
|
|
1507
|
+
return this.client.get(
|
|
1508
|
+
`/onchain/networks/${network}/pools/${poolAddress}/info`
|
|
1509
|
+
);
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* Returns OHLCV (candlestick) data for a pool.
|
|
1513
|
+
*
|
|
1514
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1515
|
+
* @param poolAddress - Pool contract address.
|
|
1516
|
+
* @param timeframe - Candle timeframe: `"minute"`, `"hour"`, or `"day"`.
|
|
1517
|
+
* @param params - Optional OHLCV query parameters (aggregate, limit, etc.).
|
|
1518
|
+
* @returns OHLCV response containing an array of candles and token metadata.
|
|
1519
|
+
*
|
|
1520
|
+
* @example
|
|
1521
|
+
* ```ts
|
|
1522
|
+
* const ohlcv = await onchain.poolOhlcv(
|
|
1523
|
+
* 'eth',
|
|
1524
|
+
* '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640',
|
|
1525
|
+
* 'hour',
|
|
1526
|
+
* { aggregate: '4', limit: 200 },
|
|
1527
|
+
* );
|
|
1528
|
+
* ohlcv.data?.attributes?.ohlcv_list?.forEach(([ts, o, h, l, c, v]) => {
|
|
1529
|
+
* console.log(new Date(ts * 1000).toISOString(), c);
|
|
1530
|
+
* });
|
|
1531
|
+
* ```
|
|
1532
|
+
*/
|
|
1533
|
+
poolOhlcv(network, poolAddress, timeframe, params) {
|
|
1534
|
+
return this.client.get(
|
|
1535
|
+
`/onchain/networks/${network}/pools/${poolAddress}/ohlcv/${timeframe}`,
|
|
1536
|
+
params
|
|
1537
|
+
);
|
|
1538
|
+
}
|
|
1539
|
+
/**
|
|
1540
|
+
* Returns recent trades for a pool.
|
|
1541
|
+
*
|
|
1542
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1543
|
+
* @param poolAddress - Pool contract address.
|
|
1544
|
+
* @param params - Optional query parameters (e.g. `trade_volume_in_usd_greater_than`).
|
|
1545
|
+
* @returns Trades response containing an array of trade objects.
|
|
1546
|
+
*
|
|
1547
|
+
* @example
|
|
1548
|
+
* ```ts
|
|
1549
|
+
* const trades = await onchain.poolTrades(
|
|
1550
|
+
* 'eth',
|
|
1551
|
+
* '0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640',
|
|
1552
|
+
* );
|
|
1553
|
+
* ```
|
|
1554
|
+
*/
|
|
1555
|
+
poolTrades(network, poolAddress, params) {
|
|
1556
|
+
return this.client.get(
|
|
1557
|
+
`/onchain/networks/${network}/pools/${poolAddress}/trades`,
|
|
1558
|
+
params
|
|
1559
|
+
);
|
|
1560
|
+
}
|
|
1561
|
+
// -------------------------------------------------------------------------
|
|
1562
|
+
// Tokens
|
|
1563
|
+
// -------------------------------------------------------------------------
|
|
1564
|
+
/**
|
|
1565
|
+
* Returns price and market data for a single token by contract address.
|
|
1566
|
+
*
|
|
1567
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1568
|
+
* @param address - Token contract address.
|
|
1569
|
+
* @returns Single token resource (JSON:API envelope).
|
|
1570
|
+
*
|
|
1571
|
+
* @example
|
|
1572
|
+
* ```ts
|
|
1573
|
+
* const { data } = await onchain.token(
|
|
1574
|
+
* 'eth',
|
|
1575
|
+
* '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1576
|
+
* );
|
|
1577
|
+
* console.log(data.attributes.symbol, data.attributes.price_usd);
|
|
1578
|
+
* ```
|
|
1579
|
+
*/
|
|
1580
|
+
token(network, address) {
|
|
1581
|
+
return this.client.get(
|
|
1582
|
+
`/onchain/networks/${network}/tokens/${address}`
|
|
1583
|
+
);
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Returns price and market data for multiple tokens in one request.
|
|
1587
|
+
*
|
|
1588
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1589
|
+
* @param addresses - Array of token contract addresses (joined as comma-separated path segment).
|
|
1590
|
+
* @returns List of token resources (JSON:API envelope).
|
|
1591
|
+
*
|
|
1592
|
+
* @example
|
|
1593
|
+
* ```ts
|
|
1594
|
+
* const { data } = await onchain.tokens('eth', [
|
|
1595
|
+
* '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1596
|
+
* '0xdac17f958d2ee523a2206206994597c13d831ec7',
|
|
1597
|
+
* ]);
|
|
1598
|
+
* ```
|
|
1599
|
+
*/
|
|
1600
|
+
tokens(network, addresses) {
|
|
1601
|
+
return this.client.get(
|
|
1602
|
+
`/onchain/networks/${network}/tokens/multi/${addresses.join(",")}`
|
|
1603
|
+
);
|
|
1604
|
+
}
|
|
1605
|
+
/**
|
|
1606
|
+
* Returns rich metadata (socials, description, security flags) for a token.
|
|
1607
|
+
*
|
|
1608
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1609
|
+
* @param address - Token contract address.
|
|
1610
|
+
* @returns Token info resource (JSON:API envelope).
|
|
1611
|
+
*
|
|
1612
|
+
* @example
|
|
1613
|
+
* ```ts
|
|
1614
|
+
* const { data } = await onchain.tokenInfo(
|
|
1615
|
+
* 'eth',
|
|
1616
|
+
* '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1617
|
+
* );
|
|
1618
|
+
* console.log(data.attributes.description, data.attributes.gt_score);
|
|
1619
|
+
* ```
|
|
1620
|
+
*/
|
|
1621
|
+
tokenInfo(network, address) {
|
|
1622
|
+
return this.client.get(
|
|
1623
|
+
`/onchain/networks/${network}/tokens/${address}/info`
|
|
1624
|
+
);
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Returns the list of pools that include a given token.
|
|
1628
|
+
*
|
|
1629
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1630
|
+
* @param address - Token contract address.
|
|
1631
|
+
* @param params - Optional pagination parameters.
|
|
1632
|
+
* @returns Paginated list of pool resources containing the token.
|
|
1633
|
+
*
|
|
1634
|
+
* @example
|
|
1635
|
+
* ```ts
|
|
1636
|
+
* const { data } = await onchain.tokenPools(
|
|
1637
|
+
* 'eth',
|
|
1638
|
+
* '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1639
|
+
* );
|
|
1640
|
+
* ```
|
|
1641
|
+
*/
|
|
1642
|
+
tokenPools(network, address, params) {
|
|
1643
|
+
return this.client.get(
|
|
1644
|
+
`/onchain/networks/${network}/tokens/${address}/pools`,
|
|
1645
|
+
params
|
|
1646
|
+
);
|
|
1647
|
+
}
|
|
1648
|
+
/**
|
|
1649
|
+
* Returns OHLCV (candlestick) data for a token.
|
|
1650
|
+
*
|
|
1651
|
+
* @remarks
|
|
1652
|
+
* **Requires Analyst+ (💼) plan.** Calls are rejected with HTTP 403 on
|
|
1653
|
+
* lower-tier keys.
|
|
1654
|
+
*
|
|
1655
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1656
|
+
* @param address - Token contract address.
|
|
1657
|
+
* @param timeframe - Candle timeframe: `"minute"`, `"hour"`, or `"day"`.
|
|
1658
|
+
* @param params - Optional OHLCV query parameters (aggregate, limit, etc.).
|
|
1659
|
+
* @returns OHLCV response containing an array of candles and token metadata.
|
|
1660
|
+
*
|
|
1661
|
+
* @example
|
|
1662
|
+
* ```ts
|
|
1663
|
+
* const ohlcv = await onchain.tokenOhlcv(
|
|
1664
|
+
* 'eth',
|
|
1665
|
+
* '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1666
|
+
* 'day',
|
|
1667
|
+
* { limit: 30 },
|
|
1668
|
+
* );
|
|
1669
|
+
* ```
|
|
1670
|
+
*/
|
|
1671
|
+
tokenOhlcv(network, address, timeframe, params) {
|
|
1672
|
+
return this.client.get(
|
|
1673
|
+
`/onchain/networks/${network}/tokens/${address}/ohlcv/${timeframe}`,
|
|
1674
|
+
params
|
|
1675
|
+
);
|
|
1676
|
+
}
|
|
1677
|
+
/**
|
|
1678
|
+
* Returns recent trades involving a specific token.
|
|
1679
|
+
*
|
|
1680
|
+
* @remarks
|
|
1681
|
+
* **Requires Analyst+ (💼) plan.** Calls are rejected with HTTP 403 on
|
|
1682
|
+
* lower-tier keys.
|
|
1683
|
+
*
|
|
1684
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1685
|
+
* @param address - Token contract address.
|
|
1686
|
+
* @param params - Optional query parameters.
|
|
1687
|
+
* @returns Trades response containing recent trade objects for the token.
|
|
1688
|
+
*
|
|
1689
|
+
* @example
|
|
1690
|
+
* ```ts
|
|
1691
|
+
* const trades = await onchain.tokenTrades(
|
|
1692
|
+
* 'eth',
|
|
1693
|
+
* '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1694
|
+
* );
|
|
1695
|
+
* ```
|
|
1696
|
+
*/
|
|
1697
|
+
tokenTrades(network, address, params) {
|
|
1698
|
+
return this.client.get(
|
|
1699
|
+
`/onchain/networks/${network}/tokens/${address}/trades`,
|
|
1700
|
+
params
|
|
1701
|
+
);
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* Returns the top traders for a specific token over the last 24 hours.
|
|
1705
|
+
*
|
|
1706
|
+
* @remarks
|
|
1707
|
+
* **Requires Analyst+ (💼) plan.** Calls are rejected with HTTP 403 on
|
|
1708
|
+
* lower-tier keys.
|
|
1709
|
+
*
|
|
1710
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1711
|
+
* @param address - Token contract address.
|
|
1712
|
+
* @returns List response containing top trader entries.
|
|
1713
|
+
*
|
|
1714
|
+
* @example
|
|
1715
|
+
* ```ts
|
|
1716
|
+
* const result = await onchain.topTraders(
|
|
1717
|
+
* 'eth',
|
|
1718
|
+
* '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1719
|
+
* );
|
|
1720
|
+
* ```
|
|
1721
|
+
*/
|
|
1722
|
+
topTraders(network, address) {
|
|
1723
|
+
return this.client.get(
|
|
1724
|
+
`/onchain/networks/${network}/tokens/${address}/top_traders`
|
|
1725
|
+
);
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* Returns the top holders (largest wallets) for a specific token.
|
|
1729
|
+
*
|
|
1730
|
+
* @remarks
|
|
1731
|
+
* **Requires Analyst+ (💼) plan.** Calls are rejected with HTTP 403 on
|
|
1732
|
+
* lower-tier keys.
|
|
1733
|
+
*
|
|
1734
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1735
|
+
* @param address - Token contract address.
|
|
1736
|
+
* @returns List response containing top holder entries.
|
|
1737
|
+
*
|
|
1738
|
+
* @example
|
|
1739
|
+
* ```ts
|
|
1740
|
+
* const result = await onchain.topHolders(
|
|
1741
|
+
* 'eth',
|
|
1742
|
+
* '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1743
|
+
* );
|
|
1744
|
+
* ```
|
|
1745
|
+
*/
|
|
1746
|
+
topHolders(network, address) {
|
|
1747
|
+
return this.client.get(
|
|
1748
|
+
`/onchain/networks/${network}/tokens/${address}/top_holders`
|
|
1749
|
+
);
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* Returns a time-series chart of holder count for a specific token.
|
|
1753
|
+
*
|
|
1754
|
+
* @remarks
|
|
1755
|
+
* **Requires Analyst+ (💼) plan.** Calls are rejected with HTTP 403 on
|
|
1756
|
+
* lower-tier keys.
|
|
1757
|
+
*
|
|
1758
|
+
* @param network - Network ID (e.g. `"eth"`).
|
|
1759
|
+
* @param address - Token contract address.
|
|
1760
|
+
* @returns Holder chart response with an array of `[timestamp, count]` data points.
|
|
1761
|
+
*
|
|
1762
|
+
* @example
|
|
1763
|
+
* ```ts
|
|
1764
|
+
* const chart = await onchain.holdersChart(
|
|
1765
|
+
* 'eth',
|
|
1766
|
+
* '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1767
|
+
* );
|
|
1768
|
+
* chart.data?.attributes?.holders_chart?.forEach(([ts, count]) => {
|
|
1769
|
+
* console.log(new Date(ts * 1000).toISOString(), count);
|
|
1770
|
+
* });
|
|
1771
|
+
* ```
|
|
1772
|
+
*/
|
|
1773
|
+
holdersChart(network, address) {
|
|
1774
|
+
return this.client.get(
|
|
1775
|
+
`/onchain/networks/${network}/tokens/${address}/holders_chart`
|
|
1776
|
+
);
|
|
1777
|
+
}
|
|
1778
|
+
/**
|
|
1779
|
+
* Returns a list of tokens whose info was recently updated on GeckoTerminal.
|
|
1780
|
+
*
|
|
1781
|
+
* Useful for syncing token metadata caches.
|
|
1782
|
+
*
|
|
1783
|
+
* @returns List of recently-updated token info resources (JSON:API).
|
|
1784
|
+
*
|
|
1785
|
+
* @example
|
|
1786
|
+
* ```ts
|
|
1787
|
+
* const { data } = await onchain.recentlyUpdatedTokens();
|
|
1788
|
+
* data.forEach(t => console.log(t.attributes.symbol, t.attributes.coingecko_coin_id));
|
|
1789
|
+
* ```
|
|
1790
|
+
*/
|
|
1791
|
+
recentlyUpdatedTokens() {
|
|
1792
|
+
return this.client.get(
|
|
1793
|
+
"/onchain/tokens/info_recently_updated"
|
|
1794
|
+
);
|
|
1795
|
+
}
|
|
1796
|
+
// -------------------------------------------------------------------------
|
|
1797
|
+
// Categories (Analyst+)
|
|
1798
|
+
// -------------------------------------------------------------------------
|
|
1799
|
+
/**
|
|
1800
|
+
* Returns the list of GeckoTerminal onchain categories.
|
|
1801
|
+
*
|
|
1802
|
+
* @remarks
|
|
1803
|
+
* **Requires Analyst+ (💼) plan.** Calls are rejected with HTTP 403 on
|
|
1804
|
+
* lower-tier keys.
|
|
1805
|
+
*
|
|
1806
|
+
* @returns Response containing an array of category objects.
|
|
1807
|
+
*
|
|
1808
|
+
* @example
|
|
1809
|
+
* ```ts
|
|
1810
|
+
* const { data } = await onchain.categories();
|
|
1811
|
+
* data.forEach(c => console.log(c.id, c.attributes?.name));
|
|
1812
|
+
* ```
|
|
1813
|
+
*/
|
|
1814
|
+
categories() {
|
|
1815
|
+
return this.client.get("/onchain/categories");
|
|
1816
|
+
}
|
|
1817
|
+
/**
|
|
1818
|
+
* Returns pools belonging to a specific GeckoTerminal onchain category.
|
|
1819
|
+
*
|
|
1820
|
+
* @remarks
|
|
1821
|
+
* **Requires Analyst+ (💼) plan.** Calls are rejected with HTTP 403 on
|
|
1822
|
+
* lower-tier keys.
|
|
1823
|
+
*
|
|
1824
|
+
* @param categoryId - Category ID (e.g. `"defi"`, `"meme"`).
|
|
1825
|
+
* @param params - Optional pagination parameters.
|
|
1826
|
+
* @returns Paginated list of pool resources in the category.
|
|
1827
|
+
*
|
|
1828
|
+
* @example
|
|
1829
|
+
* ```ts
|
|
1830
|
+
* const { data } = await onchain.categoryPools('meme', { page: 1, per_page: 50 });
|
|
1831
|
+
* data.forEach(p => console.log(p.attributes.name, p.attributes.volume_usd?.h24));
|
|
1832
|
+
* ```
|
|
1833
|
+
*/
|
|
1834
|
+
categoryPools(categoryId, params) {
|
|
1835
|
+
return this.client.get(
|
|
1836
|
+
`/onchain/categories/${categoryId}/pools`,
|
|
1837
|
+
params
|
|
1838
|
+
);
|
|
1839
|
+
}
|
|
1840
|
+
};
|
|
1841
|
+
|
|
1842
|
+
// src/endpoints/global.ts
|
|
1843
|
+
var GlobalEndpoints = class {
|
|
1844
|
+
constructor(client) {
|
|
1845
|
+
this.client = client;
|
|
1846
|
+
}
|
|
1847
|
+
// ---------------------------------------------------------------------------
|
|
1848
|
+
// /global
|
|
1849
|
+
// ---------------------------------------------------------------------------
|
|
1850
|
+
/**
|
|
1851
|
+
* Returns global cryptocurrency market data, including total market cap,
|
|
1852
|
+
* volume, dominance, and number of active coins and exchanges.
|
|
1853
|
+
*
|
|
1854
|
+
* @returns {@link GlobalData} wrapping a {@link GlobalDataPayload}.
|
|
1855
|
+
*
|
|
1856
|
+
* @example
|
|
1857
|
+
* ```ts
|
|
1858
|
+
* const { data } = await global.global();
|
|
1859
|
+
* console.log(data.market_cap_percentage?.btc); // BTC dominance %
|
|
1860
|
+
* ```
|
|
1861
|
+
*/
|
|
1862
|
+
async global() {
|
|
1863
|
+
return this.client.get("/global");
|
|
1864
|
+
}
|
|
1865
|
+
// ---------------------------------------------------------------------------
|
|
1866
|
+
// /global/decentralized_finance_defi
|
|
1867
|
+
// ---------------------------------------------------------------------------
|
|
1868
|
+
/**
|
|
1869
|
+
* Returns global DeFi market data, including total DeFi market cap, ETH
|
|
1870
|
+
* market cap, DeFi dominance, and trading volume.
|
|
1871
|
+
*
|
|
1872
|
+
* @returns {@link GlobalDefiData} wrapping a {@link GlobalDefiPayload}.
|
|
1873
|
+
*
|
|
1874
|
+
* @example
|
|
1875
|
+
* ```ts
|
|
1876
|
+
* const { data } = await global.globalDefi();
|
|
1877
|
+
* console.log(data.defi_market_cap);
|
|
1878
|
+
* ```
|
|
1879
|
+
*/
|
|
1880
|
+
async globalDefi() {
|
|
1881
|
+
return this.client.get("/global/decentralized_finance_defi");
|
|
1882
|
+
}
|
|
1883
|
+
// ---------------------------------------------------------------------------
|
|
1884
|
+
// /global/market_cap_chart (Analyst+)
|
|
1885
|
+
// ---------------------------------------------------------------------------
|
|
1886
|
+
/**
|
|
1887
|
+
* Returns historical global market cap and volume chart data.
|
|
1888
|
+
*
|
|
1889
|
+
* @param params - Required query parameters, including `days`.
|
|
1890
|
+
* @returns {@link GlobalMarketCapChartResponse} with `market_cap` and
|
|
1891
|
+
* `volume` time series arrays.
|
|
1892
|
+
*
|
|
1893
|
+
* @remarks Requires **Analyst+** plan.
|
|
1894
|
+
*
|
|
1895
|
+
* @example
|
|
1896
|
+
* ```ts
|
|
1897
|
+
* const chart = await global.globalMarketCapChart({ days: 30 });
|
|
1898
|
+
* console.log(chart.market_cap_chart.market_cap[0]); // [timestamp_ms, value]
|
|
1899
|
+
* ```
|
|
1900
|
+
*/
|
|
1901
|
+
async globalMarketCapChart(params) {
|
|
1902
|
+
return this.client.get(
|
|
1903
|
+
"/global/market_cap_chart",
|
|
1904
|
+
params
|
|
1905
|
+
);
|
|
1906
|
+
}
|
|
1907
|
+
// ---------------------------------------------------------------------------
|
|
1908
|
+
// /search
|
|
1909
|
+
// ---------------------------------------------------------------------------
|
|
1910
|
+
/**
|
|
1911
|
+
* Searches for coins, exchanges, categories, and NFT collections by a
|
|
1912
|
+
* free-text query string.
|
|
1913
|
+
*
|
|
1914
|
+
* @param query - Search term (e.g. `"bitcoin"`, `"uni"`).
|
|
1915
|
+
* @returns {@link SearchResponse} with matched coins, exchanges, categories,
|
|
1916
|
+
* and NFTs.
|
|
1917
|
+
*
|
|
1918
|
+
* @example
|
|
1919
|
+
* ```ts
|
|
1920
|
+
* const results = await global.search('uniswap');
|
|
1921
|
+
* results.coins.forEach(c => console.log(c.id, c.name));
|
|
1922
|
+
* ```
|
|
1923
|
+
*/
|
|
1924
|
+
async search(query) {
|
|
1925
|
+
return this.client.get("/search", { query });
|
|
1926
|
+
}
|
|
1927
|
+
// ---------------------------------------------------------------------------
|
|
1928
|
+
// /search/trending
|
|
1929
|
+
// ---------------------------------------------------------------------------
|
|
1930
|
+
/**
|
|
1931
|
+
* Returns the top trending coins, NFTs, and categories on CoinGecko in the
|
|
1932
|
+
* last 24 hours, determined by search volume.
|
|
1933
|
+
*
|
|
1934
|
+
* @returns {@link TrendingResponse} with arrays of trending coins, NFTs, and
|
|
1935
|
+
* categories.
|
|
1936
|
+
*
|
|
1937
|
+
* @example
|
|
1938
|
+
* ```ts
|
|
1939
|
+
* const { coins } = await global.trending();
|
|
1940
|
+
* coins.forEach(({ item }) => console.log(item.name));
|
|
1941
|
+
* ```
|
|
1942
|
+
*/
|
|
1943
|
+
async trending() {
|
|
1944
|
+
return this.client.get("/search/trending");
|
|
1945
|
+
}
|
|
1946
|
+
// ---------------------------------------------------------------------------
|
|
1947
|
+
// /exchange_rates
|
|
1948
|
+
// ---------------------------------------------------------------------------
|
|
1949
|
+
/**
|
|
1950
|
+
* Returns BTC exchange rates against fiat currencies, crypto assets, and
|
|
1951
|
+
* commodities.
|
|
1952
|
+
*
|
|
1953
|
+
* @returns {@link ExchangeRatesResponse} mapping currency codes to rate data.
|
|
1954
|
+
*
|
|
1955
|
+
* @example
|
|
1956
|
+
* ```ts
|
|
1957
|
+
* const { rates } = await global.exchangeRates();
|
|
1958
|
+
* console.log(rates['usd']?.value); // BTC price in USD
|
|
1959
|
+
* ```
|
|
1960
|
+
*/
|
|
1961
|
+
async exchangeRates() {
|
|
1962
|
+
return this.client.get("/exchange_rates");
|
|
1963
|
+
}
|
|
1964
|
+
// ---------------------------------------------------------------------------
|
|
1965
|
+
// /asset_platforms
|
|
1966
|
+
// ---------------------------------------------------------------------------
|
|
1967
|
+
/**
|
|
1968
|
+
* Returns a list of all asset platforms (blockchain networks) supported by
|
|
1969
|
+
* CoinGecko.
|
|
1970
|
+
*
|
|
1971
|
+
* @param params - Optional filter parameters (e.g. `filter: 'nft'`).
|
|
1972
|
+
* @returns Array of {@link AssetPlatform} objects.
|
|
1973
|
+
*
|
|
1974
|
+
* @example
|
|
1975
|
+
* ```ts
|
|
1976
|
+
* const platforms = await global.assetPlatforms({ filter: 'nft' });
|
|
1977
|
+
* ```
|
|
1978
|
+
*/
|
|
1979
|
+
async assetPlatforms(params) {
|
|
1980
|
+
return this.client.get(
|
|
1981
|
+
"/asset_platforms",
|
|
1982
|
+
params
|
|
1983
|
+
);
|
|
1984
|
+
}
|
|
1985
|
+
// ---------------------------------------------------------------------------
|
|
1986
|
+
// /token_lists/{platformId}/all.json
|
|
1987
|
+
// ---------------------------------------------------------------------------
|
|
1988
|
+
/**
|
|
1989
|
+
* Returns a Uniswap-compatible token list for all tokens on a given asset
|
|
1990
|
+
* platform.
|
|
1991
|
+
*
|
|
1992
|
+
* @param platformId - Asset platform ID (e.g. `"ethereum"`).
|
|
1993
|
+
* @returns Token list object in the standard Uniswap token list format.
|
|
1994
|
+
* The exact shape depends on the platform; typed as `unknown` for
|
|
1995
|
+
* flexibility.
|
|
1996
|
+
*
|
|
1997
|
+
* @example
|
|
1998
|
+
* ```ts
|
|
1999
|
+
* const list = await global.tokenLists('ethereum');
|
|
2000
|
+
* ```
|
|
2001
|
+
*/
|
|
2002
|
+
async tokenLists(platformId) {
|
|
2003
|
+
return this.client.get(
|
|
2004
|
+
`/token_lists/${encodeURIComponent(platformId)}/all.json`
|
|
2005
|
+
);
|
|
2006
|
+
}
|
|
2007
|
+
};
|
|
2008
|
+
|
|
2009
|
+
// src/endpoints/treasury.ts
|
|
2010
|
+
var TreasuryEndpoints = class {
|
|
2011
|
+
constructor(client) {
|
|
2012
|
+
this.client = client;
|
|
2013
|
+
}
|
|
2014
|
+
// ---------------------------------------------------------------------------
|
|
2015
|
+
// /entities/list
|
|
2016
|
+
// ---------------------------------------------------------------------------
|
|
2017
|
+
/**
|
|
2018
|
+
* Returns a list of all public entities (companies and governments) tracked
|
|
2019
|
+
* in CoinGecko's public treasury database.
|
|
2020
|
+
*
|
|
2021
|
+
* @returns Array of {@link Entity} objects with `id`, `name`, `symbol`, and
|
|
2022
|
+
* `country`.
|
|
2023
|
+
*
|
|
2024
|
+
* @example
|
|
2025
|
+
* ```ts
|
|
2026
|
+
* const entities = await treasury.entitiesList();
|
|
2027
|
+
* entities.forEach(e => console.log(e.id, e.name));
|
|
2028
|
+
* ```
|
|
2029
|
+
*/
|
|
2030
|
+
async entitiesList() {
|
|
2031
|
+
return this.client.get("/entities/list");
|
|
2032
|
+
}
|
|
2033
|
+
// ---------------------------------------------------------------------------
|
|
2034
|
+
// /companies/public_treasury/{coinId}
|
|
2035
|
+
// ---------------------------------------------------------------------------
|
|
2036
|
+
/**
|
|
2037
|
+
* Returns public company Bitcoin or Ethereum treasury holdings, including
|
|
2038
|
+
* aggregate totals and per-company breakdowns.
|
|
2039
|
+
*
|
|
2040
|
+
* @param coinId - Coin API ID to query holdings for.
|
|
2041
|
+
* Currently supported values: `"bitcoin"`, `"ethereum"`.
|
|
2042
|
+
* @returns {@link CompanyTreasuryResponse} with aggregate totals and a
|
|
2043
|
+
* `companies` array.
|
|
2044
|
+
*
|
|
2045
|
+
* @example
|
|
2046
|
+
* ```ts
|
|
2047
|
+
* const holdings = await treasury.companyHoldings('bitcoin');
|
|
2048
|
+
* console.log(holdings.total_holdings);
|
|
2049
|
+
* holdings.companies.forEach(c => console.log(c.name, c.total_holdings));
|
|
2050
|
+
* ```
|
|
2051
|
+
*/
|
|
2052
|
+
async companyHoldings(coinId) {
|
|
2053
|
+
return this.client.get(
|
|
2054
|
+
`/companies/public_treasury/${encodeURIComponent(coinId)}`
|
|
2055
|
+
);
|
|
2056
|
+
}
|
|
2057
|
+
// ---------------------------------------------------------------------------
|
|
2058
|
+
// /public_treasury/{entityId}
|
|
2059
|
+
// ---------------------------------------------------------------------------
|
|
2060
|
+
/**
|
|
2061
|
+
* Returns the full treasury profile for a single public entity, including
|
|
2062
|
+
* all cryptocurrency holdings and financial metrics.
|
|
2063
|
+
*
|
|
2064
|
+
* @param entityId - Entity API ID (e.g. `"strategy"`, `"tesla"`). Use
|
|
2065
|
+
* {@link entitiesList} to discover valid IDs.
|
|
2066
|
+
* @returns {@link PublicTreasuryEntity} with holdings, valuation, and PnL.
|
|
2067
|
+
*
|
|
2068
|
+
* @example
|
|
2069
|
+
* ```ts
|
|
2070
|
+
* const profile = await treasury.entityHoldings('strategy');
|
|
2071
|
+
* console.log(profile.total_treasury_value_usd);
|
|
2072
|
+
* profile.holdings?.forEach(h => console.log(h.coin_id, h.amount));
|
|
2073
|
+
* ```
|
|
2074
|
+
*/
|
|
2075
|
+
async entityHoldings(entityId) {
|
|
2076
|
+
return this.client.get(
|
|
2077
|
+
`/public_treasury/${encodeURIComponent(entityId)}`
|
|
2078
|
+
);
|
|
2079
|
+
}
|
|
2080
|
+
// ---------------------------------------------------------------------------
|
|
2081
|
+
// /public_treasury/{entityId}/{coinId}/holding_chart
|
|
2082
|
+
// ---------------------------------------------------------------------------
|
|
2083
|
+
/**
|
|
2084
|
+
* Returns historical holding amount and USD value chart data for a specific
|
|
2085
|
+
* coin in an entity's treasury.
|
|
2086
|
+
*
|
|
2087
|
+
* @param entityId - Entity API ID (e.g. `"strategy"`).
|
|
2088
|
+
* @param coinId - Coin API ID (e.g. `"bitcoin"`).
|
|
2089
|
+
* @param params - Required query parameters, including `days`.
|
|
2090
|
+
* @returns {@link TreasuryHoldingChartResponse} with `holdings` and
|
|
2091
|
+
* `holding_value_in_usd` time series.
|
|
2092
|
+
*
|
|
2093
|
+
* @example
|
|
2094
|
+
* ```ts
|
|
2095
|
+
* const chart = await treasury.entityHoldingChart('strategy', 'bitcoin', {
|
|
2096
|
+
* days: '365',
|
|
2097
|
+
* });
|
|
2098
|
+
* chart.holdings?.forEach(([ts, amount]) => console.log(ts, amount));
|
|
2099
|
+
* ```
|
|
2100
|
+
*/
|
|
2101
|
+
async entityHoldingChart(entityId, coinId, params) {
|
|
2102
|
+
return this.client.get(
|
|
2103
|
+
`/public_treasury/${encodeURIComponent(entityId)}/${encodeURIComponent(coinId)}/holding_chart`,
|
|
2104
|
+
params
|
|
2105
|
+
);
|
|
2106
|
+
}
|
|
2107
|
+
// ---------------------------------------------------------------------------
|
|
2108
|
+
// /public_treasury/{entityId}/transaction_history
|
|
2109
|
+
// ---------------------------------------------------------------------------
|
|
2110
|
+
/**
|
|
2111
|
+
* Returns the paginated transaction history for a public treasury entity,
|
|
2112
|
+
* including buy/sell events with price and value data.
|
|
2113
|
+
*
|
|
2114
|
+
* @param entityId - Entity API ID (e.g. `"strategy"`).
|
|
2115
|
+
* @param params - Optional pagination and coin filter parameters.
|
|
2116
|
+
* @returns {@link TreasuryTransactionHistoryResponse} with a `data` array of
|
|
2117
|
+
* {@link TreasuryTransaction} records.
|
|
2118
|
+
*
|
|
2119
|
+
* @example
|
|
2120
|
+
* ```ts
|
|
2121
|
+
* const history = await treasury.entityTransactions('strategy', {
|
|
2122
|
+
* coin_ids: 'bitcoin',
|
|
2123
|
+
* per_page: 50,
|
|
2124
|
+
* });
|
|
2125
|
+
* history.data?.forEach(tx => console.log(tx.date, tx.transaction_type, tx.amount));
|
|
2126
|
+
* ```
|
|
2127
|
+
*/
|
|
2128
|
+
async entityTransactions(entityId, params) {
|
|
2129
|
+
return this.client.get(
|
|
2130
|
+
`/public_treasury/${encodeURIComponent(entityId)}/transaction_history`,
|
|
2131
|
+
params
|
|
2132
|
+
);
|
|
2133
|
+
}
|
|
2134
|
+
};
|
|
2135
|
+
|
|
2136
|
+
// src/endpoints/meta.ts
|
|
2137
|
+
var MetaEndpoints = class {
|
|
2138
|
+
constructor(client) {
|
|
2139
|
+
this.client = client;
|
|
2140
|
+
}
|
|
2141
|
+
// ---------------------------------------------------------------------------
|
|
2142
|
+
// /ping
|
|
2143
|
+
// ---------------------------------------------------------------------------
|
|
2144
|
+
/**
|
|
2145
|
+
* Checks the API server status. Use this as a lightweight connectivity test
|
|
2146
|
+
* before making heavier requests.
|
|
2147
|
+
*
|
|
2148
|
+
* @returns {@link PingResponse} containing a `gecko_says` status string
|
|
2149
|
+
* (e.g. `"(V3) To the Moon!"`).
|
|
2150
|
+
*
|
|
2151
|
+
* @example
|
|
2152
|
+
* ```ts
|
|
2153
|
+
* const { gecko_says } = await meta.ping();
|
|
2154
|
+
* console.log(gecko_says); // "(V3) To the Moon!"
|
|
2155
|
+
* ```
|
|
2156
|
+
*/
|
|
2157
|
+
async ping() {
|
|
2158
|
+
return this.client.get("/ping");
|
|
2159
|
+
}
|
|
2160
|
+
// ---------------------------------------------------------------------------
|
|
2161
|
+
// /key (Analyst+)
|
|
2162
|
+
// ---------------------------------------------------------------------------
|
|
2163
|
+
/**
|
|
2164
|
+
* Returns usage statistics and plan information for the current Pro API key.
|
|
2165
|
+
*
|
|
2166
|
+
* @returns {@link ApiUsageResponse} with plan name, rate limit, monthly
|
|
2167
|
+
* credit usage, and remaining credits.
|
|
2168
|
+
*
|
|
2169
|
+
* @remarks Requires a valid **Pro API key** (Analyst+ plan). Returns 401 for
|
|
2170
|
+
* free-tier or unauthenticated requests.
|
|
2171
|
+
*
|
|
2172
|
+
* @example
|
|
2173
|
+
* ```ts
|
|
2174
|
+
* const usage = await meta.apiUsage();
|
|
2175
|
+
* console.log(usage.plan); // "Analyst"
|
|
2176
|
+
* console.log(usage.current_remaining_monthly_calls); // remaining credits
|
|
2177
|
+
* ```
|
|
2178
|
+
*/
|
|
2179
|
+
async apiUsage() {
|
|
2180
|
+
return this.client.get("/key");
|
|
2181
|
+
}
|
|
2182
|
+
};
|
|
2183
|
+
|
|
2184
|
+
// src/index.ts
|
|
2185
|
+
var CoinGecko = class {
|
|
2186
|
+
/** Coin prices, market data, charts, OHLC, supply, categories, and contract lookups. */
|
|
2187
|
+
coins;
|
|
2188
|
+
/** Exchange listings, details, tickers, and volume charts. */
|
|
2189
|
+
exchanges;
|
|
2190
|
+
/** Derivatives tickers and exchange data. */
|
|
2191
|
+
derivatives;
|
|
2192
|
+
/** NFT collections, market data, charts, and tickers. */
|
|
2193
|
+
nfts;
|
|
2194
|
+
/** On-chain DEX data (GeckoTerminal): pools, tokens, trades, OHLCV, top traders/holders. */
|
|
2195
|
+
onchain;
|
|
2196
|
+
/** Global market data, search, trending, exchange rates, and asset platforms. */
|
|
2197
|
+
global;
|
|
2198
|
+
/** Public treasury holdings, charts, and transaction history. */
|
|
2199
|
+
treasury;
|
|
2200
|
+
meta;
|
|
2201
|
+
/**
|
|
2202
|
+
* Creates a new CoinGecko SDK instance.
|
|
2203
|
+
*
|
|
2204
|
+
* @param config - Optional configuration for the underlying HTTP client.
|
|
2205
|
+
* See {@link CoinGeckoClientConfig} for all available options.
|
|
2206
|
+
*/
|
|
2207
|
+
constructor(config) {
|
|
2208
|
+
const client = new CoinGeckoClient(config);
|
|
2209
|
+
this.coins = new CoinsEndpoints(client);
|
|
2210
|
+
this.exchanges = new ExchangesEndpoints(client);
|
|
2211
|
+
this.derivatives = new DerivativesEndpoints(client);
|
|
2212
|
+
this.nfts = new NftsEndpoints(client);
|
|
2213
|
+
this.onchain = new OnchainEndpoints(client);
|
|
2214
|
+
this.global = new GlobalEndpoints(client);
|
|
2215
|
+
this.treasury = new TreasuryEndpoints(client);
|
|
2216
|
+
this.meta = new MetaEndpoints(client);
|
|
2217
|
+
}
|
|
2218
|
+
/**
|
|
2219
|
+
* Checks the CoinGecko API server status.
|
|
2220
|
+
*
|
|
2221
|
+
* Use this as a lightweight connectivity and authentication test.
|
|
2222
|
+
*
|
|
2223
|
+
* @returns Object containing the server status message
|
|
2224
|
+
* (`{ gecko_says: "(V3) To the Moon!" }`).
|
|
2225
|
+
*
|
|
2226
|
+
* @example
|
|
2227
|
+
* ```typescript
|
|
2228
|
+
* const { gecko_says } = await cg.ping();
|
|
2229
|
+
* console.log(gecko_says); // "(V3) To the Moon!"
|
|
2230
|
+
* ```
|
|
2231
|
+
*/
|
|
2232
|
+
async ping() {
|
|
2233
|
+
return this.meta.ping();
|
|
2234
|
+
}
|
|
2235
|
+
/**
|
|
2236
|
+
* Returns API key usage statistics and plan information.
|
|
2237
|
+
*
|
|
2238
|
+
* @remarks Requires a valid **Pro API key** (Analyst+ plan). Returns 401 on
|
|
2239
|
+
* free-tier or unauthenticated requests.
|
|
2240
|
+
*
|
|
2241
|
+
* @returns Usage data including plan name, rate limits, and remaining credits.
|
|
2242
|
+
*
|
|
2243
|
+
* @example
|
|
2244
|
+
* ```typescript
|
|
2245
|
+
* const usage = await cg.apiUsage();
|
|
2246
|
+
* console.log(usage.plan, usage.current_remaining_monthly_calls);
|
|
2247
|
+
* ```
|
|
2248
|
+
*/
|
|
2249
|
+
async apiUsage() {
|
|
2250
|
+
return this.meta.apiUsage();
|
|
2251
|
+
}
|
|
2252
|
+
};
|
|
2253
|
+
|
|
2254
|
+
exports.CoinGecko = CoinGecko;
|
|
2255
|
+
exports.CoinGeckoClient = CoinGeckoClient;
|
|
2256
|
+
exports.CoinGeckoError = CoinGeckoError;
|
|
2257
|
+
exports.CoinsEndpoints = CoinsEndpoints;
|
|
2258
|
+
exports.DerivativesEndpoints = DerivativesEndpoints;
|
|
2259
|
+
exports.ExchangesEndpoints = ExchangesEndpoints;
|
|
2260
|
+
exports.GlobalEndpoints = GlobalEndpoints;
|
|
2261
|
+
exports.MetaEndpoints = MetaEndpoints;
|
|
2262
|
+
exports.NftsEndpoints = NftsEndpoints;
|
|
2263
|
+
exports.OnchainEndpoints = OnchainEndpoints;
|
|
2264
|
+
exports.TreasuryEndpoints = TreasuryEndpoints;
|
|
2265
|
+
//# sourceMappingURL=index.cjs.map
|
|
2266
|
+
//# sourceMappingURL=index.cjs.map
|