From ed35f7eacaf3a67332be6805284ca4f79cb3c321 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Fri, 3 Jan 2025 19:12:14 +0100 Subject: [PATCH] bugfixing --- src/routes/+layout.svelte | 1 - .../etf/[tickerID]/holdings/+page.server.ts | 1 - .../etf/[tickerID]/holdings/+page.svelte | 20 +- src/routes/stocks/[tickerID]/+layout.svelte | 12 + .../stocks/[tickerID]/history/+page.server.ts | 25 + .../stocks/[tickerID]/history/+page.svelte | 429 ++++++++++++++++++ 6 files changed, 474 insertions(+), 14 deletions(-) create mode 100644 src/routes/stocks/[tickerID]/history/+page.server.ts create mode 100644 src/routes/stocks/[tickerID]/history/+page.svelte diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index dfc0df39..f1bdc5a9 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -48,7 +48,6 @@ import Newspaper from "lucide-svelte/icons/newspaper"; import AudioLine from "lucide-svelte/icons/audio-lines"; import Gem from "lucide-svelte/icons/gem"; - import Moon from "lucide-svelte/icons/venetian-mask"; import stocknear_logo from "$lib/images/stocknear_logo.png"; /* import { diff --git a/src/routes/etf/[tickerID]/holdings/+page.server.ts b/src/routes/etf/[tickerID]/holdings/+page.server.ts index abdc5267..3d824bc8 100644 --- a/src/routes/etf/[tickerID]/holdings/+page.server.ts +++ b/src/routes/etf/[tickerID]/holdings/+page.server.ts @@ -17,7 +17,6 @@ export const load = async ({ locals, params }) => { const output = await response.json(); - return output; }; diff --git a/src/routes/etf/[tickerID]/holdings/+page.svelte b/src/routes/etf/[tickerID]/holdings/+page.svelte index b0498783..bebc80d3 100644 --- a/src/routes/etf/[tickerID]/holdings/+page.svelte +++ b/src/routes/etf/[tickerID]/holdings/+page.svelte @@ -9,7 +9,7 @@ import Infobox from "$lib/components/Infobox.svelte"; export let data; - let rawData = data?.getETFHoldings?.holdings; + let rawData = data?.getETFHoldings?.holdings || []; const lastUpdate = new Date(data?.getETFHoldings?.lastUpdate); const options = { month: "short", day: "numeric", year: "numeric" }; @@ -106,11 +106,13 @@

{$etfTicker} Holdings List

-
- As of {formattedDate} -
+ {#if data?.getETFHoldings?.lastUpdate} +
+ As of {formattedDate} +
+ {/if}
@@ -124,12 +126,6 @@ {defaultList} {specificRows} /> - {:else} -

- No holdings are available for {$displayCompanyName}. -

{/if}
diff --git a/src/routes/stocks/[tickerID]/+layout.svelte b/src/routes/stocks/[tickerID]/+layout.svelte index 25771b91..e4176391 100644 --- a/src/routes/stocks/[tickerID]/+layout.svelte +++ b/src/routes/stocks/[tickerID]/+layout.svelte @@ -76,6 +76,7 @@ metrics: "metrics", forecast: "/forecast", financials: "/financials", + history: "/history", profile: "/profile", }; @@ -355,6 +356,7 @@ insider: "insider", dividends: "dividends", forecast: "forecast", + history: "history", profile: "profile", }; displaySection = @@ -970,6 +972,16 @@ > Dividends + changeSection("history")} + class="p-2 px-5 cursor-pointer {displaySection === + 'history' + ? 'text-white bg-secondary sm:hover:bg-opacity-[0.95] font-semibold' + : 'text-gray-400 sm:hover:text-white sm:hover:bg-secondary sm:hover:bg-opacity-[0.95]'}" + > + History + changeSection("profile")} diff --git a/src/routes/stocks/[tickerID]/history/+page.server.ts b/src/routes/stocks/[tickerID]/history/+page.server.ts new file mode 100644 index 00000000..b6f18331 --- /dev/null +++ b/src/routes/stocks/[tickerID]/history/+page.server.ts @@ -0,0 +1,25 @@ +export const load = async ({ locals, params }) => { + const { apiKey, apiURL } = locals; + const getData = async () => { + 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(); + + return output; + }; + + // Make sure to return a promise + return { + getData: await getData(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/history/+page.svelte b/src/routes/stocks/[tickerID]/history/+page.svelte new file mode 100644 index 00000000..c82b4d30 --- /dev/null +++ b/src/routes/stocks/[tickerID]/history/+page.svelte @@ -0,0 +1,429 @@ + + + + + + + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} + {$displayCompanyName} ({$stockTicker}) Holdings List · Stocknear + + + + + + + + + + + + + + + + +
+
+
+
+
+

+ {$stockTicker} Stock Price History +

+
+
+ +
+
+
+ + + + + + + Select time frame + + + + (timePeriod = "Daily")} + class="cursor-pointer hover:bg-primary" + > + Daily + + (timePeriod = "Weekly")} + class="cursor-pointer hover:bg-primary" + > + Weekly + + (timePeriod = "Monthly")} + class="cursor-pointer hover:bg-primary" + > + Monthly + + (timePeriod = "Quarterly")} + class="cursor-pointer hover:bg-primary" + > + Quarterly + + (timePeriod = "Annual")} + class="cursor-pointer hover:bg-primary" + > + Annual + + + + +
+ +
+ +
+ + + + + + + {#each stockList as item, index} + + + + + + + + + + + {/each} + +
+ {new Date(item?.time).toLocaleString("en-US", { + month: "short", + day: "numeric", + year: "numeric", + daySuffix: "2-digit", + })} + + {item?.open?.toFixed(2)} + + {item?.high?.toFixed(2)} + + {item?.low?.toFixed(2)} + + {item?.close?.toFixed(2)} + + {item?.change !== null ? item?.change : "n/a"} + + {item?.changesPercentage !== null + ? item?.changesPercentage + "%" + : "n/a"} + + {item?.volume?.toLocaleString("en-US")} +
+
+ +
+ + {#if rawData?.length !== 0}{:else} + + {/if} +
+
+
+