Я бы сделал запрос чтобы выкачать данные валют и запрос чтобы запросить текущие курсы фиатных валют. Перемножил бы цены из USD в нужные курсы и вывел бы в объект.
'use strict';
const axios = require('axios');
void async function main() {
const data = await Promise.all([
getCryptoList(3),
getConvertCurrency(['EUR', 'RUB', 'GBP', 'UAH'])
]);
const result = appendCryptoCourses(...data);
console.log(result);
}();
function appendCryptoCourses(list, courses) {
for (const id in list) {
const coin = list[id];
for (const currency in courses) {
const course = courses[currency];
coin.quotes[currency] = {
price: coin.quotes.USD.price * course,
volume_24h: coin.quotes.USD.volume_24h * course,
market_cap: coin.quotes.USD.market_cap * course,
percent_change_1h: coin.quotes.USD.percent_change_1h,
percent_change_24h: coin.quotes.USD.percent_change_24h,
percent_change_7d: coin.quotes.USD.percent_change_7d
};
}
}
return list;
}
async function getCryptoList(limit) {
const list = await request('https://api.coinmarketcap.com/v2/ticker/', { limit });
return list.data;
}
function getConvertCurrency(symbols) {
return request('https://min-api.cryptocompare.com/data/price', {
fsym: 'USD',
tsyms: Array.isArray(symbols) ? symbols.join(',') : symbols
});
}
function request(link, params) {
return new Promise((resolve, reject) => {
axios.get(link, { params }).then(response => resolve(response.data)).catch(reject);
});
}
Чтобы запустить создайте папку, в ней файл index.js. В файл index.js скиньте этот код. После этого откройте консоль в этой папке и напишите: npm install axios --save-dev
После всего этого стартуем: node index.js
Если кратко то на выходе получаем такой объект:
{
"1": {
"id": 1,
"name": "Bitcoin",
"symbol": "BTC",
"website_slug": "bitcoin",
"rank": 1,
"circulating_supply": 17388287,
"total_supply": 17388287,
"max_supply": 21000000,
"quotes": {
"USD": {
"price": 4499.33210008,
"volume_24h": 5185812375.72332,
"market_cap": 78235677865,
"percent_change_1h": -0.45,
"percent_change_24h": -2.14,
"percent_change_7d": -19.21
},
"EUR": {
"price": 3946.8141181901756,
"volume_24h": 4548994615.984496,
"market_cap": 68628336623.178,
"percent_change_1h": -0.45,
"percent_change_24h": -2.14,
"percent_change_7d": -19.21
},
"RUB": {
"price": 304109.8566444072,
"volume_24h": 350509058475.1392,
"market_cap": 5287949466895.351,
"percent_change_1h": -0.45,
"percent_change_24h": -2.14,
"percent_change_7d": -19.21
},
"GBP": {
"price": 3515.7781030025117,
"volume_24h": 4052193790.390202,
"market_cap": 61133358683.711,
"percent_change_1h": -0.45,
"percent_change_24h": -2.14,
"percent_change_7d": -19.21
},
"UAH": {
"price": 129310.80455629919,
"volume_24h": 149040247678.2882,
"market_cap": 2248493381840.1,
"percent_change_1h": -0.45,
"percent_change_24h": -2.14,
"percent_change_7d": -19.21
}
},
"last_updated": 1542886571
},
"52": {
"id": 52,
"name": "XRP",
"symbol": "XRP",
"website_slug": "ripple",
"rank": 2,
"circulating_supply": 40327341704,
"total_supply": 99991780039,
"max_supply": 100000000000,
"quotes": {
"USD": {
"price": 0.4375704632,
"volume_24h": 579102404.360952,
"market_cap": 17646053587,
"percent_change_1h": -0.18,
"percent_change_24h": -1.61,
"percent_change_7d": -4.17
},
"EUR": {
"price": 0.38383681031904,
"volume_24h": 507988629.1054271,
"market_cap": 15479118206.5164,
"percent_change_1h": -0.18,
"percent_change_24h": -1.61,
"percent_change_7d": -4.17
},
"RUB": {
"price": 29.575387607688,
"volume_24h": 39141531510.75675,
"market_cap": 1192696761945.33,
"percent_change_1h": -0.18,
"percent_change_24h": -1.61,
"percent_change_7d": -4.17
},
"GBP": {
"price": 0.34191755994448,
"volume_24h": 452510618.7676479,
"market_cap": 13788626272.8818,
"percent_change_1h": -0.18,
"percent_change_24h": -1.61,
"percent_change_7d": -4.17
},
"UAH": {
"price": 12.575775112368,
"volume_24h": 16643403101.33376,
"market_cap": 507147580090.37994,
"percent_change_1h": -0.18,
"percent_change_24h": -1.61,
"percent_change_7d": -4.17
}
},
"last_updated": 1542886561
},
"1027": {
"id": 1027,
"name": "Ethereum",
"symbol": "ETH",
"website_slug": "ethereum",
"rank": 3,
"circulating_supply": 103354703,
"total_supply": 103354703,
"max_supply": null,
"quotes": {
"USD": {
"price": 132.472624031,
"volume_24h": 2224827274.81642,
"market_cap": 13691668675,
"percent_change_1h": -0.59,
"percent_change_24h": -2.93,
"percent_change_7d": -25.14
},
"EUR": {
"price": 116.20498579999321,
"volume_24h": 1951618485.4689636,
"market_cap": 12010331761.71,
"percent_change_1h": -0.59,
"percent_change_24h": -2.93,
"percent_change_7d": -25.14
},
"RUB": {
"price": 8953.824658255291,
"volume_24h": 150376075504.84183,
"market_cap": 925419885743.25,
"percent_change_1h": -0.59,
"percent_change_24h": -2.93,
"percent_change_7d": -25.14
},
"GBP": {
"price": 103.51410841782341,
"volume_24h": 1738480032.5415506,
"market_cap": 10698669902.645,
"percent_change_1h": -0.59,
"percent_change_24h": -2.93,
"percent_change_7d": -25.14
},
"UAH": {
"price": 3807.26321465094,
"volume_24h": 63941535878.22391,
"market_cap": 393498557719.5,
"percent_change_1h": -0.59,
"percent_change_24h": -2.93,
"percent_change_7d": -25.14
}
},
"last_updated": 1542886521
}
}