fix: initialize adaptive rules for legacy exits

This commit is contained in:
Курнат Андрей
2026-07-15 00:40:45 +03:00
parent 2967cd607c
commit f7a625586e
3 changed files with 39 additions and 1 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
"""Crypto spot trading bot package."""
__version__ = "1.0.2"
__version__ = "1.0.3"
+2
View File
@@ -371,6 +371,7 @@ class SpotStrategy:
latest = candles[-1]
previous = candles[-2] if len(candles) >= 2 else latest
price = ticker.last_price
adaptive = _adaptive_rules(learning or {})
trailing = position.trailing_stop(self.settings.trailing_stop_percent)
diagnostics = {
"price": price,
@@ -383,6 +384,7 @@ class SpotStrategy:
"rsi_14": latest.rsi_14,
"ema_20": latest.ema_20,
"ema_50": latest.ema_50,
"adaptive_rules": adaptive,
}
if self.settings.stop_loss_exit_enabled and price <= position.stop_loss:
return Signal(position.symbol, "SELL", 1.0, "сработал стоп-лосс", diagnostics)
+36
View File
@@ -719,6 +719,42 @@ def test_torch_forecast_uses_legacy_exit_for_paper_fallback_position(make_settin
assert signal.diagnostics["entry_path"] == "legacy_fallback"
def test_torch_forecast_legacy_fallback_can_hold_after_minimum_time(make_settings, tmp_path) -> None:
settings = make_settings(
tmp_path,
strategy_mode="torch_forecast",
time_series_trend_fallback_enabled=True,
time_series_fallback_mode="legacy",
)
strategy = SpotStrategy(settings)
position = Position(
1,
"BTCUSDT",
1,
100,
100,
0.1,
90,
120,
101,
opened_at=utc_now() - timedelta(seconds=600),
entry_diagnostics={"entry_path": "legacy_fallback"},
)
ticker = Ticker("BTCUSDT", 101, 100.99, 101.01, 10_000_000, 1000, 1.0)
signal = strategy.exit_signal(
position,
_ready_candles(),
ticker,
learning={"adaptive_rules": {}},
forecast={},
)
assert signal.action == "HOLD"
assert signal.diagnostics["trade_mode"] == "LEGACY_FALLBACK"
assert signal.diagnostics["adaptive_rules"] == {}
def test_torch_forecast_allows_explicit_manual_quality_override(make_settings, tmp_path) -> None:
settings = make_settings(
tmp_path,