from app.core.market_regime import classify_market_regime def _overview(**overrides): data = { "sample_count": 200, "benchmarks": { "BTC/USDT": {"change_24h": 0.5}, "ETH/USDT": {"change_24h": 0.4}, }, "advance_decline_ratio": 1.0, "avg_change_24h": 0.1, "hot_count_5pct": 8, "crash_count_5pct": 4, "funding": {"avg_funding_rate": 0.0001, "extreme_positive_count": 2}, } data.update(overrides) return data def test_market_regime_blocks_clear_risk_off(): result = classify_market_regime( _overview( benchmarks={"BTC/USDT": {"change_24h": -3.4}, "ETH/USDT": {"change_24h": -4.2}}, advance_decline_ratio=0.4, crash_count_5pct=35, ) ) assert result["regime"] == "risk_off" assert result["risk_level"] == "critical" assert result["position_multiplier"] == 0 def test_market_regime_detects_altcoin_rotation(): result = classify_market_regime( _overview( benchmarks={"BTC/USDT": {"change_24h": 0.6}, "ETH/USDT": {"change_24h": 1.1}}, advance_decline_ratio=1.4, avg_change_24h=1.2, hot_count_5pct=22, crash_count_5pct=3, ) ) assert result["regime"] == "altcoin_rotation" assert result["risk_level"] == "medium"