RiskEngine

Struct RiskEngine 

Source
pub struct RiskEngine {
    pub throttled_submit_order: Throttler<SubmitOrder, Box<dyn Fn(SubmitOrder)>>,
    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 comprehensive 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_order: Throttler<SubmitOrder, Box<dyn Fn(SubmitOrder)>>§throttled_modify_order: Throttler<ModifyOrder, Box<dyn Fn(ModifyOrder)>>

Implementations§

Source§

impl RiskEngine

Source

pub fn new( config: RiskEngineConfig, portfolio: Portfolio, clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>, ) -> Self

Creates a new RiskEngine instance.

Source

pub fn execute(&mut self, command: TradingCommand)

Executes a trading command through the risk management pipeline.

Source

pub fn process(&mut self, event: OrderEventAny)

Processes an order event for risk monitoring and state updates.

Source

pub fn set_trading_state(&mut self, state: TradingState)

Sets the trading state for risk control enforcement.

Source

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.

Source

pub fn start(&mut self)

Starts the risk engine.

Source

pub fn stop(&mut self)

Stops the risk engine.

Source

pub fn reset(&mut self)

Resets the risk engine to its initial state.

Source

pub fn dispose(&mut self)

Disposes of the risk engine, releasing resources.

Source

pub fn clock(&self) -> &Rc<RefCell<dyn Clock>>

Returns a reference to the clock.

Source

pub const fn config(&self) -> &RiskEngineConfig

Returns a reference to the configuration.

Source

pub const fn trading_state(&self) -> TradingState

Returns the current trading state.

Source

pub const fn max_notional_per_order(&self) -> &AHashMap<InstrumentId, Decimal>

Returns a reference to the max notional per order settings.

Trait Implementations§

Source§

impl Debug for RiskEngine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V