Coverage for monitoring/strategy_catalog.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 12:55 +0000

1"""Static catalog of every registered multi-leg options strategy (Phase 4.8). 

2 

3Pure, read-only report builder, same "compute on read" precedent 

4`monitoring/assets_status.py`/`monitoring/neural_network_state.py` already 

5establish - `portfolio/options_strategy.py::MULTI_LEG_STRATEGY_REGISTRY` is 

6a static, in-memory Python dict (43 entries, one per registered 

7`OptionStrategies` factory), so reading it fresh on every request is 

8trivially cheap - no caching, no config/lean.json reads needed (simpler 

9than either sibling above, since this data isn't config-driven at all). 

10 

11Deliberately NOT part of `visualization/state.json`/`main.py::_write_state()`: 

12that file only exists once a Lean process (backtest/live/observation) has 

13actually run at least once. The strategy catalog is useful independent of 

14that - e.g. browsable on a fresh checkout before any backtest has ever 

15run - so it gets its own endpoint instead, following the same 

16already-established pattern `/api/assets-status`/`/api/neural-network` use 

17for data that isn't itself part of the per-bar runtime state. 

18""" 

19 

20from __future__ import annotations 

21 

22from typing import Any 

23 

24from portfolio.options_strategy import MULTI_LEG_STRATEGY_REGISTRY 

25 

26 

27def build_strategy_catalog() -> dict[str, Any]: 

28 """Returns {"strategies": [{"name", "leg_count", "risk_tier", 

29 "shape_family", "has_expiry_pair"}, ...], "total_count": int} - sorted 

30 by name for a stable, deterministic response.""" 

31 strategies = [ 

32 { 

33 "name": name, 

34 "leg_count": len(spec.legs), 

35 "risk_tier": spec.risk_tier, 

36 "shape_family": spec.shape_family, 

37 "has_expiry_pair": spec.has_expiry_pair, 

38 } 

39 for name, spec in sorted(MULTI_LEG_STRATEGY_REGISTRY.items()) 

40 ] 

41 return {"strategies": strategies, "total_count": len(strategies)}