pub trait Strategy: Send + 'static {
// Required methods
fn id(&self) -> &StrategyId;
fn on_start(&mut self, ctx: &mut dyn StrategyContext);
fn on_event(&mut self, ctx: &mut dyn StrategyContext, event: &Event);
fn on_timer(&mut self, ctx: &mut dyn StrategyContext, timer_id: TimerId);
fn on_stop(&mut self, ctx: &mut dyn StrategyContext);
// Provided method
fn sync_mechanism(&self) -> SyncMechanism { ... }
}Expand description
The Strategy trait - what every strategy must implement.
Strategies are deterministic state machines that:
- Receive canonical events
- Emit commands via the context
- Maintain internal state
Strategies never call HTTP directly.
Required Methods§
Sourcefn id(&self) -> &StrategyId
fn id(&self) -> &StrategyId
Unique identifier for this strategy instance
Sourcefn on_start(&mut self, ctx: &mut dyn StrategyContext)
fn on_start(&mut self, ctx: &mut dyn StrategyContext)
Called once when the engine starts this strategy. Use this to initialize state, set timers, etc.
Sourcefn on_event(&mut self, ctx: &mut dyn StrategyContext, event: &Event)
fn on_event(&mut self, ctx: &mut dyn StrategyContext, event: &Event)
Called for every event routed to this strategy.
Sourcefn on_timer(&mut self, ctx: &mut dyn StrategyContext, timer_id: TimerId)
fn on_timer(&mut self, ctx: &mut dyn StrategyContext, timer_id: TimerId)
Called when a timer fires.
Sourcefn on_stop(&mut self, ctx: &mut dyn StrategyContext)
fn on_stop(&mut self, ctx: &mut dyn StrategyContext)
Called once when the engine is stopping this strategy. Use this to cancel orders, log final state, etc.
Provided Methods§
Sourcefn sync_mechanism(&self) -> SyncMechanism
fn sync_mechanism(&self) -> SyncMechanism
Declare the synchronization mechanism for this strategy. Default is Poll (incremental fills).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".