From 4815509348545b12b4f93f755c3e20ad9aeda2d5 Mon Sep 17 00:00:00 2001 From: JP Richardson Date: Mon, 21 Nov 2016 23:22:19 -0600 Subject: [PATCH] fix priceHistorical() --- index.js | 4 ++-- test/cryptocompare.test.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 9554b3c..140a946 100644 --- a/index.js +++ b/index.js @@ -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) } diff --git a/test/cryptocompare.test.js b/test/cryptocompare.test.js index 1b16160..c6beb79 100644 --- a/test/cryptocompare.test.js +++ b/test/cryptocompare.test.js @@ -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()