From 46e5d91b7f9c5632607c009fd41a7afa7eb5d3b7 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Sun, 12 Jan 2025 10:20:06 +0100 Subject: [PATCH] bugfixing --- .../components/Options/GreekByExpiry.svelte | 46 +++++++++++-------- .../Options/OpenInterestByExpiry.svelte | 24 ++++++---- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/lib/components/Options/GreekByExpiry.svelte b/src/lib/components/Options/GreekByExpiry.svelte index d4f1a445..e14ae43f 100644 --- a/src/lib/components/Options/GreekByExpiry.svelte +++ b/src/lib/components/Options/GreekByExpiry.svelte @@ -30,28 +30,34 @@ let rawData = data?.getData || []; const isGamma = title === "Gamma"; + const today = new Date(); - rawData = rawData?.map((item) => { - if (title === "Gamma") { - return { - ...item, - net_gex: (item?.call_gex || 0) + (item?.put_gex || 0), - put_call_ratio: - item?.call_gex > 0 - ? Math.abs((item?.put_gex || 0) / item?.call_gex) - : null, - }; - } else { - return { - ...item, - net_delta: (item?.call_delta || 0) + (item?.put_delta || 0), - put_call_ratio: - item?.call_delta > 0 - ? Math.abs((item?.put_delta || 0) / item?.call_delta) - : null, - }; + rawData = rawData?.reduce((result, item) => { + const itemDate = new Date(item?.expiry); + if (itemDate >= today) { + if (title === "Gamma") { + result.push({ + ...item, + net_gex: (item?.call_gex || 0) + (item?.put_gex || 0), + put_call_ratio: + item?.call_gex > 0 + ? Math.abs((item?.put_gex || 0) / item?.call_gex) + : null, + }); + } else { + result.push({ + ...item, + net_delta: (item?.call_delta || 0) + (item?.put_delta || 0), + put_call_ratio: + item?.call_delta > 0 + ? Math.abs((item?.put_delta || 0) / item?.call_delta) + : null, + }); + } } - }); + return result; + }, []); + let displayList = rawData?.slice(0, 150); let options = null; diff --git a/src/lib/components/Options/OpenInterestByExpiry.svelte b/src/lib/components/Options/OpenInterestByExpiry.svelte index 36f10bda..12c53f2a 100644 --- a/src/lib/components/Options/OpenInterestByExpiry.svelte +++ b/src/lib/components/Options/OpenInterestByExpiry.svelte @@ -28,15 +28,21 @@ let rawData = data?.getData || []; - rawData = rawData?.map((item) => { - return { - ...item, - put_call_ratio: - item?.call_oi > 0 - ? Math.abs((item?.put_oi || 0) / item?.call_oi) - : null, - }; - }); + const today = new Date(); + + rawData = rawData?.reduce((result, item) => { + const itemDate = new Date(item?.expiry); + if (itemDate >= today) { + result.push({ + ...item, + put_call_ratio: + item?.call_oi > 0 + ? Math.abs((item?.put_oi || 0) / item.call_oi) + : null, + }); + } + return result; + }, []); let displayList = rawData?.slice(0, 150); let options = null;