@icgio/icg-utils 1.7.8 → 1.7.10
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-coins-map.js +1570 -1694
- package/lib/coingecko.js +29 -39
- package/package.json +1 -1
package/lib/coingecko.js
CHANGED
|
@@ -14,29 +14,7 @@ const options = {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
if (!pair_or_pairs_or_cur_curs || pair_or_pairs_or_cur_curs.length === 0) {
|
|
19
|
-
return 'null'
|
|
20
|
-
} else if (Array.isArray(pair_or_pairs_or_cur_curs)) {
|
|
21
|
-
let pairs_or_curs = pair_or_pairs_or_cur_curs[0]
|
|
22
|
-
let [cur, base_cur] = parse_pair(pairs_or_curs)
|
|
23
|
-
if (!base_cur || !cur) {
|
|
24
|
-
return 'curs'
|
|
25
|
-
} else {
|
|
26
|
-
return 'pairs'
|
|
27
|
-
}
|
|
28
|
-
} else {
|
|
29
|
-
let [cur, base_cur] = parse_pair(pair_or_pairs_or_cur_curs)
|
|
30
|
-
if (!base_cur || !cur) {
|
|
31
|
-
return 'cur'
|
|
32
|
-
} else {
|
|
33
|
-
return 'pair'
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs) => {
|
|
39
|
-
let type = determine_type(pair_or_pairs_or_cur_curs)
|
|
17
|
+
let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs, type) => {
|
|
40
18
|
if (type === 'pair') {
|
|
41
19
|
let pair = pair_or_pairs_or_cur_curs
|
|
42
20
|
let [cur, base_cur] = parse_pair(pair)
|
|
@@ -69,6 +47,12 @@ let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs) => {
|
|
|
69
47
|
delete temp['usd']
|
|
70
48
|
result[cur_id_map[cur_id]] = body[cur_id]
|
|
71
49
|
}
|
|
50
|
+
for (let stable of stablecoins) {
|
|
51
|
+
result[stable] = {
|
|
52
|
+
USD: 1,
|
|
53
|
+
USDT: 1
|
|
54
|
+
}
|
|
55
|
+
}
|
|
72
56
|
cb(result)
|
|
73
57
|
})
|
|
74
58
|
} else if (type === 'cur') {
|
|
@@ -101,6 +85,12 @@ let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs) => {
|
|
|
101
85
|
delete temp['usd']
|
|
102
86
|
result[cur_id_map[cur_id]] = body[cur_id]
|
|
103
87
|
}
|
|
88
|
+
for (let stable of stablecoins) {
|
|
89
|
+
result[stable] = {
|
|
90
|
+
USD: 1,
|
|
91
|
+
USDT: 1
|
|
92
|
+
}
|
|
93
|
+
}
|
|
104
94
|
cb(result)
|
|
105
95
|
})
|
|
106
96
|
} else {
|
|
@@ -108,7 +98,7 @@ let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs) => {
|
|
|
108
98
|
let get_coingecko_rate = (page, cb) => {
|
|
109
99
|
let url = 'https://api.coingecko.com/api/v3/coins/markets?vs_currency=' + quote_cur.toLowerCase() + '&per_page=' + per_page_nums + '&page=' + page
|
|
110
100
|
needle.get(url, options, (err, res, body) => {
|
|
111
|
-
console.log('fetching coingecko rate: body length', _.get(body, 'length'))
|
|
101
|
+
console.log('fetching coingecko rate: body length', _.get(body, 'length', body))
|
|
112
102
|
if (body && body.length > 0) {
|
|
113
103
|
for (let coin of body) {
|
|
114
104
|
let symbol = coin.symbol
|
|
@@ -167,27 +157,27 @@ let get_coingecko_rates = (cb, pair_or_pairs_or_cur_curs) => {
|
|
|
167
157
|
|
|
168
158
|
// get_coingecko_rates((res) => {
|
|
169
159
|
// console.log(res)
|
|
170
|
-
// //
|
|
171
|
-
//
|
|
172
|
-
//
|
|
173
|
-
//
|
|
160
|
+
// // }, ['BTCUSD', 'ETHUSD'])
|
|
161
|
+
// }, ['SWFTC', 'BTC', 'ETH'], 'curs')
|
|
162
|
+
// }, 'ETHUSDC', 'pair')
|
|
163
|
+
// }, 'BTC')
|
|
174
164
|
// })
|
|
175
165
|
|
|
176
166
|
// https://api.coingecko.com/api/v3/coins/list
|
|
177
167
|
|
|
178
|
-
|
|
179
|
-
|
|
168
|
+
needle.get('https://api.coingecko.com/api/v3/coins/list', (err, res, body) => {
|
|
169
|
+
let list = body
|
|
180
170
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
171
|
+
let map = {}
|
|
172
|
+
for (let line of list) {
|
|
173
|
+
let cur = line.symbol.toUpperCase()
|
|
174
|
+
_.set(map, [cur], line.id)
|
|
175
|
+
}
|
|
186
176
|
|
|
187
|
-
|
|
188
|
-
|
|
177
|
+
map['ETH'] = 'ethereum'
|
|
178
|
+
map['MTR'] = 'meter-stable'
|
|
189
179
|
|
|
190
|
-
|
|
191
|
-
|
|
180
|
+
console.log(JSON.stringify(map, null, 4))
|
|
181
|
+
})
|
|
192
182
|
|
|
193
183
|
module.exports = get_coingecko_rates
|