diff --git a/src/cerbero_bite/runtime/entry_cycle.py b/src/cerbero_bite/runtime/entry_cycle.py index a0ddfb8..aea5a06 100644 --- a/src/cerbero_bite/runtime/entry_cycle.py +++ b/src/cerbero_bite/runtime/entry_cycle.py @@ -429,6 +429,35 @@ async def run_entry_cycle( ) # 2. Entry filters + entry_cfg = cfg.entry + asset = cfg.asset.symbol + + iv_rv_history: tuple[Decimal, ...] = () + dvol_24h_ago: Decimal | None = None + if entry_cfg.iv_minus_rv_filter_enabled and entry_cfg.iv_minus_rv_adaptive_enabled: + conn = connect_state(ctx.db_path) + try: + iv_rv_history = tuple( + ctx.repository.iv_rv_history( + conn, + asset=asset, + max_days=entry_cfg.iv_minus_rv_window_target_days, + as_of=when, + ) + ) + finally: + conn.close() + if entry_cfg.vol_of_vol_guard_enabled: + conn = connect_state(ctx.db_path) + try: + dvol_24h_ago = ctx.repository.dvol_lookback( + conn, + asset=asset, + reference=when - timedelta(hours=entry_cfg.vol_of_vol_lookback_hours), + ) + finally: + conn.close() + entry_ctx = EntryContext( capital_usd=capital_usd, dvol_now=snap.dvol, @@ -439,6 +468,8 @@ async def run_entry_cycle( dealer_net_gamma=snap.dealer_net_gamma, iv_minus_rv=snap.iv_minus_rv, liquidation_squeeze_risk_high=snap.liquidation_squeeze_risk_high, + iv_rv_history=iv_rv_history, + dvol_24h_ago=dvol_24h_ago, ) decision = validate_entry(entry_ctx, cfg) inputs = { @@ -458,6 +489,10 @@ async def run_entry_cycle( "iv_minus_rv": ( str(snap.iv_minus_rv) if snap.iv_minus_rv is not None else None ), + "iv_rv_history_n": len(iv_rv_history), + "dvol_24h_ago": ( + str(dvol_24h_ago) if dvol_24h_ago is not None else None + ), } } if not decision.accepted: