rustrade_risk/lib.rs
1#![warn(missing_docs)]
2
3//! # rustrade-risk
4//!
5//! Generic risk primitives for trading bots:
6//!
7//! - [`CircuitBreaker`] — sliding-window loss breaker (ported from the
8//! kucoin bot's `circuit_breaker.rs`).
9//! - [`SessionPnl`] — daily PnL tracker with drawdown cap and automatic
10//! 00:00 UTC rollover.
11//! - [`PositionSizer`] — notional-based sizing from margin + leverage +
12//! price + contract multiplier (ported from kucoin's `sizing.rs`).
13//! - [`PortfolioRisk`] — account-level risk: an account-wide daily-loss halt
14//! plus a pre-trade gate over aggregate exposure and concurrent positions.
15//! The per-symbol primitives above bound each symbol; this bounds the whole
16//! account (multi-asset trading needs both).
17//!
18//! Nothing here is strategy- or exchange-specific. If you find yourself
19//! needing to special-case a particular strategy, the logic belongs in
20//! the `Brain` implementation, not here.
21
22pub mod circuit_breaker;
23pub mod clock;
24pub mod portfolio;
25pub mod session_pnl;
26pub mod sizing;
27
28pub use circuit_breaker::{CircuitBreaker, CircuitBreakerConfig, CircuitBreakerSnapshot};
29pub use clock::{Clock, ManualClock, SystemClock};
30pub use portfolio::{
31 PortfolioBlock, PortfolioRisk, PortfolioRiskConfig, PortfolioRiskSnapshot, PortfolioState,
32};
33pub use session_pnl::{SessionPnl, SessionPnlConfig, SessionPnlSnapshot};
34pub use sizing::{PositionSizer, SizingConfig};