Skip to main content

Crate rustrade_risk

Crate rustrade_risk 

Source
Expand description

§rustrade-risk

Generic risk primitives for trading bots:

  • CircuitBreaker — sliding-window loss breaker (ported from the kucoin bot’s circuit_breaker.rs).
  • SessionPnl — daily PnL tracker with drawdown cap and automatic 00:00 UTC rollover.
  • PositionSizer — notional-based sizing from margin + leverage + price + contract multiplier (ported from kucoin’s sizing.rs).
  • PortfolioRisk — account-level risk: an account-wide daily-loss halt plus a pre-trade gate over aggregate exposure and concurrent positions. The per-symbol primitives above bound each symbol; this bounds the whole account (multi-asset trading needs both).

Nothing here is strategy- or exchange-specific. If you find yourself needing to special-case a particular strategy, the logic belongs in the Brain implementation, not here.

Re-exports§

pub use circuit_breaker::CircuitBreaker;
pub use circuit_breaker::CircuitBreakerConfig;
pub use circuit_breaker::CircuitBreakerSnapshot;
pub use clock::Clock;
pub use clock::ManualClock;
pub use clock::SystemClock;
pub use portfolio::PortfolioBlock;
pub use portfolio::PortfolioRisk;
pub use portfolio::PortfolioRiskConfig;
pub use portfolio::PortfolioRiskSnapshot;
pub use portfolio::PortfolioState;
pub use session_pnl::SessionPnl;
pub use session_pnl::SessionPnlConfig;
pub use session_pnl::SessionPnlSnapshot;
pub use sizing::PositionSizer;
pub use sizing::SizingConfig;

Modules§

circuit_breaker
Sliding-window circuit breaker for trading strategies.
clock
Injectable clock abstraction for time-dependent risk primitives.
portfolio
Account-level (portfolio) risk.
session_pnl
Per-session realised PnL tracker with optional drawdown cap and daily 00:00 UTC rollover.
sizing
Notional-based position sizing.