Skip to main content

Strategy

Trait Strategy 

Source
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§

Source

fn id(&self) -> &StrategyId

Unique identifier for this strategy instance

Source

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.

Source

fn on_event(&mut self, ctx: &mut dyn StrategyContext, event: &Event)

Called for every event routed to this strategy.

Source

fn on_timer(&mut self, ctx: &mut dyn StrategyContext, timer_id: TimerId)

Called when a timer fires.

Source

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§

Source

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".

Implementors§