@icgio/icg-utils 1.7.43 → 1.7.45

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.
@@ -7,7 +7,7 @@
7
7
  // }
8
8
 
9
9
  module.exports = {
10
- USDCNY: 6.94,
11
- USDKRW: 1319.83,
12
- USDTHB: 35.28,
10
+ USDCNY: 7.233975,
11
+ USDKRW: 1336.393712,
12
+ USDTHB: 35.30959,
13
13
  }
@@ -1 +1 @@
1
- module.exports = ['USDT', 'TUSD', 'PAX', 'BUSD', 'USDK', 'USDC', 'HUSD', 'DAI', 'IUSD', 'USDD', 'FEI', 'FRAX', 'CUSD']
1
+ module.exports = ['BUSD', 'CUSD', 'DAI', 'FEI', 'FRAX', 'GUSD', 'HUSD', 'IUSD', 'PAX', 'SUSD', 'TUSD', 'USDC', 'USDD', 'USDJ', 'USDK', 'USDP', 'USDT']
@@ -21,26 +21,26 @@ let limiter = new Limiter({
21
21
 
22
22
  const options = {}
23
23
 
24
- let process_coins_map_coingecko = (result) => {
25
- result['ETH'] = 'ethereum'
26
- result['MTR'] = 'meter-stable'
27
- result['WAXL'] = 'axelar'
28
- return result
24
+ let process_coins_map_coingecko = (res) => {
25
+ res['ETH'] = 'ethereum'
26
+ res['MTR'] = 'meter-stable'
27
+ res['WAXL'] = 'axelar'
28
+ return res
29
29
  }
30
30
 
31
- let process_coins_map_coinmarketcap = (result) => {
32
- return result
31
+ let process_coins_map_coinmarketcap = (res) => {
32
+ return res
33
33
  }
34
34
 
35
35
  let get_coins_map_coingecko = (cb) => {
36
36
  limiter.process(needle.get, 'https://api.coingecko.com/api/v3/coins/list', (err, res, body) => {
37
37
  if (body && Array.isArray(body)) {
38
- let result = {}
38
+ let res = {}
39
39
  for (let line of body) {
40
40
  let cur = line.symbol.toUpperCase()
41
- _.set(result, [cur], line.id)
41
+ _.set(res, [cur], line.id)
42
42
  }
43
- cb({ success: true, body: process_coins_map_coingecko(result) })
43
+ cb({ success: true, body: process_coins_map_coingecko(res) })
44
44
  } else {
45
45
  cb({ success: false, body })
46
46
  }
@@ -50,21 +50,21 @@ let get_coins_map_coingecko = (cb) => {
50
50
  let get_coins_map_coinmarketcap = (cb) => {
51
51
  limiter.process(needle.get, 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/map?CMC_PRO_API_KEY=47a30ef1-a773-4da0-8ac5-69bce757fdfa', (err, res, body) => {
52
52
  if (body && body.data && Array.isArray(body.data)) {
53
- let result = {}
53
+ let res = {}
54
54
  for (let line of body.data) {
55
55
  let cur = line.symbol.toUpperCase()
56
- _.set(result, [cur], line.name)
56
+ _.set(res, [cur], line.name)
57
57
  }
58
- result = sort_keys(result)
59
- cb({ success: true, body: process_coins_map_coinmarketcap(result) })
58
+ res = sort_keys(res)
59
+ cb({ success: true, body: process_coins_map_coinmarketcap(res) })
60
60
  } else {
61
61
  cb({ success: false, body })
62
62
  }
63
63
  })
64
64
  }
65
65
 
66
+ let result = {}
66
67
  let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko') => {
67
- let result = {}
68
68
  function get_crypto_rates_base(cb, pair_or_pairs_or_cur_curs, type) {
69
69
  if (type === 'pair') {
70
70
  let pair = pair_or_pairs_or_cur_curs
@@ -236,32 +236,87 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
236
236
  }
237
237
  }
238
238
  coins_map = source === 'coingecko' ? process_coins_map_coingecko(coins_map_raw_coingecko) : process_coins_map_coinmarketcap(coins_map_raw_coinmarketcap)
239
- if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'FREN')) {
240
- let curs = _.without(pair_or_pairs_or_cur_curs, 'FREN')
241
- dex_rate().then((res) => {
242
- result = {
243
- FREN: {
239
+ try {
240
+ if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'FREN')) {
241
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'FREN')
242
+ dex_rate().then((res) => {
243
+ result.FREN = {
244
244
  USD: res.FRENUSDT,
245
245
  USDT: res.FRENUSDT,
246
- },
247
- }
248
- get_crypto_rates_base(cb, curs, type)
249
- })
250
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'DMC')) {
251
- let curs = _.without(pair_or_pairs_or_cur_curs, 'DMC')
252
- needle('get', 'https://api.gateio.ws/api/v4/spot/order_book?currency_pair=DMC_USDT').then((res) => {
253
- const { asks, bids } = res.body
254
- let rate = (parseFloat(asks[0][0]) + parseFloat(bids[0][0])) / 2
255
- result = {
256
- DMC: {
246
+ }
247
+ get_crypto_rates(cb, curs, type, source)
248
+ })
249
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'DMC')) {
250
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'DMC')
251
+ needle('get', 'https://api.gateio.ws/api/v4/spot/order_book?currency_pair=DMC_USDT').then((res) => {
252
+ const { asks, bids } = res.body
253
+ let rate = (parseFloat(asks[0][0]) + parseFloat(bids[0][0])) / 2
254
+ result.DMC = {
257
255
  USD: rate,
258
256
  USDT: rate,
259
- },
260
- }
261
- get_crypto_rates_base(cb, curs, type)
262
- })
263
- } else {
264
- get_crypto_rates_base(cb, pair_or_pairs_or_cur_curs, type)
257
+ }
258
+ get_crypto_rates(cb, curs, type, source)
259
+ })
260
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'ENIX')) {
261
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'ENIX')
262
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=ENIX_USDT&depth=100').then((res) => {
263
+ const { asks, bids } = res.body.data
264
+ let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
265
+ result.ENIX = {
266
+ USD: rate,
267
+ USDT: rate,
268
+ }
269
+ get_crypto_rates(cb, curs, type, source)
270
+ })
271
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'FINU')) {
272
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'FINU')
273
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=FINU_USDT&depth=100').then((res) => {
274
+ const { asks, bids } = res.body.data
275
+ let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
276
+ result.FINU = {
277
+ USD: rate,
278
+ USDT: rate,
279
+ }
280
+ get_crypto_rates(cb, curs, type, source)
281
+ })
282
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'GLW')) {
283
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'GLW')
284
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=GLW_USDT&depth=100').then((res) => {
285
+ const { asks, bids } = res.body.data
286
+ let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
287
+ result.GLW = {
288
+ USD: rate,
289
+ USDT: rate,
290
+ }
291
+ get_crypto_rates(cb, curs, type, source)
292
+ })
293
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'UCF')) {
294
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'UCF')
295
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=UCF_USDT&depth=100').then((res) => {
296
+ const { asks, bids } = res.body.data
297
+ let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
298
+ result.UCF = {
299
+ USD: rate,
300
+ USDT: rate,
301
+ }
302
+ get_crypto_rates(cb, curs, type, source)
303
+ })
304
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'WPAY')) {
305
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'WPAY')
306
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=WPAY_USDT&depth=100').then((res) => {
307
+ const { asks, bids } = res.body.data
308
+ let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
309
+ result.WPAY = {
310
+ USD: rate,
311
+ USDT: rate,
312
+ }
313
+ get_crypto_rates(cb, curs, type, source)
314
+ })
315
+ } else {
316
+ get_crypto_rates_base(cb, pair_or_pairs_or_cur_curs, type)
317
+ }
318
+ } catch (error) {
319
+ console.log('get_crypto_rates', error)
265
320
  }
266
321
  }
267
322
 
@@ -269,7 +324,7 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
269
324
  // (res) => {
270
325
  // console.log(res)
271
326
  // },
272
- // ['BTC', 'ETH'],
327
+ // ['BTC', 'ETH', 'ENIX', 'FINU', 'WPAY', 'FREN', 'DMC'],
273
328
  // 'curs',
274
329
  // 'coingecko'
275
330
  // )
package/lib/forex-rate.js CHANGED
@@ -3,7 +3,7 @@ const utils = require('./utils.js')
3
3
 
4
4
  let get_forex_rate = function (pair, cb) {
5
5
  let [cur, base_cur] = utils.parse_pair(pair)
6
- needle.get(`https://api.exchangerate.host/latest`, (err, res, body) => {
6
+ needle.get(`https://api.exchangerate.host/latest?base=USD`, (err, res, body) => {
7
7
  if (body.rates) {
8
8
  cb(body.rates[base_cur])
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.7.43",
3
+ "version": "1.7.45",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {