@icgio/icg-utils 1.7.36 → 1.7.38

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/lib/coingecko.js CHANGED
@@ -4,6 +4,8 @@ const needle = require('needle')
4
4
 
5
5
  const parse_pair = require('./utils.js').parse_pair
6
6
  const stablecoins = require('../constants/stablecoins')
7
+ let coins_map_raw = require('../constants/coins-map.js')
8
+ let coins_map = {}
7
9
 
8
10
  const Limiter = require('./rate-limiter.js')
9
11
 
@@ -20,18 +22,21 @@ const options = {
20
22
  },
21
23
  }
22
24
 
23
- let coins_map = {}
25
+ let process_coins_map = (body) => {
26
+ let result = {}
27
+ for (let line of body) {
28
+ let cur = line.symbol.toUpperCase()
29
+ _.set(result, [cur], line.id)
30
+ }
31
+ result['ETH'] = 'ethereum'
32
+ result['MTR'] = 'meter-stable'
33
+ return result
34
+ }
35
+
24
36
  let get_coins_map = (cb) => {
25
37
  cmc_limiter.process(needle.get, 'https://api.coingecko.com/api/v3/coins/list', (err, res, body) => {
26
38
  if (body && Array.isArray(body)) {
27
- let result = {}
28
- for (let line of body) {
29
- let cur = line.symbol.toUpperCase()
30
- _.set(result, [cur], line.id)
31
- }
32
- result['ETH'] = 'ethereum'
33
- result['MTR'] = 'meter-stable'
34
- cb({ success: true, body: result })
39
+ cb({ success: true, body: process_coins_map(body) })
35
40
  } else {
36
41
  cb({ success: false, body })
37
42
  }
@@ -180,23 +185,24 @@ let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs, type) => {
180
185
  get_coingecko_rate_page(page, cb)
181
186
  }
182
187
  }
183
- if (_.isEmpty(coins_map)) {
184
- get_coins_map((res) => {
185
- if (res.success) {
186
- coins_map = res.body
187
- }
188
- get_coingecko_rates_base(cb, pair_or_pairs_or_cur_curs, type)
189
- })
190
- } else {
188
+ // if (_.isEmpty(coins_map)) {
189
+ // get_coins_map((res) => {
190
+ // if (res.success) {
191
+ // coins_map = res.body
192
+ // }
193
+ // get_coingecko_rates_base(cb, pair_or_pairs_or_cur_curs, type)
194
+ // })
195
+ // } else {
196
+ coins_map = process_coins_map(coins_map_raw)
191
197
  get_coingecko_rates_base(cb, pair_or_pairs_or_cur_curs, type)
192
- }
198
+ // }
193
199
  }
194
200
 
195
201
  // get_coingecko_rates(
196
202
  // (res) => {
197
203
  // console.log(res)
198
204
  // },
199
- // ['RED', 'PIAS', 'PRMX'],
205
+ // ['BTC', 'ETH'],
200
206
  // 'curs'
201
207
  // )
202
208
 
package/lib/utils.js CHANGED
@@ -703,7 +703,8 @@ module.exports.parse_pair = function (pair) {
703
703
  ;[pair, time] = _.split(pair, '_')
704
704
  let result = ''
705
705
  if (stablecoins.some((c) => pair.endsWith(c))) {
706
- result = [pair.substr(0, pair.length - c.length), pair.substr(pair.length - 4, pair.length)]
706
+ let stablecoin = stablecoins.find((c) => pair.endsWith(c))
707
+ result = [pair.substr(0, pair.length - stablecoin.length), pair.substr(pair.length - stablecoin.length, pair.length)]
707
708
  } else if (pair.endsWith('QC')) {
708
709
  result = [pair.substr(0, pair.length - 2), pair.substr(pair.length - 2, pair.length)]
709
710
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.7.36",
3
+ "version": "1.7.38",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -31,6 +31,7 @@
31
31
  "nodemailer": "^4.7.0",
32
32
  "qrcode-terminal": "^0.12.0",
33
33
  "websocket": "^1.0.33",
34
- "winston": "^2.4.5"
34
+ "winston": "^2.4.5",
35
+ "ws": "^8.13.0"
35
36
  }
36
37
  }