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