diff --git a/crypto_spot_bot/__init__.py b/crypto_spot_bot/__init__.py index f875867..8e935c3 100644 --- a/crypto_spot_bot/__init__.py +++ b/crypto_spot_bot/__init__.py @@ -1,3 +1,3 @@ """Crypto spot trading bot package.""" -__version__ = "1.0.2" +__version__ = "1.0.3" diff --git a/crypto_spot_bot/strategy.py b/crypto_spot_bot/strategy.py index 1419ed7..2316321 100644 --- a/crypto_spot_bot/strategy.py +++ b/crypto_spot_bot/strategy.py @@ -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) diff --git a/tests/test_strategy.py b/tests/test_strategy.py index 76d1e68..e3e5934 100644 --- a/tests/test_strategy.py +++ b/tests/test_strategy.py @@ -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,