crypull 1.0.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.mjs ADDED
@@ -0,0 +1,701 @@
1
+ // src/providers/coingecko.ts
2
+ var CoinGeckoProvider = class {
3
+ name = "CoinGecko";
4
+ baseUrl = "https://api.coingecko.com/api/v3";
5
+ async search(query) {
6
+ try {
7
+ const res = await fetch(`${this.baseUrl}/search?query=${query}`);
8
+ if (!res.ok) return [];
9
+ const data = await res.json();
10
+ return (data.coins || []).slice(0, 10).map((coin) => ({
11
+ id: coin.id,
12
+ name: coin.name,
13
+ symbol: coin.symbol.toUpperCase(),
14
+ source: this.name
15
+ }));
16
+ } catch (e) {
17
+ return [];
18
+ }
19
+ }
20
+ async getPrice(symbolOrId) {
21
+ try {
22
+ let id = symbolOrId.toLowerCase();
23
+ const searchRes = await this.search(id);
24
+ const match = searchRes.find((s) => s.symbol.toLowerCase() === id || s.id === id);
25
+ if (match && match.id) {
26
+ id = match.id;
27
+ }
28
+ const res = await fetch(`${this.baseUrl}/simple/price?ids=${id}&vs_currencies=usd`);
29
+ if (!res.ok) return null;
30
+ const data = await res.json();
31
+ if (!data[id] || typeof data[id].usd === "undefined") return null;
32
+ return {
33
+ symbol: match ? match.symbol : id.toUpperCase(),
34
+ priceUsd: data[id].usd,
35
+ source: this.name,
36
+ lastUpdated: Date.now()
37
+ };
38
+ } catch (e) {
39
+ return null;
40
+ }
41
+ }
42
+ async getTokenInfo(id) {
43
+ try {
44
+ const res = await fetch(`${this.baseUrl}/coins/${id.toLowerCase()}?localization=false&tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false`);
45
+ if (!res.ok) return null;
46
+ const data = await res.json();
47
+ if (data.error) return null;
48
+ return {
49
+ name: data.name,
50
+ symbol: data.symbol.toUpperCase(),
51
+ description: data.description?.en,
52
+ priceUsd: data.market_data?.current_price?.usd || 0,
53
+ marketCap: data.market_data?.market_cap?.usd,
54
+ marketCapRank: data.market_cap_rank,
55
+ fdv: data.market_data?.fully_diluted_valuation?.usd,
56
+ circulatingSupply: data.market_data?.circulating_supply,
57
+ totalSupply: data.market_data?.total_supply,
58
+ maxSupply: data.market_data?.max_supply,
59
+ volume24h: data.market_data?.total_volume?.usd,
60
+ priceChange24h: data.market_data?.price_change_24h,
61
+ priceChangePercentage24h: data.market_data?.price_change_percentage_24h,
62
+ priceChangePercentage7d: data.market_data?.price_change_percentage_7d,
63
+ ath: data.market_data?.ath?.usd,
64
+ athDate: data.market_data?.ath_date?.usd,
65
+ atl: data.market_data?.atl?.usd,
66
+ atlDate: data.market_data?.atl_date?.usd,
67
+ links: {
68
+ website: data.links?.homepage?.[0],
69
+ twitter: data.links?.twitter_screen_name ? `https://twitter.com/${data.links.twitter_screen_name}` : void 0,
70
+ telegram: data.links?.telegram_channel_identifier ? `https://t.me/${data.links.telegram_channel_identifier}` : void 0,
71
+ discord: data.links?.chat_url?.find((url) => url.includes("discord")),
72
+ github: data.links?.repos_url?.github?.[0]
73
+ },
74
+ source: this.name,
75
+ lastUpdated: Date.now()
76
+ };
77
+ } catch (e) {
78
+ return null;
79
+ }
80
+ }
81
+ };
82
+
83
+ // src/providers/dexscreener.ts
84
+ var DexScreenerProvider = class {
85
+ name = "DexScreener";
86
+ baseUrl = "https://api.dexscreener.com/latest/dex";
87
+ async search(query) {
88
+ try {
89
+ const res = await fetch(`${this.baseUrl}/search?q=${query}`);
90
+ if (!res.ok) return [];
91
+ const data = await res.json();
92
+ return (data.pairs || []).slice(0, 10).map((pair) => ({
93
+ id: pair.baseToken.address,
94
+ name: pair.baseToken.name,
95
+ symbol: pair.baseToken.symbol.toUpperCase(),
96
+ network: pair.chainId,
97
+ source: this.name
98
+ }));
99
+ } catch (e) {
100
+ return [];
101
+ }
102
+ }
103
+ async getPrice(address) {
104
+ const info = await this.getTokenInfo(address);
105
+ if (!info) return null;
106
+ return {
107
+ symbol: info.symbol,
108
+ priceUsd: info.priceUsd,
109
+ source: this.name,
110
+ lastUpdated: info.lastUpdated
111
+ };
112
+ }
113
+ async getTokenInfo(address) {
114
+ try {
115
+ const res = await fetch(`${this.baseUrl}/tokens/${address}`);
116
+ if (!res.ok) return null;
117
+ const data = await res.json();
118
+ if (!data.pairs || data.pairs.length === 0) return null;
119
+ const pair = data.pairs[0];
120
+ const mappedPairs = data.pairs.slice(0, 10).map((p) => ({
121
+ dexId: p.dexId,
122
+ url: p.url,
123
+ pairAddress: p.pairAddress,
124
+ baseTokenSymbol: p.baseToken.symbol,
125
+ quoteTokenSymbol: p.quoteToken.symbol,
126
+ priceUsd: parseFloat(p.priceUsd) || 0,
127
+ volume24h: p.volume?.h24,
128
+ liquidityUsd: p.liquidity?.usd
129
+ }));
130
+ return {
131
+ name: pair.baseToken.name,
132
+ symbol: pair.baseToken.symbol.toUpperCase(),
133
+ address: pair.baseToken.address,
134
+ network: pair.chainId,
135
+ priceUsd: parseFloat(pair.priceUsd) || 0,
136
+ fdv: pair.fdv,
137
+ volume24h: pair.volume?.h24,
138
+ liquidityUsd: pair.liquidity?.usd,
139
+ priceChangePercentage24h: pair.priceChange?.h24,
140
+ pairs: mappedPairs,
141
+ links: {
142
+ website: pair.info?.websites?.[0]?.url,
143
+ twitter: pair.info?.socials?.find((s) => s.type === "twitter")?.url,
144
+ telegram: pair.info?.socials?.find((s) => s.type === "telegram")?.url,
145
+ discord: pair.info?.socials?.find((s) => s.type === "discord")?.url
146
+ },
147
+ source: this.name,
148
+ lastUpdated: Date.now()
149
+ };
150
+ } catch (e) {
151
+ return null;
152
+ }
153
+ }
154
+ };
155
+
156
+ // src/providers/geckoterminal.ts
157
+ var GeckoTerminalProvider = class {
158
+ name = "GeckoTerminal";
159
+ baseUrl = "https://api.geckoterminal.com/api/v2";
160
+ async search(query) {
161
+ try {
162
+ const res = await fetch(`${this.baseUrl}/search/pools?query=${query}`);
163
+ if (!res.ok) return [];
164
+ const data = await res.json();
165
+ const pools = data.data || [];
166
+ return pools.slice(0, 10).map((pool) => {
167
+ const attributes = pool.attributes;
168
+ const baseToken = attributes.name.split(" / ")[0];
169
+ return {
170
+ id: pool.id,
171
+ // e.g. "eth_0x..."
172
+ name: attributes.name,
173
+ symbol: baseToken,
174
+ network: pool.relationships.network.data.id,
175
+ source: this.name
176
+ };
177
+ });
178
+ } catch (e) {
179
+ return [];
180
+ }
181
+ }
182
+ async getPrice(address, network = "eth") {
183
+ const info = await this.getTokenInfo(address, network);
184
+ if (!info) return null;
185
+ return {
186
+ symbol: info.symbol,
187
+ priceUsd: info.priceUsd,
188
+ source: this.name,
189
+ lastUpdated: info.lastUpdated
190
+ };
191
+ }
192
+ async getTokenInfo(address, network = "eth") {
193
+ try {
194
+ const res = await fetch(`${this.baseUrl}/networks/${network}/tokens/${address}`);
195
+ if (!res.ok) return null;
196
+ const json = await res.json();
197
+ if (!json.data || !json.data.attributes) return null;
198
+ const attrs = json.data.attributes;
199
+ return {
200
+ name: attrs.name,
201
+ symbol: attrs.symbol.toUpperCase(),
202
+ address: attrs.address,
203
+ network,
204
+ priceUsd: parseFloat(attrs.price_usd) || 0,
205
+ fdv: parseFloat(attrs.fdv_usd),
206
+ volume24h: parseFloat(attrs.volume_usd?.h24 || 0),
207
+ source: this.name,
208
+ lastUpdated: Date.now()
209
+ };
210
+ } catch (e) {
211
+ return null;
212
+ }
213
+ }
214
+ };
215
+
216
+ // src/providers/binance.ts
217
+ var BinanceProvider = class {
218
+ name = "Binance";
219
+ baseUrl = "https://api.binance.com/api/v3";
220
+ async search(query) {
221
+ try {
222
+ const symbol = query.toUpperCase();
223
+ const res = await fetch(`${this.baseUrl}/ticker/price?symbol=${symbol}USDT`);
224
+ if (res.ok) {
225
+ return [{
226
+ id: `${symbol}USDT`,
227
+ name: symbol,
228
+ symbol,
229
+ source: this.name
230
+ }];
231
+ }
232
+ return [];
233
+ } catch (e) {
234
+ return [];
235
+ }
236
+ }
237
+ async getPrice(symbol) {
238
+ try {
239
+ let querySymbol = symbol.toUpperCase();
240
+ if (!querySymbol.endsWith("USDT") && !querySymbol.endsWith("BUSD") && !querySymbol.endsWith("BTC")) {
241
+ querySymbol += "USDT";
242
+ }
243
+ const res = await fetch(`${this.baseUrl}/ticker/price?symbol=${querySymbol}`);
244
+ if (!res.ok) return null;
245
+ const data = await res.json();
246
+ return {
247
+ symbol: symbol.toUpperCase(),
248
+ priceUsd: parseFloat(data.price) || 0,
249
+ source: this.name,
250
+ lastUpdated: Date.now()
251
+ };
252
+ } catch (e) {
253
+ return null;
254
+ }
255
+ }
256
+ async getTokenInfo(symbol) {
257
+ try {
258
+ let querySymbol = symbol.toUpperCase();
259
+ if (!querySymbol.endsWith("USDT") && !querySymbol.endsWith("BUSD") && !querySymbol.endsWith("BTC")) {
260
+ querySymbol += "USDT";
261
+ }
262
+ const res = await fetch(`${this.baseUrl}/ticker/24hr?symbol=${querySymbol}`);
263
+ if (!res.ok) return null;
264
+ const data = await res.json();
265
+ return {
266
+ name: symbol.toUpperCase(),
267
+ symbol: symbol.toUpperCase(),
268
+ priceUsd: parseFloat(data.lastPrice) || 0,
269
+ volume24h: parseFloat(data.quoteVolume) || 0,
270
+ // Quote volume in USDT roughly = USD volume
271
+ source: this.name,
272
+ lastUpdated: Date.now()
273
+ };
274
+ } catch (e) {
275
+ return null;
276
+ }
277
+ }
278
+ };
279
+
280
+ // src/providers/coinpaprika.ts
281
+ var CoinpaprikaProvider = class {
282
+ name = "Coinpaprika";
283
+ baseUrl = "https://api.coinpaprika.com/v1";
284
+ async search(query) {
285
+ try {
286
+ const res = await fetch(`${this.baseUrl}/search?q=${query}&c=currencies&limit=10`);
287
+ if (!res.ok) return [];
288
+ const data = await res.json();
289
+ return (data.currencies || []).map((coin) => ({
290
+ id: coin.id,
291
+ name: coin.name,
292
+ symbol: coin.symbol.toUpperCase(),
293
+ source: this.name
294
+ }));
295
+ } catch (e) {
296
+ return [];
297
+ }
298
+ }
299
+ async getPrice(symbolOrId) {
300
+ const info = await this.getTokenInfo(symbolOrId);
301
+ if (!info) return null;
302
+ return {
303
+ symbol: info.symbol,
304
+ priceUsd: info.priceUsd,
305
+ source: this.name,
306
+ lastUpdated: info.lastUpdated
307
+ };
308
+ }
309
+ async getTokenInfo(symbolOrId) {
310
+ try {
311
+ let id = symbolOrId.toLowerCase();
312
+ if (!id.includes("-")) {
313
+ const searchRes = await this.search(id);
314
+ const match = searchRes.find((s) => s.symbol.toLowerCase() === id || s.id === id);
315
+ if (match && match.id) {
316
+ id = match.id;
317
+ } else if (searchRes.length > 0 && searchRes[0].id) {
318
+ id = searchRes[0].id;
319
+ }
320
+ }
321
+ const res = await fetch(`${this.baseUrl}/tickers/${id}`);
322
+ if (!res.ok) return null;
323
+ const data = await res.json();
324
+ return {
325
+ name: data.name,
326
+ symbol: data.symbol.toUpperCase(),
327
+ description: data.description,
328
+ priceUsd: data.quotes?.USD?.price || 0,
329
+ marketCap: data.quotes?.USD?.market_cap,
330
+ marketCapRank: data.rank,
331
+ circulatingSupply: data.circulating_supply,
332
+ totalSupply: data.total_supply,
333
+ maxSupply: data.max_supply,
334
+ volume24h: data.quotes?.USD?.volume_24h,
335
+ priceChangePercentage24h: data.quotes?.USD?.percent_change_24h,
336
+ priceChangePercentage7d: data.quotes?.USD?.percent_change_7d,
337
+ ath: data.quotes?.USD?.ath_price,
338
+ athDate: data.quotes?.USD?.ath_date,
339
+ links: {
340
+ website: data.links?.website?.[0],
341
+ twitter: data.links?.twitter?.[0],
342
+ discord: data.links?.discord?.[0],
343
+ github: data.links?.source_code?.[0]
344
+ },
345
+ source: this.name,
346
+ lastUpdated: Date.now()
347
+ };
348
+ } catch (e) {
349
+ return null;
350
+ }
351
+ }
352
+ };
353
+
354
+ // src/providers/coincap.ts
355
+ var CoinCapProvider = class {
356
+ name = "CoinCap";
357
+ baseUrl = "https://api.coincap.io/v2";
358
+ async search(query) {
359
+ try {
360
+ const res = await fetch(`${this.baseUrl}/assets?search=${query}&limit=10`);
361
+ if (!res.ok) return [];
362
+ const data = await res.json();
363
+ return (data.data || []).map((coin) => ({
364
+ id: coin.id,
365
+ name: coin.name,
366
+ symbol: coin.symbol.toUpperCase(),
367
+ source: this.name
368
+ }));
369
+ } catch (e) {
370
+ return [];
371
+ }
372
+ }
373
+ async getPrice(symbolOrId) {
374
+ const info = await this.getTokenInfo(symbolOrId);
375
+ if (!info) return null;
376
+ return {
377
+ symbol: info.symbol,
378
+ priceUsd: info.priceUsd,
379
+ source: this.name,
380
+ lastUpdated: info.lastUpdated
381
+ };
382
+ }
383
+ async getTokenInfo(symbolOrId) {
384
+ try {
385
+ let id = symbolOrId.toLowerCase();
386
+ const searchRes = await this.search(id);
387
+ const match = searchRes.find((s) => s.symbol.toLowerCase() === id || s.id === id);
388
+ if (match && match.id) {
389
+ id = match.id;
390
+ }
391
+ const res = await fetch(`${this.baseUrl}/assets/${id}`);
392
+ if (!res.ok) return null;
393
+ const data = await res.json();
394
+ const asset = data.data;
395
+ if (!asset) return null;
396
+ return {
397
+ name: asset.name,
398
+ symbol: asset.symbol.toUpperCase(),
399
+ priceUsd: parseFloat(asset.priceUsd) || 0,
400
+ marketCap: parseFloat(asset.marketCapUsd),
401
+ volume24h: parseFloat(asset.volumeUsd24Hr),
402
+ source: this.name,
403
+ lastUpdated: Date.now()
404
+ };
405
+ } catch (e) {
406
+ return null;
407
+ }
408
+ }
409
+ };
410
+
411
+ // src/providers/cryptocompare.ts
412
+ var CryptoCompareProvider = class {
413
+ name = "CryptoCompare";
414
+ baseUrl = "https://min-api.cryptocompare.com/data";
415
+ async search(query) {
416
+ return [];
417
+ }
418
+ async getPrice(symbol) {
419
+ try {
420
+ const sym = symbol.toUpperCase();
421
+ const res = await fetch(`${this.baseUrl}/price?fsym=${sym}&tsyms=USD`);
422
+ if (!res.ok) return null;
423
+ const data = await res.json();
424
+ if (data.Response === "Error" || !data.USD) return null;
425
+ return {
426
+ symbol: sym,
427
+ priceUsd: data.USD,
428
+ source: this.name,
429
+ lastUpdated: Date.now()
430
+ };
431
+ } catch (e) {
432
+ return null;
433
+ }
434
+ }
435
+ async getTokenInfo(symbol) {
436
+ try {
437
+ const sym = symbol.toUpperCase();
438
+ const res = await fetch(`${this.baseUrl}/pricemultifull?fsyms=${sym}&tsyms=USD`);
439
+ if (!res.ok) return null;
440
+ const data = await res.json();
441
+ if (!data.RAW || !data.RAW[sym] || !data.RAW[sym].USD) return null;
442
+ const raw = data.RAW[sym].USD;
443
+ return {
444
+ name: sym,
445
+ // CryptoCompare doesn't give full name in this endpoint
446
+ symbol: sym,
447
+ priceUsd: raw.PRICE || 0,
448
+ marketCap: raw.MKTCAP,
449
+ volume24h: raw.TOTALVOLUME24HTO,
450
+ source: this.name,
451
+ lastUpdated: Date.now()
452
+ };
453
+ } catch (e) {
454
+ return null;
455
+ }
456
+ }
457
+ };
458
+
459
+ // src/Crypull.ts
460
+ var Crypull = class {
461
+ providers;
462
+ // Standard free providers
463
+ coinGecko = new CoinGeckoProvider();
464
+ dexScreener = new DexScreenerProvider();
465
+ geckoTerminal = new GeckoTerminalProvider();
466
+ binance = new BinanceProvider();
467
+ coinpaprika = new CoinpaprikaProvider();
468
+ coincap = new CoinCapProvider();
469
+ cryptoCompare = new CryptoCompareProvider();
470
+ constructor(options) {
471
+ this.providers = options?.providers || [
472
+ this.binance,
473
+ this.coinGecko,
474
+ this.coinpaprika,
475
+ this.coincap,
476
+ this.dexScreener,
477
+ this.geckoTerminal,
478
+ this.cryptoCompare
479
+ ];
480
+ }
481
+ isAddress(query) {
482
+ return query.startsWith("0x") && query.length === 42 || query.length > 30;
483
+ }
484
+ /**
485
+ * Search for a token or coin across multiple providers in parallel
486
+ */
487
+ async search(query) {
488
+ const promises = [
489
+ this.coinGecko.search(query),
490
+ this.dexScreener.search(query),
491
+ this.coinpaprika.search(query),
492
+ this.coincap.search(query)
493
+ ];
494
+ const results = await Promise.allSettled(promises);
495
+ const combined = [];
496
+ for (const res of results) {
497
+ if (res.status === "fulfilled" && res.value) {
498
+ combined.push(...res.value);
499
+ }
500
+ }
501
+ const seen = /* @__PURE__ */ new Set();
502
+ return combined.filter((item) => {
503
+ const key = `${item.symbol}`;
504
+ if (seen.has(key)) return false;
505
+ seen.add(key);
506
+ return true;
507
+ });
508
+ }
509
+ /**
510
+ * Get the current price of a cryptocurrency
511
+ * @param query Can be a symbol (e.g., 'BTC') or a contract address
512
+ * @param network Optional network for DEX addresses (e.g., 'eth', 'bsc')
513
+ */
514
+ async price(query, network) {
515
+ if (this.isAddress(query)) {
516
+ let res = await this.dexScreener.getPrice(query);
517
+ if (res) return res;
518
+ if (network) {
519
+ res = await this.geckoTerminal.getPrice(query, network);
520
+ if (res) return res;
521
+ }
522
+ } else {
523
+ let res = await this.binance.getPrice(query);
524
+ if (res) return res;
525
+ res = await this.coincap.getPrice(query);
526
+ if (res) return res;
527
+ res = await this.coinGecko.getPrice(query);
528
+ if (res) return res;
529
+ res = await this.coinpaprika.getPrice(query);
530
+ if (res) return res;
531
+ res = await this.cryptoCompare.getPrice(query);
532
+ if (res) return res;
533
+ }
534
+ return null;
535
+ }
536
+ /**
537
+ * Get detailed token info (market cap, volume, liquidity, etc.)
538
+ * @param query Can be a symbol (e.g., 'BTC') or a contract address
539
+ * @param network Optional network for DEX addresses
540
+ */
541
+ async info(query, network) {
542
+ if (this.isAddress(query)) {
543
+ let res = await this.dexScreener.getTokenInfo(query);
544
+ if (res) return res;
545
+ if (network) {
546
+ res = await this.geckoTerminal.getTokenInfo(query, network);
547
+ if (res) return res;
548
+ }
549
+ } else {
550
+ let res = await this.coinGecko.getTokenInfo(query);
551
+ if (res) return res;
552
+ res = await this.coinpaprika.getTokenInfo(query);
553
+ if (res) return res;
554
+ res = await this.coincap.getTokenInfo(query);
555
+ if (res) return res;
556
+ res = await this.binance.getTokenInfo(query);
557
+ if (res) return res;
558
+ res = await this.cryptoCompare.getTokenInfo(query);
559
+ if (res) return res;
560
+ }
561
+ return null;
562
+ }
563
+ /**
564
+ * Get global market data
565
+ */
566
+ async market() {
567
+ try {
568
+ const res = await fetch(`https://api.coingecko.com/api/v3/global`);
569
+ if (!res.ok) return null;
570
+ const data = await res.json();
571
+ const d = data.data;
572
+ return {
573
+ totalMarketCapUsd: d.total_market_cap.usd,
574
+ totalVolume24hUsd: d.total_volume.usd,
575
+ bitcoinDominancePercentage: d.market_cap_percentage.btc,
576
+ ethereumDominancePercentage: d.market_cap_percentage.eth,
577
+ activeCryptocurrencies: d.active_cryptocurrencies,
578
+ lastUpdated: d.updated_at * 1e3
579
+ };
580
+ } catch (e) {
581
+ return null;
582
+ }
583
+ }
584
+ /**
585
+ * Get trending coins
586
+ */
587
+ async trending() {
588
+ try {
589
+ const res = await fetch(`https://api.coingecko.com/api/v3/search/trending`);
590
+ if (!res.ok) return [];
591
+ const data = await res.json();
592
+ return data.coins.slice(0, 10).map((c) => ({
593
+ id: c.item.id,
594
+ name: c.item.name,
595
+ symbol: c.item.symbol.toUpperCase(),
596
+ marketCapRank: c.item.market_cap_rank,
597
+ priceUsd: c.item.data?.price,
598
+ priceChange24h: c.item.data?.price_change_percentage_24h?.usd,
599
+ volume24h: c.item.data?.total_volume
600
+ }));
601
+ } catch (e) {
602
+ return [];
603
+ }
604
+ }
605
+ /**
606
+ * Get top 50 coins by market cap
607
+ */
608
+ async top() {
609
+ try {
610
+ const res = await fetch(`https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=50&page=1&sparkline=false`);
611
+ if (!res.ok) return [];
612
+ const data = await res.json();
613
+ return data.map((c) => ({
614
+ id: c.id,
615
+ name: c.name,
616
+ symbol: c.symbol.toUpperCase(),
617
+ marketCapRank: c.market_cap_rank,
618
+ priceUsd: c.current_price,
619
+ marketCap: c.market_cap,
620
+ volume24h: c.total_volume,
621
+ priceChange24h: c.price_change_percentage_24h
622
+ }));
623
+ } catch (e) {
624
+ return [];
625
+ }
626
+ }
627
+ /**
628
+ * Get fear and greed index
629
+ */
630
+ async sentiment() {
631
+ try {
632
+ const res = await fetch(`https://api.alternative.me/fng/?limit=1`);
633
+ if (!res.ok) return null;
634
+ const data = await res.json();
635
+ const item = data.data[0];
636
+ return {
637
+ value: parseInt(item.value),
638
+ classification: item.value_classification,
639
+ lastUpdated: parseInt(item.timestamp) * 1e3
640
+ };
641
+ } catch (e) {
642
+ return null;
643
+ }
644
+ }
645
+ /**
646
+ * Get current ethereum gas prices (in Gwei)
647
+ */
648
+ async gas() {
649
+ try {
650
+ const res = await fetch(`https://api.etherscan.io/api?module=gastracker&action=gasoracle`);
651
+ if (!res.ok) return null;
652
+ const data = await res.json();
653
+ if (data.status !== "1") return null;
654
+ return {
655
+ network: "Ethereum",
656
+ low: parseFloat(data.result.SafeGasPrice),
657
+ average: parseFloat(data.result.ProposeGasPrice),
658
+ high: parseFloat(data.result.FastGasPrice),
659
+ baseFee: parseFloat(data.result.suggestBaseFee)
660
+ };
661
+ } catch (e) {
662
+ return null;
663
+ }
664
+ }
665
+ /**
666
+ * Get historical chart data for a coin
667
+ * @param query Coin symbol or ID
668
+ * @param days Number of days (e.g. 1, 7, 30)
669
+ */
670
+ async chart(query, days = 7) {
671
+ try {
672
+ let id = query.toLowerCase();
673
+ const searchRes = await this.coinGecko.search(id);
674
+ const match = searchRes.find((s) => s.symbol.toLowerCase() === id || s.id === id);
675
+ if (match && match.id) {
676
+ id = match.id;
677
+ }
678
+ const res = await fetch(`https://api.coingecko.com/api/v3/coins/${id}/market_chart?vs_currency=usd&days=${days}`);
679
+ if (!res.ok) return null;
680
+ const data = await res.json();
681
+ if (!data.prices || data.prices.length === 0) return null;
682
+ const prices = data.prices.map((p) => p[1]);
683
+ const timestamps = data.prices.map((p) => p[0]);
684
+ return {
685
+ prices,
686
+ timestamps,
687
+ minPrice: Math.min(...prices),
688
+ maxPrice: Math.max(...prices)
689
+ };
690
+ } catch (e) {
691
+ return null;
692
+ }
693
+ }
694
+ };
695
+
696
+ // src/index.ts
697
+ var crypull = new Crypull();
698
+
699
+ export { BinanceProvider, CoinCapProvider, CoinGeckoProvider, CoinpaprikaProvider, CryptoCompareProvider, Crypull, DexScreenerProvider, GeckoTerminalProvider, crypull };
700
+ //# sourceMappingURL=index.mjs.map
701
+ //# sourceMappingURL=index.mjs.map