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§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
Strategy description
Sourcefn 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_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,
Sourcefn 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 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,
Sourcefn 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 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
Sourcefn 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 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 orderorder- Order that was executedfill_price- Actual fill price
Sourcefn 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 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
Sourcefn validate(&self) -> Result<()>
fn validate(&self) -> Result<()>
Validate strategy configuration
Called during strategy setup to ensure configuration is valid.
Sourcefn risk_parameters(&self) -> StrategyRiskParameters
fn risk_parameters(&self) -> StrategyRiskParameters
Get strategy-specific risk parameters