pub struct RiskEngine {
pub throttled_submit: Throttler<TradingCommand, Box<dyn Fn(TradingCommand)>>,
pub throttled_modify_order: Throttler<ModifyOrder, Box<dyn Fn(ModifyOrder)>>,
/* private fields */
}Expand description
Central risk management engine that validates and controls trading operations.
The RiskEngine provides pre-trade risk checks including order validation,
balance verification, position sizing limits, and trading state management. It acts as
a gateway between strategy orders and execution, ensuring all trades comply with
defined risk parameters and regulatory constraints.
Fields§
§throttled_submit: Throttler<TradingCommand, Box<dyn Fn(TradingCommand)>>§throttled_modify_order: Throttler<ModifyOrder, Box<dyn Fn(ModifyOrder)>>Implementations§
Source§impl RiskEngine
impl RiskEngine
Sourcepub fn new(
config: RiskEngineConfig,
portfolio: Portfolio,
clock: Rc<RefCell<dyn Clock>>,
cache: Rc<RefCell<Cache>>,
) -> Self
pub fn new( config: RiskEngineConfig, portfolio: Portfolio, clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>, ) -> Self
Creates a new RiskEngine instance.
Sourcepub fn register_msgbus_handlers(engine: &Rc<RefCell<Self>>)
pub fn register_msgbus_handlers(engine: &Rc<RefCell<Self>>)
Registers all message bus handlers for the risk engine.
Sourcepub fn execute(&mut self, command: TradingCommand)
pub fn execute(&mut self, command: TradingCommand)
Executes a trading command through the risk management pipeline.
Sourcepub fn process(&mut self, event: OrderEventAny)
pub fn process(&mut self, event: OrderEventAny)
Processes an order event for risk monitoring and state updates.
Sourcepub fn set_trading_state(&mut self, state: TradingState)
pub fn set_trading_state(&mut self, state: TradingState)
Sets the trading state for risk control enforcement.
Sourcepub fn set_max_notional_per_order(
&mut self,
instrument_id: InstrumentId,
new_value: Decimal,
)
pub fn set_max_notional_per_order( &mut self, instrument_id: InstrumentId, new_value: Decimal, )
Sets the maximum notional value per order for the specified instrument.
Sourcepub fn portfolio_mut(&mut self) -> &mut Portfolio
pub fn portfolio_mut(&mut self) -> &mut Portfolio
Returns a mutable reference to the portfolio.
Sourcepub const fn config(&self) -> &RiskEngineConfig
pub const fn config(&self) -> &RiskEngineConfig
Returns a reference to the configuration.
Sourcepub const fn command_count(&self) -> u64
pub const fn command_count(&self) -> u64
Returns the total count of trading commands received by the engine.
Sourcepub const fn event_count(&self) -> u64
pub const fn event_count(&self) -> u64
Returns the total count of order events received by the engine.
Sourcepub const fn trading_state(&self) -> TradingState
pub const fn trading_state(&self) -> TradingState
Returns the current trading state.
Sourcepub const fn max_notional_per_order(&self) -> &AHashMap<InstrumentId, Decimal>
pub const fn max_notional_per_order(&self) -> &AHashMap<InstrumentId, Decimal>
Returns a reference to the max notional per order settings.