Keep bot operational when forecast model is unavailable

This commit is contained in:
Курнат Андрей
2026-07-13 11:57:25 +03:00
parent da53483164
commit 668e606ee2
22 changed files with 706 additions and 73 deletions
+18 -13
View File
@@ -12,7 +12,7 @@ from crypto_spot_bot.learning import TradeLearner
from crypto_spot_bot.market_data import MarketData
from crypto_spot_bot.models import BotStatus, Signal, Ticker, utc_now
from crypto_spot_bot.patterns import PatternAnalyzer
from crypto_spot_bot.strategy import SpotStrategy
from crypto_spot_bot.strategy import SpotStrategy, torch_model_readiness_reasons
from crypto_spot_bot.storage import Storage
from crypto_spot_bot.time_series import TimeSeriesForecaster
@@ -78,6 +78,9 @@ class CryptoSpotBot:
self.started_at = utc_now()
self.message = "бот работает"
self._safe_event("Бот запущен")
# Maintenance must never delay the first market decision after startup.
# The bounded telemetry prune starts after the configured interval.
self._last_prune_at = utc_now()
if self.settings.websocket_enabled:
self._ws_task = asyncio.create_task(self.market.websocket_loop())
self._loop_task = asyncio.create_task(self._run_loop())
@@ -458,20 +461,19 @@ class CryptoSpotBot:
invalid_models = []
for symbol in self.market.symbols:
forecast = self.market.forecasts.get(symbol, {})
if not forecast.get("usable"):
invalid_models.append(symbol)
continue
if (
self.settings.time_series_require_quality_gate
and not self.settings.time_series_manual_quality_override
and forecast.get("quality_gate_passed") is not True
):
invalid_models.append(symbol)
continue
if self.settings.time_series_require_fresh_model and forecast.get("model_fresh") is not True:
if torch_model_readiness_reasons(self.settings, forecast):
invalid_models.append(symbol)
if invalid_models:
reasons.append("forecast_model_not_ready")
if self.settings.time_series_trend_fallback_enabled:
forecast_fallback_active = True
else:
forecast_fallback_active = False
reasons.append("forecast_model_not_ready")
else:
forecast_fallback_active = False
else:
invalid_models = []
forecast_fallback_active = False
reconciliation: dict = {}
if isinstance(self.broker, LiveBroker):
reconciliation = dict(self.broker.reconciliation_state)
@@ -485,6 +487,9 @@ class CryptoSpotBot:
"stale_symbols": stale_symbols,
"consecutive_loop_errors": self._consecutive_loop_errors,
"reconciliation": reconciliation,
"forecast_model_ready": not invalid_models,
"forecast_fallback_active": forecast_fallback_active,
"forecast_invalid_symbols": invalid_models,
}
def account_snapshot(self) -> dict[str, float]: