clean code

This commit is contained in:
MuslemRahimi 2024-07-26 14:09:09 +02:00
parent 65e1066b45
commit 1c7d6950a4
24 changed files with 120 additions and 410 deletions

View File

@ -34,7 +34,7 @@ async function updateSentiment(sentiment:string) {
const response = await fetch('/api/community-sentiment', {
method: 'POST',
headers: {
"Content-Type": "application/json","X-API-KEY": apiKey
"Content-Type": "application/json"
},
body: JSON.stringify(postData),
}); // make a POST request to the server with the FormData object

View File

@ -1,13 +1,11 @@
<script lang="ts">
import { stockTicker, etfTicker, assetType, screenWidth } from '$lib/store';
import { abbreviateNumber, formatString } from '$lib/utils';
import { goto } from '$app/navigation';
import InfoModal from '$lib/components/InfoModal.svelte';
import Lazy from 'svelte-lazy';
export let correlationList;
let charNumber = 20;
let showFullStats = false;
@ -38,16 +36,7 @@
$: {
if ($screenWidth < 640)
{
charNumber = 10;
}
else {
charNumber = 20;
}
}
$: charNumber = $screenWidth < 640 ? 10 : 20;

View File

@ -1,28 +1,13 @@
<script lang ='ts'>
import { darkPoolComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
import { darkPoolComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, getCache, setCache} from '$lib/store';
import InfoModal from '$lib/components/InfoModal.svelte';
import { Chart } from 'svelte-echarts'
import { abbreviateNumber, formatDateRange } from "$lib/utils";
import Lazy from 'svelte-lazy';
export let data;
let isLoaded = false;
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
let rawData = [];
let optionsData;
@ -183,10 +168,10 @@ const getDarkPool = async (ticker) => {
const postData = {'ticker': ticker};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/dark-pool', {
const response = await fetch(data?.apiURL + '/dark-pool', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,29 +1,13 @@
<script lang ='ts'>
import { enterpriseComponent, displayCompanyName, stockTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
import { enterpriseComponent, displayCompanyName, stockTicker, screenWidth, getCache, setCache} from '$lib/store';
import InfoModal from '$lib/components/InfoModal.svelte';
import { Chart } from 'svelte-echarts'
import { Chart } from 'svelte-echarts';
import Lazy from 'svelte-lazy';
export let data;
let isLoaded = false;
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
let rawData = [];
let optionsData;
@ -143,10 +127,10 @@ const getEnterPriseValues = async (ticker) => {
const postData = {'ticker': ticker};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/enterprise-values', {
const response = await fetch(data?.apiURL + '/enterprise-values', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,24 +1,10 @@
<script lang ='ts'>
import { fundamentalAnalysisComponent, displayCompanyName, stockTicker, userRegion, getCache, setCache} from '$lib/store';
import { fundamentalAnalysisComponent, displayCompanyName, stockTicker, getCache, setCache} from '$lib/store';
import InfoModal from '$lib/components/InfoModal.svelte';
let fundamentalAnalysisDict = {};
let isLoaded = false;
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
export let data;
@ -40,10 +26,10 @@ const getFundamentalAnalysis = async (ticker) => {
const postData = {'ticker': ticker};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/fundamental-predictor-analysis', {
const response = await fetch(data?.apiURL + '/fundamental-predictor-analysis', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,28 +1,14 @@
<script lang ='ts'>
import { impliedVolatilityComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
import { impliedVolatilityComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, getCache, setCache} from '$lib/store';
import InfoModal from '$lib/components/InfoModal.svelte';
import { Chart } from 'svelte-echarts'
import { formatDateRange } from "$lib/utils";
import Lazy from 'svelte-lazy';
export let data;
let isLoaded = false;
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
let rawData = [];
let optionsData;
@ -220,10 +206,10 @@ function findLowestAndhighestIV(data, lastDateStr) {
const postData = {'ticker': ticker};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/implied-volatility', {
const response = await fetch(data?.apiURL + '/implied-volatility', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,5 +1,5 @@
<script lang ='ts'>
import { marketMakerComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
import { marketMakerComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, getCache, setCache} from '$lib/store';
import InfoModal from '$lib/components/InfoModal.svelte';
import { Chart } from 'svelte-echarts'
import { abbreviateNumber, formatString, formatDateRange } from "$lib/utils";
@ -8,22 +8,7 @@
export let data;
let isLoaded = false;
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
let rawData = {};
let historyData = [];
@ -168,10 +153,10 @@ const getMarketMaker = async (ticker) => {
const postData = {'ticker': ticker};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/market-maker', {
const response = await fetch(data?.apiURL + '/market-maker', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,25 +1,11 @@
<script lang='ts'>
import { optionComponent, assetType, stockTicker, etfTicker, displayCompanyName, userRegion, getCache, setCache} from "$lib/store";
import { optionComponent, assetType, stockTicker, etfTicker, displayCompanyName, getCache, setCache} from "$lib/store";
import { abbreviateNumber } from "$lib/utils";
import InfoModal from '$lib/components/InfoModal.svelte';
import { LayerCake, Html } from 'layercake';
import Circle from '$lib/components/Circle/Circle.html.svelte';
export let data;
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
let optionsDict = {};
@ -58,10 +44,10 @@ const getOptionsBubble = async (ticker) => {
const postData = {'ticker': ticker};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/options-bubble', {
const response = await fetch(data?.apiURL + '/options-bubble', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -2,27 +2,12 @@
import { optionsNetFlowComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
import InfoModal from '$lib/components/InfoModal.svelte';
import { Chart } from 'svelte-echarts'
import { abbreviateNumber, formatString } from "$lib/utils";
import Lazy from 'svelte-lazy';
export let data;
let isLoaded = false;
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
let rawData = [];
let optionsData;
@ -175,10 +160,10 @@ let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
const postData = {'ticker': ticker};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/options-net-flow-ticker', {
const response = await fetch(data?.apiURL + '/options-net-flow-ticker', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,30 +1,17 @@
<script lang ='ts'>
import { priceAnalysisComponent, displayCompanyName, stockTicker, etfTicker, cryptoTicker, assetType, screenWidth, userRegion, getCache, setCache} from '$lib/store';
import { priceAnalysisComponent, displayCompanyName, stockTicker, etfTicker, cryptoTicker, assetType, screenWidth, getCache, setCache} from '$lib/store';
import InfoModal from '$lib/components/InfoModal.svelte';
import { Chart } from 'svelte-echarts'
import Lazy from 'svelte-lazy';
export let data;
let isLoaded = false;
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
import Lazy from 'svelte-lazy';
let priceAnalysisDict = {};
export let data;
const modalContent = `
Our AI model, employing a Bayesian approach, predicts future prices by breaking down trends, seasonality, and holiday effects. It integrates uncertainty to offer forecasts with intervals.<br><br>
@ -148,10 +135,10 @@ const getPriceAnalysis = async (ticker) => {
const postData = {'ticker': ticker};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/price-analysis', {
const response = await fetch(data?.apiURL + '/price-analysis', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,34 +1,18 @@
<script lang ='ts'>
import { retailVolumeComponent,displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
import { retailVolumeComponent,displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, getCache, setCache} from '$lib/store';
import InfoModal from '$lib/components/InfoModal.svelte';
import { Chart } from 'svelte-echarts'
import { abbreviateNumber, formatDateRange } from "$lib/utils";
import Lazy from 'svelte-lazy';
export let data;
let isLoaded = false;
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let historyData = [];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
let historyData = []
let rawData = [];
let optionsData;
let avgVolume;
@ -209,10 +193,10 @@ const getRetailVolume = async (ticker) => {
const postData = {'ticker': ticker};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/retail-volume', {
const response = await fetch(data?.apiURL + '/retail-volume', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,38 +1,23 @@
<script lang='ts'>
import { Chart } from 'svelte-echarts'
import { shareholderComponent, screenWidth, stockTicker, userRegion, getCache, setCache, displayCompanyName} from '$lib/store';
import { shareholderComponent, screenWidth, stockTicker, getCache, setCache, displayCompanyName} from '$lib/store';
import { formatString } from '$lib/utils';
import { goto } from '$app/navigation';
import { abbreviateNumber } from '$lib/utils';
import InfoModal from '$lib/components/InfoModal.svelte';
import Lazy from 'svelte-lazy';
export let data;
let isLoaded = false;
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let callPercentage;
let putPercentage;
let totalCalls;
let totalPuts;
let latestPutCallRatio;
let putCallRatio;
export let data;
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
let rawData = {};
let shareholderList = []
@ -44,7 +29,6 @@ let showFullStats = false;
const plotPieChart = () => {
shareholderList = shareholderList?.filter(item => item?.ownership <= 100);
@ -102,10 +86,10 @@ const getShareholders = async (ticker) => {
const postData = {'ticker': ticker};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/shareholders', {
const response = await fetch(data?.apiURL + '/shareholders', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,21 +1,6 @@
import { userRegion, getCache, setCache } from '$lib/store';
import {getCache, setCache } from '$lib/store';
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
export const load = async ({parent}) => {
@ -28,10 +13,10 @@ export const load = async ({parent}) => {
output = cachedData;
} else {
// make the POST request to the endpoint
const response = await fetch(apiURL + '/cramer-tracker', {
const response = await fetch(data?.apiURL + '/cramer-tracker', {
method: 'GET',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
});

View File

@ -19,7 +19,6 @@ const checkMarketHour = async () => {
}
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let wsURL;

View File

@ -1,24 +1,7 @@
import { userRegion, getCache, setCache } from '$lib/store';
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL = import.meta.env.VITE_EU_API_URL; // Set a default API URL
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
import { getCache, setCache } from '$lib/store';
export const load = async ({ params }) => {
export const load = async ({ parent, params }) => {
const getAnalystTickerHistory = async () => {
@ -28,15 +11,17 @@ export const load = async ({ params }) => {
if (cachedData) {
output = cachedData;
} else {
const data = await parent();
const postData = {
ticker: params.tickerID
};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/analyst-ticker-history', {
const response = await fetch(data?.apiURL + '/analyst-ticker-history', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,22 +1,7 @@
import { userRegion, getCache, setCache } from '$lib/store';
import { getCache, setCache } from '$lib/store';
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL = import.meta.env.VITE_EU_API_URL; // Set a default API URL
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
export const load = async ({ params }) => {
export const load = async ({ parent, params }) => {
const getStockDividend = async () => {
let newsList;
@ -25,15 +10,18 @@ export const load = async ({ params }) => {
if (cachedData) {
newsList = cachedData;
} else {
const data = await parent();
const postData = {
ticker: params.tickerID
};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/stock-dividend', {
const response = await fetch(data?.apiURL + '/stock-dividend', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,19 +1,4 @@
import { userRegion, getCache, setCache } from '$lib/store';
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL = import.meta.env.VITE_EU_API_URL; // Set a default API URL
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
import { getCache, setCache } from '$lib/store';
@ -39,7 +24,10 @@ const transactionTypeMap = {
'': 'n/a'
};
export const load = async ({ params }) => {
export const load = async ({ parent, params }) => {
const data = await parent();
const getInsiderTrading = async () => {
let output;
@ -54,10 +42,10 @@ export const load = async ({ params }) => {
};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/insider-trading', {
const response = await fetch(data?.apiURL + '/insider-trading', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});
@ -92,10 +80,10 @@ export const load = async ({ params }) => {
};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/insider-trading-statistics', {
const response = await fetch(data?.apiURL + '/insider-trading-statistics', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});
@ -122,10 +110,10 @@ async function historicalPrice() {
timePeriod: 'max',
};
const response = await fetch(apiURL+'/historical-price', {
const response = await fetch(data?.apiURL+'/historical-price', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,24 +1,8 @@
import { userRegion, getCache, setCache } from '$lib/store';
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
import { getCache, setCache } from '$lib/store';
export const load = async ({ params }) => {
export const load = async ({ parent, params }) => {
const getSenateTrading = async () => {
let output;
@ -27,15 +11,18 @@ export const load = async ({ params }) => {
if (cachedData) {
output = cachedData;
} else {
const data = await parent();
const postData = {
ticker: params.tickerID
};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/congress-trading-ticker', {
const response = await fetch(data?.apiURL + '/congress-trading-ticker', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,23 +1,8 @@
import { userRegion, getCache, setCache } from '$lib/store';
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL = import.meta.env.VITE_EU_API_URL; // Set a default API URL
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
import { getCache, setCache } from '$lib/store';
export const load = async ({ params }) => {
export const load = async ({ parent, params }) => {
const getStockNews = async () => {
let output;
@ -26,15 +11,18 @@ export const load = async ({ params }) => {
if (cachedData) {
output = cachedData;
} else {
const data = await parent();
const postData = {
ticker: params.tickerID
};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/stock-news', {
const response = await fetch(data?.apiURL + '/stock-news', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,19 +1,4 @@
import { userRegion, getCache, setCache } from '$lib/store';
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL = import.meta.env.VITE_EU_API_URL; // Set a default API URL
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
import { getCache, setCache } from '$lib/store';
function daysLeft(targetDate) {
@ -28,7 +13,10 @@ function daysLeft(targetDate) {
}
export const load = async ({ params }) => {
export const load = async ({ parent, params }) => {
const data = await parent();
const getOptionsPlotData = async () => {
@ -38,16 +26,15 @@ export const load = async ({ params }) => {
if (cachedData) {
res = cachedData;
} else {
// make the POST request to the endpoint
const postData = {
ticker: params.tickerID
};
const response = await fetch(apiURL + '/options-plot-ticker', {
const response = await fetch(data?.apiURL + '/options-plot-ticker', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});
@ -105,10 +92,10 @@ export const load = async ({ params }) => {
};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/options-flow-ticker', {
const response = await fetch(data?.apiURL + '/options-flow-ticker', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,19 +1,8 @@
import { userRegion, getCache, setCache } from '$lib/store';
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL = import.meta.env.VITE_EU_API_URL; // Set a default API URL
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
import {getCache, setCache } from '$lib/store';
export const load = async ({ params }) => {
export const load = async ({ parent, params }) => {
const getBalanceSheetStatement = async () => {
let output;
@ -22,15 +11,17 @@ export const load = async ({ params }) => {
if (cachedData) {
output = cachedData;
} else {
const data = await parent();
const postData = {
ticker: params.tickerID
};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/stock-balance-sheet', {
const response = await fetch(data?.apiURL + '/stock-balance-sheet', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,18 +1,7 @@
import { userRegion, getCache, setCache } from '$lib/store';
import { getCache, setCache } from '$lib/store';
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL = import.meta.env.VITE_EU_API_URL; // Set a default API URL
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
export const load = async ({ params }) => {
export const load = async ({ parent, params }) => {
const getCashFlowStatement = async () => {
let output;
@ -21,15 +10,18 @@ export const load = async ({ params }) => {
if (cachedData) {
output = cachedData;
} else {
const data = await parent();
const postData = {
ticker: params.tickerID
};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/stock-cash-flow', {
const response = await fetch(data?.apiURL + '/stock-cash-flow', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,18 +1,7 @@
import { userRegion, getCache, setCache } from '$lib/store';
import { getCache, setCache } from '$lib/store';
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
export const load = async ({ params }) => {
export const load = async ({ parent, params }) => {
const getIncomeStatement = async () => {
let output;
@ -21,15 +10,17 @@ export const load = async ({ params }) => {
if (cachedData) {
output = cachedData;
} else {
const data = await parent();
const postData = {
ticker: params.tickerID
};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/stock-income', {
const response = await fetch(data?.apiURL + '/stock-income', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});

View File

@ -1,21 +1,7 @@
import { userRegion, getCache, setCache } from '$lib/store';
const usRegion = ['cle1','iad1','pdx1','sfo1'];
let apiURL;
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
import { getCache, setCache } from '$lib/store';
userRegion.subscribe(value => {
if (usRegion.includes(value)) {
apiURL = import.meta.env.VITE_USEAST_API_URL;
} else {
apiURL = import.meta.env.VITE_EU_API_URL;
}
});
export const load = async ({ params }) => {
export const load = async ({ parent, params }) => {
const getRatiosStatement = async () => {
let output;
@ -24,15 +10,17 @@ export const load = async ({ params }) => {
if (cachedData) {
output = cachedData;
} else {
const data = await parent();
const postData = {
ticker: params.tickerID
};
// make the POST request to the endpoint
const response = await fetch(apiURL + '/stock-ratios', {
const response = await fetch(data?.apiURL + '/stock-ratios', {
method: 'POST',
headers: {
"Content-Type": "application/json", "X-API-KEY": apiKey
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
},
body: JSON.stringify(postData)
});