bugfixing: add historical data back

This commit is contained in:
MuslemRahimi 2024-06-15 11:08:06 +02:00
parent a6771db026
commit 1d3fd92bf2
2 changed files with 46 additions and 2 deletions

View File

@ -251,7 +251,7 @@ const handleMessage = async (event) => {
const loadWorker = async () => {
const SyncWorker = await import('./workers/insiderWorker?worker');
syncWorker = new SyncWorker.default();
syncWorker.postMessage({ message: data?.getInsiderTrading, historicalPrice: data?.getHistoricalPrice?.MAX});
syncWorker.postMessage({ message: data?.getInsiderTrading, historicalPrice: data?.getHistoricalPrice});
syncWorker.onmessage = handleMessage;

View File

@ -121,9 +121,53 @@ export const load = async ({ params }) => {
return sums;
};
async function historicalPrice() {
let output;
const cachedData = getCache(params.tickerID, 'historicalPrice'+'max');
if (cachedData) {
output = cachedData;
} else {
const postData = {
ticker: params.tickerID,
timePeriod: 'max',
};
const response = await fetch(apiURL+'/historical-price', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(postData)
});
output = await response?.json() ?? [];
/*
const mapData = (data) => data?.map(({ time, open, high, low, close }) => ({
time: Date.parse(time),
open,
high,
low,
close
}));
*/
setCache(params.tickerID, output, 'historicalPrice'+'max');
}
return output;
}
// Make sure to return a promise
return {
getInsiderTrading: await getInsiderTrading(),
getInsiderTradingStatistics: await getInsiderTradingStatistics()
getInsiderTradingStatistics: await getInsiderTradingStatistics(),
getHistoricalPrice: await historicalPrice()
};
};