clean code
This commit is contained in:
parent
4add3521b3
commit
65e1066b45
@ -22,14 +22,23 @@ export const handle = async ({ event, resolve }) => {
|
||||
event?.request?.headers?.get('x-vercel-id') ?? 'fra1::fra1::8t4xg-1700258428633-157d82fdfcc7',
|
||||
);
|
||||
|
||||
const userRegion = event?.locals?.region?.split("::")?.at(0)?.split("::")?.at(0)
|
||||
const userRegion = event?.locals?.region?.split("::")?.at(0)?.split("::")?.at(0) || '';
|
||||
|
||||
// Set a default API URL
|
||||
let pbUrl = import.meta.env.VITE_EU_POCKETBASE_URL;
|
||||
let apiURL = import.meta.env.VITE_EU_API_URL;
|
||||
let fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
|
||||
|
||||
let pbUrl = import.meta.env.VITE_EU_POCKETBASE_URL; // Set a default API URL
|
||||
|
||||
if (usRegion?.includes(userRegion)) {
|
||||
pbUrl = import.meta.env.VITE_USEAST_POCKETBASE_URL;
|
||||
apiURL = import.meta.env.VITE_USEAST_API_URL;
|
||||
fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
|
||||
} else {
|
||||
pbUrl = import.meta.env.VITE_EU_POCKETBASE_URL;
|
||||
apiURL = import.meta.env.VITE_EU_API_URL;
|
||||
fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
}
|
||||
|
||||
|
||||
@ -42,10 +51,16 @@ export const handle = async ({ event, resolve }) => {
|
||||
if (event?.locals?.pb?.authStore?.isValid) {
|
||||
await event?.locals?.pb?.collection('users')?.authRefresh();
|
||||
event.locals.user = serializeNonPOJOs(event?.locals?.pb?.authStore?.model);
|
||||
event.locals.apiURL = apiURL;
|
||||
event.locals.fastifyURL = fastifyURL;
|
||||
event.locals.apiKey = apiKey;
|
||||
}
|
||||
} catch(_) {
|
||||
event?.locals?.pb?.authStore?.clear();
|
||||
event.locals.user = undefined;
|
||||
event.locals.apiURL = apiURL;
|
||||
event.locals.fastifyURL = fastifyURL;
|
||||
event.locals.apiKey = apiKey;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,22 +1,10 @@
|
||||
<script lang='ts'>
|
||||
import toast from 'svelte-french-toast';
|
||||
import { userRegion, stockTicker, etfTicker, cryptoTicker, assetType, screenWidth } from "$lib/store";
|
||||
import { stockTicker, etfTicker, cryptoTicker, assetType, screenWidth } from "$lib/store";
|
||||
import { page } from '$app/stores';
|
||||
|
||||
export let data;
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
|
||||
let fastifyURL;
|
||||
|
||||
userRegion.subscribe(value => {
|
||||
if (usRegion.includes(value)) {
|
||||
fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
|
||||
} else {
|
||||
fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
let isClicked = false;
|
||||
|
||||
@ -27,7 +15,7 @@ async function createPortfolio(event) {
|
||||
|
||||
const postData = {'userId': data?.user?.id}
|
||||
|
||||
const response = await fetch(fastifyURL+'/create-portfolio', {
|
||||
const response = await fetch(data?.fastifyURL+'/create-portfolio', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<script lang='ts'>
|
||||
import {analystEstimateComponent, stockTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
|
||||
import {analystEstimateComponent, stockTicker, screenWidth, getCache, setCache} from '$lib/store';
|
||||
import InfoModal from '$lib/components/InfoModal.svelte';
|
||||
|
||||
import { LayerCake, Html } from 'layercake';
|
||||
@ -13,19 +13,6 @@ export let data;
|
||||
|
||||
let analystEstimateList = [];
|
||||
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 deactivateContent = data?.user?.tier === 'Pro' ? false : true;
|
||||
|
||||
@ -75,10 +62,10 @@ const getAnalystEstimate = async (ticker) => {
|
||||
|
||||
const postData = {'ticker': ticker};
|
||||
// make the POST request to the endpoint
|
||||
const response = await fetch(apiURL + '/analyst-estimate', {
|
||||
const response = await fetch(data?.apiURL + '/analyst-estimate', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
||||
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
|
||||
},
|
||||
body: JSON.stringify(postData)
|
||||
});
|
||||
|
||||
@ -1,25 +1,10 @@
|
||||
<script lang ='ts'>
|
||||
import { analystInsightComponent, stockTicker, userRegion, getCache, setCache} from '$lib/store';
|
||||
import { analystInsightComponent, stockTicker, getCache, setCache} from '$lib/store';
|
||||
import InfoModal from '$lib/components/InfoModal.svelte';
|
||||
|
||||
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 = {};
|
||||
|
||||
@ -51,10 +36,10 @@ function latestInfoDate(inputDate) {
|
||||
|
||||
const postData = {'ticker': ticker};
|
||||
// make the POST request to the endpoint
|
||||
const response = await fetch(apiURL + '/analyst-insight', {
|
||||
const response = await fetch(data?.apiURL + '/analyst-insight', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
||||
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
|
||||
},
|
||||
body: JSON.stringify(postData)
|
||||
});
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<script lang ='ts'>
|
||||
import { borrowedShareComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
|
||||
import { borrowedShareComponent, 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";
|
||||
@ -8,21 +8,6 @@
|
||||
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;
|
||||
@ -190,10 +175,10 @@ function findLowestAndHighestFee(data, lastDateStr) {
|
||||
|
||||
const postData = {'ticker': ticker};
|
||||
// make the POST request to the endpoint
|
||||
const response = await fetch(apiURL + '/borrowed-share', {
|
||||
const response = await fetch(data?.apiURL + '/borrowed-share', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
||||
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
|
||||
},
|
||||
body: JSON.stringify(postData)
|
||||
});
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<script lang ='ts'>
|
||||
import { clinicalTrialComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
|
||||
import { clinicalTrialComponent, 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 } from "$lib/utils";
|
||||
@ -8,20 +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;
|
||||
}
|
||||
});
|
||||
|
||||
let rawData = [];
|
||||
let displayList = []
|
||||
@ -172,10 +159,10 @@ const getClinicalTrial = async (ticker) => {
|
||||
|
||||
const postData = {'ticker': ticker};
|
||||
// make the POST request to the endpoint
|
||||
const response = await fetch(apiURL + '/clinical-trial', {
|
||||
const response = await fetch(data?.apiURL + '/clinical-trial', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
||||
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
|
||||
},
|
||||
body: JSON.stringify(postData)
|
||||
});
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
import {getImageURL, formatDate} from '$lib/utils';
|
||||
import toast from 'svelte-french-toast';
|
||||
import { userRegion, commentAdded, commentIdDeleted, screenWidth, replyCommentClicked, editCommentClicked, scrollToComment } from '$lib/store';
|
||||
import { commentAdded, commentIdDeleted, screenWidth, replyCommentClicked, editCommentClicked, scrollToComment } from '$lib/store';
|
||||
import TextEditor from '$lib/components/TextEditor.svelte';
|
||||
import { marked } from 'marked';
|
||||
import { tick } from 'svelte';
|
||||
@ -115,7 +115,7 @@ const handleUpvote = async (event) => {
|
||||
} else {
|
||||
upvoteCounter--;
|
||||
}
|
||||
const response = await fetch(fastifyURL+'/upvote-comment', {
|
||||
const response = await fetch(data?.fastifyURL+'/upvote-comment', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@ -151,7 +151,7 @@ const handleDownvote = async (event) => {
|
||||
}
|
||||
|
||||
|
||||
const response = await fetch(fastifyURL+'/downvote-comment', {
|
||||
const response = await fetch(data?.fastifyURL+'/downvote-comment', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@ -161,18 +161,6 @@ const handleDownvote = async (event) => {
|
||||
|
||||
};
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
|
||||
let fastifyURL;
|
||||
|
||||
userRegion.subscribe(value => {
|
||||
if (usRegion.includes(value)) {
|
||||
fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
|
||||
} else {
|
||||
fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
let deleteCommentId = comment?.id
|
||||
|
||||
@ -201,7 +189,7 @@ const handleDownvote = async (event) => {
|
||||
|
||||
|
||||
|
||||
const response = await fetch(fastifyURL+'/delete-comment', {
|
||||
const response = await fetch(data?.fastifyURL+'/delete-comment', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<script lang ='ts'>
|
||||
import { failToDeliverComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
|
||||
import { failToDeliverComponent, 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";
|
||||
@ -8,20 +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;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
let rawData = [];
|
||||
@ -40,7 +27,7 @@ function findLowestAndHighestPrice(data, lastDateStr) {
|
||||
const firstDate = new Date(lastDate.getFullYear(), lastDate.getMonth(), 1);
|
||||
|
||||
// Filter data to include only prices within the specified month period
|
||||
const filteredData = data.filter(item => {
|
||||
const filteredData = data?.filter(item => {
|
||||
const currentDate = new Date(item?.date);
|
||||
return currentDate >= firstDate && currentDate <= lastDate;
|
||||
});
|
||||
@ -184,10 +171,10 @@ function findLowestAndHighestPrice(data, lastDateStr) {
|
||||
|
||||
const postData = {'ticker': ticker};
|
||||
// make the POST request to the endpoint
|
||||
const response = await fetch(apiURL + '/fail-to-deliver', {
|
||||
const response = await fetch(data?.apiURL + '/fail-to-deliver', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
||||
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
|
||||
},
|
||||
body: JSON.stringify(postData)
|
||||
});
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<script lang ='ts'>
|
||||
import { governmentContractComponent, displayCompanyName, stockTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
|
||||
import { governmentContractComponent, displayCompanyName, stockTicker, screenWidth, getCache, setCache} from '$lib/store';
|
||||
import InfoModal from '$lib/components/InfoModal.svelte';
|
||||
import { Chart } from 'svelte-echarts'
|
||||
import { abbreviateNumber, formatString } from "$lib/utils";
|
||||
@ -8,20 +8,6 @@
|
||||
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 = [];
|
||||
@ -161,10 +147,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 + '/government-contract', {
|
||||
const response = await fetch(data?.apiURL + '/government-contract', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
||||
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
|
||||
},
|
||||
body: JSON.stringify(postData)
|
||||
});
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<script lang='ts'>
|
||||
import { revenueSegmentationComponent, stockTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
|
||||
import { revenueSegmentationComponent, stockTicker, screenWidth, getCache, setCache} from '$lib/store';
|
||||
import { abbreviateNumber, formatString } from '$lib/utils';
|
||||
import Sankey from '$lib/components/Sankey.svelte';
|
||||
import { LayerCake, Svg } from 'layercake';
|
||||
@ -8,23 +8,10 @@
|
||||
import InfoModal from '$lib/components/InfoModal.svelte';
|
||||
|
||||
export let userTier;
|
||||
export let apiURL;
|
||||
export let apiKey;
|
||||
|
||||
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 revenueSegmentation = [];
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
|
||||
import { userRegion, searchBarData, stockTicker, etfTicker, cryptoTicker, screenWidth} from '$lib/store';
|
||||
import { searchBarData, stockTicker, etfTicker, cryptoTicker, userRegion, screenWidth} from '$lib/store';
|
||||
import { goto } from '$app/navigation';
|
||||
import { onMount } from 'svelte';
|
||||
import Search from "lucide-svelte/icons/search";
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
let apiURL;
|
||||
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
|
||||
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
|
||||
|
||||
|
||||
userRegion.subscribe(value => {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
|
||||
<script lang ='ts'>
|
||||
import { shareStatisticsComponent, displayCompanyName, stockTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
|
||||
import { shareStatisticsComponent, displayCompanyName, stockTicker, screenWidth, getCache, setCache} from '$lib/store';
|
||||
import InfoModal from '$lib/components/InfoModal.svelte';
|
||||
import { Chart } from 'svelte-echarts'
|
||||
import { abbreviateNumber } from "$lib/utils";
|
||||
@ -10,20 +10,6 @@
|
||||
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 = {};
|
||||
@ -123,10 +109,10 @@ const getShareStatistics = async (ticker) => {
|
||||
|
||||
const postData = {'ticker': ticker};
|
||||
// make the POST request to the endpoint
|
||||
const response = await fetch(apiURL + '/share-statistics', {
|
||||
const response = await fetch(data?.apiURL + '/share-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)
|
||||
});
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<script lang ='ts'>
|
||||
import { abbreviateNumber } from "$lib/utils";
|
||||
|
||||
import { swapComponent, stockTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store';
|
||||
import { swapComponent, stockTicker, screenWidth, getCache, setCache} from '$lib/store';
|
||||
import InfoModal from '$lib/components/InfoModal.svelte';
|
||||
import { Chart } from 'svelte-echarts'
|
||||
import { Motion, AnimateSharedLayout } from "svelte-motion";
|
||||
@ -28,21 +28,6 @@
|
||||
optionsData = getPlotOptions(activeIdx === 0 ? 'effectiveDate' : 'expirationDate');
|
||||
}
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
|
||||
let apiURL;
|
||||
|
||||
|
||||
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;
|
||||
let avgNotionalAmount;
|
||||
@ -190,11 +175,11 @@
|
||||
rawData = cachedData;
|
||||
} else {
|
||||
try {
|
||||
const response = await fetch(`${apiURL}/swap-ticker`, {
|
||||
const response = await fetch(`${data?.apiURL}/swap-ticker`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-API-KEY": import.meta.env.VITE_STOCKNEAR_API_KEY
|
||||
"X-API-KEY": data?.apiKey
|
||||
},
|
||||
body: JSON.stringify({ ticker })
|
||||
});
|
||||
|
||||
@ -1,26 +1,12 @@
|
||||
|
||||
<script lang ='ts'>
|
||||
import { displayCompanyName, trendAnalysisComponent, stockTicker, etfTicker, cryptoTicker, assetType, userRegion, getCache, setCache} from '$lib/store';
|
||||
import { displayCompanyName, trendAnalysisComponent, stockTicker, etfTicker, cryptoTicker, assetType, getCache, setCache} from '$lib/store';
|
||||
import InfoModal from '$lib/components/InfoModal.svelte';
|
||||
//import Chart from '$lib/components/Chart.svelte';
|
||||
//import Lazy from 'svelte-lazy';
|
||||
|
||||
let trendList = [];
|
||||
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;
|
||||
|
||||
@ -50,10 +36,10 @@ const getTrendAnalysis = async (ticker) => {
|
||||
|
||||
const postData = {'ticker': ticker};
|
||||
// make the POST request to the endpoint
|
||||
const response = await fetch(apiURL + '/trend-analysis', {
|
||||
const response = await fetch(data?.apiURL + '/trend-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)
|
||||
});
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
|
||||
<script lang ='ts'>
|
||||
import { varComponent, displayCompanyName, stockTicker, etfTicker, cryptoTicker, userRegion, assetType, getCache, setCache} from '$lib/store';
|
||||
import { varComponent, displayCompanyName, stockTicker, etfTicker, cryptoTicker, assetType, getCache, setCache} from '$lib/store';
|
||||
import InfoModal from '$lib/components/InfoModal.svelte';
|
||||
|
||||
export let data;
|
||||
@ -11,20 +11,6 @@
|
||||
let valueAtRisk;
|
||||
let varDict = {}
|
||||
|
||||
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 getVaR = async (ticker) => {
|
||||
// Get cached data for the specific tickerID
|
||||
@ -35,10 +21,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 + '/value-at-risk', {
|
||||
const response = await fetch(data?.apiURL + '/value-at-risk', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
||||
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
|
||||
},
|
||||
body: JSON.stringify(postData)
|
||||
});
|
||||
|
||||
@ -8,6 +8,9 @@ export const load = ({ locals, cookies }) => {
|
||||
user: locals.user,
|
||||
region: locals.region,
|
||||
cookieConsent: consent,
|
||||
apiURL: locals.apiURL,
|
||||
fastifyURL: locals.fastifyURL,
|
||||
apiKey: locals.apiKey,
|
||||
};
|
||||
}
|
||||
|
||||
@ -17,6 +20,9 @@ export const load = ({ locals, cookies }) => {
|
||||
user: undefined,
|
||||
region: locals.region,
|
||||
cookieConsent: consent,
|
||||
apiURL: locals.apiURL,
|
||||
fastifyURL: locals.fastifyURL,
|
||||
apiKey: locals.apiKey,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
|
||||
let companyName;
|
||||
let apiKey = import.meta.env.VITE_STOCKNEAR_API_KEY;
|
||||
|
||||
function cleanString(input) {
|
||||
// Define a list of substrings to remove (case insensitive)
|
||||
@ -29,7 +28,7 @@ function cleanString(input) {
|
||||
return input?.replace(pattern, '')?.trim();
|
||||
}
|
||||
|
||||
const fetchData = async (apiURL, endpoint, ticker) => {
|
||||
const fetchData = async (apiURL, apiKey, endpoint, ticker) => {
|
||||
|
||||
const postData = {
|
||||
ticker: ticker
|
||||
@ -121,33 +120,32 @@ export const load = async ({ params, locals, cookies, setHeaders}) => {
|
||||
|
||||
const userRegion = locals?.region?.split("::")[0];
|
||||
|
||||
let apiURL;
|
||||
|
||||
let fastifyURL;
|
||||
let apiURL = locals?.apiURL;
|
||||
let fastifyURL = locals?.fastifyURL;
|
||||
let apiKey = locals?.apiKey;
|
||||
let wsURL;
|
||||
|
||||
if (usRegion?.includes(userRegion)) {
|
||||
apiURL = import.meta.env.VITE_USEAST_API_URL;
|
||||
fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
|
||||
wsURL = import.meta.env.VITE_USEAST_WS_URL;
|
||||
} else {
|
||||
apiURL = import.meta.env.VITE_EU_API_URL;
|
||||
fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
wsURL = import.meta.env.VITE_EU_WS_URL;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
const promises = [
|
||||
fetchData(apiURL,'/fair-price',params.tickerID),
|
||||
fetchData(apiURL,'/similar-stocks',params.tickerID),
|
||||
fetchData(apiURL,'/stockdeck',params.tickerID),
|
||||
fetchData(apiURL,'/stock-correlation',params.tickerID),
|
||||
fetchData(apiURL,'/analyst-summary-rating',params.tickerID),
|
||||
fetchData(apiURL,'/stock-quote',params.tickerID),
|
||||
fetchData(apiURL,'/stock-rating',params.tickerID),
|
||||
fetchData(apiURL,'/bull-bear-say',params.tickerID),
|
||||
fetchData(apiURL,'/wiim',params.tickerID),
|
||||
fetchData(apiURL,'/top-etf-ticker-holder',params.tickerID),
|
||||
fetchData(apiURL,'/one-day-price',params.tickerID),
|
||||
fetchData(apiURL,apiKey, '/fair-price',params.tickerID),
|
||||
fetchData(apiURL,apiKey, '/similar-stocks',params.tickerID),
|
||||
fetchData(apiURL,apiKey, '/stockdeck',params.tickerID),
|
||||
fetchData(apiURL,apiKey, '/stock-correlation',params.tickerID),
|
||||
fetchData(apiURL,apiKey, '/analyst-summary-rating',params.tickerID),
|
||||
fetchData(apiURL,apiKey, '/stock-quote',params.tickerID),
|
||||
fetchData(apiURL,apiKey, '/stock-rating',params.tickerID),
|
||||
fetchData(apiURL,apiKey, '/bull-bear-say',params.tickerID),
|
||||
fetchData(apiURL,apiKey, '/wiim',params.tickerID),
|
||||
fetchData(apiURL,apiKey, '/top-etf-ticker-holder',params.tickerID),
|
||||
fetchData(apiURL,apiKey, '/one-day-price',params.tickerID),
|
||||
fetchWatchlist(fastifyURL, locals?.user?.id),
|
||||
fetchPortfolio(fastifyURL, locals?.user?.id),
|
||||
fetchCommunitySentiment(locals?.pb, params.tickerID, cookies)
|
||||
@ -192,6 +190,7 @@ export const load = async ({ params, locals, cookies, setHeaders}) => {
|
||||
getUserPortfolio,
|
||||
getCommunitySentiment,
|
||||
companyName,
|
||||
wsURL,
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<script lang='ts'>
|
||||
|
||||
import {searchBarData, userRegion, globalForm, screenWidth, openPriceAlert, currentPortfolioPrice, realtimePrice, isCrosshairMoveActive, currentPrice, priceIncrease, displayCompanyName, traded, stockTicker, isOpen } from '$lib/store';
|
||||
import {searchBarData, globalForm, screenWidth, openPriceAlert, currentPortfolioPrice, realtimePrice, isCrosshairMoveActive, currentPrice, priceIncrease, displayCompanyName, traded, stockTicker, isOpen } from '$lib/store';
|
||||
|
||||
import { onMount, onDestroy, afterUpdate} from "svelte";
|
||||
import { goto } from '$app/navigation';
|
||||
@ -15,24 +15,6 @@
|
||||
$realtimePrice = null;
|
||||
|
||||
|
||||
const usRegion = ['cle1','iad1','pdx1','sfo1'];
|
||||
let fastifyURL;
|
||||
let wsURL;
|
||||
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;
|
||||
fastifyURL = import.meta.env.VITE_USEAST_FASTIFY_URL;
|
||||
wsURL = import.meta.env.VITE_USEAST_WS_URL;
|
||||
} else {
|
||||
apiURL = import.meta.env.VITE_EU_API_URL;
|
||||
fastifyURL = import.meta.env.VITE_EU_FASTIFY_URL;
|
||||
wsURL = import.meta.env.VITE_EU_WS_URL;
|
||||
}
|
||||
});
|
||||
|
||||
async function loadSearchData() {
|
||||
|
||||
@ -43,10 +25,10 @@ async function loadSearchData() {
|
||||
else {
|
||||
|
||||
// make the GET request to the endpoint
|
||||
const response = await fetch(apiURL+'/searchbar-data', {
|
||||
const response = await fetch(data?.apiURL+'/searchbar-data', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
"Content-Type": "application/json","X-API-KEY": apiKey
|
||||
"Content-Type": "application/json","X-API-KEY": data?.apiKey
|
||||
},
|
||||
});
|
||||
|
||||
@ -180,7 +162,7 @@ async function toggleUserWatchlist(watchListId: string) {
|
||||
'ticker': $stockTicker,
|
||||
};
|
||||
|
||||
const response = await fetch(fastifyURL + '/update-watchlist', {
|
||||
const response = await fetch(data?.fastifyURL + '/update-watchlist', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@ -215,7 +197,7 @@ async function fetchPortfolio()
|
||||
{
|
||||
const postData = {'userId': data?.user?.id};
|
||||
|
||||
const response = await fetch(fastifyURL+'/get-portfolio-data', {
|
||||
const response = await fetch(data?.fastifyURL+'/get-portfolio-data', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
@ -250,7 +232,7 @@ async function websocketRealtimeData() {
|
||||
|
||||
previousTicker = $stockTicker;
|
||||
try {
|
||||
socket = new WebSocket(wsURL+"/realtime-data");
|
||||
socket = new WebSocket(data?.wsURL+"/realtime-data");
|
||||
|
||||
socket.addEventListener('open', () => {
|
||||
//console.log('WebSocket connection opened');
|
||||
|
||||
@ -24,6 +24,7 @@ import { displayCompanyName, stockTicker, assetType, isOpen, isAfterMarketClose,
|
||||
|
||||
export const load = async ({ params, data }) => {
|
||||
|
||||
|
||||
stockTicker.update( value => params.tickerID?.toUpperCase());
|
||||
assetType.update( value => 'stock');
|
||||
|
||||
|
||||
@ -3,25 +3,12 @@
|
||||
import {AreaSeries, Chart, PriceLine, CandlestickSeries} from 'svelte-lightweight-charts';
|
||||
|
||||
import { TrackingModeExitMode } from 'lightweight-charts';
|
||||
import {getCache, setCache, swapComponent, analystInsightComponent, governmentContractComponent, optionsNetFlowComponent, impliedVolatilityComponent, borrowedShareComponent, clinicalTrialComponent, optionComponent, failToDeliverComponent, marketMakerComponent, analystEstimateComponent, sentimentComponent, screenWidth, displayCompanyName, numberOfUnreadNotification, globalForm, varComponent, shareStatisticsComponent, enterpriseComponent, darkPoolComponent, retailVolumeComponent, shareholderComponent, trendAnalysisComponent, revenueSegmentationComponent, priceAnalysisComponent, fundamentalAnalysisComponent, userRegion, isCrosshairMoveActive, realtimePrice, priceIncrease, currentPortfolioPrice, currentPrice, stockTicker, isOpen, isBeforeMarketOpen, isWeekend} from '$lib/store';
|
||||
import {getCache, setCache, swapComponent, analystInsightComponent, governmentContractComponent, optionsNetFlowComponent, impliedVolatilityComponent, borrowedShareComponent, clinicalTrialComponent, optionComponent, failToDeliverComponent, marketMakerComponent, analystEstimateComponent, sentimentComponent, screenWidth, displayCompanyName, numberOfUnreadNotification, globalForm, varComponent, shareStatisticsComponent, enterpriseComponent, darkPoolComponent, retailVolumeComponent, shareholderComponent, trendAnalysisComponent, revenueSegmentationComponent, priceAnalysisComponent, fundamentalAnalysisComponent, isCrosshairMoveActive, realtimePrice, priceIncrease, currentPortfolioPrice, currentPrice, stockTicker, isOpen, isBeforeMarketOpen, isWeekend} from '$lib/store';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import BullBearSay from '$lib/components/BullBearSay.svelte';
|
||||
import CommunitySentiment from '$lib/components/CommunitySentiment.svelte';
|
||||
import Lazy from '$lib/components/Lazy.svelte';
|
||||
|
||||
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;
|
||||
export let form;
|
||||
@ -333,10 +320,10 @@ async function historicalPrice(timePeriod:string) {
|
||||
timePeriod: timePeriod,
|
||||
};
|
||||
|
||||
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)
|
||||
});
|
||||
@ -430,10 +417,10 @@ async function getPrePostQuote() {
|
||||
|
||||
if(!$isOpen) {
|
||||
const postData = { ticker: $stockTicker};
|
||||
const response = await fetch(apiURL+'/pre-post-quote', {
|
||||
const response = await fetch(data?.apiURL+'/pre-post-quote', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
||||
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
|
||||
},
|
||||
body: JSON.stringify(postData)
|
||||
});
|
||||
@ -1369,7 +1356,7 @@ function changeChartType() {
|
||||
<Lazy>
|
||||
<div class="w-full pt-10 sm:pl-6 sm:pb-6 sm:pt-6 m-auto {!$revenueSegmentationComponent ? 'hidden' : ''}">
|
||||
{#await import('$lib/components/RevenueSegmentation.svelte') then {default: Comp}}
|
||||
<svelte:component this={Comp} userTier={data?.user?.tier}/>
|
||||
<svelte:component this={Comp} apiURL={data?.apiURL} apiKey={data?.apiKey} userTier={data?.user?.tier}/>
|
||||
{/await}
|
||||
</div>
|
||||
</Lazy>
|
||||
|
||||
@ -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 getQuantStats = async () => {
|
||||
@ -24,15 +13,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 + '/get-quant-stats', {
|
||||
const response = await fetch(data?.apiURL + '/get-quant-stats', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
||||
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
|
||||
},
|
||||
body: JSON.stringify(postData)
|
||||
});
|
||||
|
||||
@ -1,35 +1,25 @@
|
||||
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 getHistoryEmployee = async () => {
|
||||
let output;
|
||||
|
||||
// Get cached data for the specific tickerID
|
||||
const cachedData = getCache(params.tickerID, 'getHistoryEmployee');
|
||||
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 + '/history-employees', {
|
||||
const response = await fetch(data?.apiURL + '/history-employees', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json", "X-API-KEY": apiKey
|
||||
"Content-Type": "application/json", "X-API-KEY": data?.apiKey
|
||||
},
|
||||
body: JSON.stringify(postData)
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user