From 2827d4dde3b22e6e7ef50c5d94c3d3ec03d96d18 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 23 Sep 2024 00:03:09 +0200 Subject: [PATCH] protect endpoints --- src/lib/components/AnalystInsight.svelte | 5 +- src/lib/components/BorrowedShare.svelte | 6 +- src/lib/components/ClinicalTrial.svelte | 8 +- src/lib/components/CorporateLobbying.svelte | 6 +- src/lib/components/Correlation.svelte | 6 +- src/lib/components/DCF.svelte | 5 +- src/lib/components/DarkPool.svelte | 8 +- src/lib/components/Enterprise.svelte | 6 +- src/lib/components/ExecutiveCard.svelte | 11 +- src/lib/components/FailToDeliver.svelte | 6 +- src/lib/components/FundamentalAnalysis.svelte | 6 +- src/lib/components/GovernmentContract.svelte | 8 +- src/lib/components/ImpliedVolatility.svelte | 8 +- src/lib/components/MarketMaker.svelte | 8 +- src/lib/components/OptionsData.svelte | 8 +- src/lib/components/OptionsNetFlow.svelte | 6 +- src/lib/components/PriceAnalysis.svelte | 6 +- src/lib/components/RetailVolume.svelte | 6 +- src/lib/components/RevenueSegmentation.svelte | 9 +- src/lib/components/SECFilingsCard.svelte | 9 +- src/lib/components/Searchbar.svelte | 8 +- src/lib/components/SentimentAnalysis.svelte | 6 +- src/lib/components/ShareHolders.svelte | 6 +- src/lib/components/ShareStatistics.svelte | 8 +- src/lib/components/Swap.svelte | 9 +- src/lib/components/TARating.svelte | 7 +- src/lib/components/TrendAnalysis.svelte | 6 +- src/lib/components/VaR.svelte | 6 +- src/lib/components/WatchListCard.svelte | 12 +- src/routes/+layout.server.ts | 5 +- src/routes/+layout.svelte | 2 +- .../api/earnings-call-transcripts/+server.ts | 24 ++ src/routes/api/export-price-data/+server.ts | 20 ++ src/routes/api/get-watchlist/+server.ts | 20 ++ src/routes/api/historical-price/+server.ts | 20 ++ src/routes/api/info-text/+server.ts | 20 ++ .../api/options-daily-transactions/+server.ts | 20 ++ src/routes/api/searchbar-data/+server.ts | 17 ++ src/routes/api/stock-screener-data/+server.ts | 21 ++ src/routes/api/ticker-data/+server.ts | 20 ++ src/routes/crypto/[tickerID]/+layout.svelte | 4 +- src/routes/crypto/[tickerID]/+page.svelte | 4 +- .../workers/historicalPriceWorker.ts | 153 ------------- src/routes/etf/[tickerID]/+layout.svelte | 4 +- src/routes/etf/[tickerID]/+page.svelte | 15 +- .../etf/[tickerID]/options/+page.svelte | 5 +- src/routes/stock-screener/+page.svelte | 4 +- .../stock-screener/workers/downloadWorker.ts | 11 +- src/routes/stocks/[tickerID]/+layout.svelte | 3 +- src/routes/stocks/[tickerID]/+page.svelte | 10 +- .../insider/transcripts/+page.svelte | 4 +- .../stocks/[tickerID]/options/+page.svelte | 3 +- .../stocks/[tickerID]/stats/+page.svelte | 2 +- src/routes/trending/+page.svelte | 209 ------------------ src/routes/trending/+page.ts | 35 --- src/routes/watchlist/+page.svelte | 2 - 56 files changed, 309 insertions(+), 557 deletions(-) create mode 100644 src/routes/api/earnings-call-transcripts/+server.ts create mode 100644 src/routes/api/export-price-data/+server.ts create mode 100644 src/routes/api/get-watchlist/+server.ts create mode 100644 src/routes/api/historical-price/+server.ts create mode 100644 src/routes/api/info-text/+server.ts create mode 100644 src/routes/api/options-daily-transactions/+server.ts create mode 100644 src/routes/api/searchbar-data/+server.ts create mode 100644 src/routes/api/stock-screener-data/+server.ts create mode 100644 src/routes/api/ticker-data/+server.ts delete mode 100644 src/routes/crypto/[tickerID]/workers/historicalPriceWorker.ts delete mode 100644 src/routes/trending/+page.svelte delete mode 100644 src/routes/trending/+page.ts diff --git a/src/lib/components/AnalystInsight.svelte b/src/lib/components/AnalystInsight.svelte index 5c76e798..d7e3b9a3 100644 --- a/src/lib/components/AnalystInsight.svelte +++ b/src/lib/components/AnalystInsight.svelte @@ -31,13 +31,12 @@ if (cachedData) { rawData = cachedData; } else { - const postData = { ticker: ticker }; + const postData = { ticker: ticker, path: 'analyst-insight' }; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + "/analyst-insight", { + const response = await fetch("/api/ticker-data", { method: "POST", headers: { "Content-Type": "application/json", - "X-API-KEY": data?.apiKey, }, body: JSON.stringify(postData), }); diff --git a/src/lib/components/BorrowedShare.svelte b/src/lib/components/BorrowedShare.svelte index bdb55a28..2f032b50 100644 --- a/src/lib/components/BorrowedShare.svelte +++ b/src/lib/components/BorrowedShare.svelte @@ -184,12 +184,12 @@ function findLowestAndHighestFee(data, lastDateStr) { rawData = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'borrowed-share'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/borrowed-share', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json", }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/ClinicalTrial.svelte b/src/lib/components/ClinicalTrial.svelte index f43386e9..3f8f43aa 100644 --- a/src/lib/components/ClinicalTrial.svelte +++ b/src/lib/components/ClinicalTrial.svelte @@ -169,17 +169,17 @@ const getClinicalTrial = async (ticker) => { displayList = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'clinical-trial'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/clinical-trial', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); - rawData = await response.json(); + rawData = await response?.json(); displayList = rawData; // Cache the data for this specific tickerID with a specific name 'getClinicalTrial' setCache(ticker, rawData, 'getClinicalTrial'); diff --git a/src/lib/components/CorporateLobbying.svelte b/src/lib/components/CorporateLobbying.svelte index 0190d6f7..344b1245 100644 --- a/src/lib/components/CorporateLobbying.svelte +++ b/src/lib/components/CorporateLobbying.svelte @@ -106,12 +106,12 @@ const getCorporateLobbing = async (ticker) => { rawData = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'corporate-lobbying'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/corporate-lobbying', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/Correlation.svelte b/src/lib/components/Correlation.svelte index bbc3e276..a3fc42d2 100644 --- a/src/lib/components/Correlation.svelte +++ b/src/lib/components/Correlation.svelte @@ -33,15 +33,15 @@ rawData = cachedData; } else { try { - const response = await fetch(data?.apiURL+'/correlation-ticker', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { "Content-Type": "application/json", "X-API-KEY": data?.apiKey }, - body: JSON.stringify({ ticker }) + body: JSON.stringify({ ticker:ticker, path: 'correlation-ticker' }) }); - rawData = (await response.json()) || []; + rawData = (await response?.json()) || []; + setCache(ticker, rawData, 'getCorrelation'); } catch (error) { diff --git a/src/lib/components/DCF.svelte b/src/lib/components/DCF.svelte index d3af3ef4..81f8ddad 100644 --- a/src/lib/components/DCF.svelte +++ b/src/lib/components/DCF.svelte @@ -190,13 +190,12 @@ async function getFairPrice(ticker) { fairPrice = cachedData; } else { try { - const response = await fetch(data?.apiURL+'/fair-price', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { "Content-Type": "application/json", - "X-API-KEY": data?.apiKey }, - body: JSON.stringify({ ticker }) + body: JSON.stringify({ ticker: ticker, path: 'fair-price' }) }); fairPrice = await response.json(); diff --git a/src/lib/components/DarkPool.svelte b/src/lib/components/DarkPool.svelte index d29a894c..5411dad8 100644 --- a/src/lib/components/DarkPool.svelte +++ b/src/lib/components/DarkPool.svelte @@ -167,12 +167,12 @@ const getDarkPool = async (ticker) => { rawData = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'dark-pool'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/dark-pool', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); @@ -192,7 +192,7 @@ const getDarkPool = async (ticker) => { $: { if($assetType === 'stock' ? $stockTicker :$etfTicker && typeof window !== 'undefined') { isLoaded=false; - const ticker = $assetType === 'stock' ? $stockTicker :$etfTicker + const ticker = $assetType === 'stock' ? $stockTicker : $etfTicker const asyncFunctions = [ getDarkPool(ticker) ]; diff --git a/src/lib/components/Enterprise.svelte b/src/lib/components/Enterprise.svelte index d080da7c..5044438e 100644 --- a/src/lib/components/Enterprise.svelte +++ b/src/lib/components/Enterprise.svelte @@ -137,12 +137,12 @@ const getEnterPriseValues = async (ticker) => { rawData = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'enterprise-values'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/enterprise-values', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/ExecutiveCard.svelte b/src/lib/components/ExecutiveCard.svelte index 2f413d9c..8e37d208 100644 --- a/src/lib/components/ExecutiveCard.svelte +++ b/src/lib/components/ExecutiveCard.svelte @@ -6,11 +6,6 @@ //export let executiveList; let executiveList = []; - -let apiURL = import.meta.env.VITE_USEAST_API_URL; -let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; - - let isLoaded = false; const currentYear = new Date().getFullYear(); @@ -25,11 +20,11 @@ async function fetchData() { executiveList = $clientSideCache[$stockTicker]?.getExecutives; } else { - const postData = { ticker: $stockTicker}; - const response = await fetch(apiURL+'/get-executives', { + const postData = { ticker: $stockTicker, path: 'get-executives'}; + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/FailToDeliver.svelte b/src/lib/components/FailToDeliver.svelte index 26f76883..7f46659e 100644 --- a/src/lib/components/FailToDeliver.svelte +++ b/src/lib/components/FailToDeliver.svelte @@ -179,12 +179,12 @@ function findLowestAndHighestPrice(data, lastDateStr) { rawData = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'fail-to-deliver'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/fail-to-deliver', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/FundamentalAnalysis.svelte b/src/lib/components/FundamentalAnalysis.svelte index ced20b86..21317f8b 100644 --- a/src/lib/components/FundamentalAnalysis.svelte +++ b/src/lib/components/FundamentalAnalysis.svelte @@ -24,12 +24,12 @@ const getFundamentalAnalysis = async (ticker) => { fundamentalAnalysisDict = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'fundamental-predictor-analysis'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/fundamental-predictor-analysis', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/GovernmentContract.svelte b/src/lib/components/GovernmentContract.svelte index 7f298c5c..f7671a49 100644 --- a/src/lib/components/GovernmentContract.svelte +++ b/src/lib/components/GovernmentContract.svelte @@ -154,17 +154,17 @@ use([BarChart, GridComponent, CanvasRenderer]) rawData = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'government-contract'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/government-contract', { + const response = await fetch('/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); - rawData = (await response.json()); + rawData = await response?.json(); // Cache the data for this specific tickerID with a specific name 'getGovernmentContract' setCache(ticker, rawData, 'getGovernmentContract'); } diff --git a/src/lib/components/ImpliedVolatility.svelte b/src/lib/components/ImpliedVolatility.svelte index d254a084..956eb572 100644 --- a/src/lib/components/ImpliedVolatility.svelte +++ b/src/lib/components/ImpliedVolatility.svelte @@ -188,17 +188,17 @@ function changeStatement(event) rawData = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'implied-volatility'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/implied-volatility', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); - rawData = (await response.json()); + rawData = await response?.json(); // Cache the data for this specific tickerID with a specific name 'getImpliedVolatility' setCache(ticker, rawData, 'getImpliedVolatility'); } diff --git a/src/lib/components/MarketMaker.svelte b/src/lib/components/MarketMaker.svelte index ff1a45c0..d85ab854 100644 --- a/src/lib/components/MarketMaker.svelte +++ b/src/lib/components/MarketMaker.svelte @@ -166,17 +166,17 @@ const getMarketMaker = async (ticker) => { rawData = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'market-maker'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/market-maker', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); - rawData = await response.json(); + rawData = await response?.json(); // Cache the data for this specific tickerID with a specific name 'getMarketMaker' setCache(ticker, rawData, 'getMarketMaker'); } diff --git a/src/lib/components/OptionsData.svelte b/src/lib/components/OptionsData.svelte index 60e80636..05077e82 100644 --- a/src/lib/components/OptionsData.svelte +++ b/src/lib/components/OptionsData.svelte @@ -42,17 +42,17 @@ const getOptionsBubble = async (ticker) => { optionsDict = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'options-bubble'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/options-bubble', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); - optionsDict = await response.json(); + optionsDict = await response?.json(); // Cache the data for this specific tickerID with a specific name 'getOptionsBubble' setCache(ticker, optionsDict, 'getOptionsBubble'); diff --git a/src/lib/components/OptionsNetFlow.svelte b/src/lib/components/OptionsNetFlow.svelte index 9991f809..029ca966 100644 --- a/src/lib/components/OptionsNetFlow.svelte +++ b/src/lib/components/OptionsNetFlow.svelte @@ -152,12 +152,12 @@ rawData = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'options-net-flow-ticker'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/options-net-flow-ticker', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/PriceAnalysis.svelte b/src/lib/components/PriceAnalysis.svelte index 831629e6..ff598f34 100644 --- a/src/lib/components/PriceAnalysis.svelte +++ b/src/lib/components/PriceAnalysis.svelte @@ -145,12 +145,12 @@ const getPriceAnalysis = async (ticker) => { priceAnalysisDict = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'price-analysis'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/price-analysis', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/RetailVolume.svelte b/src/lib/components/RetailVolume.svelte index 47288cdc..71e0cef7 100644 --- a/src/lib/components/RetailVolume.svelte +++ b/src/lib/components/RetailVolume.svelte @@ -204,12 +204,12 @@ const getRetailVolume = async (ticker) => { historyData = rawData?.history; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'retail-volume'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/retail-volume', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/RevenueSegmentation.svelte b/src/lib/components/RevenueSegmentation.svelte index 3b93a7e7..56a70c34 100644 --- a/src/lib/components/RevenueSegmentation.svelte +++ b/src/lib/components/RevenueSegmentation.svelte @@ -8,8 +8,6 @@ import InfoModal from "$lib/components/InfoModal.svelte"; export let userTier; - export let apiURL; - export let apiKey; let isLoaded = false; @@ -128,18 +126,17 @@ if (cachedData) { revenueSegmentation = cachedData; } else { - const postData = { ticker: ticker }; + const postData = { ticker: ticker, path: 'revenue-segmentation' }; // make the POST request to the endpoint - const response = await fetch(apiURL + "/revenue-segmentation", { + const response = await fetch("/api/ticker-data", { method: "POST", headers: { "Content-Type": "application/json", - "X-API-KEY": apiKey, }, body: JSON.stringify(postData), }); - revenueSegmentation = await response.json(); + revenueSegmentation = await response?.json(); // Cache the data for this specific tickerID with a specific name 'getRevenueSegmentation' setCache(ticker, revenueSegmentation, "getRevenueSegmentation"); diff --git a/src/lib/components/SECFilingsCard.svelte b/src/lib/components/SECFilingsCard.svelte index 0cedcda4..a8897d47 100644 --- a/src/lib/components/SECFilingsCard.svelte +++ b/src/lib/components/SECFilingsCard.svelte @@ -7,9 +7,6 @@ import { fade } from 'svelte/transition'; let secFilingsList; -let apiURL = import.meta.env.VITE_USEAST_API_URL; -let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; - let displayList = []; let accordionOpen = {}; @@ -86,11 +83,11 @@ async function fetchData() { secFilingsList = $clientSideCache[$stockTicker]?.getSECFilings; } else { - const postData = { ticker: $stockTicker}; - const response = await fetch(apiURL+'/get-sec-filings', { + const postData = { ticker: $stockTicker, path: 'get-sec-filings'}; + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/Searchbar.svelte b/src/lib/components/Searchbar.svelte index 20f41ee1..dc1e7ba7 100644 --- a/src/lib/components/Searchbar.svelte +++ b/src/lib/components/Searchbar.svelte @@ -5,10 +5,6 @@ import { onMount } from 'svelte'; import Search from "lucide-svelte/icons/search"; - - export let apiURL; - export let apiKey; - let dataLoaded = false; // Flag to track data loading let assetType = ''; @@ -27,10 +23,10 @@ else { dataLoaded = true; // make the GET request to the endpoint - const response = await fetch(apiURL+'/searchbar-data', { + const response = await fetch('/api/searchbar-data', { method: 'GET', headers: { - "Content-Type": "application/json","X-API-KEY": apiKey + "Content-Type": "application/json" }, }); diff --git a/src/lib/components/SentimentAnalysis.svelte b/src/lib/components/SentimentAnalysis.svelte index 430ab0f9..2f6cdc03 100644 --- a/src/lib/components/SentimentAnalysis.svelte +++ b/src/lib/components/SentimentAnalysis.svelte @@ -33,12 +33,12 @@ const getSentimentAnalysis = async (ticker) => { sentimentList = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'sentiment-analysis'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/sentiment-analysis', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/ShareHolders.svelte b/src/lib/components/ShareHolders.svelte index 9ecd6167..df689230 100644 --- a/src/lib/components/ShareHolders.svelte +++ b/src/lib/components/ShareHolders.svelte @@ -91,12 +91,12 @@ const getShareholders = async (ticker) => { rawData = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'shareholders'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/shareholders', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/ShareStatistics.svelte b/src/lib/components/ShareStatistics.svelte index 296f27f8..2eb0f1df 100644 --- a/src/lib/components/ShareStatistics.svelte +++ b/src/lib/components/ShareStatistics.svelte @@ -121,17 +121,17 @@ const getShareStatistics = async (ticker) => { rawData = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'share-statistics'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/share-statistics', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); - rawData = await response.json(); + rawData = await response?.json(); // Cache the data for this specific tickerID with a specific name 'getShareStatistics' setCache(ticker, rawData, 'getShareStatistics'); diff --git a/src/lib/components/Swap.svelte b/src/lib/components/Swap.svelte index 40767342..8cb3c99f 100644 --- a/src/lib/components/Swap.svelte +++ b/src/lib/components/Swap.svelte @@ -170,19 +170,19 @@ return option; } - async function getSwapData(ticker) { + async function getSwapData(ticker) { const cachedData = getCache(ticker, 'getSwapData'); if (cachedData) { rawData = cachedData; } else { try { - const response = await fetch(`${data?.apiURL}/swap-ticker`, { + const postData = {ticker: ticker, path: 'swap-ticker'} + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { "Content-Type": "application/json", - "X-API-KEY": data?.apiKey }, - body: JSON.stringify({ ticker }) + body: JSON.stringify(postData) }); if (!response.ok) throw new Error('API request failed'); rawData = await response.json(); @@ -194,7 +194,6 @@ } $swapComponent = rawData?.length !== 0; } - $: if ($stockTicker && typeof window !== 'undefined') { isLoaded = false; diff --git a/src/lib/components/TARating.svelte b/src/lib/components/TARating.svelte index 3b14f1af..ea36ac0f 100644 --- a/src/lib/components/TARating.svelte +++ b/src/lib/components/TARating.svelte @@ -28,15 +28,14 @@ async function getTaRating(ticker) { rawData = cachedData; } else { try { - const response = await fetch(data?.apiURL+'/stock-rating', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { "Content-Type": "application/json", - "X-API-KEY": data?.apiKey }, - body: JSON.stringify({ ticker }) + body: JSON.stringify({ ticker: ticker, path: 'stock-rating' }) }); - rawData = await response.json(); + rawData = await response?.json(); setCache(ticker, rawData, 'getTaRating'); } catch (error) { diff --git a/src/lib/components/TrendAnalysis.svelte b/src/lib/components/TrendAnalysis.svelte index 696e9f2a..0f4203b6 100644 --- a/src/lib/components/TrendAnalysis.svelte +++ b/src/lib/components/TrendAnalysis.svelte @@ -34,12 +34,12 @@ const getTrendAnalysis = async (ticker) => { trendList = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, path: 'trend-analysis'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/trend-analysis', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/VaR.svelte b/src/lib/components/VaR.svelte index ca67661d..7a1db20e 100644 --- a/src/lib/components/VaR.svelte +++ b/src/lib/components/VaR.svelte @@ -113,12 +113,12 @@ function getPlotOptions() { varDict = cachedData; } else { - const postData = {'ticker': ticker}; + const postData = {'ticker': ticker, 'path': 'value-at-risk'}; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/value-at-risk', { + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/lib/components/WatchListCard.svelte b/src/lib/components/WatchListCard.svelte index d4b3e5a4..4bc992d0 100644 --- a/src/lib/components/WatchListCard.svelte +++ b/src/lib/components/WatchListCard.svelte @@ -6,9 +6,7 @@ import InfoModal from '$lib/components/InfoModal.svelte'; export let watchListId; - export let apiKey; - export let apiURL; - + const sortTickersByName = (tickerList) => { @@ -126,18 +124,18 @@ async function getWatchlistData() const postData = {'watchListId': watchListId} - const response = await fetch(apiURL+'/get-watchlist', { + const response = await fetch('/api/get-watchlist', { method: 'POST', headers: { - "Content-Type": "application/json","X-API-KEY": apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); -const output = await response.json(); +const output = await response?.json(); try { - watchList = sortTickersByChange(output[0]); + watchList = sortTickersByChange(output?.at(0)); } catch(e) { watchList = [] diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index 75de40c0..549d8a38 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -1,13 +1,10 @@ export const load = ({ locals, cookies }) => { - const { user, isUSRegion, apiURL, fastifyURL, wsURL, apiKey } = locals; + const { user, isUSRegion, wsURL } = locals; return { user: user || undefined, isUSRegion, cookieConsent: cookies?.get("cookie-consent"), - apiURL, - fastifyURL, wsURL, - apiKey, }; }; diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 0f3d5538..7ee324e4 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -628,7 +628,7 @@ $: { autocomplete="off" /> --> - + { + const data = await request.json(); + const { apiURL, apiKey } = locals; + + const postData = { + ticker: data?.ticker, + quarter: data?.quarter, + year: data?.year, + }; + const response = await fetch(apiURL + "/earnings-call-transcripts", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/export-price-data/+server.ts b/src/routes/api/export-price-data/+server.ts new file mode 100644 index 00000000..27a47a5d --- /dev/null +++ b/src/routes/api/export-price-data/+server.ts @@ -0,0 +1,20 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { apiURL, apiKey } = locals; + + const postData = { ticker: data?.ticker, timePeriod: data?.timePeriod }; + const response = await fetch(apiURL + "/export-price-data", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/get-watchlist/+server.ts b/src/routes/api/get-watchlist/+server.ts new file mode 100644 index 00000000..57995598 --- /dev/null +++ b/src/routes/api/get-watchlist/+server.ts @@ -0,0 +1,20 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { apiURL, apiKey } = locals; + + const postData = { watchListId: data?.watchListId }; + const response = await fetch(apiURL + "/get-watchlist", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/historical-price/+server.ts b/src/routes/api/historical-price/+server.ts new file mode 100644 index 00000000..9d1409b0 --- /dev/null +++ b/src/routes/api/historical-price/+server.ts @@ -0,0 +1,20 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { apiURL, apiKey } = locals; + + const postData = { ticker: data?.ticker, timePeriod: data?.timePeriod }; + 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 new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/info-text/+server.ts b/src/routes/api/info-text/+server.ts new file mode 100644 index 00000000..f409fdd4 --- /dev/null +++ b/src/routes/api/info-text/+server.ts @@ -0,0 +1,20 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { apiURL, apiKey } = locals; + + const postData = { parameter: data?.parameter }; + const response = await fetch(apiURL + "/info-text", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/options-daily-transactions/+server.ts b/src/routes/api/options-daily-transactions/+server.ts new file mode 100644 index 00000000..98c6a825 --- /dev/null +++ b/src/routes/api/options-daily-transactions/+server.ts @@ -0,0 +1,20 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { apiURL, apiKey } = locals; + + const postData = { transactionId: data?.transactionId }; + const response = await fetch(apiURL + "/options-daily-transactions", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/searchbar-data/+server.ts b/src/routes/api/searchbar-data/+server.ts new file mode 100644 index 00000000..590a6717 --- /dev/null +++ b/src/routes/api/searchbar-data/+server.ts @@ -0,0 +1,17 @@ +import type { RequestHandler } from "./$types"; + +export const GET: RequestHandler = async ({ locals }) => { + const { apiURL, apiKey } = locals; + + const response = await fetch(apiURL + "/searchbar-data", { + method: "GET", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + }); + + const output = await response?.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/stock-screener-data/+server.ts b/src/routes/api/stock-screener-data/+server.ts new file mode 100644 index 00000000..be865984 --- /dev/null +++ b/src/routes/api/stock-screener-data/+server.ts @@ -0,0 +1,21 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { apiURL, apiKey } = locals; + + const postData = { ruleOfList: data?.ruleOfList }; + + const response = await fetch(apiURL + "/stock-screener-data", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response?.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/api/ticker-data/+server.ts b/src/routes/api/ticker-data/+server.ts new file mode 100644 index 00000000..667a6a79 --- /dev/null +++ b/src/routes/api/ticker-data/+server.ts @@ -0,0 +1,20 @@ +import type { RequestHandler } from "./$types"; + +export const POST: RequestHandler = async ({ request, locals }) => { + const data = await request.json(); + const { apiURL, apiKey } = locals; + + const postData = { ticker: data?.ticker }; + const response = await fetch(apiURL + "/" + data?.path, { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return new Response(JSON.stringify(output)); +}; diff --git a/src/routes/crypto/[tickerID]/+layout.svelte b/src/routes/crypto/[tickerID]/+layout.svelte index e50e7fd4..5725f9f0 100644 --- a/src/routes/crypto/[tickerID]/+layout.svelte +++ b/src/routes/crypto/[tickerID]/+layout.svelte @@ -25,10 +25,10 @@ async function loadSearchData() { else { // make the GET request to the endpoint - const response = await fetch(data?.apiURL+'/searchbar-data', { + const response = await fetch('/api/searchbar-data', { method: 'GET', headers: { - "Content-Type": "application/json","X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, }); diff --git a/src/routes/crypto/[tickerID]/+page.svelte b/src/routes/crypto/[tickerID]/+page.svelte index 23fb0c18..99b33284 100644 --- a/src/routes/crypto/[tickerID]/+page.svelte +++ b/src/routes/crypto/[tickerID]/+page.svelte @@ -291,10 +291,10 @@ timePeriod: timePeriod, }; - const response = await fetch(data?.apiURL+'/historical-price', { + const response = await fetch('/api/historical-price', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/routes/crypto/[tickerID]/workers/historicalPriceWorker.ts b/src/routes/crypto/[tickerID]/workers/historicalPriceWorker.ts deleted file mode 100644 index 706f5443..00000000 --- a/src/routes/crypto/[tickerID]/workers/historicalPriceWorker.ts +++ /dev/null @@ -1,153 +0,0 @@ -// lib/workers/test.ts - -let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY; - -async function getOneDayPrice(ticker: string, apiURL: string) { - let oneDayPrice = []; - - try { - const postData = { ticker: ticker }; - const response = await fetch(apiURL + "/one-day-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - oneDayPrice = await response.json(); - - oneDayPrice = oneDayPrice?.map((item) => ({ - time: Date.parse(item?.time), - open: item?.open !== null ? item?.open : NaN, - high: item?.high !== null ? item?.high : NaN, - low: item?.low !== null ? item?.low : NaN, - close: item?.close !== null ? item?.close : NaN, - })); - - // Set worker status to finished and send chart data - return oneDayPrice; - } catch (error) { - // Set worker status to idle and send error message - return oneDayPrice; - } -} - -async function getHistoricalPrice(ticker: string, apiURL: string) { - let oneWeekPrice; - let oneMonthPrice; - let sixMonthPrice; - let oneYearPrice; - let threeYearPrice; - - try { - const postData = { ticker: ticker }; - const response = await fetch(apiURL + "/historical-price", { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-KEY": apiKey, - }, - body: JSON.stringify(postData), - }); - - const pastPriceList = await response.json(); - - oneWeekPrice = pastPriceList["1W"]?.map( - ({ time, open, high, low, close }) => ({ - time: Date.parse(time), - open, - high, - low, - close, - }), - ); - oneMonthPrice = pastPriceList["1M"]?.map( - ({ time, open, high, low, close }) => ({ - time: Date.parse(time), - open, - high, - low, - close, - }), - ); - sixMonthPrice = pastPriceList["6M"]?.map( - ({ time, open, high, low, close }) => ({ - time: Date.parse(time), - open, - high, - low, - close, - }), - ); - oneYearPrice = pastPriceList["1Y"]?.map( - ({ time, open, high, low, close }) => ({ - time: Date.parse(time), - open, - high, - low, - close, - }), - ); - threeYearPrice = pastPriceList["MAX"]?.map( - ({ time, open, high, low, close }) => ({ - time: Date.parse(time), - open, - high, - low, - close, - }), - ); - - // Set worker status to finished and send chart data - return { - oneWeekPrice, - oneMonthPrice, - sixMonthPrice, - oneYearPrice, - threeYearPrice, - pastPriceList, - }; - } catch (error) { - // Set worker status to idle and send error message - return {}; - } -} - -onmessage = async (event: MessageEvent) => { - const ticker = event.data?.message?.ticker; - const apiURL = event.data?.message?.apiURL; - //console.log(ticker, apiURL); - try { - const [output, oneDayPrice] = await Promise.all([ - getHistoricalPrice(ticker, apiURL), - getOneDayPrice(ticker, apiURL), - ]); - - const oneWeekPrice = output?.oneWeekPrice; - const oneMonthPrice = output?.oneMonthPrice; - const sixMonthPrice = output?.sixMonthPrice; - const oneYearPrice = output?.oneYearPrice; - const threeYearPrice = output?.threeYearPrice; - const pastPriceList = output?.pastPriceList; - - const chartData = { - oneDayPrice, - oneWeekPrice, - oneMonthPrice, - sixMonthPrice, - oneYearPrice, - threeYearPrice, - pastPriceList, - }; - //console.log(pastPriceList) - postMessage({ message: "success", chartData }); - } catch (e) { - postMessage({ message: "error", e }); - } - // Sending data back to the main thread - //postMessage({ message: 'Data received in the worker'}); -}; - -export {}; diff --git a/src/routes/etf/[tickerID]/+layout.svelte b/src/routes/etf/[tickerID]/+layout.svelte index 84f1a354..d1e579c3 100644 --- a/src/routes/etf/[tickerID]/+layout.svelte +++ b/src/routes/etf/[tickerID]/+layout.svelte @@ -29,10 +29,10 @@ async function loadSearchData() { else { // make the GET request to the endpoint - const response = await fetch(data?.apiURL+'/searchbar-data', { + const response = await fetch('/api/searchbar-data', { method: 'GET', headers: { - "Content-Type": "application/json","X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, }); diff --git a/src/routes/etf/[tickerID]/+page.svelte b/src/routes/etf/[tickerID]/+page.svelte index b56bcbdc..59df1e67 100644 --- a/src/routes/etf/[tickerID]/+page.svelte +++ b/src/routes/etf/[tickerID]/+page.svelte @@ -318,10 +318,10 @@ async function historicalPrice(timePeriod:string) { timePeriod: timePeriod, }; - const response = await fetch(data?.apiURL+'/historical-price', { + const response = await fetch('/api/historical-price', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); @@ -416,11 +416,11 @@ async function initializePrice() { async function getPrePostQuote() { if(!$isOpen) { - const postData = { ticker: $etfTicker}; - const response = await fetch(data?.apiURL+'/pre-post-quote', { + const postData = { ticker: $etfTicker, path: 'pre-post-quote'}; + const response = await fetch('/api/ticker-data', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); @@ -729,16 +729,15 @@ async function initializePrice() { timePeriod: timePeriod, }; - const response = await fetch(data?.apiURL + "/export-price-data", { + const response = await fetch("/api/export-price-data", { method: "POST", headers: { "Content-Type": "application/json", - "X-API-KEY": data?.apiKey, }, body: JSON.stringify(postData), }); - const output = (await response?.json()) ?? []; + const output = await response?.json() ?? []; setCache($etfTicker, output, "exportPriceData" + timePeriod); return output; diff --git a/src/routes/etf/[tickerID]/options/+page.svelte b/src/routes/etf/[tickerID]/options/+page.svelte index 13fb9aab..38e86320 100644 --- a/src/routes/etf/[tickerID]/options/+page.svelte +++ b/src/routes/etf/[tickerID]/options/+page.svelte @@ -31,16 +31,15 @@ let activeIdx = 0; }; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + "/options-daily-transactions", { + const response = await fetch("/api/options-daily-transactions", { method: "POST", headers: { "Content-Type": "application/json", - "X-API-KEY": data?.apiKey, }, body: JSON.stringify(postData), }); - output = await response.json(); + output = await response?.json(); setCache(transactionId, output, "getDailyTransactions"); } diff --git a/src/routes/stock-screener/+page.svelte b/src/routes/stock-screener/+page.svelte index 6c6bce0f..5d65aae5 100644 --- a/src/routes/stock-screener/+page.svelte +++ b/src/routes/stock-screener/+page.svelte @@ -229,7 +229,7 @@ async function getInfoText(parameter, title) { infoText = cachedData; } else { const postData = { parameter }; - const response = await fetch(data?.apiURL + "/info-text", { + const response = await fetch("/api/info-text", { method: "POST", headers: { "Content-Type": "application/json", @@ -406,7 +406,7 @@ const loadWorker = async () => { }; const updateStockScreenerData = async () => { - downloadWorker.postMessage({ ruleOfList: ruleOfList, apiURL: data?.apiURL, apiKey: data?.apiKey }); + downloadWorker.postMessage({ ruleOfList: ruleOfList}); }; function handleAddRule() { diff --git a/src/routes/stock-screener/workers/downloadWorker.ts b/src/routes/stock-screener/workers/downloadWorker.ts index 00e2b81d..689d38fe 100644 --- a/src/routes/stock-screener/workers/downloadWorker.ts +++ b/src/routes/stock-screener/workers/downloadWorker.ts @@ -22,7 +22,7 @@ const getStockScreenerData = async (rules, apiKey, apiURL) => { // Function to check and add missing EMA parameters const ensureAllEmaParameters = (params) => { const includedEmaParameters = params.filter((param) => - emaParameters.includes(param), + emaParameters.includes(param) ); if (includedEmaParameters.length > 0) { emaParameters.forEach((param) => { @@ -47,11 +47,10 @@ const getStockScreenerData = async (rules, apiKey, apiURL) => { // Fetch new data if it's not in the cache const postData = { ruleOfList: getRuleOfList }; - const response = await fetch(apiURL + "/stock-screener-data", { + const response = await fetch("/api/stock-screener-data", { method: "POST", headers: { "Content-Type": "application/json", - "X-API-KEY": apiKey, }, body: JSON.stringify(postData), }); @@ -76,9 +75,9 @@ onmessage = async (event) => { value !== undefined && (typeof value !== "object" || Object.values(value)?.every( - (subValue) => subValue !== null && subValue !== undefined, - )), - ), + (subValue) => subValue !== null && subValue !== undefined + )) + ) ); postMessage({ message: "success", stockScreenerData }); diff --git a/src/routes/stocks/[tickerID]/+layout.svelte b/src/routes/stocks/[tickerID]/+layout.svelte index 1631832a..e1f08c8e 100644 --- a/src/routes/stocks/[tickerID]/+layout.svelte +++ b/src/routes/stocks/[tickerID]/+layout.svelte @@ -17,11 +17,10 @@ return; } else { // make the GET request to the endpoint - const response = await fetch(data?.apiURL + "/searchbar-data", { + const response = await fetch("/api/searchbar-data", { method: "GET", headers: { "Content-Type": "application/json", - "X-API-KEY": data?.apiKey, }, }); diff --git a/src/routes/stocks/[tickerID]/+page.svelte b/src/routes/stocks/[tickerID]/+page.svelte index 07af7097..65db2312 100644 --- a/src/routes/stocks/[tickerID]/+page.svelte +++ b/src/routes/stocks/[tickerID]/+page.svelte @@ -280,11 +280,10 @@ async function historicalPrice(timePeriod: string) { timePeriod: timePeriod, }; - const response = await fetch(data?.apiURL + "/historical-price", { + const response = await fetch("/api/historical-price", { method: "POST", headers: { "Content-Type": "application/json", - "X-API-KEY": data?.apiKey, }, body: JSON.stringify(postData), }); @@ -375,12 +374,11 @@ async function historicalPrice(timePeriod: string) { async function getPrePostQuote() { if (!$isOpen) { - const postData = { ticker: $stockTicker }; - const response = await fetch(data?.apiURL + "/pre-post-quote", { + const postData = { ticker: $stockTicker, path: 'pre-post-quote' }; + const response = await fetch("/api/ticker-data", { method: "POST", headers: { "Content-Type": "application/json", - "X-API-KEY": data?.apiKey, }, body: JSON.stringify(postData), }); @@ -605,7 +603,7 @@ async function historicalPrice(timePeriod: string) { timePeriod: timePeriod, }; - const response = await fetch(data?.apiURL + "/export-price-data", { + const response = await fetch("/api/export-price-data", { method: "POST", headers: { "Content-Type": "application/json", diff --git a/src/routes/stocks/[tickerID]/insider/transcripts/+page.svelte b/src/routes/stocks/[tickerID]/insider/transcripts/+page.svelte index 0dd8c775..ff9bf6fd 100644 --- a/src/routes/stocks/[tickerID]/insider/transcripts/+page.svelte +++ b/src/routes/stocks/[tickerID]/insider/transcripts/+page.svelte @@ -41,10 +41,10 @@ year: year }; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + '/earnings-call-transcripts', { + const response = await fetch('/api/earnings-call-transcripts', { method: 'POST', headers: { - "Content-Type": "application/json", "X-API-KEY": data?.apiKey + "Content-Type": "application/json" }, body: JSON.stringify(postData) }); diff --git a/src/routes/stocks/[tickerID]/options/+page.svelte b/src/routes/stocks/[tickerID]/options/+page.svelte index df6e773a..6492f17b 100644 --- a/src/routes/stocks/[tickerID]/options/+page.svelte +++ b/src/routes/stocks/[tickerID]/options/+page.svelte @@ -31,11 +31,10 @@ let activeIdx = 0; }; // make the POST request to the endpoint - const response = await fetch(data?.apiURL + "/options-daily-transactions", { + const response = await fetch("/api/options-daily-transactions", { method: "POST", headers: { "Content-Type": "application/json", - "X-API-KEY": data?.apiKey, }, body: JSON.stringify(postData), }); diff --git a/src/routes/stocks/[tickerID]/stats/+page.svelte b/src/routes/stocks/[tickerID]/stats/+page.svelte index 3420a2e7..cd945ee6 100644 --- a/src/routes/stocks/[tickerID]/stats/+page.svelte +++ b/src/routes/stocks/[tickerID]/stats/+page.svelte @@ -208,7 +208,7 @@ updateYearRange()
- +
diff --git a/src/routes/trending/+page.svelte b/src/routes/trending/+page.svelte deleted file mode 100644 index 49a4a112..00000000 --- a/src/routes/trending/+page.svelte +++ /dev/null @@ -1,209 +0,0 @@ - - - - - - {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ''} Today's Top Trending Stocks · stocknear - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - -
-
-

- Trending Stocks -

-
- - - Get the latest data on the top-viewed stock in the last 24 hours. - - - -
- - - - - -
- - -
- - -
- - - - -
- - - - - - - - - - - - - - {#each trendingList as item,index} - - assetSelector(item?.symbol, item?.assetType)} class="sm:hover:bg-[#245073] sm:hover:bg-opacity-[0.2] odd:bg-[#27272A] border-b-[#09090B] shake-ticker cursor-pointer"> - - - - - - - - - - - - - - - - - - - - - {/each} - -
No.SymbolViewsMarket CapVolumeEPS
- {index+1} - - {item?.symbol} - - {item?.views} - - {item?.marketCap !== null ? abbreviateNumber(item?.marketCap,true) : '-'} - - {item?.volume !== null ? abbreviateNumber(item?.volume) : '-'} - - {item?.eps !== null ? item?.eps?.toFixed(2) : '-'} -
- - - - - - -
- - - - -
- - - \ No newline at end of file diff --git a/src/routes/trending/+page.ts b/src/routes/trending/+page.ts deleted file mode 100644 index 956d3ccd..00000000 --- a/src/routes/trending/+page.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { getCache, setCache } from "$lib/store"; - -export const load = async ({ parent }) => { - const getTrendingStocks = async () => { - let output; - - // Get cached data for the specific tickerID - const cachedData = getCache("", "getTrendingStocks"); - if (cachedData) { - output = cachedData; - } else { - const { apiKey, apiURL } = await parent(); - // make the POST request to the endpoint - const response = await fetch(apiURL + "/trending", { - 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 'getTrendingStocks' - setCache("", output, "getTrendingStocks"); - } - - return output; - }; - - // Make sure to return a promise - return { - getTrendingStocks: await getTrendingStocks(), - }; -}; diff --git a/src/routes/watchlist/+page.svelte b/src/routes/watchlist/+page.svelte index f4257aea..36ea765d 100644 --- a/src/routes/watchlist/+page.svelte +++ b/src/routes/watchlist/+page.svelte @@ -511,8 +511,6 @@ onDestroy( () => {