@icgio/icg-utils 1.9.42 → 1.9.43

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.
@@ -581,9 +581,24 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
581
581
  update_time: new Date(coin.last_updated),
582
582
  }
583
583
  }
584
+ // Continue pagination if BTC/ETH not found yet
584
585
  if (!result.BTC || !result.ETH) {
585
- get_crypto_rates(cb)
586
+ if (body.length < per_page_nums) {
587
+ // Last page and still no BTC/ETH - return what we have
588
+ console.warn('BTC or ETH not found in CoinGecko pagination, returning partial results')
589
+ for (let cur in result) {
590
+ if (result.BTC) result[cur].BTC = result[cur].USD / result.BTC.USD
591
+ if (result.ETH) result[cur].ETH = result[cur].USD / result.ETH.USD
592
+ }
593
+ cb(result)
594
+ } else {
595
+ // Continue to next page
596
+ page++
597
+ console.log('fetching coingecko rate: page', page, 'good (searching for BTC/ETH)')
598
+ get_coingecko_rate_page(page, cb)
599
+ }
586
600
  } else {
601
+ // BTC and ETH found, calculate BTC/ETH rates for all currencies
587
602
  for (let cur in result) {
588
603
  result[cur].BTC = result[cur].USD / result.BTC.USD
589
604
  result[cur].ETH = result[cur].USD / result.ETH.USD
@@ -597,10 +612,37 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
597
612
  }
598
613
  }
599
614
  } else {
600
- setTimeout(() => {
601
- console.log('fetching coingecko rate: page', page, 'timeout')
602
- get_crypto_rates(cb)
603
- }, 60000)
615
+ // Handle error or empty response
616
+ if (err || (body && body.status && body.status.error_code === 429)) {
617
+ // Rate limit error - wait longer before retrying
618
+ console.error('CoinGecko rate limit error (429), waiting 60s before retry')
619
+ setTimeout(() => {
620
+ console.log('fetching coingecko rate: page', page, 'retry after rate limit')
621
+ get_coingecko_rate_page(page, cb)
622
+ }, 60000)
623
+ } else if (body && body.length === 0) {
624
+ // Empty response - might be last page or error
625
+ if (Object.keys(result).length > 0) {
626
+ // Return what we have
627
+ for (let cur in result) {
628
+ if (result.BTC) result[cur].BTC = result[cur].USD / result.BTC.USD
629
+ if (result.ETH) result[cur].ETH = result[cur].USD / result.ETH.USD
630
+ }
631
+ cb(result)
632
+ } else {
633
+ // No results at all - retry after delay
634
+ console.log('fetching coingecko rate: page', page, 'empty response, retrying')
635
+ setTimeout(() => {
636
+ get_coingecko_rate_page(page, cb)
637
+ }, 60000)
638
+ }
639
+ } else {
640
+ // Unknown error - retry
641
+ console.error('fetching coingecko rate: page', page, 'error', err || body)
642
+ setTimeout(() => {
643
+ get_coingecko_rate_page(page, cb)
644
+ }, 60000)
645
+ }
604
646
  }
605
647
  })
606
648
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.9.42",
3
+ "version": "1.9.43",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {