convert +page.ts to +page.server.ts

This commit is contained in:
MuslemRahimi 2024-09-20 01:14:48 +02:00
parent 8149d25f29
commit 8d5b87f1ca
88 changed files with 1303 additions and 1802 deletions

View File

@ -0,0 +1,26 @@
export const load = async ({ locals, setHeaders }) => {
const getTopAnalyst = async () => {
const { apiURL, apiKey, user } = locals;
const response = await fetch(apiURL + "/top-analysts", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
let output = await response?.json();
output = user?.tier !== "Pro" ? output?.reverse()?.slice(0, 6) : output;
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getTopAnalyst: await getTopAnalyst(),
};
};

View File

@ -157,7 +157,7 @@ $: {
<div class="text-sm sm:text-[1rem] breadcrumbs ml-4">
<ul>
<li><a href="/" class="text-gray-300">Home</a></li>
<li class="text-gray-300">Top Shorted Stocks</li>
<li class="text-gray-300">Top Wall Street Analysts</li>
</ul>
</div>

View File

@ -1,34 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getTopAnalyst = async () => {
const { apiURL, apiKey, user } = await parent();
let output;
const cachedData = getCache("", "getTopAnalyst");
if (cachedData) {
output = cachedData;
} else {
const response = await fetch(apiURL + "/top-analysts", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response?.json();
setCache("", output, "getTopAnalyst");
}
output = user?.tier !== "Pro" ? output?.reverse()?.slice(0, 6) : output;
return output;
};
// Make sure to return a promise
return {
getTopAnalyst: await getTopAnalyst(),
};
};

View File

@ -0,0 +1,27 @@
export const load = async ({ locals, setHeaders, params }) => {
const getAnalystStats = async () => {
const { apiURL, apiKey } = locals;
const postData = { analystId: params.slug };
// make the POST request to the endpoint
const response = await fetch(apiURL + "/analyst-stats", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
let output = await response.json();
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getAnalystStats: await getAnalystStats(),
};
};

View File

@ -1,38 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getAnalystStats = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(params.slug, "getAnalystStats");
if (cachedData) {
output = cachedData;
} else {
const { apiURL, apiKey } = await parent();
const postData = { analystId: params.slug };
// make the POST request to the endpoint
const response = await fetch(apiURL + "/analyst-stats", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getAnalystStats'
setCache(params.slug, output, "getAnalystStats");
}
return output;
};
// Make sure to return a promise
return {
getAnalystStats: await getAnalystStats(),
};
};

View File

@ -0,0 +1,25 @@
export const load = async ({ locals, setHeaders }) => {
const getTopAnalystStocks = async () => {
const { apiURL, apiKey, user } = locals;
const response = await fetch(apiURL + "/top-analysts-stocks", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
let output = await response.json();
output = user?.tier !== "Pro" ? output?.reverse()?.slice(0, 6) : output;
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getTopAnalystStocks: await getTopAnalystStocks(),
};
};

View File

@ -1,33 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getTopAnalystStocks = async () => {
let output;
const { apiURL, apiKey, user } = await parent();
const cachedData = getCache("", "getTopAnalystStocks");
if (cachedData) {
output = cachedData;
} else {
const response = await fetch(apiURL + "/top-analysts-stocks", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
setCache("", output, "getTopAnalystStocksg");
}
output = user?.tier !== "Pro" ? output?.reverse()?.slice(0, 6) : output;
return output;
};
// Make sure to return a promise
return {
getTopAnalystStocks: await getTopAnalystStocks(),
};
};

View File

@ -0,0 +1,26 @@
export const load = async ({ locals, setHeaders }) => {
const getCorporateLobbyingTracker = async () => {
const { apiKey, apiURL, user } = locals;
const response = await fetch(apiURL + "/lobbying-tracker", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
let output = await response.json();
output = user?.tier !== "Pro" ? output?.slice(0, 6) : output;
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getCorporateLobbyingTracker: await getCorporateLobbyingTracker(),
};
};

View File

@ -1,34 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getCorporateLobbyingTracker = async () => {
let output;
const { apiKey, apiURL, user } = await parent();
const cachedData = getCache("", "getCorporateLobbyingTracker");
if (cachedData) {
output = cachedData;
} else {
const response = await fetch(apiURL + "/lobbying-tracker", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
setCache("", output, "getCorporateLobbyingTracker");
}
output = user?.tier !== "Pro" ? output?.slice(0, 6) : output;
return output;
};
// Make sure to return a promise
return {
getCorporateLobbyingTracker: await getCorporateLobbyingTracker(),
};
};

View File

@ -0,0 +1,26 @@
export const load = async ({ locals, setHeaders }) => {
const getCramerTracker = async () => {
const { apiKey, apiURL, user } = locals;
const response = await fetch(apiURL + "/cramer-tracker", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
let output = await response.json();
output = user?.tier !== "Pro" ? output?.slice(0, 5) : output;
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getCramerTracker: await getCramerTracker(),
};
};

View File

@ -1,36 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getCramerTracker = async () => {
let output;
const { apiKey, apiURL, user } = await parent();
const cachedData = getCache("", "getCramerTracker");
if (cachedData) {
output = cachedData;
} else {
const response = await fetch(apiURL + "/cramer-tracker", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
setCache("", output, "getCramerTracker");
}
output = user?.tier !== "Pro" ? output?.slice(0, 5) : output;
//output = data?.user?.tier !== 'Pro' ? output?.slice(0,6) : output;
return output;
};
// Make sure to return a promise
return {
getCramerTracker: await getCramerTracker(),
};
};

View File

@ -0,0 +1,23 @@
export const load = async ({ locals, setHeaders }) => {
const getDividendCalendar = async () => {
const { apiKey, apiURL } = locals;
const response = await fetch(apiURL + "/dividends-calendar", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getDividendCalendar: await getDividendCalendar(),
};
};

View File

@ -1,35 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getDividendCalendar = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getDividendCalendar");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
// make the POST request to the endpoint
const response = await fetch(apiURL + "/dividends-calendar", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getDividendCalendar'
setCache("", output, "getDividendCalendar");
}
return output;
};
// Make sure to return a promise
return {
getDividendCalendar: await getDividendCalendar(),
};
};

View File

@ -0,0 +1,23 @@
export const load = async ({ locals, setHeaders }) => {
const getEarningsCalendar = async () => {
const { apiKey, apiURL } = locals;
// make the POST request to the endpoint
const response = await fetch(apiURL + "/earnings-calendar", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getEarningsCalendar: await getEarningsCalendar(),
};
};

View File

@ -1,35 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getEarningsCalendar = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getEarningsCalendar");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
// make the POST request to the endpoint
const response = await fetch(apiURL + "/earnings-calendar", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getEarningsCalendar'
setCache("", output, "getEarningsCalendar");
}
return output;
};
// Make sure to return a promise
return {
getEarningsCalendar: await getEarningsCalendar(),
};
};

View File

@ -0,0 +1,23 @@
export const load = async ({ locals, setHeaders }) => {
const getEconomicCalendar = async () => {
const { apiURL, apiKey } = locals;
// make the POST request to the endpoint
const response = await fetch(apiURL + "/economic-calendar", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getEconomicCalendar: await getEconomicCalendar(),
};
};

View File

@ -1,35 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getEconomicCalendar = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getEconomicCalendar");
if (cachedData) {
output = cachedData;
} else {
const { apiURL, apiKey } = await parent();
// make the POST request to the endpoint
const response = await fetch(apiURL + "/economic-calendar", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getEconomicCalendar'
setCache("", output, "getEconomicCalendar");
}
return output;
};
// Make sure to return a promise
return {
getEconomicCalendar: await getEconomicCalendar(),
};
};

View File

@ -0,0 +1,24 @@
export const load = async ({ locals, setHeaders }) => {
const getEconomicIndicator = async () => {
const { apiKey, apiURL } = locals;
const response = await fetch(apiURL + "/economic-indicator", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getEconomicIndicator: await getEconomicIndicator(),
};
};

View File

@ -1,32 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getEconomicIndicator = async () => {
let output;
const { apiKey, apiURL } = await parent();
const cachedData = getCache("", "getEconomicIndicator");
if (cachedData) {
output = cachedData;
} else {
const response = await fetch(apiURL + "/economic-indicator", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
setCache("", output, "getEconomicIndicator");
}
return output;
};
// Make sure to return a promise
return {
getEconomicIndicator: await getEconomicIndicator(),
};
};

View File

@ -1,14 +1,6 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
export const load = async ({ locals, setHeaders }) => {
const getAllHedgeFunds = async () => {
const cachedData = getCache("", "getAllHedgeFunds");
if (cachedData) {
return cachedData;
}
const { apiURL, apiKey } = await parent();
const { apiURL, apiKey } = locals;
const response = await fetch(apiURL + "/all-hedge-funds", {
method: "GET",
headers: {
@ -18,8 +10,8 @@ export const load = async ({ parent }) => {
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=3000" });
setCache("", output, "getAllHedgeFunds");
return output;
};

View File

@ -1,20 +1,12 @@
import { displayCompanyName, getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
export const load = async ({ params, locals, setHeaders }) => {
const getCIKNumber = async () => {
return params.slug;
};
const getHedgeFundsData = async () => {
const cachedData = getCache(params.slug, "getHedgeFundsData");
if (cachedData) {
displayCompanyName.update(() => cachedData?.name ?? params.slug);
return cachedData;
}
const { apiURL, apiKey } = await parent();
const { apiURL, apiKey } = locals;
const response = await fetch(apiURL + "/cik-data", {
method: "POST",
headers: {
@ -28,12 +20,12 @@ export const load = async ({ parent, params }) => {
if (output?.holdings) {
output.holdings = output?.holdings?.filter(
(item) => item?.sharesNumber && item?.symbol,
(item) => item?.sharesNumber && item?.symbol
);
}
displayCompanyName.update(() => output?.name ?? params.slug);
//displayCompanyName.update(() => output?.name ?? params.slug);
setHeaders({ "cache-control": "public, max-age=3000" });
setCache(params.slug, output, "getHedgeFundsData");
return output;
};

View File

@ -20,6 +20,7 @@ use([BarChart, GridComponent, TooltipComponent, CanvasRenderer])
export let data;
let cloudFrontUrl = import.meta.env.VITE_IMAGE_URL;
function sectorSelector(sector) {
let path;
@ -73,6 +74,7 @@ use([BarChart, GridComponent, TooltipComponent, CanvasRenderer])
let isLoaded = false;
let rawData = data?.getHedgeFundsData;
displayCompanyName.update(() => rawData?.name ?? 'Company Data')
let rawList = []
let displayList = [];
let optionsData = {};

View File

@ -0,0 +1,23 @@
export const load = async ({ locals, setHeaders }) => {
const getSectorIndustryOverview = async () => {
const { apiKey, apiURL } = locals;
const response = await fetch(apiURL + "/sector-industry-overview", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response?.json();
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getSectorIndustryOverview: await getSectorIndustryOverview(),
};
};

View File

@ -1,34 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getSectorIndustryOverview = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getSectorIndustryOverview");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const response = await fetch(apiURL + "/sector-industry-overview", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
setCache("", output, "getSectorIndustryOverview");
}
return output;
};
// Make sure to return a promise
return {
getSectorIndustryOverview: await getSectorIndustryOverview(),
};
};

View File

@ -0,0 +1,23 @@
export const load = async ({ locals, setHeaders }) => {
const getIndustryOverview = async () => {
const { apiKey, apiURL } = locals;
const response = await fetch(apiURL + "/industry-overview", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getIndustryOverview: await getIndustryOverview(),
};
};

View File

@ -1,34 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getIndustryOverview = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getIndustryOverview");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const response = await fetch(apiURL + "/industry-overview", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
setCache("", output, "getIndustryOverview");
}
return output;
};
// Make sure to return a promise
return {
getIndustryOverview: await getIndustryOverview(),
};
};

View File

@ -0,0 +1,24 @@
export const load = async ({ locals, setHeaders }) => {
const getSectorOverview = async () => {
const { apiKey, apiURL } = locals;
const response = await fetch(apiURL + "/sector-overview", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getSectorOverview: await getSectorOverview(),
};
};

View File

@ -1,34 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getSectorOverview = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getSectorOverview");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const response = await fetch(apiURL + "/sector-overview", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
setCache("", output, "getSectorOverview");
}
return output;
};
// Make sure to return a promise
return {
getSectorOverview: await getSectorOverview(),
};
};

View File

@ -0,0 +1,29 @@
export const load = async ({ params, locals, setHeaders }) => {
const getIndustryStocks = async () => {
const { apiKey, apiURL } = locals;
const postData = { ticker: params.slug };
const response = await fetch(apiURL + "/industry-stocks", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=3000" });
//output = user?.tier !== "Pro" ? output?.slice(0, 5) : output;
//output = data?.user?.tier !== 'Pro' ? output?.slice(0,6) : output;
return output;
};
// Make sure to return a promise
return {
getIndustryStocks: await getIndustryStocks(),
};
};

View File

@ -1,38 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getIndustryStocks = async () => {
let output;
const { apiKey, apiURL } = await parent();
const cachedData = getCache(params.slug, "getIndustryStocks");
if (cachedData) {
output = cachedData;
} else {
const postData = { ticker: params.slug };
const response = await fetch(apiURL + "/industry-stocks", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
setCache(params.slug, output, "getIndustryStocks");
}
//output = user?.tier !== "Pro" ? output?.slice(0, 5) : output;
//output = data?.user?.tier !== 'Pro' ? output?.slice(0,6) : output;
return output;
};
// Make sure to return a promise
return {
getIndustryStocks: await getIndustryStocks(),
};
};

View File

@ -0,0 +1,38 @@
export const load = async ({ locals, setHeaders }) => {
const { apiURL, apiKey } = locals;
const getDailyGainerLoserActive = async () => {
const response = await fetch(apiURL + "/market-movers", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
return output;
};
const getMiniPlotsIndex = async () => {
const response = await fetch(apiURL + "/mini-plots-index", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
return output;
};
setHeaders({ "cache-control": "public, max-age=3000" });
// Make sure to return a promise
return {
getDailyGainerLoserActive: await getDailyGainerLoserActive(),
getMiniPlotsIndex: await getMiniPlotsIndex(),
};
};

View File

@ -1,61 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const { apiURL, apiKey } = await parent();
const getDailyGainerLoserActive = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getDailyGainerLoserActive");
if (cachedData) {
output = cachedData;
} else {
// make the POST request to the endpoint
const response = await fetch(apiURL + "/market-movers", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
setCache("", output, "getDailyGainerLoserActive");
}
return output;
};
const getMiniPlotsIndex = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getMiniPlotsIndex");
if (cachedData) {
output = cachedData;
} else {
// make the POST request to the endpoint
const response = await fetch(apiURL + "/mini-plots-index", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
setCache("", output, "getMiniPlotsIndex");
}
return output;
};
// Make sure to return a promise
return {
getDailyGainerLoserActive: await getDailyGainerLoserActive(),
getMiniPlotsIndex: await getMiniPlotsIndex(),
};
};

View File

@ -0,0 +1,24 @@
export const load = async ({ locals }) => {
const getMarketNews = async () => {
const { apiURL, apiKey } = locals;
const postData = { newsType: "stock-news" };
// make the POST request to the endpoint
const response = await fetch(apiURL + "/market-news", {
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 {
getMarketNews: await getMarketNews(),
};
};

View File

@ -1,37 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getMarketNews = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getMarketNews");
if (cachedData) {
output = cachedData;
} else {
const { apiURL, apiKey } = await parent();
const postData = { newsType: "stock-news" };
// make the POST request to the endpoint
const response = await fetch(apiURL + "/market-news", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getMarketNews'
setCache("", output, "getMarketNews");
}
return output;
};
// Make sure to return a promise
return {
getMarketNews: await getMarketNews(),
};
};

View File

@ -0,0 +1,25 @@
export const load = async ({ locals }) => {
const getGeneralNews = async () => {
const { apiURL, apiKey } = locals;
const postData = { newsType: "general-news" };
// make the POST request to the endpoint
const response = await fetch(apiURL + "/market-news", {
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 {
getGeneralNews: await getGeneralNews(),
};
};

View File

@ -1,38 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getGeneralNews = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getGeneralNews");
if (cachedData) {
output = cachedData;
} else {
const { apiURL, apiKey } = await parent();
const postData = { newsType: "general-news" };
// make the POST request to the endpoint
const response = await fetch(apiURL + "/market-news", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getGeneralNews'
setCache("", output, "getGeneralNews");
}
return output;
};
// Make sure to return a promise
return {
getGeneralNews: await getGeneralNews(),
};
};

View File

@ -0,0 +1,26 @@
export const load = async ({ locals, setHeaders }) => {
const getMostRetailVolume = async () => {
const { apiKey, apiURL, user } = locals;
// make the POST request to the endpoint
const response = await fetch(apiURL + "/most-retail-volume", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
let output = await response.json();
output = user?.tier !== "Pro" ? output?.slice(0, 6) : output;
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getMostRetailVolume: await getMostRetailVolume(),
};
};

View File

@ -1,35 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getMostRetailVolume = async () => {
let output;
const { apiKey, apiURL, user } = await parent();
const cachedData = getCache("", "getMostRetailVolume");
if (cachedData) {
output = cachedData;
} else {
// make the POST request to the endpoint
const response = await fetch(apiURL + "/most-retail-volume", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
setCache("", output, "getMostRetailVolume");
}
output = user?.tier !== "Pro" ? output?.slice(0, 6) : output;
return output;
};
// Make sure to return a promise
return {
getMostRetailVolume: await getMostRetailVolume(),
};
};

View File

@ -0,0 +1,25 @@
export const load = async ({ locals, setHeaders }) => {
const getMostShortedStocks = async () => {
const { apiKey, apiURL, user } = locals;
const response = await fetch(apiURL + "/most-shorted-stocks", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
let output = await response.json();
output = user?.tier !== "Pro" ? output?.slice(0, 6) : output;
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getMostShortedStocks: await getMostShortedStocks(),
};
};

View File

@ -1,34 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getMostShortedStocks = async () => {
let output;
const { apiKey, apiURL, user } = await parent();
const cachedData = getCache("", "getMostShortedStocks");
if (cachedData) {
output = cachedData;
} else {
const response = await fetch(apiURL + "/most-shorted-stocks", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
setCache("", output, "getMostShortedStocks");
}
output = user?.tier !== "Pro" ? output?.slice(0, 6) : output;
return output;
};
// Make sure to return a promise
return {
getMostShortedStocks: await getMostShortedStocks(),
};
};

View File

@ -0,0 +1,22 @@
export const load = async ({ locals }) => {
const { apiURL, apiKey } = locals;
const getOptionsFlowFeed = async () => {
// make the POST request to the endpoint
const response = await fetch(apiURL + "/options-flow-feed", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getOptionsFlowFeed: await getOptionsFlowFeed(),
};
};

View File

@ -37,30 +37,10 @@ const checkMarketHour = async () => {
isBeforeMarketOpenValue ||
isAfterMarketCloseValue ||
holidays?.includes(currentDate)
),
)
);
};
export const load = async ({ parent }) => {
export const load = async () => {
await checkMarketHour();
const { apiURL, apiKey } = await parent();
const getOptionsFlowFeed = async () => {
// make the POST request to the endpoint
const response = await fetch(apiURL + "/options-flow-feed", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getOptionsFlowFeed: await getOptionsFlowFeed(),
};
};

View File

@ -0,0 +1,50 @@
import { getPartyForPoliticians } from "$lib/utils";
export const load = async ({ locals }) => {
const getAllPolitician = async () => {
let output;
const { apiKey, apiURL } = locals;
const response = await fetch(apiURL + "/all-politicians", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getAllPolitician'
output?.forEach((item) => {
let representative = item?.representative || "";
representative = representative
?.replace("Jr", "")
.replace(/Dr./g, "")
.replace(/Dr_/g, "");
const fullName = representative
?.replace(/(\s(?:Dr\s)?\w(?:\.|(?=\s)))?\s/g, "_")
.trim();
item.representative = fullName?.replace(/_/g, " ");
});
output = output?.map((item) => {
const party = getPartyForPoliticians(item?.representative);
return {
...item,
party: party,
};
});
return output;
};
// Make sure to return a promise
return {
getAllPolitician: await getAllPolitician(),
};
};

View File

@ -1,59 +0,0 @@
import { getCache, setCache } from "$lib/store";
import { getPartyForPoliticians } from "$lib/utils";
export const load = async ({ parent }) => {
const getAllPolitician = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getAllPolitician");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const response = await fetch(apiURL + "/all-politicians", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getAllPolitician'
output?.forEach((item) => {
let representative = item?.representative || "";
representative = representative
?.replace("Jr", "")
.replace(/Dr./g, "")
.replace(/Dr_/g, "");
const fullName = representative
?.replace(/(\s(?:Dr\s)?\w(?:\.|(?=\s)))?\s/g, "_")
.trim();
item.representative = fullName?.replace(/_/g, " ");
});
output = output?.map((item) => {
const party = getPartyForPoliticians(item?.representative);
return {
...item,
party: party,
};
});
setCache("", output, "getAllPolitician");
}
return output;
};
// Make sure to return a promise
return {
getAllPolitician: await getAllPolitician(),
};
};

View File

@ -0,0 +1,50 @@
import { getPartyForPoliticians } from "$lib/utils";
export const load = async ({ locals }) => {
const getPoliticianRSS = async () => {
let output;
const { apiKey, apiURL } = locals;
const response = await fetch(apiURL + "/congress-rss-feed", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getPoliticianRSS'
output?.forEach((item) => {
let representative = item?.representative || "";
representative = representative
?.replace("Jr", "")
.replace(/Dr./g, "")
.replace(/Dr_/g, "");
const fullName = representative
?.replace(/(\s(?:Dr\s)?\w(?:\.|(?=\s)))?\s/g, "_")
.trim();
item.representative = fullName?.replace(/_/g, " ");
});
output = output?.map((item) => {
const party = getPartyForPoliticians(item?.representative);
return {
...item,
party: party,
};
});
return output;
};
// Make sure to return a promise
return {
getPoliticianRSS: await getPoliticianRSS(),
};
};

View File

@ -1,58 +0,0 @@
import { getCache, setCache } from "$lib/store";
import { getPartyForPoliticians } from "$lib/utils";
export const load = async ({ parent }) => {
const getPoliticianRSS = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getPoliticianRSS");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const response = await fetch(apiURL + "/congress-rss-feed", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getPoliticianRSS'
output?.forEach((item) => {
let representative = item?.representative || "";
representative = representative
?.replace("Jr", "")
.replace(/Dr./g, "")
.replace(/Dr_/g, "");
const fullName = representative
?.replace(/(\s(?:Dr\s)?\w(?:\.|(?=\s)))?\s/g, "_")
.trim();
item.representative = fullName?.replace(/_/g, " ");
});
output = output?.map((item) => {
const party = getPartyForPoliticians(item?.representative);
return {
...item,
party: party,
};
});
setCache("", output, "getPoliticianRSS");
}
return output;
};
// Make sure to return a promise
return {
getPoliticianRSS: await getPoliticianRSS(),
};
};

View File

@ -0,0 +1,40 @@
export const load = async ({ locals }) => {
const { apiKey, apiURL, fastifyURL, user } = locals;
const getPriceAlert = async () => {
const postData = { userId: user?.id };
const response = await fetch(fastifyURL + "/get-price-alert", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(postData),
});
let output = (await response.json())?.items;
output = output?.sort((a, b) => a?.symbol?.localeCompare(b?.symbol));
return output;
};
const getMiniPlotsIndex = async () => {
// make the POST request to the endpoint
const response = await fetch(apiURL + "/mini-plots-index", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getMiniPlotsIndex: await getMiniPlotsIndex(),
getPriceAlert: await getPriceAlert(),
};
};

View File

@ -83,24 +83,8 @@ rawData?.forEach(({ symbol, priceData, changesPercentage, previousClose }) => {
});
let isLoaded = false;
let priceAlertList = [];
let priceAlertList = data?.getPriceAlert;
async function getPriceAlert()
{
const postData = {'userId': data?.user?.id}
const response = await fetch(data?.fastifyURL+'/get-price-alert', {
method: 'POST',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(postData)
});
priceAlertList = (await response.json())?.items;
priceAlertList= priceAlertList?.sort((a, b) => a?.symbol?.localeCompare(b?.symbol));
}
@ -164,11 +148,7 @@ async function handleDelete() {
onMount( async () => {
if (data?.user)
{
await getPriceAlert()
}
isLoaded = true;

View File

@ -1,34 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getMiniPlotsIndex = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getMiniPlotsIndex");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
// make the POST request to the endpoint
const response = await fetch(apiURL + "/mini-plots-index", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
setCache("", output, "getMiniPlotsIndex");
}
return output;
};
// Make sure to return a promise
return {
getMiniPlotsIndex: await getMiniPlotsIndex(),
};
};

View File

@ -1,7 +1,3 @@
export const config = {
runtime: "nodejs20.x",
};
const pages = [
{ title: "/" },
{ title: "/cramer-tracker" },
@ -133,7 +129,7 @@ const sitemap = (
posts,
articles,
stocks,
pages,
pages
) => `<?xml version="1.0" encoding="UTF-8" ?>
<urlset
xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"
@ -149,7 +145,7 @@ const sitemap = (
<url>
<loc>${website}${page.title}</loc>
</url>
`,
`
)
.join("")}
${stocks
@ -174,7 +170,7 @@ const sitemap = (
<url>
<loc>${website}/blog/article/${article.id}</loc>
</url>
`,
`
)
.join("")}
${posts
@ -183,7 +179,7 @@ const sitemap = (
<url>
<loc>${website}/community/post/${post.id}</loc>
</url>
`,
`
)
.join("")}
</urlset>`;

View File

@ -0,0 +1,23 @@
export const load = async ({ locals, setHeaders }) => {
const getStockSplitsCalendar = async () => {
const { apiKey, apiURL } = locals;
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-splits-calendar", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=3000" });
return output;
};
// Make sure to return a promise
return {
getStockSplitsCalendar: await getStockSplitsCalendar(),
};
};

View File

@ -1,35 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getStockSplitsCalendar = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getStockSplitsCalendar");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-splits-calendar", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getStockSplitsCalendar'
setCache("", output, "getStockSplitsCalendar");
}
return output;
};
// Make sure to return a promise
return {
getStockSplitsCalendar: await getStockSplitsCalendar(),
};
};

View File

@ -0,0 +1,23 @@
export const load = async ({ locals }) => {
const getStockList = async () => {
const { apiKey, apiURL } = locals;
// make the POST request to the endpoint
const response = await fetch(apiURL + "/all-stock-tickers", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getStockList: await getStockList(),
};
};

View File

@ -1,35 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent }) => {
const getStockList = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("", "getStockList");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
// make the POST request to the endpoint
const response = await fetch(apiURL + "/all-stock-tickers", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getStockList'
setCache("", output, "getStockList");
}
return output;
};
// Make sure to return a promise
return {
getStockList: await getStockList(),
};
};

View File

@ -0,0 +1,30 @@
export const load = async ({ params, locals }) => {
const getStockDividend = async () => {
let newsList;
const { apiURL, apiKey } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-dividend", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
newsList = await response.json();
return newsList;
};
// Make sure to return a promise
return {
getStockDividend: await getStockDividend(),
};
};

View File

@ -1,41 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getStockDividend = async () => {
let newsList;
// Get cached data for the specific tickerID
const cachedData = getCache(params.tickerID, "getStockDividend");
if (cachedData) {
newsList = cachedData;
} else {
const { apiURL, apiKey } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-dividend", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
newsList = await response.json();
// Cache the data for this specific tickerID with a specific name 'getStockDividend'
setCache(params.tickerID, newsList, "getStockDividend");
}
return newsList;
};
// Make sure to return a promise
return {
getStockDividend: await getStockDividend(),
};
};

View File

@ -0,0 +1,28 @@
export const load = async ({ locals, params }) => {
const getAnalystEstimate = async () => {
const { apiURL, apiKey } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/analyst-estimate", {
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 {
getAnalystEstimate: await getAnalystEstimate(),
};
};

View File

@ -1,39 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getAnalystEstimate = async () => {
let output;
const cachedData = getCache(params.tickerID, "getAnalystEstimate");
if (cachedData) {
output = cachedData;
} else {
const { apiURL, apiKey } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/analyst-estimate", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
setCache(params.tickerID, output, "getAnalystEstimate");
}
return output;
};
// Make sure to return a promise
return {
getAnalystEstimate: await getAnalystEstimate(),
};
};

View File

@ -0,0 +1,28 @@
export const load = async ({ locals, params }) => {
const getAnalystTickerHistory = async () => {
const { apiURL, apiKey } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/analyst-ticker-history", {
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 {
getAnalystTickerHistory: await getAnalystTickerHistory(),
};
};

View File

@ -1,39 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getAnalystTickerHistory = async () => {
let output;
const cachedData = getCache(params.tickerID, "getAnalystTickerHistory");
if (cachedData) {
output = cachedData;
} else {
const { apiURL, apiKey } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/analyst-ticker-history", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
setCache(params.tickerID, output, "getAnalystTickerHistory");
}
return output;
};
// Make sure to return a promise
return {
getAnalystTickerHistory: await getAnalystTickerHistory(),
};
};

View File

@ -0,0 +1,28 @@
export const load = async ({ parent, params }) => {
const getAnalystTickerHistory = async () => {
const { apiURL, apiKey } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/analyst-ticker-history", {
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 {
getAnalystTickerHistory: await getAnalystTickerHistory(),
};
};

View File

@ -1,39 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getAnalystTickerHistory = async () => {
let output;
const cachedData = getCache(params.tickerID, "getAnalystTickerHistory");
if (cachedData) {
output = cachedData;
} else {
const { apiURL, apiKey } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/analyst-ticker-history", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
setCache(params.tickerID, output, "getAnalystTickerHistory");
}
return output;
};
// Make sure to return a promise
return {
getAnalystTickerHistory: await getAnalystTickerHistory(),
};
};

View File

@ -0,0 +1,112 @@
const transactionTypeMap = {
"P-Purchase": "Bought",
"A-Award": "Grant",
"D-Return": "Grant",
"G-Gift": "Grant",
"S-Sale": "Sold",
"M-Exempt": "Exercise",
"X-InTheMoney": "Exercise",
"C-Conversion": "Exercise",
"F-InKind": "Sold",
"J-Other": (item) => {
if (item.acquistionOrDisposition === "D") {
return "Sold";
} else if (item.acquistionOrDisposition === "A") {
return "Bought";
} else {
return "Other";
}
},
"": "n/a",
};
export const load = async ({ locals, params }) => {
const { apiURL, apiKey } = locals;
const getInsiderTrading = async () => {
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/insider-trading", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
let output = await response.json();
output = output?.map((item) => ({
...item,
transactionType:
typeof transactionTypeMap[item?.transactionType] === "function"
? transactionTypeMap[item?.transactionType](item)
: transactionTypeMap[item?.transactionType] || "n/a",
}));
return output;
};
const getInsiderTradingStatistics = async () => {
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/insider-trading-statistics", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response?.json();
return output;
};
async function historicalPrice() {
const postData = {
ticker: params.tickerID,
timePeriod: "max",
};
const response = await fetch(apiURL + "/historical-price", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = (await response?.json()) ?? [];
//Adding this would create a bug hence I cant use the historicalPrice endpoint such as in +page.svelte but rather need to call
// it again without modification.
/*
output= (data) => map(({ time, open, high, low, close }) => ({
time: Date.parse(time),
open,
high,
low,
close
}));
*/
return output;
}
// Make sure to return a promise
return {
getInsiderTrading: await getInsiderTrading(),
getInsiderTradingStatistics: await getInsiderTradingStatistics(),
getHistoricalPrice: await historicalPrice(),
};
};

View File

@ -1,141 +0,0 @@
import { getCache, setCache } from "$lib/store";
const transactionTypeMap = {
"P-Purchase": "Bought",
"A-Award": "Grant",
"D-Return": "Grant",
"G-Gift": "Grant",
"S-Sale": "Sold",
"M-Exempt": "Exercise",
"X-InTheMoney": "Exercise",
"C-Conversion": "Exercise",
"F-InKind": "Sold",
"J-Other": (item) => {
if (item.acquistionOrDisposition === "D") {
return "Sold";
} else if (item.acquistionOrDisposition === "A") {
return "Bought";
} else {
return "Other";
}
},
"": "n/a",
};
export const load = async ({ parent, params }) => {
const { apiURL, apiKey } = await parent();
const getInsiderTrading = async () => {
let output;
const cachedData = getCache(params.tickerID, "getInsiderTrading");
if (cachedData) {
output = cachedData;
} else {
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/insider-trading", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
output = output?.map((item) => ({
...item,
transactionType:
typeof transactionTypeMap[item?.transactionType] === "function"
? transactionTypeMap[item?.transactionType](item)
: transactionTypeMap[item?.transactionType] || "n/a",
}));
setCache(params.tickerID, output, "getInsiderTrading");
}
return output;
};
const getInsiderTradingStatistics = async () => {
let output;
const cachedData = getCache(params.tickerID, "getInsiderTradingStatistics");
if (cachedData) {
output = cachedData;
} else {
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/insider-trading-statistics", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response?.json();
setCache(params.tickerID, output, "getInsiderTradingStatistics");
}
return output;
};
async function historicalPrice() {
let output;
const cachedData = getCache(params.tickerID, "historicalPrice" + "insider");
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",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = (await response?.json()) ?? [];
//Adding this would create a bug hence I cant use the historicalPrice endpoint such as in +page.svelte but rather need to call
// it again without modification.
/*
output= (data) => map(({ time, open, high, low, close }) => ({
time: Date.parse(time),
open,
high,
low,
close
}));
*/
setCache(params.tickerID, output, "historicalPrice" + "insider");
}
return output;
}
// Make sure to return a promise
return {
getInsiderTrading: await getInsiderTrading(),
getInsiderTradingStatistics: await getInsiderTradingStatistics(),
getHistoricalPrice: await historicalPrice(),
};
};

View File

@ -0,0 +1,28 @@
export const load = async ({ locals, params }) => {
const getSenateTrading = async () => {
const { apiURL, apiKey } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/congress-trading-ticker", {
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 {
getSenateTrading: await getSenateTrading(),
};
};

View File

@ -1,41 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getSenateTrading = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(params.tickerID, "getSenateTrading");
if (cachedData) {
output = cachedData;
} else {
const { apiURL, apiKey } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/congress-trading-ticker", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getSenateTrading'
setCache(params.tickerID, output, "getSenateTrading");
}
return output;
};
// Make sure to return a promise
return {
getSenateTrading: await getSenateTrading(),
};
};

View File

@ -0,0 +1,38 @@
const now = new Date();
const year = now?.getFullYear()?.toString();
const quarter = (Math.floor(now?.getMonth() / 3) + 1)?.toString();
export const load = async ({ locals, params }) => {
const getTranscripts = async () => {
let output;
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
quarter: quarter,
year: year,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/earnings-call-transcripts", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
return output;
};
// Make sure to return a promise
return {
getTranscripts: await getTranscripts(),
quarter,
year,
};
};

View File

@ -1,56 +0,0 @@
import { getCache, setCache } from "$lib/store";
const now = new Date();
const year = now?.getFullYear()?.toString();
const quarter = (Math.floor(now?.getMonth() / 3) + 1)?.toString();
export const load = async ({ parent, params }) => {
const getTranscripts = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(
`${params.tickerID}-Q-1-2024`,
"getTranscripts",
);
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = {
ticker: params.tickerID,
quarter: quarter,
year: year,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/earnings-call-transcripts", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getTranscripts'
setCache(
`${params.tickerID}-Q-${quarter}-${year}`,
output,
"getTranscripts",
);
}
return output;
};
// Make sure to return a promise
return {
getTranscripts: await getTranscripts(),
quarter,
year,
};
};

View File

@ -0,0 +1,28 @@
export const load = async ({ locals, params }) => {
const getStockNews = async () => {
const { apiURL, apiKey } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-news", {
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 {
getStockNews: await getStockNews(),
};
};

View File

@ -91,10 +91,10 @@ function loadMoreData() {
<section class="w-auto max-w-4xl bg-[#09090B] overflow-hidden text-black h-full mb-40">
<div class="m-auto h-full overflow-hidden ">
<main class="">
<div class="sm:p-7 m-auto mt-2 sm:mt-0">
<div class="mb-6">
<div class="m-auto h-full overflow-hidden w-full">
<main class="w-full">
<div class="sm:p-7 m-auto mt-2 sm:mt-0 w-full">
<div class="mb-6 w-full">
<h1 class="text-2xl sm:text-3xl text-white font-bold">
News
</h1>

View File

@ -1,41 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getStockNews = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(params.tickerID, "getStockNews");
if (cachedData) {
output = cachedData;
} else {
const { apiURL, apiKey } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-news", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getStockNews'
setCache(params.tickerID, output, "getStockNews");
}
return output;
};
// Make sure to return a promise
return {
getStockNews: await getStockNews(),
};
};

View File

@ -0,0 +1,94 @@
export const load = async ({ locals, params }) => {
const getOptionsPlotData = async () => {
const postData = {
ticker: params.tickerID,
};
const response = await fetch(locals?.apiURL + "/options-plot-ticker", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": locals?.apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
const getOptionsHistoricalData = async () => {
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(
locals?.apiURL + "/options-historical-data-ticker",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": locals?.apiKey,
},
body: JSON.stringify(postData),
}
);
const output = await response.json();
return output;
};
const getOptionsChainData = async () => {
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(
locals?.apiURL + "/options-chain-data-ticker",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": locals?.apiKey,
},
body: JSON.stringify(postData),
}
);
const output = await response.json();
return output;
};
const getOptionsGexData = async () => {
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(locals?.apiURL + "/options-gex-ticker", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": locals?.apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
return output;
};
// Make sure to return a promise
return {
getOptionsPlotData: await getOptionsPlotData(),
getOptionsHistoricalData: await getOptionsHistoricalData(),
getOptionsChainData: await getOptionsChainData(),
getOptionsGexData: await getOptionsGexData(),
};
};

View File

@ -1,122 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const { apiKey, apiURL } = await parent();
const getOptionsPlotData = async () => {
const cachedData = getCache(params.tickerID, "getOptionsPlotData");
if (cachedData) {
return cachedData;
} else {
const postData = {
ticker: params.tickerID,
};
const response = await fetch(apiURL + "/options-plot-ticker", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
setCache(params.tickerID, output, "getOptionsPlotData");
return output;
}
};
const getOptionsHistoricalData = async () => {
let output;
const cachedData = getCache(params.tickerID, "getOptionsHistoricalData");
if (cachedData) {
output = cachedData;
} else {
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/options-historical-data-ticker", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
setCache(params.tickerID, output, "getOptionsHistoricalData");
}
return output;
};
const getOptionsChainData = async () => {
let output;
const cachedData = getCache(params.tickerID, "getOptionsChainData");
if (cachedData) {
output = cachedData;
} else {
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/options-chain-data-ticker", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
setCache(params.tickerID, output, "getOptionsChainData");
}
return output;
};
const getOptionsGexData = async () => {
let output;
const cachedData = getCache(params.tickerID, "getOptionsGexData");
if (cachedData) {
output = cachedData;
} else {
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/options-gex-ticker", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
setCache(params.tickerID, output, "getOptionsGexData");
}
return output;
};
// Make sure to return a promise
return {
getOptionsPlotData: await getOptionsPlotData(),
getOptionsHistoricalData: await getOptionsHistoricalData(),
getOptionsChainData: await getOptionsChainData(),
getOptionsGexData: await getOptionsGexData(),
};
};

View File

@ -2,11 +2,40 @@ import { error, fail, redirect } from "@sveltejs/kit";
import { validateData } from "$lib/utils";
import { loginUserSchema, registerUserSchema } from "$lib/schemas";
export const load = async ({ locals, params }) => {
const getQuantStats = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/get-quant-stats", {
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 {
getQuantStats: await getQuantStats(),
};
};
export const actions = {
login: async ({ request, locals }) => {
const { formData, errors } = await validateData(
await request.formData(),
loginUserSchema,
loginUserSchema
);
if (errors) {
@ -40,7 +69,7 @@ export const actions = {
register: async ({ locals, request }) => {
const { formData, errors } = await validateData(
await request.formData(),
registerUserSchema,
registerUserSchema
);
if (errors) {
@ -94,7 +123,7 @@ await locals.pb?.collection('users').update(
const redirectURL = `${url.origin}/oauth`;
const targetItem = authMethods.authProviders?.findIndex(
(item) => item?.name === providerSelected,
(item) => item?.name === providerSelected
);
//console.log("==================")
//console.log(authMethods.authProviders)

View File

@ -1,41 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getQuantStats = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(params.tickerID, "getQuantStats");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/get-quant-stats", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getQuantStats'
setCache(params.tickerID, output, "getQuantStats");
}
return output;
};
// Make sure to return a promise
return {
getQuantStats: await getQuantStats(),
};
};

View File

@ -0,0 +1,29 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ locals, params }) => {
const getBalanceSheetStatement = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-balance-sheet", {
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 {
getBalanceSheetStatement: await getBalanceSheetStatement(),
};
};

View File

@ -1,40 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getBalanceSheetStatement = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(params.tickerID, "getBalanceSheetStatement");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-balance-sheet", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getBalanceSheetStatement'
setCache(params.tickerID, output, "getBalanceSheetStatement");
}
return output;
};
// Make sure to return a promise
return {
getBalanceSheetStatement: await getBalanceSheetStatement(),
};
};

View File

@ -0,0 +1,28 @@
export const load = async ({ locals, params }) => {
const getCashFlowStatement = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-cash-flow", {
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 {
getCashFlowStatement: await getCashFlowStatement(),
};
};

View File

@ -1,41 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getCashFlowStatement = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(params.tickerID, "getCashFlowStatement");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-cash-flow", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getCashFlowStatement'
setCache(params.tickerID, output, "getCashFlowStatement");
}
return output;
};
// Make sure to return a promise
return {
getCashFlowStatement: await getCashFlowStatement(),
};
};

View File

@ -0,0 +1,27 @@
export const load = async ({ locals, params }) => {
const getHistoryEmployee = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/history-employees", {
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 {
getHistoryEmployee: await getHistoryEmployee(),
};
};

View File

@ -1,39 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getHistoryEmployee = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(params.tickerID, "getHistoryEmployee");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/history-employees", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getHistoryEmployee'
setCache(params.tickerID, output, "getHistoryEmployee");
}
return output;
};
// Make sure to return a promise
return {
getHistoryEmployee: await getHistoryEmployee(),
};
};

View File

@ -0,0 +1,27 @@
export const load = async ({ locals, params }) => {
const getIncomeStatement = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-income", {
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 {
getIncomeStatement: await getIncomeStatement(),
};
};

View File

@ -1,40 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getIncomeStatement = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(params.tickerID, "getIncomeStatement");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-income", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getIncomeStatement'
setCache(params.tickerID, output, "getIncomeStatement");
}
return output;
};
// Make sure to return a promise
return {
getIncomeStatement: await getIncomeStatement(),
};
};

View File

@ -0,0 +1,27 @@
export const load = async ({ locals, params }) => {
const getHistoricalMarketCap = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/historical-market-cap", {
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 {
getHistoricalMarketCap: await getHistoricalMarketCap(),
};
};

View File

@ -249,6 +249,7 @@ async function plotData()
type: 'line',
areaStyle: {opacity: 0.2},
smooth: true,
symbol: 'none',
},
],
tooltip: {

View File

@ -1,40 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getHistoricalMarketCap = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(params.tickerID, "getHistoricalMarketCap");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/historical-market-cap", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getHistoricalMarketCap'
setCache(params.tickerID, output, "getHistoricalMarketCap");
}
return output;
};
// Make sure to return a promise
return {
getHistoricalMarketCap: await getHistoricalMarketCap(),
};
};

View File

@ -0,0 +1,28 @@
export const load = async ({ locals, params }) => {
const getRatiosStatement = async () => {
const { apiKey, apiURL } = locals;
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-ratios", {
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 {
getRatiosStatement: await getRatiosStatement(),
};
};

View File

@ -1,41 +0,0 @@
import { getCache, setCache } from "$lib/store";
export const load = async ({ parent, params }) => {
const getRatiosStatement = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache(params.tickerID, "getRatiosStatement");
if (cachedData) {
output = cachedData;
} else {
const { apiKey, apiURL } = await parent();
const postData = {
ticker: params.tickerID,
};
// make the POST request to the endpoint
const response = await fetch(apiURL + "/stock-ratios", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
output = await response.json();
// Cache the data for this specific tickerID with a specific name 'getRatiosStatement'
setCache(params.tickerID, output, "getRatiosStatement");
}
return output;
};
// Make sure to return a promise
return {
getRatiosStatement: await getRatiosStatement(),
};
};