frontend/src/routes/stocks/[tickerID]/forecast/ai/+page.server.ts
2024-10-02 12:00:17 +02:00

55 lines
1.3 KiB
TypeScript

export const load = async ({ locals, params }) => {
const { apiURL, apiKey } = locals;
const postData = {
ticker: params.tickerID,
};
const getAnalystInsight = async () => {
const response = await fetch(apiURL + "/analyst-insight", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getPriceAnalysis = async () => {
const response = await fetch(apiURL + "/price-analysis", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getSentimentAnalysis = async () => {
const response = await fetch(apiURL + "/sentiment-analysis", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getAnalystInsight: await getAnalystInsight(),
getPriceAnalysis: await getPriceAnalysis(),
getSentimentAnalysis: await getSentimentAnalysis(),
};
};