Expand description
Injectable clock abstraction for time-dependent risk primitives.
CircuitBreaker and
SessionPnl both depend on wall-clock time —
the breaker’s rolling loss window, the PnL session’s 00:00 UTC
rollover. Real code uses the SystemClock; tests can substitute
ManualClock (or any other Clock impl) so they don’t have to
sleep for hours to exercise rollover boundaries.
use std::sync::Arc;
use rustrade_risk::clock::{Clock, ManualClock};
let clock = Arc::new(ManualClock::new(1_000));
assert_eq!(clock.now_unix_secs(), 1_000);
clock.advance_secs(86_400);
assert_eq!(clock.now_unix_secs(), 87_400);Structs§
- Manual
Clock - A manually-advanceable clock for tests.
- System
Clock - The default clock — reads the OS wall clock via
SystemTime.
Traits§
- Clock
- Source of wall-clock time, in whole UNIX seconds.