add rule
This commit is contained in:
parent
f37df0b407
commit
137fcfb480
@ -26,6 +26,7 @@
|
|||||||
const allRules = {
|
const allRules = {
|
||||||
volume: { label: 'Volume', step: ['100K','10K','1K'], defaultCondition: 'over', defaultValue: '1K' },
|
volume: { label: 'Volume', step: ['100K','10K','1K'], defaultCondition: 'over', defaultValue: '1K' },
|
||||||
open_interest: { label: 'Open Interest', step: ['100K','10K','1K'], defaultCondition: 'over', defaultValue: '1K' },
|
open_interest: { label: 'Open Interest', step: ['100K','10K','1K'], defaultCondition: 'over', defaultValue: '1K' },
|
||||||
|
volumeOIRatio: { label: 'Volume / Open Interest', step: ['100%','80%','60%','50%','30%','15%','10%','5%'], defaultCondition: 'over', defaultValue: 'any' },
|
||||||
cost_basis: { label: 'Premium', step: ['10M','5M','1M','500K','100K','50K','10K','5K'], defaultCondition: 'over', defaultValue: '50K' },
|
cost_basis: { label: 'Premium', step: ['10M','5M','1M','500K','100K','50K','10K','5K'], defaultCondition: 'over', defaultValue: '50K' },
|
||||||
put_call: { label: 'Contract Type', step: ["Calls", "Puts"], defaultValue: 'any' },
|
put_call: { label: 'Contract Type', step: ["Calls", "Puts"], defaultValue: 'any' },
|
||||||
sentiment: { label: 'Sentiment', step: ["Bullish","Neutral", "Bearish"], defaultValue: 'any' },
|
sentiment: { label: 'Sentiment', step: ["Bullish","Neutral", "Bearish"], defaultValue: 'any' },
|
||||||
|
|||||||
@ -114,9 +114,26 @@ async function filterRawData(rawData, ruleOfList, filterQuery) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ruleOfList.every((rule) => {
|
return ruleOfList.every((rule) => {
|
||||||
const itemValue = item[rule.name];
|
|
||||||
const ruleValue = convertUnitToValue(rule.value);
|
|
||||||
const ruleName = rule.name.toLowerCase();
|
const ruleName = rule.name.toLowerCase();
|
||||||
|
const ruleValue = convertUnitToValue(rule.value);
|
||||||
|
|
||||||
|
// Handle volumeOIRatio
|
||||||
|
if (ruleName === "volumeoiratio") {
|
||||||
|
const volume = parseFloat(item.volume);
|
||||||
|
const openInterest = parseFloat(item.open_interest);
|
||||||
|
|
||||||
|
if (isNaN(volume) || isNaN(openInterest) || openInterest === 0) {
|
||||||
|
return false; // Invalid data, exclude this item
|
||||||
|
}
|
||||||
|
|
||||||
|
const ratio = (volume / openInterest) * 100;
|
||||||
|
|
||||||
|
if (rule.condition === "over" && ratio <= ruleValue) return false;
|
||||||
|
if (rule.condition === "under" && ratio >= ruleValue) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const itemValue = item[rule.name];
|
||||||
|
|
||||||
// Handle date_expiration
|
// Handle date_expiration
|
||||||
if (ruleName === "date_expiration") {
|
if (ruleName === "date_expiration") {
|
||||||
@ -127,7 +144,7 @@ async function filterRawData(rawData, ruleOfList, filterQuery) {
|
|||||||
return isDateWithinRange(itemValue, ruleValue as string);
|
return isDateWithinRange(itemValue, ruleValue as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle categorical data like analyst ratings, sector, country
|
// Handle categorical data
|
||||||
else if (
|
else if (
|
||||||
[
|
[
|
||||||
"put_call",
|
"put_call",
|
||||||
@ -138,28 +155,29 @@ async function filterRawData(rawData, ruleOfList, filterQuery) {
|
|||||||
].includes(ruleName)
|
].includes(ruleName)
|
||||||
) {
|
) {
|
||||||
if (isAny(ruleValue)) return true;
|
if (isAny(ruleValue)) return true;
|
||||||
|
|
||||||
// Ensure itemValue is not null/undefined and is a string
|
|
||||||
if (itemValue === null || itemValue === undefined) return false;
|
if (itemValue === null || itemValue === undefined) return false;
|
||||||
|
|
||||||
const lowerItemValue = itemValue.toString().toLowerCase();
|
const lowerItemValue = itemValue.toString().toLowerCase();
|
||||||
|
|
||||||
if (Array.isArray(ruleValue)) {
|
if (Array.isArray(ruleValue)) {
|
||||||
// Make sure ruleValue items are also treated case-insensitively
|
|
||||||
return ruleValue.some(
|
return ruleValue.some(
|
||||||
(value) => lowerItemValue === value.toLowerCase()
|
(value) => lowerItemValue === value.toString().toLowerCase()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare case-insensitively
|
|
||||||
return lowerItemValue === ruleValue.toString().toLowerCase();
|
return lowerItemValue === ruleValue.toString().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default numeric or string comparison
|
// Default numeric or string comparison
|
||||||
if (typeof ruleValue === "string") return true;
|
if (typeof ruleValue === "string") return true;
|
||||||
if (itemValue === null) return false;
|
if (itemValue === null || itemValue === undefined) return false;
|
||||||
if (rule.condition === "over" && itemValue <= ruleValue) return false;
|
const numericItemValue = parseFloat(itemValue);
|
||||||
if (rule.condition === "under" && itemValue > ruleValue) return false;
|
if (isNaN(numericItemValue)) return false;
|
||||||
|
|
||||||
|
if (rule.condition === "over" && numericItemValue <= ruleValue)
|
||||||
|
return false;
|
||||||
|
if (rule.condition === "under" && numericItemValue >= ruleValue)
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user