forked from DavideViolante/investing-com-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters