From a2421b7632ced3de62e163957ccdeda3039858f6 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 16 Sep 2024 15:49:14 +0200 Subject: [PATCH] add industry --- src/lib/components/IndustryTable.svelte | 67 ++++++ src/routes/industry/+layout.svelte | 258 ++++++++++++++++++++++++ src/routes/industry/+page.svelte | 55 +++++ src/routes/industry/+page.ts | 34 ++++ src/routes/list/reit-stocks/+page.ts | 4 +- 5 files changed, 416 insertions(+), 2 deletions(-) create mode 100644 src/lib/components/IndustryTable.svelte create mode 100644 src/routes/industry/+layout.svelte create mode 100644 src/routes/industry/+page.svelte create mode 100644 src/routes/industry/+page.ts diff --git a/src/lib/components/IndustryTable.svelte b/src/lib/components/IndustryTable.svelte new file mode 100644 index 00000000..f2f8da79 --- /dev/null +++ b/src/lib/components/IndustryTable.svelte @@ -0,0 +1,67 @@ + + + +
+ + + + + + + + + + + + + + + + {#each industryList as item} + + + + + + + + + + + + + + + + + + + + + + + + {/each} + +
Industry NameStocksMarket CapDiv. YieldPE RatioProfit Margin1M Change1Y Change
+ {item?.industry?.length > charNumber ? item?.industry?.slice(0,charNumber) + "..." : item?.industry} + + {item?.numStocks} + + {abbreviateNumber(item?.totalMarketCap) ?? '-'} + + {item?.avgDividendYield?.toFixed(2) ?? '-'}% + + {item?.pe?.toFixed(2) ?? '-'} + + {item?.profitMargin?.toFixed(2)}% + + {item?.avgChange1M?.toFixed(2) ?? '-'}% + + {item?.avgChange1Y?.toFixed(2) ?? '-'}% +
+
\ No newline at end of file diff --git a/src/routes/industry/+layout.svelte b/src/routes/industry/+layout.svelte new file mode 100644 index 00000000..38b09b01 --- /dev/null +++ b/src/routes/industry/+layout.svelte @@ -0,0 +1,258 @@ + + + + + + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} Industry · stocknear + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + +
+ +
+ {#each navigation as item} + {#if item?.link === $page.url.pathname} + + {item?.title} + + {/if} + {/each} +
+ +
+ +
+ +
+ +
+ + + +
+ + + +
+ + +
+ + +
+ + \ No newline at end of file diff --git a/src/routes/industry/+page.svelte b/src/routes/industry/+page.svelte new file mode 100644 index 00000000..beaf2ba8 --- /dev/null +++ b/src/routes/industry/+page.svelte @@ -0,0 +1,55 @@ + + +
+ + +
+ + + These are all the actively traded REITs (Real Estate Investment Trusts) on the US stock market. + +
+ + + + +
+ + + + +
+ {#each sectorList as sector} +

+ Sector: {sector} +

+ +
+ + +
+ {/each} + + +
+ + + +
+ + + + \ No newline at end of file diff --git a/src/routes/industry/+page.ts b/src/routes/industry/+page.ts new file mode 100644 index 00000000..090e3468 --- /dev/null +++ b/src/routes/industry/+page.ts @@ -0,0 +1,34 @@ +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, "getAllReEITs"); + } + + return output; + }; + + // Make sure to return a promise + return { + getIndustryOverview: await getIndustryOverview(), + }; +}; diff --git a/src/routes/list/reit-stocks/+page.ts b/src/routes/list/reit-stocks/+page.ts index db6fa6d6..a8930b06 100644 --- a/src/routes/list/reit-stocks/+page.ts +++ b/src/routes/list/reit-stocks/+page.ts @@ -5,7 +5,7 @@ export const load = async ({ parent }) => { let output; // Get cached data for the specific tickerID - const cachedData = getCache("", "getAllReEITs"); + const cachedData = getCache("", "getAllREITs"); if (cachedData) { output = cachedData; } else { @@ -23,7 +23,7 @@ export const load = async ({ parent }) => { output = await response.json(); - setCache("", output, "getAllReEITs"); + setCache("", output, "getAllREITs"); } return output;