Make symbol risk guard configurable
This commit is contained in:
@@ -34,7 +34,12 @@ def test_risk_guard_reduces_size_after_consecutive_losses(make_settings, tmp_pat
|
||||
|
||||
|
||||
def test_risk_guard_blocks_only_bad_symbol(make_settings, tmp_path) -> None:
|
||||
settings = make_settings(tmp_path, risk_max_consecutive_losses=3, symbols=["BTCUSDT", "ETHUSDT"])
|
||||
settings = make_settings(
|
||||
tmp_path,
|
||||
risk_symbol_guard_enabled=True,
|
||||
risk_max_consecutive_losses=3,
|
||||
symbols=["BTCUSDT", "ETHUSDT"],
|
||||
)
|
||||
storage = Storage(settings.database_path)
|
||||
now = utc_now()
|
||||
for _ in range(3):
|
||||
@@ -76,6 +81,41 @@ def test_risk_guard_blocks_only_bad_symbol(make_settings, tmp_path) -> None:
|
||||
assert symbol_rows["ETHUSDT"]["block_new_entries"] is False
|
||||
|
||||
|
||||
def test_risk_guard_can_disable_symbol_blocks(make_settings, tmp_path) -> None:
|
||||
settings = make_settings(
|
||||
tmp_path,
|
||||
risk_symbol_guard_enabled=False,
|
||||
risk_max_consecutive_losses=3,
|
||||
symbols=["BTCUSDT", "ETHUSDT"],
|
||||
)
|
||||
storage = Storage(settings.database_path)
|
||||
now = utc_now()
|
||||
for _ in range(3):
|
||||
storage.insert_trade(
|
||||
Trade(
|
||||
id=None,
|
||||
symbol="BTCUSDT",
|
||||
side="SELL",
|
||||
qty=1.0,
|
||||
entry_price=100.0,
|
||||
exit_price=99.0,
|
||||
net_pnl=-1.0,
|
||||
opened_at=now,
|
||||
closed_at=now,
|
||||
entry_diagnostics={"forecast": {"probability_up": 0.64, "model": "torch_gru"}},
|
||||
)
|
||||
)
|
||||
|
||||
guard = risk_guard_snapshot(settings, storage.closed_trades(), storage.latest_equity())
|
||||
|
||||
assert guard["symbol_guard_enabled"] is False
|
||||
assert guard["blocked_symbols"] == []
|
||||
symbol_rows = {row["symbol"]: row for row in guard["symbols"]}
|
||||
assert symbol_rows["BTCUSDT"]["consecutive_losses"] == 3
|
||||
assert symbol_rows["BTCUSDT"]["block_new_entries"] is False
|
||||
assert symbol_rows["BTCUSDT"]["reasons"] == []
|
||||
|
||||
|
||||
def test_risk_guard_ignores_trades_outside_active_universe(make_settings, tmp_path) -> None:
|
||||
settings = make_settings(tmp_path, risk_max_consecutive_losses=2, symbols=["BTCUSDT", "ETHUSDT"])
|
||||
storage = Storage(settings.database_path)
|
||||
|
||||
Reference in New Issue
Block a user