Add analytics risk guard and redesigned dashboard
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
|
||||
from crypto_spot_bot.analytics import risk_guard_snapshot
|
||||
from crypto_spot_bot.config import Settings
|
||||
from crypto_spot_bot.execution import LiveBroker, PaperBroker
|
||||
from crypto_spot_bot.learning import TradeLearner
|
||||
@@ -123,6 +124,11 @@ class CryptoSpotBot:
|
||||
|
||||
async def _process_entries(self) -> None:
|
||||
prices = self.market.prices()
|
||||
risk_guard = risk_guard_snapshot(
|
||||
self.settings,
|
||||
self.storage.closed_trades(self.settings.learning_lookback_trades),
|
||||
self.storage.latest_equity(),
|
||||
)
|
||||
for symbol in self.market.symbols:
|
||||
cooldown_since = self._entry_cooldown_until.get(symbol)
|
||||
if cooldown_since:
|
||||
@@ -149,6 +155,22 @@ class CryptoSpotBot:
|
||||
learning = self.learner.adjustment_for(symbol, str(pattern.get("label", ""))).as_dict()
|
||||
learning["adaptive_rules"] = self._with_exposure_context(learning.get("adaptive_rules") or {})
|
||||
account = self.broker.account_state(prices)
|
||||
account["risk_guard"] = risk_guard
|
||||
if risk_guard.get("block_new_entries"):
|
||||
self.storage.insert_signal(
|
||||
Signal(
|
||||
symbol,
|
||||
"HOLD",
|
||||
0.0,
|
||||
"risk_guard: new entries blocked",
|
||||
{
|
||||
"strategy_mode": self.settings.strategy_mode,
|
||||
"risk_guard": risk_guard,
|
||||
"checks": {"risk_guard_ok": False},
|
||||
},
|
||||
)
|
||||
)
|
||||
continue
|
||||
llm = {}
|
||||
if (
|
||||
self.settings.llm_advisor_enabled
|
||||
|
||||
Reference in New Issue
Block a user