pub struct RiskManager { /* private fields */ }Expand description
Minimal risk management component used by the higher level trading engines.
Implementations§
Source§impl RiskManager
impl RiskManager
Sourcepub fn new(config: RiskConfig, portfolio_value: f64) -> Self
pub fn new(config: RiskConfig, portfolio_value: f64) -> Self
Create a new RiskManager with the provided configuration.
Sourcepub fn config(&self) -> &RiskConfig
pub fn config(&self) -> &RiskConfig
Access the underlying risk configuration.
Sourcepub fn update_portfolio_value(
&mut self,
new_value: f64,
_realized_pnl_delta: f64,
) -> Result<()>
pub fn update_portfolio_value( &mut self, new_value: f64, _realized_pnl_delta: f64, ) -> Result<()>
Update the tracked portfolio value. The current implementation simply records the latest value so that position size checks have an up-to-date notion of the account size.
Sourcepub fn validate_order(
&self,
order: &OrderRequest,
_positions: &HashMap<String, Position>,
) -> Result<()>
pub fn validate_order( &self, order: &OrderRequest, _positions: &HashMap<String, Position>, ) -> Result<()>
Validate an order against simple position size limits and the emergency stop flag.
Sourcepub fn generate_stop_loss(
&self,
position: &Position,
order_id: &str,
) -> Option<RiskOrder>
pub fn generate_stop_loss( &self, position: &Position, order_id: &str, ) -> Option<RiskOrder>
Produce a stop-loss order for the supplied position.
Sourcepub fn generate_take_profit(
&self,
position: &Position,
order_id: &str,
) -> Option<RiskOrder>
pub fn generate_take_profit( &self, position: &Position, order_id: &str, ) -> Option<RiskOrder>
Produce a take-profit order for the supplied position.
Sourcepub fn register_stop_loss(&mut self, order: RiskOrder)
pub fn register_stop_loss(&mut self, order: RiskOrder)
Store a generated stop-loss order.
Sourcepub fn register_take_profit(&mut self, order: RiskOrder)
pub fn register_take_profit(&mut self, order: RiskOrder)
Store a generated take-profit order.
Sourcepub fn check_risk_orders(
&mut self,
current_prices: &HashMap<String, f64>,
) -> Vec<RiskOrder>
pub fn check_risk_orders( &mut self, current_prices: &HashMap<String, f64>, ) -> Vec<RiskOrder>
Inspect tracked risk orders against the latest market prices.
Sourcepub fn activate_emergency_stop(&mut self)
pub fn activate_emergency_stop(&mut self)
Manually trigger the emergency stop.
Sourcepub fn deactivate_emergency_stop(&mut self)
pub fn deactivate_emergency_stop(&mut self)
Clear the emergency stop condition.
Sourcepub fn should_stop_trading(&self) -> bool
pub fn should_stop_trading(&self) -> bool
Check whether trading should be halted.
Trait Implementations§
Source§impl Clone for RiskManager
impl Clone for RiskManager
Source§fn clone(&self) -> RiskManager
fn clone(&self) -> RiskManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more