From b193edd2f6baed947c291705378393b2ac59e123 Mon Sep 17 00:00:00 2001 From: Alexander Weber Date: Tue, 27 Aug 2024 19:34:40 +0200 Subject: [PATCH] analyst tab => forecast tab --- src/routes/stocks/[tickerID]/+layout.svelte | 26 ++--- src/routes/stocks/[tickerID]/+page.svelte | 47 --------- .../stocks/[tickerID]/forecast/+layout.svelte | 98 +++++++++++++++++++ .../stocks/[tickerID]/forecast/+page.svelte | 44 +++++++++ .../[tickerID]/{analyst => forecast}/+page.ts | 0 .../[tickerID]/forecast/ai/+page.svelte | 76 ++++++++++++++ .../stocks/[tickerID]/forecast/ai/+page.ts | 43 ++++++++ .../{ => forecast}/analyst/+page.svelte | 0 .../[tickerID]/forecast/analyst/+page.ts | 43 ++++++++ .../stocks/[tickerID]/stats/+page.svelte | 10 +- 10 files changed, 318 insertions(+), 69 deletions(-) create mode 100644 src/routes/stocks/[tickerID]/forecast/+layout.svelte create mode 100644 src/routes/stocks/[tickerID]/forecast/+page.svelte rename src/routes/stocks/[tickerID]/{analyst => forecast}/+page.ts (100%) create mode 100644 src/routes/stocks/[tickerID]/forecast/ai/+page.svelte create mode 100644 src/routes/stocks/[tickerID]/forecast/ai/+page.ts rename src/routes/stocks/[tickerID]/{ => forecast}/analyst/+page.svelte (100%) create mode 100644 src/routes/stocks/[tickerID]/forecast/analyst/+page.ts diff --git a/src/routes/stocks/[tickerID]/+layout.svelte b/src/routes/stocks/[tickerID]/+layout.svelte index dd2463aa..fcd4249e 100644 --- a/src/routes/stocks/[tickerID]/+layout.svelte +++ b/src/routes/stocks/[tickerID]/+layout.svelte @@ -97,7 +97,7 @@ function handleTypeOfTrade(state:string) options: "/options", dividends: "/dividends", fundamental: "/stats", - analyst: "/analyst", + forecast: "/forecast", news: "/news", }; @@ -320,7 +320,7 @@ $: { options: "options", insider: "insider", dividends: "dividends", - analyst: "analyst", + forecast: "forecast", news: "news", }; displaySection = sectionMap[parts?.find((part) => Object?.keys(sectionMap)?.includes(part))] || "overview"; @@ -613,6 +613,17 @@ $: { >
+
  • + changeSection("forecast", "item3")} + class="px-3 text-sm sm:text-[1rem] font-medium text-gray-400 sm:hover:text-white {displaySection === 'forecast' ? 'text-white ' : 'bg-[#09090B]'}" + > + Forecast + +
    +
  • -
  • - changeSection("analyst", "item3")} - class="px-3 text-sm sm:text-[1rem] font-medium text-gray-400 sm:hover:text-white {displaySection === 'analyst' ? 'text-white ' : 'bg-[#09090B]'}" - > - Analyst - -
    -
  • - -
    - {#await import("$lib/components/AnalystInsight.svelte") then { default: Comp }} - - {/await} -
    -
    -
    {#await import("$lib/components/ClinicalTrial.svelte") then { default: Comp }} @@ -951,38 +936,6 @@
    - -
    - {#await import("$lib/components/PriceAnalysis.svelte") then { default: Comp }} - - {/await} -
    -
    - - -
    - {#await import("$lib/components/TrendAnalysis.svelte") then { default: Comp }} - - {/await} -
    -
    - - -
    - {#await import("$lib/components/FundamentalAnalysis.svelte") then { default: Comp }} - - {/await} -
    -
    - - -
    - {#await import("$lib/components/SentimentAnalysis.svelte") then { default: Comp }} - - {/await} -
    -
    -
    {#await import("$lib/components/VaR.svelte") then { default: Comp }} diff --git a/src/routes/stocks/[tickerID]/forecast/+layout.svelte b/src/routes/stocks/[tickerID]/forecast/+layout.svelte new file mode 100644 index 00000000..2d88696c --- /dev/null +++ b/src/routes/stocks/[tickerID]/forecast/+layout.svelte @@ -0,0 +1,98 @@ + + +
    + +
    + + diff --git a/src/routes/stocks/[tickerID]/forecast/+page.svelte b/src/routes/stocks/[tickerID]/forecast/+page.svelte new file mode 100644 index 00000000..ed968eee --- /dev/null +++ b/src/routes/stocks/[tickerID]/forecast/+page.svelte @@ -0,0 +1,44 @@ + + + + + + + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} + {$displayCompanyName} ({$stockTicker}) Forecast Overview · stocknear + + + + + + + + + + + + + + + + +
    +
    +
    +
    + +
    + {#await import("$lib/components/AnalystEstimate.svelte") then { default: Comp }} + + {/await} +
    +
    +
    +
    +
    +
    diff --git a/src/routes/stocks/[tickerID]/analyst/+page.ts b/src/routes/stocks/[tickerID]/forecast/+page.ts similarity index 100% rename from src/routes/stocks/[tickerID]/analyst/+page.ts rename to src/routes/stocks/[tickerID]/forecast/+page.ts diff --git a/src/routes/stocks/[tickerID]/forecast/ai/+page.svelte b/src/routes/stocks/[tickerID]/forecast/ai/+page.svelte new file mode 100644 index 00000000..f107eb71 --- /dev/null +++ b/src/routes/stocks/[tickerID]/forecast/ai/+page.svelte @@ -0,0 +1,76 @@ + + + + + + + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} + {$displayCompanyName} ({$stockTicker}) Forecast AI · stocknear + + + + + + + + + + + + + + + + +
    +
    +
    +
    + +
    + {#await import("$lib/components/AnalystInsight.svelte") then { default: Comp }} + + {/await} +
    +
    + + +
    + {#await import("$lib/components/PriceAnalysis.svelte") then { default: Comp }} + + {/await} +
    +
    + + +
    + {#await import("$lib/components/TrendAnalysis.svelte") then { default: Comp }} + + {/await} +
    +
    + + +
    + {#await import("$lib/components/FundamentalAnalysis.svelte") then { default: Comp }} + + {/await} +
    +
    + + +
    + {#await import("$lib/components/SentimentAnalysis.svelte") then { default: Comp }} + + {/await} +
    +
    +
    +
    +
    +
    diff --git a/src/routes/stocks/[tickerID]/forecast/ai/+page.ts b/src/routes/stocks/[tickerID]/forecast/ai/+page.ts new file mode 100644 index 00000000..095a324c --- /dev/null +++ b/src/routes/stocks/[tickerID]/forecast/ai/+page.ts @@ -0,0 +1,43 @@ +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() + }; +}; diff --git a/src/routes/stocks/[tickerID]/analyst/+page.svelte b/src/routes/stocks/[tickerID]/forecast/analyst/+page.svelte similarity index 100% rename from src/routes/stocks/[tickerID]/analyst/+page.svelte rename to src/routes/stocks/[tickerID]/forecast/analyst/+page.svelte diff --git a/src/routes/stocks/[tickerID]/forecast/analyst/+page.ts b/src/routes/stocks/[tickerID]/forecast/analyst/+page.ts new file mode 100644 index 00000000..095a324c --- /dev/null +++ b/src/routes/stocks/[tickerID]/forecast/analyst/+page.ts @@ -0,0 +1,43 @@ +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() + }; +}; diff --git a/src/routes/stocks/[tickerID]/stats/+page.svelte b/src/routes/stocks/[tickerID]/stats/+page.svelte index 4b6d5ff9..6e51817f 100644 --- a/src/routes/stocks/[tickerID]/stats/+page.svelte +++ b/src/routes/stocks/[tickerID]/stats/+page.svelte @@ -1,7 +1,7 @@