diff --git a/CHANGELOG.md b/CHANGELOG.md index 27eb078..f200120 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Switched to https://min-api.cryptocompare.com/ - changed: `price()` returns a different data structure - changed: `priceHistorical()` returns a different data structure - added: `priceMulti()` +- added: `priceFull()` 0.0.2 / 2016-11-21 ------------------ diff --git a/README.md b/README.md index 4bf3fdd..98aaa6e 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,54 @@ cc.priceMulti('BTC', 'USD') .catch(console.error) ``` +### `priceFull()` + +Get all the current trading info (price, vol, open, high, low etc) of any list of cryptocurrencies in any other currency. + +`priceFull(fsym, tsyms[, tryConversion])` + +- `fsyms` (Array of Strings | String) From Symbol(s) +- `tsyms` (Array of Strings | String) To Symbol(s) +- `tryConversion` (Boolean) By default, if the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Set `tryConversion` to `false` to disable using BTC for conversion. + +```js +const cc = require('cryptocompare') + +cc.priceFull(['BTC', 'ETH'], ['USD', 'EUR']) +.then(prices => { + console.log(prices) + // { + // BTC: { + // USD: { + // TYPE: '5', + // MARKET: 'CCCAGG', + // FROMSYMBOL: 'BTC', + // TOSYMBOL: 'USD', + // FLAGS: '4', + // PRICE: 1152.42, + // LASTUPDATE: 1487865689, + // LASTVOLUME: 0.21, + // LASTVOLUMETO: 242.20349999999996, + // LASTTRADEID: 1224703, + // VOLUME24HOUR: 53435.45299122338, + // VOLUME24HOURTO: 60671593.843186244, + // OPEN24HOUR: 1119.31, + // HIGH24HOUR: 1170, + // LOW24HOUR: 1086.641, + // LASTMARKET: 'itBit', + // CHANGE24HOUR: 33.11000000000013, + // CHANGEPCT24HOUR: 2.958072383879366, + // SUPPLY: 16177825, + // MKTCAP: 18643649086.5 + // }, + // EUR: ... + // }, + // ETH: ... + // } +}) +.catch(console.error) +``` + ### priceHistorical `priceHistorical(fsym, tsyms, time[, tryConversion])` diff --git a/index.js b/index.js index 0ad9251..5bf647d 100644 --- a/index.js +++ b/index.js @@ -24,6 +24,13 @@ function priceMulti (fsyms, tsyms, tryConversion) { return fetchJSON(url) } +function priceFull (fsyms, tsyms, tryConversion) { + let url = `${baseUrl}pricemultifull?fsyms=${fsyms}&tsyms=${tsyms}` + if (tryConversion === false) url += '&tryConversion=false' + // We want the RAW data, not the DISPLAY data: + return fetchJSON(url).then(result => result.RAW) +} + function priceHistorical (fsym, tsyms, time, tryConversion) { if (!(time instanceof Date)) throw new Error('time parameter must be an instance of Date.') time = Math.floor(time.getTime() / 1000) @@ -36,5 +43,6 @@ function priceHistorical (fsym, tsyms, time, tryConversion) { module.exports = { price, priceMulti, + priceFull, priceHistorical } diff --git a/test/cryptocompare.test.js b/test/cryptocompare.test.js index 705c0ac..60327b9 100644 --- a/test/cryptocompare.test.js +++ b/test/cryptocompare.test.js @@ -51,6 +51,36 @@ test('priceMulti() allows passing strings instead of arrays', t => { }).catch(t.end) }) +test('priceFull()', t => { + t.plan(5 * 2 * 2) + cc.priceFull(['BTC', 'ETH'], ['USD', 'EUR']).then(prices => { + for (let fsym in prices) { + for (let tsym in prices[fsym]) { + t.is(typeof prices[fsym][tsym].PRICE, 'number', `prices.${fsym}.${tsym}.PRICE is a number`) + t.is(typeof prices[fsym][tsym].SUPPLY, 'number', `prices.${fsym}.${tsym}.SUPPLY is a number`) + t.is(typeof prices[fsym][tsym].MKTCAP, 'number', `prices.${fsym}.${tsym}.MKTCAP is a number`) + + t.is(typeof prices[fsym][tsym].MARKET, 'string', `prices.${fsym}.${tsym}.MARKET is a string`) + t.is(typeof prices[fsym][tsym].LASTMARKET, 'string', `prices.${fsym}.${tsym}.LASTMARKET is a string`) + } + } + t.end() + }).catch(t.end) +}) + +test('priceFull() allows passing strings instead of arrays', t => { + t.plan(5) + cc.priceFull('BTC', 'USD').then(prices => { + t.is(typeof prices.BTC.USD.PRICE, 'number', `prices.BTC.USD.PRICE is a number`) + t.is(typeof prices.BTC.USD.SUPPLY, 'number', `prices.BTC.USD.SUPPLY is a number`) + t.is(typeof prices.BTC.USD.MKTCAP, 'number', `prices.BTC.USD.MKTCAP is a number`) + + t.is(typeof prices.BTC.USD.MARKET, 'string', `prices.BTC.USD.MARKET is a string`) + t.is(typeof prices.BTC.USD.LASTMARKET, 'string', `prices.BTC.USD.LASTMARKET is a string`) + t.end() + }).catch(t.end) +}) + test('priceHistorical()', t => { t.plan(3) // NOTE: Historical values are hard-coded into this test