Files
purple-explorer/lib/apis/coingecko.js
T
joeuhren 460ca331b6 Add support for USD price lookup of any altcoin
-Market sync now sets the last USD price based on the default market pair even if it is not BTC
-Removed the coindesk api which was only really useful for getting the USD price of BTC
-Added a couple coingecko apis which are used to get the current USD value of the default market pair
-Updated the readme, settings file comments and info/api page with better verbiage regarding the market price which was previously only measured in BTC
2021-05-29 20:40:35 -06:00

43 lines
1.0 KiB
JavaScript

var request = require('postman-request');
var base_url = 'https://api.coingecko.com/api/v3/';
function get_coin_list(cb) {
request({ uri: base_url + 'coins/list?include_platform=false', json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, body) {
if (error)
return cb(error, []);
else
return cb(null, body);
});
}
function get_usd_value(id, cb) {
request({ uri: base_url + 'simple/price?ids=' + id + '&vs_currencies=usd', json: true, headers: {'User-Agent': 'eiquidus'} }, function (error, response, body) {
if (error)
return cb(error, 0);
else
return cb(null, body[id].usd);
});
}
module.exports = {
get_coin_data: function (cb) {
var error = null;
get_coin_list(function (err, coin_list) {
if (err)
error = err;
return cb(error, coin_list);
});
},
get_data: function (id, cb) {
var error = null;
get_usd_value(id, function (err, last_usd) {
if (err)
error = err;
return cb(error, last_usd);
});
}
};