diff --git a/src/lib/components/NextEarnings.svelte b/src/lib/components/NextEarnings.svelte index e739fce0..cc6e2f2c 100644 --- a/src/lib/components/NextEarnings.svelte +++ b/src/lib/components/NextEarnings.svelte @@ -68,8 +68,7 @@ $: { {:else} during market hours. {/if} -
- Analysts project revenue of {abbreviateNumber(rawData?.revenueEst,true)}, reflecting a +
Analysts project revenue of {abbreviateNumber(rawData?.revenueEst,true)}, reflecting a {revenueRatio}% YoY {revenueRatio > 0 ? 'growth' : revenueRatio < 0 ? 'shrinking' : ''} and earnings per share of {rawData?.epsEst}, making a {epsRatio}% {epsRatio > 0 ? 'increase' : epsRatio < 0 ? 'decrease' : ''} YoY. diff --git a/src/routes/crypto/+page.server.ts b/src/routes/crypto/+page.server.ts new file mode 100644 index 00000000..3073addf --- /dev/null +++ b/src/routes/crypto/+page.server.ts @@ -0,0 +1,23 @@ +export const load = async ({ locals }) => { + const getCryptoList = async () => { + const { apiKey, apiURL } = locals; + const response = await fetch(apiURL + "/all-crypto-tickers", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = (await response.json())?.sort( + (a, b) => b?.marketCap - a?.marketCap + ); + + return output; + }; + + // Make sure to return a promise + return { + getCryptoList: await getCryptoList(), + }; +}; diff --git a/src/routes/crypto/+page.svelte b/src/routes/crypto/+page.svelte index fe3b04f3..58bbe32b 100644 --- a/src/routes/crypto/+page.svelte +++ b/src/routes/crypto/+page.svelte @@ -2,38 +2,20 @@ import { goto } from '$app/navigation'; import { numberOfUnreadNotification, screenWidth } from '$lib/store'; import { abbreviateNumber } from '$lib/utils'; -import { page } from '$app/stores'; import logo from '$lib/images/box_logo.png'; +import ArrowLogo from "lucide-svelte/icons/move-up-right"; export let data; - -let charNumber =50; -let notDestroyed = true; - let rawData = data?.getCryptoList; let symbolList = rawData //rawData?.slice(0,30); -$: { - if($screenWidth < 640) - { - charNumber = 20; - } - else { - charNumber =50; - } -} - -$: { - if ($page.url.pathname !== '/crypto') { - notDestroyed = false; - } -} +$: charNumber = $screenWidth < 640 ? 15 : 40; @@ -62,18 +44,25 @@ $: { -
- +
+ + + +
+ +
+
-
-
+ +
+ +
+
@@ -196,11 +185,65 @@ $: {
- +
+ + +
+
+ + +
-
- \ No newline at end of file + +
+ \ No newline at end of file diff --git a/src/routes/crypto/+page.ts b/src/routes/crypto/+page.ts deleted file mode 100644 index ce45a5c9..00000000 --- a/src/routes/crypto/+page.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getCryptoList = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getCryptoList"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const response = await fetch(apiURL + "/all-crypto-tickers", { - method: "GET", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - }); - - output = (await response.json())?.sort( - (a, b) => b?.marketCap - a?.marketCap, - ); - - // Cache the data for this specific tickerID with a specific name 'getCryptoList' - setCache("", output, "getCryptoList"); - } - - return output; - }; - - // Make sure to return a promise - return { - getCryptoList: await getCryptoList(), - }; -}; diff --git a/src/routes/crypto/[tickerID]/congress-trading/+page.server.ts b/src/routes/crypto/[tickerID]/congress-trading/+page.server.ts new file mode 100644 index 00000000..8fa115a0 --- /dev/null +++ b/src/routes/crypto/[tickerID]/congress-trading/+page.server.ts @@ -0,0 +1,28 @@ +export const load = async ({ locals, params }) => { + const getSenateTrading = async () => { + const { apiKey, apiURL } = 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(), + }; +}; diff --git a/src/routes/crypto/[tickerID]/congress-trading/+page.ts b/src/routes/crypto/[tickerID]/congress-trading/+page.ts deleted file mode 100644 index 696fb635..00000000 --- a/src/routes/crypto/[tickerID]/congress-trading/+page.ts +++ /dev/null @@ -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 { apiKey, apiURL } = 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(), - }; -}; diff --git a/src/routes/crypto/[tickerID]/news/+page.server.ts b/src/routes/crypto/[tickerID]/news/+page.server.ts new file mode 100644 index 00000000..fec97bd6 --- /dev/null +++ b/src/routes/crypto/[tickerID]/news/+page.server.ts @@ -0,0 +1,28 @@ +export const load = async ({ locals, params }) => { + const getStockNews = async () => { + const { apiKey, apiURL } = 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(), + }; +}; diff --git a/src/routes/crypto/[tickerID]/news/+page.ts b/src/routes/crypto/[tickerID]/news/+page.ts deleted file mode 100644 index 795da7da..00000000 --- a/src/routes/crypto/[tickerID]/news/+page.ts +++ /dev/null @@ -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 { apiKey, apiURL } = 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(), - }; -}; diff --git a/src/routes/crypto/[tickerID]/stats/+page.server.ts b/src/routes/crypto/[tickerID]/stats/+page.server.ts new file mode 100644 index 00000000..734b08b6 --- /dev/null +++ b/src/routes/crypto/[tickerID]/stats/+page.server.ts @@ -0,0 +1,27 @@ +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(), + }; +}; diff --git a/src/routes/crypto/[tickerID]/stats/+page.ts b/src/routes/crypto/[tickerID]/stats/+page.ts deleted file mode 100644 index 04f2c9b7..00000000 --- a/src/routes/crypto/[tickerID]/stats/+page.ts +++ /dev/null @@ -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"); - } - - console.log(output); - return output; - }; - - // Make sure to return a promise - return { - getQuantStats: await getQuantStats(), - }; -}; diff --git a/src/routes/etf/[tickerID]/congress-trading/+page.server.ts b/src/routes/etf/[tickerID]/congress-trading/+page.server.ts new file mode 100644 index 00000000..ccb5e16b --- /dev/null +++ b/src/routes/etf/[tickerID]/congress-trading/+page.server.ts @@ -0,0 +1,26 @@ +export const load = async ({ locals, params }) => { + const getSenateTrading = async () => { + const { apiKey, apiURL } = 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; + }; + + return { + getSenateTrading: await getSenateTrading(), + }; +}; diff --git a/src/routes/etf/[tickerID]/congress-trading/+page.ts b/src/routes/etf/[tickerID]/congress-trading/+page.ts deleted file mode 100644 index c80dc466..00000000 --- a/src/routes/etf/[tickerID]/congress-trading/+page.ts +++ /dev/null @@ -1,40 +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 { apiKey, apiURL } = 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(), - }; -}; diff --git a/src/routes/etf/[tickerID]/dividends/+page.server.ts b/src/routes/etf/[tickerID]/dividends/+page.server.ts new file mode 100644 index 00000000..fdb462a0 --- /dev/null +++ b/src/routes/etf/[tickerID]/dividends/+page.server.ts @@ -0,0 +1,27 @@ +export const load = async ({ locals, params }) => { + const getStockDividend = async () => { + const { apiKey, apiURL } = 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), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getStockDividend: await getStockDividend(), + }; +}; diff --git a/src/routes/etf/[tickerID]/dividends/+page.ts b/src/routes/etf/[tickerID]/dividends/+page.ts deleted file mode 100644 index ec2b688a..00000000 --- a/src/routes/etf/[tickerID]/dividends/+page.ts +++ /dev/null @@ -1,40 +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 { apiKey, apiURL } = 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(), - }; -}; diff --git a/src/routes/etf/[tickerID]/holdings/+page.server.ts b/src/routes/etf/[tickerID]/holdings/+page.server.ts new file mode 100644 index 00000000..4993e205 --- /dev/null +++ b/src/routes/etf/[tickerID]/holdings/+page.server.ts @@ -0,0 +1,27 @@ +export const load = async ({ locals, params }) => { + const getETFHoldings = async () => { + const { apiKey, apiURL } = locals; + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/etf-holdings", { + 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 { + getETFHoldings: await getETFHoldings(), + }; +}; diff --git a/src/routes/etf/[tickerID]/holdings/+page.ts b/src/routes/etf/[tickerID]/holdings/+page.ts deleted file mode 100644 index 1bc7dadf..00000000 --- a/src/routes/etf/[tickerID]/holdings/+page.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent, params }) => { - const getETFHoldings = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.tickerID, "getETFHoldings"); - 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 + "/etf-holdings", { - 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 'getETFHoldings' - setCache(params.tickerID, output, "getETFHoldings"); - } - - return output; - }; - - // Make sure to return a promise - return { - getETFHoldings: await getETFHoldings(), - }; -}; diff --git a/src/routes/etf/[tickerID]/news/+page.server.ts b/src/routes/etf/[tickerID]/news/+page.server.ts new file mode 100644 index 00000000..4eb3b120 --- /dev/null +++ b/src/routes/etf/[tickerID]/news/+page.server.ts @@ -0,0 +1,27 @@ +export const load = async ({ locals, params }) => { + const getStockNews = async () => { + const { apiKey, apiURL } = 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(), + }; +}; diff --git a/src/routes/etf/[tickerID]/news/+page.ts b/src/routes/etf/[tickerID]/news/+page.ts deleted file mode 100644 index dd644fd7..00000000 --- a/src/routes/etf/[tickerID]/news/+page.ts +++ /dev/null @@ -1,40 +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 { apiKey, apiURL } = 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(), - }; -}; diff --git a/src/routes/etf/[tickerID]/options/+page.server.ts b/src/routes/etf/[tickerID]/options/+page.server.ts new file mode 100644 index 00000000..1bb17d33 --- /dev/null +++ b/src/routes/etf/[tickerID]/options/+page.server.ts @@ -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(), + }; +}; diff --git a/src/routes/etf/[tickerID]/options/+page.ts b/src/routes/etf/[tickerID]/options/+page.ts deleted file mode 100644 index 10ff6ef1..00000000 --- a/src/routes/etf/[tickerID]/options/+page.ts +++ /dev/null @@ -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(), - }; -}; diff --git a/src/routes/etf/[tickerID]/stats/+page.server.ts b/src/routes/etf/[tickerID]/stats/+page.server.ts new file mode 100644 index 00000000..b3fbd2dd --- /dev/null +++ b/src/routes/etf/[tickerID]/stats/+page.server.ts @@ -0,0 +1,28 @@ +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(), + }; +}; diff --git a/src/routes/etf/[tickerID]/stats/+page.ts b/src/routes/etf/[tickerID]/stats/+page.ts deleted file mode 100644 index 105649da..00000000 --- a/src/routes/etf/[tickerID]/stats/+page.ts +++ /dev/null @@ -1,42 +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"); - } - - console.log(output); - return output; - }; - - // Make sure to return a promise - return { - getQuantStats: await getQuantStats(), - }; -}; diff --git a/src/routes/etf/etf-providers/+page.server.ts b/src/routes/etf/etf-providers/+page.server.ts new file mode 100644 index 00000000..069fae7f --- /dev/null +++ b/src/routes/etf/etf-providers/+page.server.ts @@ -0,0 +1,21 @@ +export const load = async ({ locals }) => { + const getAllETFProviders = async () => { + const { apiKey, apiURL } = locals; + const response = await fetch(apiURL + "/all-etf-providers", { + 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 { + getAllETFProviders: await getAllETFProviders(), + }; +}; diff --git a/src/routes/etf/etf-providers/+page.ts b/src/routes/etf/etf-providers/+page.ts deleted file mode 100644 index c3a82a76..00000000 --- a/src/routes/etf/etf-providers/+page.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getAllETFProviders = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getAllETFProviders"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const response = await fetch(apiURL + "/all-etf-providers", { - 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 'getAllETFProviders' - setCache("", output, "getAllETFProviders"); - } - - return output; - }; - - // Make sure to return a promise - return { - getAllETFProviders: await getAllETFProviders(), - }; -}; diff --git a/src/routes/etf/etf-providers/[slug]/+page.server.ts b/src/routes/etf/etf-providers/[slug]/+page.server.ts new file mode 100644 index 00000000..9f3911b1 --- /dev/null +++ b/src/routes/etf/etf-providers/[slug]/+page.server.ts @@ -0,0 +1,29 @@ +export const load = async ({ params, locals }) => { + const getProviderName = async () => { + return params.slug; + }; + + const getETFProviderData = async () => { + const { apiKey, apiURL } = locals; + const postData = { etfProvider: params.slug }; + + const response = await fetch(apiURL + "/etf-provider", { + 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 { + getETFProviderData: await getETFProviderData(), + getProviderName: await getProviderName(), + }; +}; diff --git a/src/routes/etf/etf-providers/[slug]/+page.ts b/src/routes/etf/etf-providers/[slug]/+page.ts deleted file mode 100644 index 1bd92415..00000000 --- a/src/routes/etf/etf-providers/[slug]/+page.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ params, parent }) => { - const getProviderName = async () => { - return params.slug; - }; - - const getETFProviderData = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache(params.slug, "getETFProviderData"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - const postData = { etfProvider: params.slug }; - - const response = await fetch(apiURL + "/etf-provider", { - 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 'getETFProviderData' - setCache(params.slug, output, "getETFProviderData"); - } - - return output; - }; - - // Make sure to return a promise - return { - getETFProviderData: await getETFProviderData(), - getProviderName: await getProviderName(), - }; -}; diff --git a/src/routes/etf/new-launches/+page.server.ts b/src/routes/etf/new-launches/+page.server.ts new file mode 100644 index 00000000..5accfc67 --- /dev/null +++ b/src/routes/etf/new-launches/+page.server.ts @@ -0,0 +1,22 @@ +export const load = async ({ locals }) => { + const getETFNewLaunches = async () => { + const { apiKey, apiURL } = locals; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/etf-new-launches", { + 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 { + getETFNewLaunches: await getETFNewLaunches(), + }; +}; diff --git a/src/routes/etf/new-launches/+page.ts b/src/routes/etf/new-launches/+page.ts deleted file mode 100644 index 01a6794e..00000000 --- a/src/routes/etf/new-launches/+page.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getETFNewLaunches = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getETFNewLaunches"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - - // make the POST request to the endpoint - const response = await fetch(apiURL + "/etf-new-launches", { - 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 'getETFNewLaunches' - setCache("", output, "getETFNewLaunches"); - } - - return output; - }; - - // Make sure to return a promise - return { - getETFNewLaunches: await getETFNewLaunches(), - }; -};