def test_longer_dated_contract_request_is_out_of_scope(): """STILL REFUSED beyond 1DTE. The expiry guard was WIDENED to 0DTE-or-1DTE (operator 2026-08-04) but NOT removed: it is what stops an order path reaching for a far-dated contract whose risk profile has nothing to do with the intraday sleeve. NOW is Fri 2026-07-31, so 1DTE is Mon 2026-08-03 and the requested 2026-08-07 is several trading days out.""" with pytest.raises(ValueError, match="only 0DTE .* or 1DTE"): > OE.select_contract( FakeBroker(), "call", date(2026, 8, 7), now=NOW, underlying="IWM" ) tests/services/test_options_execution.py:129: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ broker = right = 'call', expiry = datetime.date(2026, 8, 7) def select_contract( broker: Any, right: str, expiry: _date, *, now: datetime, underlying: str = UNDERLYING_IWM, strike_band_pct: float = 3.0, max_strike_distance_usd: float = MAX_STRIKE_DISTANCE_USD, max_strike_distance_pct: float = MAX_STRIKE_DISTANCE_PCT, max_dte: int = 1, ) -> Optional[Dict[str, Any]]: """Select nearest ATM from the full broker chain, hard-filtered to 0DTE or 1DTE expiry. EXPIRY IS BOUNDED TO TODAY OR THE NEXT TRADING DAY (operator 2026-08-04: "have it support 1DTE as well as 0DTE"). This previously refused anything but same-day. That guard was not incidental — it is what stops an order path reaching for a far-dated contract whose risk profile has nothing to do with the intraday sleeve — so it is WIDENED BY EXACTLY ONE TRADING DAY rather than removed. Anything beyond 1DTE still raises. The 1DTE date comes from ``scheduler.get_next_trading_date``, which is NYSE-HOLIDAY AWARE. ``get_next_businessday_from_day`` would be wrong here: it only skips weekends, so on the day before a market holiday it would name a date on which no expiry exists, and the chain lookup would come back empty for a reason nobody could see from the error. """ if right not in VALID_RIGHTS: raise ValueError(f"right must be call|put, got {right!r}") if now.tzinfo is None: raise ValueError("contract selection requires a timezone-aware now") current_day = now.astimezone(ET).date() # THE CEILING IS A PARAMETER, AND ITS DEFAULT IS THE OLD BEHAVIOUR EXACTLY (max_dte=1). The guard # is not incidental — it stops an order path reaching for a far-dated contract whose risk profile # has nothing to do with the intraday sleeve — so the 0DTE mirror, which passes nothing, keeps the # identical 0/1DTE bound it has always had. Only a caller that explicitly asks for more gets more: # the operator's manual N-DTE entry (2026-08-05: "0DTE, 1DTE, 2DTE, 3DTE") passes max_dte=3 and # reuses THIS selector rather than growing a second strike-picking path ("use the same logic to # pick option contract target strike price as current 0DTE mirror feature"). if int(max_dte) < 0: raise ValueError(f"max_dte must be >= 0, got {max_dte}") allowed = [current_day] + [ scheduler.get_next_trading_date(date=current_day, offset=i) for i in range(1, int(max_dte) + 1) ] if expiry not in allowed: > raise ValueError( f"expiry must be within {max_dte}DTE (holiday-aware trading days): " f"expiry={expiry} allowed={[str(d) for d in allowed]}" ) E ValueError: expiry must be within 1DTE (holiday-aware trading days): expiry=2026-08-07 allowed=['2026-07-31', '2026-08-03'] rtrader/services/options_execution.py:451: ValueError During handling of the above exception, another exception occurred: def test_longer_dated_contract_request_is_out_of_scope(): """STILL REFUSED beyond 1DTE. The expiry guard was WIDENED to 0DTE-or-1DTE (operator 2026-08-04) but NOT removed: it is what stops an order path reaching for a far-dated contract whose risk profile has nothing to do with the intraday sleeve. NOW is Fri 2026-07-31, so 1DTE is Mon 2026-08-03 and the requested 2026-08-07 is several trading days out.""" > with pytest.raises(ValueError, match="only 0DTE .* or 1DTE"): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E AssertionError: Regex pattern did not match. E Expected regex: 'only 0DTE .* or 1DTE' E Actual message: "expiry must be within 1DTE (holiday-aware trading days): expiry=2026-08-07 allowed=['2026-07-31', '2026-08-03']" tests/services/test_options_execution.py:128: AssertionError