UNPKG

investing-com-api

Version:

Unofficial APIs for Investing.com website.

2 lines (1 loc) 1.05 kB
"use strict";function t(t,e,o,r){return new(o||(o=Promise))((function(n,i){function s(t){try{a(r.next(t))}catch(t){i(t)}}function c(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,c)}a((r=r.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;exports.getHistoricalData=e=>t(void 0,void 0,void 0,(function*(){const t=yield fetch((({input:t,resolution:e="D",from:o,to:r})=>"https://tvc6.investing.com/d8f62270e64f9eb6e4e6a07c3ffeab0b/1729428526/9/9/16/history?"+new URLSearchParams({symbol:t,resolution:e,from:o&&Math.round(o.getTime()/1e3).toString(),to:r&&Math.round(r.getTime()/1e3).toString()}))(e));if(!t.ok)return Promise.reject(`Response status: ${t.status}`);const o=yield t.json();if(Array.isArray(o)||"no_data"===o.s)return Promise.reject(o);return(t=>t.map((t=>({date:t[0],price_open:t[1],price_high:t[2],price_low:t[3],price_close:t[4],volume:t[5]}))))(o.t.map(((t,e)=>[1e3*o.t[e],o.o[e],o.h[e],o.l[e],o.c[e],o.v[e]])))}));