refactor code

This commit is contained in:
MuslemRahimi 2024-11-04 18:59:12 +01:00
parent 6a308b41fa
commit 1e0c87b378

View File

@ -360,10 +360,6 @@
let displayPutVolume;
let callPercentage;
let putPercentage;
let mostFrequentTicker;
let highestVolumeTicker;
let highestPremiumTicker;
let highestOpenInterestTicker;
let audio;
let muted = false;
@ -372,7 +368,6 @@
let notFound = false;
let isLoaded = false;
let mode = $isOpen === true ? true : false;
let showMore = false;
let optionSymbol;
let optionDescription;
@ -663,84 +658,6 @@ function sendMessage(message) {
displayCallVolume = callVolumeSum;
displayPutVolume = putVolumeSum;
mostFrequentTicker = findMostFrequentTicker(data);
highestVolumeTicker = findHighestVolume(data);
highestPremiumTicker = findHighestCostBasis(data);
highestOpenInterestTicker = findHighestOpenInterest(data);
}
function findMostFrequentTicker(data) {
const tickerCountMap = new Map();
// Iterate through the data and update the count for each ticker
data?.forEach((item) => {
const ticker = item?.ticker;
if (tickerCountMap?.has(ticker)) {
tickerCountMap?.set(ticker, tickerCountMap?.get(ticker) + 1);
} else {
tickerCountMap?.set(ticker, 1);
}
});
let maxTicker;
let maxCount = -1;
// Find the ticker with the highest count
tickerCountMap?.forEach((count, ticker) => {
if (count > maxCount) {
maxCount = count;
maxTicker = ticker;
}
});
return { ticker: maxTicker, count: maxCount };
}
function findHighestVolume(data) {
let maxVolume = -1;
let maxVolumeTicker = null;
// Iterate through the data and find the ticker with the highest volume
data?.forEach((item) => {
const volume = parseInt(item?.volume); // Assuming volume is a string, parse it to an integer
if (volume > maxVolume) {
maxVolume = volume;
maxVolumeTicker = item?.ticker;
}
});
return { ticker: maxVolumeTicker, volume: maxVolume };
}
function findHighestCostBasis(data) {
let maxCostBasis = -1;
let maxCostBasisTicker = null;
// Iterate through the data and find the ticker with the highest cost basis
data?.forEach((item) => {
if (item?.cost_basis > maxCostBasis) {
maxCostBasis = item?.cost_basis;
maxCostBasisTicker = item?.ticker;
}
});
return { ticker: maxCostBasisTicker, costBasis: maxCostBasis };
}
function findHighestOpenInterest(data) {
let maxOpenInterest = -1;
let maxOpenInterestTicker = null;
// Iterate through the data and find the ticker with the highest open interest
data?.forEach((item) => {
const openInterest = parseInt(item?.open_interest); // Assuming open interest is a string, parse it to an integer
if (openInterest > maxOpenInterest) {
maxOpenInterest = openInterest;
maxOpenInterestTicker = item?.ticker;
}
});
return { ticker: maxOpenInterestTicker, openInterest: maxOpenInterest };
}
const getHistoricalFlow = async () => {
@ -1653,87 +1570,9 @@ function sendMessage(message) {
</div>
<!-- End Circular Progress -->
</div>
<!--End Put Flow-->
<!--
{#if showMore}
<div class="flex flex-row items-center flex-wrap w-full px-5 bg-[#262626] shadow-lg rounded-md h-20">
<div class="flex flex-col items-start">
<span class="font-semibold text-gray-200 text-sm sm:text-[1rem] ">Most Traded Option</span>
<span class="text-start text-[1rem] font-semibold text-white mt-0.5">
<span class="text-blue-400 ">
{mostFrequentTicker?.ticker}
</span>
{new Intl.NumberFormat("en", {
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(mostFrequentTicker?.count)}
</span>
</div>
</div>
<div class="flex flex-row items-center flex-wrap w-full px-5 bg-[#262626] shadow-lg rounded-md h-20">
<div class="flex flex-col items-start">
<span class="font-semibold text-gray-200 text-sm sm:text-[1rem] ">Highest Premium</span>
<span class="text-start text-[1rem] font-semibold text-white mt-0.5">
<span class="text-blue-400 ">
{highestPremiumTicker?.ticker}
</span>
${new Intl.NumberFormat("en", {
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(highestPremiumTicker?.costBasis)}
</span>
</div>
</div>
<div class="flex flex-row items-center flex-wrap w-full px-5 bg-[#262626] shadow-lg rounded-md h-20">
<div class="flex flex-col items-start">
<span class="font-semibold text-gray-200 text-sm sm:text-[1rem] ">Highest Volume</span>
<span class="text-start text-[1rem] font-semibold text-white mt-0.5">
<span class="text-blue-400 ">
{highestVolumeTicker?.ticker}
</span>
{new Intl.NumberFormat("en", {
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(highestVolumeTicker?.volume)}
</span>
</div>
</div>
<div class="flex flex-row items-center flex-wrap w-full px-5 bg-[#262626] shadow-lg rounded-md h-20">
<div class="flex flex-col items-start">
<span class="font-semibold text-gray-200 text-sm sm:text-[1rem] ">Highest Open Interest</span>
<span class="text-start text-[1rem] font-semibold text-white mt-0.5">
<span class="text-blue-400 ">
{highestOpenInterestTicker?.ticker}
</span>
{new Intl.NumberFormat("en", {
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(highestOpenInterestTicker?.openInterest)}
</span>
</div>
</div>
{/if}
-->
</div>
</div>
<!--Start Expand-->
<!--
<label on:click={() => showMore=!showMore} class="cursor-pointer w-full flex justify-center items-center -mt-5 transition duration-150 ease-in-out group">
<div class="tracking-normal group-hover:translate-y-0.5 transition-transform duration-150 ease-in-out">
<svg class="w-10 h-10 {showMore ? 'rotate-180' : ''}" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="white" d="M12 14.373q-.162 0-.298-.053q-.137-.053-.267-.183L7.046 9.748q-.14-.14-.15-.344q-.01-.204.15-.364t.354-.16t.354.16L12 13.287l4.246-4.247q.14-.14.344-.15q.204-.01.364.15t.16.354q0 .194-.16.354l-4.389 4.389q-.13.13-.267.183q-.136.053-.298.053"/></svg>
</div>
</label>
-->
<!--End Expand-->
<!-- Page wrapper -->
<div class="flex w-full m-auto h-full overflow-hidden">
{#if displayedData?.length !== 0}