This commit is contained in:
MuslemRahimi 2024-09-13 13:14:12 +02:00
parent 137fcfb480
commit 0cb3651309

View File

@ -373,10 +373,14 @@ function handleViewData(optionData) {
previousCallVolume = displayCallVolume ?? 0; previousCallVolume = displayCallVolume ?? 0;
if(mode === true) { if(mode === true) {
try { try {
const newData = JSON.parse(event.data); let newData = JSON.parse(event.data);
if(rawData?.length !== newData?.length) { if(rawData?.length !== newData?.length) {
newIncomingData = true; newIncomingData = true;
} }
newData = newData?.forEach((item) => {
item.dte = daysLeft(item?.date_expiration);
});
rawData = [...newData]; rawData = [...newData];
if(ruleOfList?.length !== 0 || filterQuery?.length !== 0) { if(ruleOfList?.length !== 0 || filterQuery?.length !== 0) {
@ -405,10 +409,24 @@ function handleViewData(optionData) {
} }
function daysLeft(targetDate) {
const targetTime = new Date(targetDate).getTime();
const currentTime = new Date().getTime();
const difference = targetTime - currentTime;
const millisecondsPerDay = 1000 * 60 * 60 * 24;
const daysLeft = Math?.ceil(difference / millisecondsPerDay);
return daysLeft;
}
onMount(async () => { onMount(async () => {
audio = new Audio(notifySound); audio = new Audio(notifySound);
rawData = data?.getOptionsFlowFeed; rawData = data?.getOptionsFlowFeed;
rawData?.forEach((item) => {
item.dte = daysLeft(item?.date_expiration);
});
displayedData = rawData; displayedData = rawData;
calculateStats(rawData); calculateStats(rawData);
@ -1059,6 +1077,7 @@ $: {
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">
<!-- Table headers -->
<div class="td bg-[#161618] text-slate-300 font-bold text-xs text-start uppercase">Time</div> <div class="td bg-[#161618] text-slate-300 font-bold text-xs text-start uppercase">Time</div>
<div class="td bg-[#161618] font-bold text-slate-300 text-xs text-start uppercase">Symbol</div> <div class="td bg-[#161618] font-bold text-slate-300 text-xs text-start uppercase">Symbol</div>
<div class="td bg-[#161618] text-slate-300 font-bold text-xs text-start uppercase">Expiry</div> <div class="td bg-[#161618] text-slate-300 font-bold text-xs text-start uppercase">Expiry</div>
@ -1073,9 +1092,15 @@ $: {
<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(displayedData[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 {index % 2 === 0 ? 'bg-[#27272A]' : 'bg-[#09090B]'}"
>
<!-- Row data -->
<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(displayedData[index]?.time)} {formatTime(displayedData[index]?.time)}
</div> </div>
@ -1085,7 +1110,7 @@ $: {
</div> </div>
<div style="justify-content: center;" class="td text-sm sm:text-[1rem] text-white text-start"> <div style="justify-content: center;" class="td text-sm sm:text-[1rem] text-white text-start">
{reformatDate(displayedData[index]?.date_expiration)} {displayedData[index]?.dte < 0 ? 'expired' : displayedData[index]?.dte + 'd'}
</div> </div>
<div style="justify-content: center;" class="td text-sm sm:text-[1rem] text-white text-start"> <div style="justify-content: center;" class="td text-sm sm:text-[1rem] text-white text-start">
@ -1108,7 +1133,7 @@ $: {
{displayedData[index]?.price} {displayedData[index]?.price}
</div> </div>
<div style="justify-content: center;" class="td text-sm sm:text-[1rem] text-start font-semibold {displayedData[index]?.put_call === 'Puts' ? 'text-[#CB281C]' : 'text-[#0FB307]'} "> <div style="justify-content: center;" class="td text-sm sm:text-[1rem] text-start font-semibold {displayedData[index]?.put_call === 'Puts' ? 'text-[#CB281C]' : 'text-[#0FB307]'}">
{abbreviateNumber(displayedData[index]?.cost_basis)} {abbreviateNumber(displayedData[index]?.cost_basis)}
</div> </div>
@ -1117,26 +1142,16 @@ $: {
</div> </div>
<div style="justify-content: center;" class="td text-sm sm:text-[1rem] text-white text-end"> <div style="justify-content: center;" class="td text-sm sm:text-[1rem] text-white text-end">
{new Intl.NumberFormat("en", { {new Intl.NumberFormat('en', { minimumFractionDigits: 0, maximumFractionDigits: 0 }).format(displayedData[index]?.volume)}
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(displayedData[index]?.volume)}
</div> </div>
<div style="justify-content: center;" class="td text-sm sm:text-[1rem] text-white text-end"> <div style="justify-content: center;" class="td text-sm sm:text-[1rem] text-white text-end">
{new Intl.NumberFormat("en", { {new Intl.NumberFormat('en', { minimumFractionDigits: 0, maximumFractionDigits: 0 }).format(displayedData[index]?.open_interest)}
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(displayedData[index]?.open_interest)}
</div> </div>
</div> </div>
</VirtualList> </VirtualList>
</div> </div>
</div> </div>
<!--<InfiniteLoading on:infinite={infiniteHandler} />-->
</div> </div>
{:else} {:else}
<div class="text-white text-center p-3 sm:p-5 mb-10 rounded-lg sm:flex sm:flex-row sm:items-center border border-slate-800 text-sm sm:text-[1rem]"> <div class="text-white text-center p-3 sm:p-5 mb-10 rounded-lg sm:flex sm:flex-row sm:items-center border border-slate-800 text-sm sm:text-[1rem]">
@ -1462,11 +1477,11 @@ $: {
flex-flow: row nowrap; flex-flow: row nowrap;
} }
.tr:nth-of-type(even) { .tr.even {
background-color: #27272A; background-color: #27272A;
} }
.tr:nth-of-type(odd) { .tr.odd {
background-color: #09090B; background-color: #09090B;
} }