Move settings hints into rules; add OO amplitude filter toggle default off.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -192,13 +192,24 @@ def _hedge_mode() -> str:
|
||||
return "perp_option"
|
||||
|
||||
|
||||
def _oo_settings() -> tuple[float, float, float, float, float]:
|
||||
"""amplitude_pct, amplitude_hours, min_option_hours, min_leverage, strike_max_dev_pct"""
|
||||
def _oo_settings() -> tuple[float, float, float, float, float, bool]:
|
||||
"""amplitude_pct, amplitude_hours, min_option_hours, min_leverage, strike_max_dev_pct, amp_filter_on"""
|
||||
s = get_settings()
|
||||
try:
|
||||
from ..models.db import get_db
|
||||
|
||||
db = get_db()
|
||||
filt_raw = db.get_setting(
|
||||
"oo_amplitude_filter_enabled", str(s.oo_amplitude_filter_enabled)
|
||||
)
|
||||
filt_on = str(filt_raw or "").strip().lower() in (
|
||||
"1",
|
||||
"true",
|
||||
"yes",
|
||||
"on",
|
||||
)
|
||||
if filt_raw is None or filt_raw == "":
|
||||
filt_on = bool(s.oo_amplitude_filter_enabled)
|
||||
return (
|
||||
float(db.get_setting("oo_amplitude_pct", str(s.oo_amplitude_pct)) or s.oo_amplitude_pct),
|
||||
float(
|
||||
@@ -216,6 +227,7 @@ def _oo_settings() -> tuple[float, float, float, float, float]:
|
||||
)
|
||||
or s.oo_strike_max_dev_pct
|
||||
),
|
||||
filt_on,
|
||||
)
|
||||
except Exception:
|
||||
return (
|
||||
@@ -224,6 +236,7 @@ def _oo_settings() -> tuple[float, float, float, float, float]:
|
||||
s.oo_min_option_hours,
|
||||
s.oo_min_leverage,
|
||||
s.oo_strike_max_dev_pct,
|
||||
bool(s.oo_amplitude_filter_enabled),
|
||||
)
|
||||
|
||||
|
||||
@@ -457,7 +470,7 @@ class StrategySession:
|
||||
try:
|
||||
from ..exchange.candles import fetch_amplitude_hl_for_runtime
|
||||
|
||||
amp_pct, amp_hours, _, _, _ = _oo_settings()
|
||||
amp_pct, amp_hours, _, _, _, amp_filt = _oo_settings()
|
||||
amp = fetch_amplitude_hl_for_runtime(amp_hours)
|
||||
if amp is None:
|
||||
return self._oo_amp
|
||||
@@ -468,7 +481,12 @@ class StrategySession:
|
||||
"range_pct": float(amp.range_pct),
|
||||
"hours": float(amp_hours),
|
||||
"max_pct": float(amp_pct),
|
||||
"ok": float(amp.range_pct) <= float(amp_pct) + 1e-12,
|
||||
"filter_enabled": bool(amp_filt),
|
||||
"ok": (
|
||||
True
|
||||
if not amp_filt
|
||||
else float(amp.range_pct) <= float(amp_pct) + 1e-12
|
||||
),
|
||||
}
|
||||
return self._oo_amp
|
||||
except Exception:
|
||||
@@ -484,7 +502,7 @@ class StrategySession:
|
||||
if _has_open_position():
|
||||
return self.align_to_held_position()
|
||||
s = self.settings
|
||||
amp_pct, amp_hours, min_hours, _min_lev, max_dev = _oo_settings()
|
||||
amp_pct, amp_hours, min_hours, _min_lev, max_dev, _amp_filt = _oo_settings()
|
||||
idx = self.ex.fetch_index(s.index_inst_id)
|
||||
mark = self.ex.fetch_mark(s.perp_inst_id) or idx
|
||||
if mark is None or mark <= 0:
|
||||
@@ -535,7 +553,7 @@ class StrategySession:
|
||||
from .selection import _complete_by_expiry, option_leverage
|
||||
|
||||
s = self.settings
|
||||
amp_pct, amp_hours, min_hours, min_lev, max_dev = _oo_settings()
|
||||
amp_pct, amp_hours, min_hours, min_lev, max_dev, amp_filt = _oo_settings()
|
||||
idx = self.ex.fetch_index(s.index_inst_id)
|
||||
mark = self.ex.fetch_mark(s.perp_inst_id) or idx
|
||||
if mark is None or mark <= 0:
|
||||
@@ -553,9 +571,14 @@ class StrategySession:
|
||||
"range_pct": float(amp.range_pct),
|
||||
"hours": float(amp_hours),
|
||||
"max_pct": float(amp_pct),
|
||||
"ok": float(amp.range_pct) <= float(amp_pct) + 1e-12,
|
||||
"filter_enabled": bool(amp_filt),
|
||||
"ok": (
|
||||
True
|
||||
if not amp_filt
|
||||
else float(amp.range_pct) <= float(amp_pct) + 1e-12
|
||||
),
|
||||
}
|
||||
if float(amp.range_pct) > float(amp_pct) + 1e-12:
|
||||
if amp_filt and float(amp.range_pct) > float(amp_pct) + 1e-12:
|
||||
logger.info(
|
||||
"oo: amplitude %.3f%% > max %.3f%% (H=%.2f L=%.2f)",
|
||||
amp.range_pct,
|
||||
@@ -852,7 +875,7 @@ class StrategySession:
|
||||
def oo_needs_realign(self) -> bool:
|
||||
if self._pair is None:
|
||||
return True
|
||||
_amp_pct, amp_hours, min_hours, _, max_dev = _oo_settings()
|
||||
_amp_pct, amp_hours, min_hours, _, max_dev, amp_filt = _oo_settings()
|
||||
if (
|
||||
hours_until_expiry(self._pair.expiry_ymd, expiry_ms=self._pair.expiry_ms)
|
||||
+ 1e-9
|
||||
@@ -879,7 +902,12 @@ class StrategySession:
|
||||
"range_pct": float(amp.range_pct),
|
||||
"hours": float(amp_hours),
|
||||
"max_pct": float(_amp_pct),
|
||||
"ok": float(amp.range_pct) <= float(_amp_pct) + 1e-12,
|
||||
"filter_enabled": bool(amp_filt),
|
||||
"ok": (
|
||||
True
|
||||
if not amp_filt
|
||||
else float(amp.range_pct) <= float(_amp_pct) + 1e-12
|
||||
),
|
||||
}
|
||||
contracts = self.ex.list_option_contracts(self.settings.option_inst_family)
|
||||
picked = select_oo_pair(
|
||||
|
||||
Reference in New Issue
Block a user