From 8aad6b7d54fb0ddcfa8d4274ead8fca2512a809c Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Sun, 20 Oct 2024 01:54:59 +0200 Subject: [PATCH] add metrics --- src/routes/stocks/[tickerID]/+layout.svelte | 49 ++++++---- .../stocks/[tickerID]/metrics/+page.server.ts | 28 ++++++ .../stocks/[tickerID]/metrics/+page.svelte | 89 +++++++++++++++++++ 3 files changed, 151 insertions(+), 15 deletions(-) create mode 100644 src/routes/stocks/[tickerID]/metrics/+page.server.ts create mode 100644 src/routes/stocks/[tickerID]/metrics/+page.svelte diff --git a/src/routes/stocks/[tickerID]/+layout.svelte b/src/routes/stocks/[tickerID]/+layout.svelte index 206f2e0a..280bdf8d 100644 --- a/src/routes/stocks/[tickerID]/+layout.svelte +++ b/src/routes/stocks/[tickerID]/+layout.svelte @@ -113,7 +113,7 @@ function handleTypeOfTrade(state:string) insider: "/insider", options: "/options", dividends: "/dividends", - fundamental: "/stats", + stats: "/stats", forecast: "/forecast", news: "/news", }; @@ -333,8 +333,9 @@ function handleTypeOfTrade(state:string) if ($page.url.pathname) { const parts = $page?.url?.pathname?.split("/"); const sectionMap = { - stats: "fundamental", + stats: "stats", options: "options", + metrics: "metrics", insider: "insider", dividends: "dividends", forecast: "forecast", @@ -763,7 +764,7 @@ function handleTypeOfTrade(state:string)
diff --git a/src/routes/stocks/[tickerID]/metrics/+page.server.ts b/src/routes/stocks/[tickerID]/metrics/+page.server.ts new file mode 100644 index 00000000..0762cadb --- /dev/null +++ b/src/routes/stocks/[tickerID]/metrics/+page.server.ts @@ -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(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/metrics/+page.svelte b/src/routes/stocks/[tickerID]/metrics/+page.svelte new file mode 100644 index 00000000..38e87b4f --- /dev/null +++ b/src/routes/stocks/[tickerID]/metrics/+page.svelte @@ -0,0 +1,89 @@ + + + + + + + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} + {$displayCompanyName} ({$stockTicker}) Forecast Overview · stocknear + + + + + + + + + + +
+
+
+
+

{$displayCompanyName} Revenue Breakdown

+ {#if data?.getAnalystEstimate?.length !== 0} +
+ + + + + {#each xData as item} + + {/each} + + + + {#each categories as category, index} + + + {#each categoryValues[index] as value} + + {/each} + + + + {#each growthValues[index] as growthValue} + + {/each} + + {/each} + +
Quarter{new Date(item ?? null)?.toLocaleString('en-US', { + month: 'short', + day: 'numeric', + year: 'numeric', + })}
{category} Revenue + {abbreviateNumber(value)} +
+ {category} Revenue Growth + + {growthValue !== null ? growthValue.toFixed(2) + '%' : '-'} +
+
+ {:else} +
+ + + +

No estimates available.

+
+ {/if} +
+
+
+