Strategy

Trait Strategy 

Source
pub trait Strategy: Send + Sync {
    // Required methods
    fn id(&self) -> &str;
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn on_tick<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        tick: &'life1 MarketTick,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Signal>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn on_bar<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        bar: &'life1 Bar,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Signal>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn generate_signals<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Signal>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn on_order_filled<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        signal: &'life1 Signal,
        order: &'life2 Order,
        fill_price: Decimal,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn initialize<'life0, 'async_trait>(
        &'life0 mut self,
        bars: Vec<Bar>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn validate(&self) -> Result<()>;
    fn symbols(&self) -> Vec<Symbol>;
    fn risk_parameters(&self) -> StrategyRiskParameters;
}
Expand description

Trait for trading strategies

Each strategy must implement this trait to be used by the trading system. Strategies receive market data and generate trading signals.

Required Methods§

Source

fn id(&self) -> &str

Unique identifier for this strategy

Source

fn name(&self) -> &str

Human-readable name for this strategy

Source

fn description(&self) -> &str

Strategy description

Source

fn on_tick<'life0, 'life1, 'async_trait>( &'life0 mut self, tick: &'life1 MarketTick, ) -> Pin<Box<dyn Future<Output = Result<Option<Signal>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Process incoming market data and potentially generate signals

This method is called whenever new market data arrives for symbols the strategy is interested in.

§Arguments
  • tick - Market tick data
§Returns

Optional trading signal if conditions are met

Source

fn on_bar<'life0, 'life1, 'async_trait>( &'life0 mut self, bar: &'life1 Bar, ) -> Pin<Box<dyn Future<Output = Result<Option<Signal>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Process bar data (OHLCV) and potentially generate signals

This method is called when a new bar is complete.

§Arguments
  • bar - OHLCV bar data
§Returns

Optional trading signal if conditions are met

Source

fn generate_signals<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Signal>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Generate signals based on current state (called periodically)

This method is called on a schedule (e.g., every minute) to allow strategies to generate signals based on accumulated state.

§Returns

Vector of trading signals

Source

fn on_order_filled<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, signal: &'life1 Signal, order: &'life2 Order, fill_price: Decimal, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Update strategy state based on order execution feedback

This method is called when an order is filled, allowing the strategy to update its internal state.

§Arguments
  • signal - Original signal that triggered the order
  • order - Order that was executed
  • fill_price - Actual fill price
Source

fn initialize<'life0, 'async_trait>( &'life0 mut self, bars: Vec<Bar>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Initialize the strategy with historical data

Called once before the strategy starts processing live data. Allows strategies to warm up indicators with historical data.

§Arguments
  • bars - Historical bar data per symbol
Source

fn validate(&self) -> Result<()>

Validate strategy configuration

Called during strategy setup to ensure configuration is valid.

Source

fn symbols(&self) -> Vec<Symbol>

Get the symbols this strategy is interested in

Source

fn risk_parameters(&self) -> StrategyRiskParameters

Get strategy-specific risk parameters

Implementors§