Keep bot operational when forecast model is unavailable
This commit is contained in:
@@ -566,6 +566,71 @@ def test_torch_forecast_blocks_failed_quality_gate(make_settings, tmp_path) -> N
|
||||
assert signal.diagnostics["checks"]["quality_gate_ok"] is False
|
||||
|
||||
|
||||
def test_torch_forecast_uses_trend_fallback_when_model_is_not_ready(make_settings, tmp_path) -> None:
|
||||
settings = make_settings(
|
||||
tmp_path,
|
||||
strategy_mode="torch_forecast",
|
||||
time_series_trend_fallback_enabled=True,
|
||||
time_series_require_quality_gate=True,
|
||||
time_series_require_fresh_model=True,
|
||||
max_position_usdt=50,
|
||||
)
|
||||
strategy = SpotStrategy(settings)
|
||||
ticker = Ticker("BTCUSDT", 105, 104.99, 105.01, 10_000_000, 1000, 1.0)
|
||||
|
||||
signal = strategy.entry_signal(
|
||||
"BTCUSDT",
|
||||
_trend_entry_candles(),
|
||||
ticker,
|
||||
open_positions_for_symbol=0,
|
||||
forecast={"usable": False, "model": "none", "quality_gate_passed": False},
|
||||
account={"equity": 100.0},
|
||||
trend_candles=_daily_trend_candles(),
|
||||
)
|
||||
|
||||
assert signal.action == "BUY"
|
||||
assert signal.diagnostics["trade_mode"] == "TREND_MACD_FALLBACK"
|
||||
assert signal.diagnostics["entry_path"] == "trend_macd_fallback"
|
||||
assert signal.diagnostics["forecast_fallback_reasons"] == [
|
||||
"torch_model_unavailable",
|
||||
"quality_gate_not_passed",
|
||||
"model_not_fresh",
|
||||
]
|
||||
|
||||
|
||||
def test_torch_forecast_uses_trend_exit_for_fallback_position(make_settings, tmp_path) -> None:
|
||||
settings = make_settings(
|
||||
tmp_path,
|
||||
strategy_mode="torch_forecast",
|
||||
time_series_trend_fallback_enabled=True,
|
||||
)
|
||||
strategy = SpotStrategy(settings)
|
||||
candles = _trend_entry_candles()
|
||||
candles[-2].macd = 0.2
|
||||
candles[-2].macd_signal = 0.0
|
||||
candles[-1].macd = -0.1
|
||||
candles[-1].macd_signal = 0.0
|
||||
position = Position(
|
||||
1,
|
||||
"BTCUSDT",
|
||||
1,
|
||||
100,
|
||||
100,
|
||||
0.1,
|
||||
96,
|
||||
120,
|
||||
100,
|
||||
entry_diagnostics={"entry_path": "trend_macd_fallback"},
|
||||
)
|
||||
ticker = Ticker("BTCUSDT", 104, 103.99, 104.01, 1_000_000, 100, 0)
|
||||
|
||||
signal = strategy.exit_signal(position, candles, ticker, forecast={})
|
||||
|
||||
assert signal.action == "SELL"
|
||||
assert signal.diagnostics["trade_mode"] == "TREND_MACD_FALLBACK"
|
||||
assert "MACD" in signal.reason
|
||||
|
||||
|
||||
def test_torch_forecast_allows_explicit_manual_quality_override(make_settings, tmp_path) -> None:
|
||||
settings = make_settings(
|
||||
tmp_path,
|
||||
|
||||
Reference in New Issue
Block a user