node-coindesk-api
Version:
Simple module to query the CoinDesk Bitcoin Price Index API
47 lines (38 loc) • 1.18 kB
JavaScript
;
if (!Array.prototype.includes) {
require('core-js/fn/array/includes');
}
var request = require('./request');
var formatDate = require('./formatDate');
// memoize 1'
function getSupportedCurrencies() {
return request('/supported-currencies.json');
}
// memoize 1' TTL 15"
function getCurrentPrice(currency) {
if (!currency) {
return request('/currentprice.json');
}
return request('/currentprice/' + currency + '.json');
}
// memoize 1' TTL 15"
function getHistoricalClosePrices() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var index = options.index,
currency = options.currency,
start = options.start,
end = options.end,
yesterday = options.yesterday;
return request('/historical/close.json', {
index: index,
currency: currency,
start: start && end && formatDate(start) || undefined,
end: start && end && formatDate(end) || undefined,
for: yesterday ? 'yesterday' : undefined
});
}
module.exports = {
getCurrentPrice: getCurrentPrice,
getSupportedCurrencies: getSupportedCurrencies,
getHistoricalClosePrices: getHistoricalClosePrices
};