bugfixing
This commit is contained in:
parent
ce45e12d2f
commit
9dc12f34ed
@ -1,25 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
let companyName;
|
let companyName;
|
||||||
|
|
||||||
const fetchData = async (apiURL, apiKey, endpoint, ticker) => {
|
const fetchData = async (apiURL, apiKey, endpoint, ticker) => {
|
||||||
|
|
||||||
const postData = {
|
const postData = {
|
||||||
ticker: ticker
|
ticker: ticker,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await fetch(apiURL + endpoint, {
|
const response = await fetch(apiURL + endpoint, {
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
"Content-Type": "application/json",
|
||||||
|
"X-API-KEY": apiKey,
|
||||||
},
|
},
|
||||||
body: JSON.stringify(postData)
|
body: JSON.stringify(postData),
|
||||||
});
|
});
|
||||||
|
|
||||||
const output = await response.json();
|
const output = await response.json();
|
||||||
|
|
||||||
if(endpoint === '/crypto-profile')
|
if (endpoint === "/crypto-profile") {
|
||||||
{
|
|
||||||
companyName = output?.name;
|
companyName = output?.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,20 +24,23 @@ const fetchData = async (apiURL, apiKey, endpoint, ticker) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fetchWatchlist = async (fastifyURL, userId) => {
|
const fetchWatchlist = async (fastifyURL, userId) => {
|
||||||
|
try {
|
||||||
const postData = {'userId': userId}
|
const postData = { userId: userId };
|
||||||
const response = await fetch(fastifyURL+'/all-watchlists', {
|
const response = await fetch(fastifyURL + "/all-watchlists", {
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(postData)
|
body: JSON.stringify(postData),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const output = (await response.json())?.items;
|
const output = (await response.json())?.items;
|
||||||
return output;
|
return output;
|
||||||
}
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
async function fetchPortfolio(fastifyURL, userId)
|
async function fetchPortfolio(fastifyURL, userId)
|
||||||
@ -61,34 +61,26 @@ async function fetchPortfolio(fastifyURL, userId)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const load = async ({ params, locals, setHeaders}) => {
|
export const load = async ({ params, locals, setHeaders }) => {
|
||||||
|
|
||||||
|
|
||||||
let apiURL = locals?.apiURL;
|
let apiURL = locals?.apiURL;
|
||||||
let fastifyURL = locals?.fastifyURL;
|
let fastifyURL = locals?.fastifyURL;
|
||||||
let apiKey = locals?.apiKey;
|
let apiKey = locals?.apiKey;
|
||||||
|
|
||||||
const promises = [
|
const promises = [
|
||||||
fetchData(apiURL,apiKey,'/crypto-profile',params.tickerID),
|
fetchData(apiURL, apiKey, "/crypto-profile", params.tickerID),
|
||||||
fetchData(apiURL,apiKey,'/stock-quote',params.tickerID),
|
fetchData(apiURL, apiKey, "/stock-quote", params.tickerID),
|
||||||
fetchData(apiURL,apiKey,'/one-day-price',params.tickerID),
|
fetchData(apiURL, apiKey, "/one-day-price", params.tickerID),
|
||||||
fetchWatchlist(fastifyURL, locals?.user?.id),
|
fetchWatchlist(fastifyURL, locals?.user?.id),
|
||||||
//fetchPortfolio(fastifyURL, locals?.user?.id)
|
//fetchPortfolio(fastifyURL, locals?.user?.id)
|
||||||
];
|
];
|
||||||
|
|
||||||
const [
|
const [getCryptoProfile, getStockQuote, getOneDayPrice, getUserWatchlist] =
|
||||||
getCryptoProfile,
|
await Promise.all(promises);
|
||||||
getStockQuote,
|
|
||||||
getOneDayPrice,
|
|
||||||
getUserWatchlist,
|
|
||||||
] = await Promise.all(promises);
|
|
||||||
|
|
||||||
|
|
||||||
setHeaders({
|
setHeaders({
|
||||||
'cache-control': 'public, max-age=300'
|
"cache-control": "public, max-age=300",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getCryptoProfile,
|
getCryptoProfile,
|
||||||
getStockQuote,
|
getStockQuote,
|
||||||
@ -96,6 +88,4 @@ export const load = async ({ params, locals, setHeaders}) => {
|
|||||||
getUserWatchlist,
|
getUserWatchlist,
|
||||||
companyName,
|
companyName,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,33 +1,48 @@
|
|||||||
const cleanString = (input) => {
|
const cleanString = (input) => {
|
||||||
const substringsToRemove = [
|
const substringsToRemove = [
|
||||||
'Depositary', 'Inc.', 'Incorporated', 'Holdings', 'Corporation', 'Corporations',
|
"Depositary",
|
||||||
'LLC', 'Holdings plc American Depositary Shares', 'Holding Corporation', 'Oyj',
|
"Inc.",
|
||||||
'Company', 'The', 'plc',
|
"Incorporated",
|
||||||
|
"Holdings",
|
||||||
|
"Corporation",
|
||||||
|
"Corporations",
|
||||||
|
"LLC",
|
||||||
|
"Holdings plc American Depositary Shares",
|
||||||
|
"Holding Corporation",
|
||||||
|
"Oyj",
|
||||||
|
"Company",
|
||||||
|
"The",
|
||||||
|
"plc",
|
||||||
];
|
];
|
||||||
const pattern = new RegExp(`\\b(${substringsToRemove.join('|')})\\b|,`, 'gi');
|
const pattern = new RegExp(`\\b(${substringsToRemove.join("|")})\\b|,`, "gi");
|
||||||
return input?.replace(pattern, '').trim();
|
return input?.replace(pattern, "").trim();
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchData = async (apiURL, apiKey, endpoint, ticker) => {
|
const fetchData = async (apiURL, apiKey, endpoint, ticker) => {
|
||||||
const response = await fetch(`${apiURL}${endpoint}`, {
|
const response = await fetch(`${apiURL}${endpoint}`, {
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"X-API-KEY": apiKey
|
"X-API-KEY": apiKey,
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ ticker })
|
body: JSON.stringify({ ticker }),
|
||||||
});
|
});
|
||||||
return response.json();
|
return response.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchFromFastify = async (fastifyURL, endpoint, userId) => {
|
const fetchFromFastify = async (fastifyURL, endpoint, userId) => {
|
||||||
|
try {
|
||||||
const response = await fetch(`${fastifyURL}${endpoint}`, {
|
const response = await fetch(`${fastifyURL}${endpoint}`, {
|
||||||
method: 'POST',
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ userId })
|
body: JSON.stringify({ userId }),
|
||||||
});
|
});
|
||||||
const { items } = await response.json();
|
const { items } = await response.json();
|
||||||
return items;
|
return items;
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const load = async ({ params, locals, setHeaders }) => {
|
export const load = async ({ params, locals, setHeaders }) => {
|
||||||
@ -35,13 +50,21 @@ export const load = async ({ params, locals, setHeaders }) => {
|
|||||||
const { tickerID } = params;
|
const { tickerID } = params;
|
||||||
|
|
||||||
const endpoints = [
|
const endpoints = [
|
||||||
'/etf-profile', '/similar-etfs', '/etf-country-weighting', '/etf-holdings',
|
"/etf-profile",
|
||||||
'/stock-dividend', '/stock-quote', '/wiim', '/one-day-price'
|
"/similar-etfs",
|
||||||
|
"/etf-country-weighting",
|
||||||
|
"/etf-holdings",
|
||||||
|
"/stock-dividend",
|
||||||
|
"/stock-quote",
|
||||||
|
"/wiim",
|
||||||
|
"/one-day-price",
|
||||||
];
|
];
|
||||||
|
|
||||||
const promises = [
|
const promises = [
|
||||||
...endpoints.map(endpoint => fetchData(apiURL, apiKey, endpoint, tickerID)),
|
...endpoints.map((endpoint) =>
|
||||||
fetchFromFastify(fastifyURL, '/all-watchlists', user?.id),
|
fetchData(apiURL, apiKey, endpoint, tickerID)
|
||||||
|
),
|
||||||
|
fetchFromFastify(fastifyURL, "/all-watchlists", user?.id),
|
||||||
//fetchFromFastify(fastifyURL, '/get-portfolio-data', user?.id)
|
//fetchFromFastify(fastifyURL, '/get-portfolio-data', user?.id)
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -57,7 +80,7 @@ export const load = async ({ params, locals, setHeaders }) => {
|
|||||||
getUserWatchlist,
|
getUserWatchlist,
|
||||||
] = await Promise.all(promises);
|
] = await Promise.all(promises);
|
||||||
|
|
||||||
setHeaders({ 'cache-control': 'public, max-age=300' });
|
setHeaders({ "cache-control": "public, max-age=300" });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getETFProfile,
|
getETFProfile,
|
||||||
|
|||||||
@ -31,6 +31,7 @@ const fetchData = async (apiURL, apiKey, endpoint, ticker) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fetchFromFastify = async (fastifyURL, endpoint, userId) => {
|
const fetchFromFastify = async (fastifyURL, endpoint, userId) => {
|
||||||
|
try {
|
||||||
const response = await fetch(`${fastifyURL}${endpoint}`, {
|
const response = await fetch(`${fastifyURL}${endpoint}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
@ -38,6 +39,10 @@ const fetchFromFastify = async (fastifyURL, endpoint, userId) => {
|
|||||||
});
|
});
|
||||||
const { items } = await response.json();
|
const { items } = await response.json();
|
||||||
return items;
|
return items;
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchCommunitySentiment = async (pb, ticker, cookies) => {
|
const fetchCommunitySentiment = async (pb, ticker, cookies) => {
|
||||||
|
|||||||
@ -50,6 +50,8 @@ export const load = async ({ parent, params }) => {
|
|||||||
|
|
||||||
output = await response.json();
|
output = await response.json();
|
||||||
|
|
||||||
|
console.log(output);
|
||||||
|
|
||||||
setCache(params.tickerID, output, "getOptionsHistoricalData");
|
setCache(params.tickerID, output, "getOptionsHistoricalData");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user