fix: initialize adaptive rules for legacy exits
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
"""Crypto spot trading bot package."""
|
"""Crypto spot trading bot package."""
|
||||||
|
|
||||||
__version__ = "1.0.2"
|
__version__ = "1.0.3"
|
||||||
|
|||||||
@@ -371,6 +371,7 @@ class SpotStrategy:
|
|||||||
latest = candles[-1]
|
latest = candles[-1]
|
||||||
previous = candles[-2] if len(candles) >= 2 else latest
|
previous = candles[-2] if len(candles) >= 2 else latest
|
||||||
price = ticker.last_price
|
price = ticker.last_price
|
||||||
|
adaptive = _adaptive_rules(learning or {})
|
||||||
trailing = position.trailing_stop(self.settings.trailing_stop_percent)
|
trailing = position.trailing_stop(self.settings.trailing_stop_percent)
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
"price": price,
|
"price": price,
|
||||||
@@ -383,6 +384,7 @@ class SpotStrategy:
|
|||||||
"rsi_14": latest.rsi_14,
|
"rsi_14": latest.rsi_14,
|
||||||
"ema_20": latest.ema_20,
|
"ema_20": latest.ema_20,
|
||||||
"ema_50": latest.ema_50,
|
"ema_50": latest.ema_50,
|
||||||
|
"adaptive_rules": adaptive,
|
||||||
}
|
}
|
||||||
if self.settings.stop_loss_exit_enabled and price <= position.stop_loss:
|
if self.settings.stop_loss_exit_enabled and price <= position.stop_loss:
|
||||||
return Signal(position.symbol, "SELL", 1.0, "сработал стоп-лосс", diagnostics)
|
return Signal(position.symbol, "SELL", 1.0, "сработал стоп-лосс", diagnostics)
|
||||||
|
|||||||
@@ -719,6 +719,42 @@ def test_torch_forecast_uses_legacy_exit_for_paper_fallback_position(make_settin
|
|||||||
assert signal.diagnostics["entry_path"] == "legacy_fallback"
|
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:
|
def test_torch_forecast_allows_explicit_manual_quality_override(make_settings, tmp_path) -> None:
|
||||||
settings = make_settings(
|
settings = make_settings(
|
||||||
tmp_path,
|
tmp_path,
|
||||||
|
|||||||
Reference in New Issue
Block a user