Skip to content

Commit 7ffbea9

Browse files
committed
Add topExchanges()
1 parent dcfbbe2 commit 7ffbea9

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Switched to https://min-api.cryptocompare.com/
99
- added: `priceMulti()`
1010
- added: `priceFull()`
1111
- added: `topPairs()`
12+
- added: `topExchanges()`
1213

1314
0.0.2 / 2016-11-21
1415
------------------

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,36 @@ cc.topPairs('BTC', 2)
197197
.catch(console.error)
198198
```
199199

200+
### `topExchanges()`
201+
202+
Get top exchanges by volume for a currency pair.
203+
204+
`topExchanges(fsym, tsym[, limit])`
205+
206+
- `fsym` (String) From Symbol
207+
- `tsym` (String) To Symbol
208+
- `limit` (Number) Limit the number of exchanges you receive (default 5).
209+
210+
```js
211+
const cc = require('cryptocompare')
212+
213+
cc.topExchanges('BTC', 'USD', 2)
214+
.then(exchanges => {
215+
console.log(exchanges)
216+
// -> [ { exchange: 'Bitfinex',
217+
// fromSymbol: 'BTC',
218+
// toSymbol: 'USD',
219+
// volume24h: 35239.36701090003,
220+
// volume24hTo: 41472258.85534388 },
221+
// { exchange: 'Bitstamp',
222+
// fromSymbol: 'BTC',
223+
// toSymbol: 'USD',
224+
// volume24h: 19658.748675010014,
225+
// volume24hTo: 23047071.74260772 } ]
226+
})
227+
.catch(console.error)
228+
```
229+
200230
## License
201231

202232
[MIT](LICENSE.md)

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,17 @@ function topPairs (fsym, limit) {
4646
return fetchJSON(url).then(result => result.Data)
4747
}
4848

49+
function topExchanges (fsym, tsym, limit) {
50+
let url = `${baseUrl}top/exchanges?fsym=${fsym}&tsym=${tsym}`
51+
if (limit) url += `&limit=${limit}`
52+
return fetchJSON(url).then(result => result.Data)
53+
}
54+
4955
module.exports = {
5056
price,
5157
priceMulti,
5258
priceFull,
5359
priceHistorical,
54-
topPairs
60+
topPairs,
61+
topExchanges
5562
}

test/cryptocompare.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,32 @@ test("topPairs()'s limit option works", t => {
127127
}).catch(t.end)
128128
})
129129

130+
test('topExchanges()', t => {
131+
t.plan(6 * 5 + 1)
132+
cc.topExchanges('BTC', 'USD').then(exchanges => {
133+
let prev
134+
t.equal(exchanges.length, 5, 'returns 5 pairs by default')
135+
exchanges.forEach(item => {
136+
t.is(typeof item.exchange, 'string', 'item.exchange is a string')
137+
t.notEqual(item.exchange, prev, 'item.exchange is unique')
138+
prev = item.exchange
139+
t.is(typeof item.fromSymbol, 'string', 'item.fromSymbol is a string')
140+
t.is(typeof item.toSymbol, 'string', 'item.toSymbol is a string')
141+
t.is(typeof item.volume24h, 'number', 'item.volume24hr is a number')
142+
t.is(typeof item.volume24hTo, 'number', 'item.volume24hrTo is a number')
143+
})
144+
t.end()
145+
}).catch(t.end)
146+
})
147+
148+
test("topExchanges()'s limit option works", t => {
149+
t.plan(1)
150+
cc.topExchanges('BTC', 'USD', 3).then(exchanges => {
151+
t.equal(exchanges.length, 3, 'limit works')
152+
t.end()
153+
}).catch(t.end)
154+
})
155+
130156
test('error handling', t => {
131157
cc.price('BTC').then(prices => {
132158
t.end('Promise should not resolve')

0 commit comments

Comments
 (0)