add new filter for options flow page moneyness

This commit is contained in:
MuslemRahimi 2024-12-13 20:29:09 +01:00
parent 48293f38ae
commit 2471ce872a
2 changed files with 36 additions and 4 deletions

View File

@ -90,6 +90,11 @@
defaultCondition: "over",
defaultValue: "any",
},
moneyness: {
label: "Moneyness",
step: ["ITM", "OTM"],
defaultValue: "any",
},
put_call: {
label: "Contract Type",
step: ["Calls", "Puts"],
@ -212,6 +217,7 @@
let newRule;
switch (ruleName) {
case "moneyness":
case "put_call":
case "sentiment":
case "execution_estimate":
@ -343,6 +349,7 @@
// Specific rule handling for options-related rules
if (
[
"moneyness",
"put_call",
"sentiment",
"execution_estimate",
@ -1123,7 +1130,7 @@
<DropdownMenu.Content
class="w-64 min-h-auto max-h-72 overflow-y-auto scroller"
>
{#if !["put_call", "sentiment", "execution_estimate", "option_activity_type", "underlying_type"]?.includes(row?.rule)}
{#if !["moneyness", "put_call", "sentiment", "execution_estimate", "option_activity_type", "underlying_type"]?.includes(row?.rule)}
<DropdownMenu.Label
class="absolute mt-2 h-11 border-gray-800 border-b -top-1 z-20 fixed sticky bg-[#09090B]"
>
@ -1283,7 +1290,7 @@
></div>
{/if}
<DropdownMenu.Group class="min-h-10 mt-2">
{#if !["put_call", "sentiment", "execution_estimate", "option_activity_type", "underlying_type"]?.includes(row?.rule)}
{#if !["moneyness", "put_call", "sentiment", "execution_estimate", "option_activity_type", "underlying_type"]?.includes(row?.rule)}
{#each row?.step as newValue, index}
{#if ruleCondition[row?.rule] === "between"}
{#if newValue && row?.step[index + 1]}
@ -1327,7 +1334,7 @@
</DropdownMenu.Item>
{/if}
{/each}
{:else if ["put_call", "sentiment", "execution_estimate", "option_activity_type", "underlying_type"]?.includes(row?.rule)}
{:else if ["moneyness", "put_call", "sentiment", "execution_estimate", "option_activity_type", "underlying_type"]?.includes(row?.rule)}
{#each row?.step as item}
<DropdownMenu.Item
class="sm:hover:bg-[#2A2E39]"

View File

@ -17,7 +17,7 @@ function convertUnitToValue(
`Expected a string or number, but received ${typeof input}`,
);
}
const lowerInput = input.toLowerCase();
const lowerInput = input?.toLowerCase();
const nonNumericValues = new Set([
"any",
"puts",
@ -34,6 +34,8 @@ function convertUnitToValue(
"trade",
"stock",
"etf",
"itm",
"otm",
]);
if (nonNumericValues.has(lowerInput)) return input;
if (input.endsWith("%")) {
@ -70,6 +72,29 @@ function createRuleCheck(rule, ruleName, ruleValue) {
const now = new Date(new Date().toLocaleString("en-US", { timeZone: "America/New_York" }));
if (ruleName === 'moneyness') {
return (item) => {
if (ruleValue === 'any') return true;
const currentPrice = parseFloat(item?.underlying_price);
const strikePrice = parseFloat(item?.strike_price);
const optionType = item?.put_call;
if (isNaN(currentPrice) || isNaN(strikePrice)) return false;
// Determine moneyness
let moneyness = '';
if (optionType === 'Calls') {
moneyness = currentPrice > strikePrice ? 'ITM' : 'OTM';
} else if (optionType === 'Puts') {
moneyness = currentPrice < strikePrice ? 'ITM' : 'OTM';
}
// Check if the item matches the ruleValue ('itm' or 'otm')
if (!ruleValue?.includes(moneyness)) return false;
return true;
};
}
if (ruleName === 'volumeoiratio') {
return (item) => {
const volume = parseFloat(item.volume);