@icgio/icg-utils 1.7.15 → 1.7.17

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.
Files changed (2) hide show
  1. package/lib/coingecko.js +5 -16
  2. package/package.json +1 -1
package/lib/coingecko.js CHANGED
@@ -22,7 +22,7 @@ const options = {
22
22
 
23
23
  let coins_map = {}
24
24
  let get_coins_map = (cb) => {
25
- needle.get('https://api.coingecko.com/api/v3/coins/list', (err, res, body) => {
25
+ cmc_limiter.process(needle.get, 'https://api.coingecko.com/api/v3/coins/list', (err, res, body) => {
26
26
  if (body && Array.isArray(body)) {
27
27
  let result = {}
28
28
  for (let line of body) {
@@ -38,21 +38,14 @@ let get_coins_map = (cb) => {
38
38
  })
39
39
  }
40
40
 
41
- let lock = false
42
41
  let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs, type) => {
43
- if (lock) {
44
- console.error('avoid calling get_coingecko_rates multiple times in a short time')
45
- return
46
- }
47
42
  function get_coingecko_rates_base(cb, pair_or_pairs_or_cur_curs, type) {
48
- lock = true
49
43
  if (type === 'pair') {
50
44
  let pair = pair_or_pairs_or_cur_curs
51
45
  let [cur, base_cur] = parse_pair(pair)
52
46
  let cur_id = coins_map[cur],
53
47
  vs_cur = stablecoins.indexOf(base_cur) > -1 ? 'usd' : base_cur.toLowerCase()
54
- needle.get(`https://api.coingecko.com/api/v3/simple/price?ids=${cur_id}&vs_currencies=${vs_cur}`, (err, res, body) => {
55
- lock = false
48
+ cmc_limiter.process(needle.get, `https://api.coingecko.com/api/v3/simple/price?ids=${cur_id}&vs_currencies=${vs_cur}`, (err, res, body) => {
56
49
  if (err) {
57
50
  console.error(pair, err)
58
51
  } else if (!body[cur_id]) {
@@ -69,8 +62,7 @@ let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs, type) => {
69
62
  })
70
63
  )
71
64
  let url = `https://api.coingecko.com/api/v3/simple/price?ids=${String(_.keys(cur_id_map))}&vs_currencies=usd`
72
- needle.get(url, (err, res, body) => {
73
- lock = false
65
+ cmc_limiter.process(needle.get, url, (err, res, body) => {
74
66
  if (err) {
75
67
  console.error(err)
76
68
  return
@@ -94,8 +86,7 @@ let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs, type) => {
94
86
  } else if (type === 'cur') {
95
87
  let cur = pair_or_pairs_or_cur_curs,
96
88
  cur_id = coins_map[cur]
97
- needle.get(`https://api.coingecko.com/api/v3/simple/price?ids=${cur_id}&vs_currencies=usd`, (err, res, body) => {
98
- lock = false
89
+ cmc_limiter.process(needle.get, `https://api.coingecko.com/api/v3/simple/price?ids=${cur_id}&vs_currencies=usd`, (err, res, body) => {
99
90
  if (err) {
100
91
  console.error(cur, err)
101
92
  } else if (!body[cur_id]) {
@@ -112,8 +103,7 @@ let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs, type) => {
112
103
  })
113
104
  )
114
105
  let url = `https://api.coingecko.com/api/v3/simple/price?ids=${String(_.keys(cur_id_map))}&vs_currencies=usd`
115
- needle.get(url, (err, res, body) => {
116
- lock = false
106
+ cmc_limiter.process(needle.get, url, (err, res, body) => {
117
107
  if (err) {
118
108
  console.error(err)
119
109
  return
@@ -171,7 +161,6 @@ let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs, type) => {
171
161
  result[cur].ETH = result[cur].USD / result.ETH.USD
172
162
  }
173
163
  if (body.length < per_page_nums) {
174
- lock = false
175
164
  cb(result)
176
165
  } else {
177
166
  page++
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.7.15",
3
+ "version": "1.7.17",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {