Skip to content

Commit

Permalink
set resolution D as default DavideViolante#143
Browse files Browse the repository at this point in the history
  • Loading branch information
liardoecp committed Oct 23, 2024
1 parent 95002cd commit d45fef8
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
3 changes: 1 addition & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# TODO
- Aggiornare README.md
- valore di default di resolution 'D'
- Aggiornare README.md
2 changes: 1 addition & 1 deletion src/getHistoricalData.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
57 changes: 57 additions & 0 deletions test/getHistoricalData.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit d45fef8

Please sign in to comment.