Skip to content

Commit

Permalink
added price()
Browse files Browse the repository at this point in the history
  • Loading branch information
jprichardson committed Aug 1, 2016
1 parent 0f191d1 commit 1af6495
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cryptocompare
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[standard-url]: http://npm.im/standard

CryptoCompare JavaScript API
[CryptoCompare](https://www.cryptocompare.com/) JavaScript API

Install
-------
Expand All @@ -33,6 +33,8 @@ Reference: https://www.cryptocompare.com/api/#-api-data-coinlist-
- Parameters: (none)
- Returns: A Promise function that returns contains an associative array of coins.

**Example:**

```js
var cc = require('cryptocompare')
cc.coinList()
Expand All @@ -42,7 +44,7 @@ cc.coinList()
.catch(console.error.bind(console)
```
outputs:
**Outputs:**
```
{ Id: '1182',
Expand All @@ -60,6 +62,14 @@ outputs:
SortOrder: '1' }
```
### price
Reference: https://www.cryptocompare.com/api/#-api-data-price-
## License
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ function coinList () {
return fetchJSON(url)
}

function price (fsym, tsyms, useBtc) {
if (!Array.isArray(tsyms)) tsyms = [tsyms]
var url = baseUrl + 'price?fsym=' + fsym + '&tsyms=' + tsyms.join(',')
if (useBtc) url += 'usebtc=true'
return fetchJSON(url)
}

module.exports = {
coinList
coinList,
price
}
14 changes: 12 additions & 2 deletions test/cryptocompare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ var cc = require('../')
test('coinList()', function (t) {
t.plan(1)
cc.coinList().then(coinList => {
console.dir(coinList.BTC)
t.strictEqual(coinList.BTC.CoinName, 'Bitcoin')
t.strictEqual(coinList.BTC.CoinName, 'Bitcoin', 'CoinName field should be Bitcoin')
}).catch(t.end)
})

test('price()', function (t) {
t.plan(4)
cc.price('BTC', ['USD', 'CNY']).then(prices => {
t.strictEqual(prices[0].Symbol, 'USD', 'prices[0].Symbol === USD')
t.strictEqual(typeof prices[0].Price, 'number', 'prices[0].Price is a number')
t.strictEqual(prices[1].Symbol, 'CNY')
t.strictEqual(typeof prices[1].Price, 'number')
t.end()
}).catch(t.end)
})

0 comments on commit 1af6495

Please sign in to comment.