Add risk management features: implement loss limits, trade limits, and pre-trade validation; update settings and tests

This commit is contained in:
2026-06-01 11:16:37 +02:00
parent 9d8a8a8a45
commit 45e219d103
14 changed files with 718 additions and 20 deletions
+26
View File
@@ -278,3 +278,29 @@ def test_incremental_detector_emits_structured_opportunity_event() -> None:
assert event.gross_pct == pytest.approx(4.0)
assert event.net_pct == pytest.approx(4.0)
assert event.est_profit == pytest.approx(20.0)
def test_incremental_detector_estimated_profit_scales_with_capital() -> None:
cycle = TriangularCycle(
currencies=("USD", "BTC", "ETH"),
pairs=("BTC/USD", "ETH/BTC", "ETH/USD"),
)
detector = IncrementalCycleDetector(
CurrencyGraph.index_cycles_by_pair([cycle]),
min_profit_threshold=0.0,
)
books = {
"BTC/USD": _make_book(bid=99.9, ask=100.0),
"ETH/BTC": _make_book(bid=0.049, ask=0.05),
"ETH/USD": _make_book(bid=5.20, ask=5.21),
}
opportunities = detector.opportunities_for_updated_pair(
"ETH/BTC",
books,
base_capital=250.0,
)
assert len(opportunities) == 1
assert opportunities[0].est_profit == pytest.approx(10.0)