pub struct StrategyCore {
pub config: StrategyConfig,
/* private fields */
}Expand description
The core component of a Strategy, managing data, orders,
and state.
This struct is intended to be held as a member within a user’s custom strategy struct.
Use the nautilus_strategy! macro to provide the trait accessors required by
Strategy, StrategyNative, and
DataActor. It does not deref to
[DataActorCore]; normal strategy logic should use facade methods on the
strategy value.
Fields§
§config: StrategyConfigThe strategy configuration.
Implementations§
Source§impl StrategyCore
impl StrategyCore
Sourcepub fn new_checked(config: StrategyConfig) -> CorrectnessResult<Self>
pub fn new_checked(config: StrategyConfig) -> CorrectnessResult<Self>
Creates a new StrategyCore instance with correctness checking.
§Errors
Returns an error if the configured order ID tag contains the ‘-’ strategy ID separator,
or if composing it into the strategy ID does not produce a valid [StrategyId].
Sourcepub fn new(config: StrategyConfig) -> Self
pub fn new(config: StrategyConfig) -> Self
Creates a new StrategyCore instance.
§Panics
Panics if the configured order ID tag contains the ‘-’ strategy ID separator,
or if composing it into the strategy ID does not produce a valid [StrategyId].
Sourcepub fn config(&self) -> &StrategyConfig
pub fn config(&self) -> &StrategyConfig
Returns the strategy configuration.
Sourcepub fn change_id(&mut self, strategy_id: StrategyId) -> Result<()>
pub fn change_id(&mut self, strategy_id: StrategyId) -> Result<()>
Changes the strategy ID before registration.
§Errors
Returns an error if composing the current order ID tag into strategy_id does not
produce a valid [StrategyId].
Sourcepub fn change_order_id_tag(&mut self, order_id_tag: &str) -> Result<()>
pub fn change_order_id_tag(&mut self, order_id_tag: &str) -> Result<()>
Changes the order ID tag before registration.
§Errors
Returns an error if order_id_tag contains the ‘-’ strategy ID separator, or if
composing it into the current strategy ID does not produce a valid [StrategyId].
Sourcepub fn order_id_tag(&self) -> Option<&str>
pub fn order_id_tag(&self) -> Option<&str>
Returns the runtime order ID tag.
Sourcepub fn strategy_id(&self) -> Option<StrategyId>
pub fn strategy_id(&self) -> Option<StrategyId>
Returns the runtime strategy ID.
Sourcepub fn register(
&mut self,
trader_id: TraderId,
clock: Rc<RefCell<dyn Clock>>,
cache: Rc<RefCell<Cache>>,
portfolio: Rc<RefCell<Portfolio>>,
) -> Result<()>
pub fn register( &mut self, trader_id: TraderId, clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>, portfolio: Rc<RefCell<Portfolio>>, ) -> Result<()>
Registers the strategy with the trading engine components.
This is typically called by the framework when the strategy is added to an engine.
§Errors
Returns an error if the configured order ID tag contains the ‘-’ strategy ID separator, or if registration with the actor core fails.
Sourcepub fn reset_market_exit_state(&mut self)
pub fn reset_market_exit_state(&mut self)
Resets the market exit state.