From d45fef860e4eac24dbe37d04cade48bc98b12d3d Mon Sep 17 00:00:00 2001 From: Emanuele Liardo Date: Wed, 23 Oct 2024 23:52:58 +0200 Subject: [PATCH] set resolution D as default #143 --- TODO.md | 3 +- src/getHistoricalData.js | 2 +- test/getHistoricalData.spec.js | 57 ++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 3fe4ae1..cde0d4f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,2 @@ # TODO -- Aggiornare README.md -- valore di default di resolution 'D' \ No newline at end of file +- Aggiornare README.md \ No newline at end of file diff --git a/src/getHistoricalData.js b/src/getHistoricalData.js index a9d5b91..d615c42 100644 --- a/src/getHistoricalData.js +++ b/src/getHistoricalData.js @@ -1,7 +1,7 @@ const { mapResponse } = require('../functions'); const { getPairId } = require('../mapping'); -const buildUrl = ({ input, resolution, from, to } = {}) => { +const buildUrl = ({ input, resolution = 'D', from, to } = {}) => { const query = new URLSearchParams({ symbol: getPairId(input), resolution, diff --git a/test/getHistoricalData.spec.js b/test/getHistoricalData.spec.js index cf2bcf0..28f5e63 100644 --- a/test/getHistoricalData.spec.js +++ b/test/getHistoricalData.spec.js @@ -178,4 +178,61 @@ describe('Tests for getHistoricalData()', () => { ]; expect(data).toEqual(expected); }); + + it('should use resolution \'D\' as default', async () => { + scope + .get('/d8f62270e64f9eb6e4e6a07c3ffeab0b/1729428526/9/9/16/history') + .query({ + symbol: '1', + resolution: 'D', + from: 1729123200, + to: 1729209600, + }) + .reply(200, { + 't': [ + 1729123200, + ], + 'c': [ + 1.08309996128082008937099089962430298328399658203125, + ], + 'o': [ + 1.086099982261659935289799250313080847263336181640625, + ], + 'h': [ + 1.0872999429702800977537435755948536098003387451171875, + ], + 'l': [ + 1.0809999704360999661645337255322374403476715087890625, + ], + 'v': [ + 1, + ], + 'vo': [ + 'n/a', + ], + 'vac': [ + 'n/a', + ], + 's': 'ok', + }); + + const data = await getHistoricalData({ + input: 'currencies/eur-usd', + from: new Date(1729123200000), + to: new Date(1729209600000), + }); + + const expected = [ + { + date: 1729123200000, + value: 1.08309996128082008937099089962430298328399658203125, + price_open: 1.086099982261659935289799250313080847263336181640625, + price_high: 1.0872999429702800977537435755948536098003387451171875, + price_low: 1.0809999704360999661645337255322374403476715087890625, + price_close: 1.08309996128082008937099089962430298328399658203125, + volume: 1, + }, + ]; + expect(data).toEqual(expected); + }); });