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;
if(mode === true) {
try {
const newData = JSON.parse(event.data);
let newData = JSON.parse(event.data);
if(rawData?.length !== newData?.length) {
newIncomingData = true;
}
newData = newData?.forEach((item) => {
item.dte = daysLeft(item?.date_expiration);
});
rawData = [...newData];
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 () => {
audio = new Audio(notifySound);
rawData = data?.getOptionsFlowFeed;
rawData?.forEach((item) => {
item.dte = daysLeft(item?.date_expiration);
});
displayedData = rawData;
calculateStats(rawData);
@ -1059,6 +1077,7 @@ $: {
itemSize={40}
>
<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] 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>
@ -1073,9 +1092,15 @@ $: {
<div class="td bg-[#161618] text-slate-300 font-bold text-xs text-end uppercase">OI</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">
{formatTime(displayedData[index]?.time)}
</div>
@ -1085,7 +1110,7 @@ $: {
</div>
<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 style="justify-content: center;" class="td text-sm sm:text-[1rem] text-white text-start">
@ -1117,26 +1142,16 @@ $: {
</div>
<div style="justify-content: center;" class="td text-sm sm:text-[1rem] text-white text-end">
{new Intl.NumberFormat("en", {
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(displayedData[index]?.volume)}
{new Intl.NumberFormat('en', { minimumFractionDigits: 0, maximumFractionDigits: 0 }).format(displayedData[index]?.volume)}
</div>
<div style="justify-content: center;" class="td text-sm sm:text-[1rem] text-white text-end">
{new Intl.NumberFormat("en", {
minimumFractionDigits: 0,
maximumFractionDigits: 0
}).format(displayedData[index]?.open_interest)}
{new Intl.NumberFormat('en', { minimumFractionDigits: 0, maximumFractionDigits: 0 }).format(displayedData[index]?.open_interest)}
</div>
</div>
</VirtualList>
</div>
</div>
<!--<InfiniteLoading on:infinite={infiniteHandler} />-->
</div>
{: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]">
@ -1462,11 +1477,11 @@ $: {
flex-flow: row nowrap;
}
.tr:nth-of-type(even) {
.tr.even {
background-color: #27272A;
}
.tr:nth-of-type(odd) {
.tr.odd {
background-color: #09090B;
}