bugfixing options flow page

This commit is contained in:
MuslemRahimi 2024-08-03 09:43:31 +02:00
parent 4a688ee38a
commit 8ac1c1ad13

View File

@ -14,6 +14,7 @@
let rawData = []; let rawData = [];
let filterList = []; let filterList = [];
let displayedData =[];
let flowSentiment; let flowSentiment;
let putCallRatio; let putCallRatio;
@ -35,7 +36,6 @@
let isLoaded = false; let isLoaded = false;
let mode = $isOpen === true ? true : false; let mode = $isOpen === true ? true : false;
let showMore = false; let showMore = false;
let newIncomingData = false;
let optionSymbol; let optionSymbol;
let optionDescription; let optionDescription;
@ -140,65 +140,48 @@ function handleViewData(optionData) {
socket.addEventListener('message', (event) => { socket.addEventListener('message', (event) => {
previousCallVolume = displayCallVolume ?? 0; previousCallVolume = displayCallVolume ?? 0;
if(mode === true) { if(mode === true) {
try { try {
const newData = JSON.parse(event.data); const newData = JSON.parse(event.data);
if(rawData?.length !== newData?.length) { if(rawData?.length !== newData?.length) {
newIncomingData = true; newIncomingData = true;
} }
rawData = [...newData];
rawData = [...newData]; // Apply current filters to the new rawData
let filteredData = rawData;
// Apply filterQuery if it exists
if (filterQuery?.length !== 0) {
filteredData = filteredData.filter(item => item?.ticker === filterQuery?.toUpperCase());
}
// Variables to track filter status // Apply filterList if it exists
let queryFilteredData = rawData; if (filterList?.length !== 0) {
let listFilteredData = rawData; filteredData = filterExpiringSoon(filteredData, Math.max(...filterList));
}
// Apply filterQuery if it exists if (filteredData.length !== 0) {
if (filterQuery?.length !== 0) { notFound = false;
queryFilteredData = rawData.filter(item => item?.ticker === filterQuery?.toUpperCase()); } else {
} notFound = true;
}
// Apply filterList if it exists // Update displayedData instead of rawData
if (filterList?.length !== 0) { displayedData = filteredData;
listFilteredData = filterExpiringSoon(rawData, Math.max(...filterList));
}
// Determine the final filtered data based on both filters calculateStats(displayedData);
if (filterQuery?.length !== 0 && filterList?.length !== 0) {
rawData = queryFilteredData.filter(item => listFilteredData.includes(item));
} else if (filterQuery?.length !== 0) {
rawData = queryFilteredData;
} else if (filterList?.length !== 0) {
rawData = listFilteredData;
}
if (rawData?.length !== 0 && newIncomingData === true) { if (previousCallVolume !== displayCallVolume && !muted) {
notFound = false; audio?.play();
newIncomingData = false; }
} else if (!newIncomingData) { }
notFound = false; catch(e) {
newIncomingData = false; console.log(e)
} else { }
notFound = true; }
newIncomingData = false; });
rawData = data?.getOptionsFlowFeed ?? [];
}
calculateStats(rawData);
if (previousCallVolume !== displayCallVolume && !muted) {
audio?.play();
}
}
catch(e) {
console.log(e)
}
}
});
socket.addEventListener('close', (event) => { socket.addEventListener('close', (event) => {
@ -212,12 +195,11 @@ function handleViewData(optionData) {
} }
let scrollContainer;
onMount(async () => { onMount(async () => {
audio = new Audio(notifySound); audio = new Audio(notifySound);
rawData = data?.getOptionsFlowFeed; rawData = data?.getOptionsFlowFeed;
displayedData = rawData;
calculateStats(rawData); calculateStats(rawData);
isLoaded = true; isLoaded = true;
@ -384,27 +366,26 @@ function calculateStats(data) {
} }
function handleInput(event) { function handleInput(event) {
filterQuery = event.target.value; filterQuery = event.target.value;
let newData = [];
setTimeout(() => { setTimeout(() => {
let filteredData = rawData;
if (filterQuery?.length !== 0) { if (filterQuery?.length !== 0) {
newData = [...rawData?.filter(item => item?.ticker === filterQuery?.toUpperCase())]; filteredData = rawData.filter(item => item?.ticker === filterQuery?.toUpperCase());
if (newData?.length !== 0) {
rawData = newData;
notFound = false;
} else {
notFound = true;
rawData = data?.getOptionsFlowFeed;
}
} else {
notFound = false;
rawData = data?.getOptionsFlowFeed;
} }
calculateStats(rawData); if (filteredData.length !== 0) {
notFound = false;
} else {
notFound = true;
}
// Update a separate variable for displayed data, not rawData itself
displayedData = filteredData;
calculateStats(displayedData);
}, 200); }, 200);
} }
@ -418,7 +399,7 @@ function debounce(fn, delay) {
}; };
} }
const debouncedHandleInput = debounce(handleInput, 200); const debouncedHandleInput = debounce(handleInput, 300);
async function handleFilter(newFilter) { async function handleFilter(newFilter) {
@ -809,7 +790,7 @@ $: {
<VirtualList <VirtualList
width="100%" width="100%"
height={850} height={850}
itemCount={rawData.length} itemCount={displayedData.length}
itemSize={40} itemSize={40}
> >
<div slot="header" class="tr th sticky z-40 top-0"> <div slot="header" class="tr th sticky z-40 top-0">
@ -827,61 +808,61 @@ $: {
<div class="td bg-[#161618] text-slate-300 font-bold text-xs text-end uppercase">OI</div> <div class="td bg-[#161618] text-slate-300 font-bold text-xs text-end uppercase">OI</div>
</div> </div>
<div on:click={() => handleViewData(rawData[index])} slot="item" let:index let:style {style} class="tr cursor-pointer"> <div on:click={() => handleViewData(displayedData[index])} slot="item" let:index let:style {style} class="tr cursor-pointer">
<div style="justify-content: center;" class="td text-white pb-3 text-xs sm:text-sm text-start"> <div style="justify-content: center;" class="td text-white pb-3 text-xs sm:text-sm text-start">
{formatTime(rawData[index]?.time)} {formatTime(displayedData[index]?.time)}
</div> </div>
<div on:click|stopPropagation={() => assetSelector(rawData[index]?.ticker, rawData[index]?.assetType)} style="justify-content: center;" class="td text-sm text-blue-400 font-normal"> <div on:click|stopPropagation={() => assetSelector(displayedData[index]?.ticker, displayedData[index]?.assetType)} style="justify-content: center;" class="td text-sm text-blue-400 font-normal">
{rawData[index]?.ticker} {displayedData[index]?.ticker}
</div> </div>
<div style="justify-content: center;" class="td text-sm text-white text-start"> <div style="justify-content: center;" class="td text-sm text-white text-start">
{reformatDate(rawData[index]?.date_expiration)} {reformatDate(displayedData[index]?.date_expiration)}
</div> </div>
<div style="justify-content: center;" class="td text-sm text-white text-start"> <div style="justify-content: center;" class="td text-sm text-white text-start">
{rawData[index]?.strike_price} {displayedData[index]?.strike_price}
</div> </div>
<div style="justify-content: center;" class="td text-sm {rawData[index]?.put_call === 'Calls' ? 'text-[#00FC50]' : 'text-[#FC2120]'} text-start"> <div style="justify-content: center;" class="td text-sm {displayedData[index]?.put_call === 'Calls' ? 'text-[#00FC50]' : 'text-[#FC2120]'} text-start">
{rawData[index]?.put_call} {displayedData[index]?.put_call}
</div> </div>
<div style="justify-content: center;" class="td text-sm {rawData[index]?.sentiment === 'Bullish' ? 'text-[#00FC50]' : rawData[index]?.sentiment === 'Bearish' ? 'text-[#FC2120]' : 'text-[#C6A755]'} text-start"> <div style="justify-content: center;" class="td text-sm {displayedData[index]?.sentiment === 'Bullish' ? 'text-[#00FC50]' : displayedData[index]?.sentiment === 'Bearish' ? 'text-[#FC2120]' : 'text-[#C6A755]'} text-start">
{rawData[index]?.sentiment} {displayedData[index]?.sentiment}
</div> </div>
<div style="justify-content: center;" class="td text-sm text-start text-white"> <div style="justify-content: center;" class="td text-sm text-start text-white">
{rawData[index]?.underlying_price} {displayedData[index]?.underlying_price}
</div> </div>
<div style="justify-content: center;" class="td text-sm text-start text-white"> <div style="justify-content: center;" class="td text-sm text-start text-white">
{rawData[index]?.price} {displayedData[index]?.price}
</div> </div>
<div style="justify-content: center;" class="td text-sm text-start font-semibold {rawData[index]?.put_call === 'Puts' ? 'text-[#CB281C]' : 'text-[#0FB307]'} "> <div style="justify-content: center;" class="td text-sm text-start font-semibold {displayedData[index]?.put_call === 'Puts' ? 'text-[#CB281C]' : 'text-[#0FB307]'} ">
{abbreviateNumber(rawData[index]?.cost_basis)} {abbreviateNumber(displayedData[index]?.cost_basis)}
</div> </div>
<div style="justify-content: center;" class="td text-sm text-start {rawData[index]?.type === 'Sweep' ? 'text-[#C6A755]' : 'text-[#976DB7]'}"> <div style="justify-content: center;" class="td text-sm text-start {displayedData[index]?.type === 'Sweep' ? 'text-[#C6A755]' : 'text-[#976DB7]'}">
{rawData[index]?.type} {displayedData[index]?.type}
</div> </div>
<div style="justify-content: center;" class="td text-sm text-white text-end"> <div style="justify-content: center;" class="td text-sm text-white text-end">
{new Intl.NumberFormat("en", { {new Intl.NumberFormat("en", {
minimumFractionDigits: 0, minimumFractionDigits: 0,
maximumFractionDigits: 0 maximumFractionDigits: 0
}).format(rawData[index]?.volume)} }).format(displayedData[index]?.volume)}
</div> </div>
<div style="justify-content: center;" class="td text-sm text-white text-end"> <div style="justify-content: center;" class="td text-sm text-white text-end">
{new Intl.NumberFormat("en", { {new Intl.NumberFormat("en", {
minimumFractionDigits: 0, minimumFractionDigits: 0,
maximumFractionDigits: 0 maximumFractionDigits: 0
}).format(rawData[index]?.open_interest)} }).format(displayedData[index]?.open_interest)}
</div> </div>
</div> </div>