Skip to content

Commit

Permalink
fix lint (DavideViolante#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
liardoecp committed Oct 22, 2024
1 parent 5e6e248 commit 8e4850d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const puppeteer = require('puppeteer');
const { mapping } = require('./mapping');
const { getJsonContent, mapResponse } = require('./functions');
const getHistoricalData = require('./src/getHistoricalData')
const getHistoricalData = require('./src/getHistoricalData');

const validPeriod = ['P1D', 'P1W', 'P1M', 'P3M', 'P6M', 'P1Y', 'P5Y', 'MAX'];
const validInterval = ['PT1M', 'PT5M', 'PT15M', 'PT30M', 'PT1H', 'PT5H', 'P1D', 'P1W', 'P1M'];
Expand Down Expand Up @@ -85,5 +85,5 @@ async function investing(input, period = 'P1M', interval = 'P1D', pointscount =

module.exports = {
investing,
getHistoricalData
}
getHistoricalData,
};
76 changes: 38 additions & 38 deletions src/getHistoricalData.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
const { mapResponse } = require('../functions')
const { mapResponse } = require('../functions');

const buildUrl = ({ input, resolution, from, to } = {}) => {
const query = new URLSearchParams({
symbol: input,
resolution,
from: from && from.getTime() / 1000,
to: to && to.getTime() / 1000,
})
return 'https://tvc6.investing.com/d8f62270e64f9eb6e4e6a07c3ffeab0b/1729428526/9/9/16/history?' + query
}
const query = new URLSearchParams({
symbol: input,
resolution,
from: from && from.getTime() / 1000,
to: to && to.getTime() / 1000,
});
return 'https://tvc6.investing.com/d8f62270e64f9eb6e4e6a07c3ffeab0b/1729428526/9/9/16/history?' + query;
};

const getHistoricalData = async (params) => {
const response = await fetch(buildUrl(params),{
headers: new Headers({
"upgrade-insecure-requests": "1"
})
});

if (!response.ok) {
throw new Error(`Response status: ${response.status}`);
}

const json = await response.json();
const response = await fetch(buildUrl(params), {
headers: new Headers({
'upgrade-insecure-requests': '1',
}),
});

if (json.s != "ok") {
throw new Error(json.s);
}
if (!response.ok) {
throw new Error(`Response status: ${response.status}`);
}

const json = await response.json();

if (json.s != 'ok') {
throw new Error(json.s);
}

const array = []
if (Array.isArray(json.t)) {
for (let index = 0; index < json.t.length; index++) {
array.push([
json.t[index] * 1000,
json.o[index],
json.h[index],
json.l[index],
json.c[index],
json.v[index]
])
}
const array = [];
if (Array.isArray(json.t)) {
for (let index = 0; index < json.t.length; index++) {
array.push([
json.t[index] * 1000,
json.o[index],
json.h[index],
json.l[index],
json.c[index],
json.v[index],
]);
}
}

return mapResponse(array)
}
return mapResponse(array);
};

module.exports = getHistoricalData
module.exports = getHistoricalData;
4 changes: 2 additions & 2 deletions test/getHistoricalData.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('Tests for getHistoricalData()', () => {
price_high: 1.0872999429702800977537435755948536098003387451171875,
price_low: 1.0809999704360999661645337255322374403476715087890625,
price_close: 1.08309996128082008937099089962430298328399658203125,
volume: 1
volume: 1,
},
{
date: 1729209600000,
Expand All @@ -115,7 +115,7 @@ describe('Tests for getHistoricalData()', () => {
price_high: 1.086899995803829899188031049561686813831329345703125,
price_low: 1.0822999477386499034281541753443889319896697998046875,
price_close: 1.0865999460220299166479662744677625596523284912109375,
volume: 2
volume: 2,
},
];
expect(data).toEqual(expected);
Expand Down

0 comments on commit 8e4850d

Please sign in to comment.