use strict const request require superagent run then console log done

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
'use strict';
const request = require('superagent');
run()
.then(() => console.log('done'))
.catch(err => console.error(err))
.then(() => process.exit(0));
async function run() {
let response = await request.get('https://api.simpleswap.io/get_all_currencies');
let currencies = response.body;
console.log(`total ${currencies.length} currencies\n`);
let promises = currencies.map(async (from, i) => {
try {
console.log(`[${i + 1}/${currencies.length}] ${from.symbol}:`);
let min = await request.get(`https://api.simpleswap.io/get_min?currency_from=${from.symbol}&currency_to=btc`);
console.log(`[${i + 1}/${currencies.length}] ${from.symbol}\t\tmin: ${min.body}`);
let estimated = await request.get(`https://api.simpleswap.io/get_estimated?currency_from=${from.symbol}&currency_to=btc&amount=${min}`);
console.log(`[${i + 1}/${currencies.length}] ${from.symbol}\t\testimated (->btc): ${estimated.body}`);
} catch (err) {
console.error('catched', err);
}
});
await Promise.all(promises);
}