optimize data loading for market mover page

This commit is contained in:
MuslemRahimi 2024-11-20 23:58:50 +01:00
parent f17326af7b
commit 77b0bab391
29 changed files with 156 additions and 48 deletions

View File

@ -1,22 +1,26 @@
export const load = async ({ locals }) => {
const { apiURL, apiKey } = locals;
const getMarketMover = async () => {
const response = await fetch(apiURL + "/market-movers", {
method: "GET",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
});
const output = await response.json();
return output;
};
return {
getMarketMover: await getMarketMover(),
};
};
export const load = async ({ locals, setHeaders }) => {
const { apiURL, apiKey } = locals;
const getMarketMover = async () => {
const postData = {'params': 'active'};
const response = await fetch(apiURL + "/market-movers", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData)
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=60*5" });
return output;
};
return {
getMarketMover: await getMarketMover(),
};
};

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.active["1D"];
let rawData = data?.getMarketMover["1D"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.active["3Y"];
let rawData = data?.getMarketMover["3Y"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.active["5Y"];
let rawData = data?.getMarketMover["5Y"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.active["1M"];
let rawData = data?.getMarketMover["1M"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.active["1W"];
let rawData = data?.getMarketMover["1W"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.active["1Y"];
let rawData = data?.getMarketMover["1Y"];
let excludedRules = new Set([
"volume",

View File

@ -0,0 +1,25 @@
export const load = async ({ locals, setHeaders }) => {
const { apiURL, apiKey } = locals;
const getMarketMover = async () => {
const postData = { category: "afterhours", params: 'gainers' };
const response = await fetch(apiURL + "/pre-after-market-movers", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=60*5" });
return output;
};
return {
getMarketMover: await getMarketMover(),
};
};

View File

@ -2,7 +2,7 @@
import Table from "$lib/components/Table/Table.svelte";
export let data;
let rawData = data?.getMarketMover?.gainers;
let rawData = data?.getMarketMover;
const excludedRules = new Set([
"volume",

View File

@ -1,9 +1,9 @@
export const load = async ({ locals }) => {
export const load = async ({ locals, setHeaders }) => {
const { apiURL, apiKey } = locals;
const getMarketMover = async () => {
const postData = { params: "premarket" };
const postData = { category: "afterhours", params: 'losers' };
const response = await fetch(apiURL + "/pre-after-market-movers", {
method: "POST",
headers: {
@ -14,6 +14,7 @@ export const load = async ({ locals }) => {
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=60*5" });
return output;
};

View File

@ -2,7 +2,7 @@
import Table from "$lib/components/Table/Table.svelte";
export let data;
let rawData = data?.getMarketMover?.losers;
let rawData = data?.getMarketMover;
const excludedRules = new Set([
"volume",

View File

@ -0,0 +1,26 @@
export const load = async ({ locals, setHeaders }) => {
const { apiURL, apiKey } = locals;
const getMarketMover = async () => {
const postData = {'params': 'gainers'};
const response = await fetch(apiURL + "/market-movers", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData)
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=60*5" });
return output;
};
return {
getMarketMover: await getMarketMover(),
};
};

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.gainers["1D"];
let rawData = data?.getMarketMover["1D"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.gainers["3Y"];
let rawData = data?.getMarketMover["3Y"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.gainers["5Y"];
let rawData = data?.getMarketMover["5Y"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.gainers["1M"];
let rawData = data?.getMarketMover["1M"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.gainers["1W"];
let rawData = data?.getMarketMover["1W"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.gainers["1Y"];
let rawData = data?.getMarketMover["1Y"];
let excludedRules = new Set([
"volume",

View File

@ -0,0 +1,26 @@
export const load = async ({ locals, setHeaders }) => {
const { apiURL, apiKey } = locals;
const getMarketMover = async () => {
const postData = {'params': 'losers'};
const response = await fetch(apiURL + "/market-movers", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData)
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=60*5" });
return output;
};
return {
getMarketMover: await getMarketMover(),
};
};

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.losers["1D"];
let rawData = data?.getMarketMover["1D"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.losers["3Y"];
let rawData = data?.getMarketMover["3Y"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.losers["5Y"];
let rawData = data?.getMarketMover["5Y"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.losers["1M"];
let rawData = data?.getMarketMover["1M"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.losers["1W"];
let rawData = data?.getMarketMover["1W"];
let excludedRules = new Set([
"volume",

View File

@ -3,7 +3,7 @@
export let data;
let rawData = data?.getMarketMover?.losers["1Y"];
let rawData = data?.getMarketMover["1Y"];
let excludedRules = new Set([
"volume",

View File

@ -0,0 +1,25 @@
export const load = async ({ locals, setHeaders }) => {
const { apiURL, apiKey } = locals;
const getMarketMover = async () => {
const postData = { category: "premarket", params: 'gainers' };
const response = await fetch(apiURL + "/pre-after-market-movers", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-KEY": apiKey,
},
body: JSON.stringify(postData),
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=60*5" });
return output;
};
return {
getMarketMover: await getMarketMover(),
};
};

View File

@ -2,7 +2,7 @@
import Table from "$lib/components/Table/Table.svelte";
export let data;
let rawData = data?.getMarketMover?.gainers;
let rawData = data?.getMarketMover || [];
const excludedRules = new Set([
"volume",

View File

@ -1,9 +1,9 @@
export const load = async ({ locals }) => {
export const load = async ({ locals, setHeaders }) => {
const { apiURL, apiKey } = locals;
const getMarketMover = async () => {
const postData = { params: "afterhours" };
const postData = { category: "premarket", params: 'losers' };
const response = await fetch(apiURL + "/pre-after-market-movers", {
method: "POST",
headers: {
@ -14,6 +14,7 @@ export const load = async ({ locals }) => {
});
const output = await response.json();
setHeaders({ "cache-control": "public, max-age=60*5" });
return output;
};

View File

@ -2,7 +2,7 @@
import Table from "$lib/components/Table/Table.svelte";
export let data;
let rawData = data?.getMarketMover?.losers;
let rawData = data?.getMarketMover || [];
const excludedRules = new Set([
"volume",