@icgio/icg-utils 1.7.1 → 1.7.3
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 +5 -0
- package/constants/stablecoins.js +1 -0
- package/index.js +5 -1
- package/jsconfig.json +7 -0
- package/lib/coingecko.js +4 -3
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = ['USDT', 'TUSD', 'PAX', 'BUSD', 'USDK', 'USDC', 'HUSD', 'DAI', 'IUSD', 'USDD', 'FEI']
|
package/index.js
CHANGED
|
@@ -9,5 +9,9 @@ module.exports = {
|
|
|
9
9
|
mail: require('./lib/mail.js'),
|
|
10
10
|
rate_limiter: require('./lib/rate-limiter.js'),
|
|
11
11
|
utils: require('./lib/utils.js'),
|
|
12
|
-
wechat: require('./lib/wechat-bot-client.js')
|
|
12
|
+
wechat: require('./lib/wechat-bot-client.js'),
|
|
13
|
+
constants: {
|
|
14
|
+
stablecoins: require('./constants/stablecoins.js'),
|
|
15
|
+
forex_rate: require('./constants/forex-rate.js')
|
|
16
|
+
}
|
|
13
17
|
}
|
package/jsconfig.json
ADDED
package/lib/coingecko.js
CHANGED
|
@@ -4,6 +4,7 @@ const needle = require('needle')
|
|
|
4
4
|
|
|
5
5
|
const coins_map = require('./coingecko-coins-map.js')
|
|
6
6
|
const parse_pair = require('./utils.js').parse_pair
|
|
7
|
+
const stablecoins = require('../constants/stablecoins')
|
|
7
8
|
|
|
8
9
|
const options = {
|
|
9
10
|
headers: {
|
|
@@ -39,7 +40,7 @@ let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs) => {
|
|
|
39
40
|
if (type === 'pair') {
|
|
40
41
|
let pair = pair_or_pairs_or_cur_curs
|
|
41
42
|
let [cur, base_cur] = parse_pair(pair)
|
|
42
|
-
let cur_id = coins_map[cur], vs_cur =
|
|
43
|
+
let cur_id = coins_map[cur], vs_cur = stablecoins.indexOf(base_cur) > -1 ? 'usd' : base_cur.toLowerCase()
|
|
43
44
|
needle.get(`https://api.coingecko.com/api/v3/simple/price?ids=${cur_id}&vs_currencies=${vs_cur}`, (err, res, body) => {
|
|
44
45
|
if (err) {
|
|
45
46
|
console.error(pair, err)
|
|
@@ -74,9 +75,9 @@ let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs) => {
|
|
|
74
75
|
let cur = pair_or_pairs_or_cur_curs, cur_id = coins_map[cur]
|
|
75
76
|
needle.get(`https://api.coingecko.com/api/v3/simple/price?ids=${cur_id}&vs_currencies=usd`, (err, res, body) => {
|
|
76
77
|
if (err) {
|
|
77
|
-
console.error(
|
|
78
|
+
console.error(cur, err)
|
|
78
79
|
} else if (!body[cur_id]) {
|
|
79
|
-
console.error('coingecko cur_id incorrect:',
|
|
80
|
+
console.error('coingecko cur_id incorrect:', cur, cur_id, 'usd', err)
|
|
80
81
|
}
|
|
81
82
|
cb(body[cur_id]['usd'])
|
|
82
83
|
})
|