@icgio/icg-utils 1.7.43 → 1.7.44
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/constants/forex-rate.js +3 -3
- package/constants/stablecoins.js +1 -1
- package/lib/crypto-rates.js +71 -38
- package/lib/forex-rate.js +1 -1
- package/package.json +1 -1
package/constants/forex-rate.js
CHANGED
package/constants/stablecoins.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = ['
|
|
1
|
+
module.exports = ['BUSD', 'CUSD', 'DAI', 'FEI', 'FRAX', 'GUSD', 'HUSD', 'IUSD', 'PAX', 'SUSD', 'TUSD', 'USDC', 'USDD', 'USDJ', 'USDK', 'USDP', 'USDT']
|
package/lib/crypto-rates.js
CHANGED
|
@@ -21,26 +21,26 @@ let limiter = new Limiter({
|
|
|
21
21
|
|
|
22
22
|
const options = {}
|
|
23
23
|
|
|
24
|
-
let process_coins_map_coingecko = (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return
|
|
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 = (
|
|
32
|
-
return
|
|
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
|
|
38
|
+
let res = {}
|
|
39
39
|
for (let line of body) {
|
|
40
40
|
let cur = line.symbol.toUpperCase()
|
|
41
|
-
_.set(
|
|
41
|
+
_.set(res, [cur], line.id)
|
|
42
42
|
}
|
|
43
|
-
cb({ success: true, body: process_coins_map_coingecko(
|
|
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
|
|
53
|
+
let res = {}
|
|
54
54
|
for (let line of body.data) {
|
|
55
55
|
let cur = line.symbol.toUpperCase()
|
|
56
|
-
_.set(
|
|
56
|
+
_.set(res, [cur], line.name)
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
cb({ success: true, body: process_coins_map_coinmarketcap(
|
|
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,65 @@ 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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
|
|
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, 'WPAY')) {
|
|
283
|
+
let curs = _.without(pair_or_pairs_or_cur_curs, 'WPAY')
|
|
284
|
+
needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=WPAY_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.WPAY = {
|
|
288
|
+
USD: rate,
|
|
289
|
+
USDT: rate,
|
|
290
|
+
}
|
|
291
|
+
get_crypto_rates(cb, curs, type, source)
|
|
292
|
+
})
|
|
293
|
+
} else {
|
|
294
|
+
get_crypto_rates_base(cb, pair_or_pairs_or_cur_curs, type)
|
|
295
|
+
}
|
|
296
|
+
} catch (error) {
|
|
297
|
+
console.log('get_crypto_rates', error)
|
|
265
298
|
}
|
|
266
299
|
}
|
|
267
300
|
|
|
@@ -269,7 +302,7 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
|
|
|
269
302
|
// (res) => {
|
|
270
303
|
// console.log(res)
|
|
271
304
|
// },
|
|
272
|
-
// ['BTC', 'ETH'],
|
|
305
|
+
// ['BTC', 'ETH', 'ENIX', 'FINU', 'WPAY', 'FREN', 'DMC'],
|
|
273
306
|
// 'curs',
|
|
274
307
|
// 'coingecko'
|
|
275
308
|
// )
|
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
|
}
|