Skip to content

Commit

Permalink
fix priceHistorical()
Browse files Browse the repository at this point in the history
  • Loading branch information
jprichardson committed Nov 22, 2016
1 parent cd6e358 commit 4815509
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function price (fsym, tsyms, useBtc) {
function priceHistorical (fsym, tsyms, time) {
if (!Array.isArray(tsyms)) tsyms = [tsyms]
if (!time instanceof Date) throw new Error('time parameter must be an instance of Date.')
time = time.getTime() / 1000
var url = baseUrl + 'price?fsym=' + fsym + '&tsyms=' + tsyms.join(',') + '&ts=' + time
time = Math.floor(time.getTime() / 1000)
var url = baseUrl + 'pricehistorical?fsym=' + fsym + '&tsyms=' + tsyms.join(',') + '&ts=' + time
return fetchJSON(url)
}

Expand Down
3 changes: 2 additions & 1 deletion test/cryptocompare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ test('price()', function (t) {
})

test('priceHistorical()', function (t) {
t.plan(4)
t.plan(5)
var oneYearAgo = new Date((Date.now() / 1000 - 31536000) * 1000)
cc.priceHistorical('BTC', ['USD', 'CNY'], oneYearAgo).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.is(prices[0].Price, 321.68, 'prices[0] is set')
t.strictEqual(prices[1].Symbol, 'CNY')
t.strictEqual(typeof prices[1].Price, 'number')
t.end()
Expand Down

0 comments on commit 4815509

Please sign in to comment.