Trait Strategy

Source
pub trait Strategy: Send + Sync {
    // Required methods
    fn id(&self) -> &str;
    fn instruments(&self) -> &[InstrumentId];
    fn process_trade<'life0, 'async_trait>(
        &'life0 self,
        trade: MarketTrade,
    ) -> Pin<Box<dyn Future<Output = Result<SmallSignalVec<Signal>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn process_depth<'life0, 'async_trait>(
        &'life0 self,
        depth: OrderBookSnapshot,
    ) -> Pin<Box<dyn Future<Output = Result<SmallSignalVec<Signal>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn process_bar<'life0, 'async_trait>(
        &'life0 self,
        bar: Bar,
    ) -> Pin<Box<dyn Future<Output = Result<SmallSignalVec<Signal>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn update_from_orderbook<'life0, 'async_trait>(
        &'life0 self,
        order_book: Arc<SharedSimdOrderBook>,
    ) -> Pin<Box<dyn Future<Output = Result<SmallSignalVec<Signal>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn on_timer<'life0, 'async_trait>(
        &'life0 self,
        timestamp_ns: u64,
    ) -> Pin<Box<dyn Future<Output = Result<SmallSignalVec<Signal>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn initialize<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn shutdown<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

The Strategy trait defines the interface for all trading strategies.

Required Methods§

Source

fn id(&self) -> &str

Returns the unique identifier for this strategy

Source

fn instruments(&self) -> &[InstrumentId]

Returns a list of instruments that this strategy is interested in

Source

fn process_trade<'life0, 'async_trait>( &'life0 self, trade: MarketTrade, ) -> Pin<Box<dyn Future<Output = Result<SmallSignalVec<Signal>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Processes a new trade event

§Parameters
  • trade - The trade event to process
§Returns

A SmallSignalVec of signals generated by the strategy

Source

fn process_depth<'life0, 'async_trait>( &'life0 self, depth: OrderBookSnapshot, ) -> Pin<Box<dyn Future<Output = Result<SmallSignalVec<Signal>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Processes a new order book depth update

§Parameters
  • depth - The order book depth update to process
§Returns

A SmallSignalVec of signals generated by the strategy

Source

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

Processes a new bar (OHLCV) event

§Parameters
  • bar - The bar event to process
§Returns

A SmallSignalVec of signals generated by the strategy

Source

fn update_from_orderbook<'life0, 'async_trait>( &'life0 self, order_book: Arc<SharedSimdOrderBook>, ) -> Pin<Box<dyn Future<Output = Result<SmallSignalVec<Signal>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Updates the strategy’s internal state based on a shared SIMD order book

§Parameters
  • order_book - The shared SIMD order book to use for updating the strategy’s state
§Returns

A SmallSignalVec of signals generated by the strategy

Source

fn on_timer<'life0, 'async_trait>( &'life0 self, timestamp_ns: u64, ) -> Pin<Box<dyn Future<Output = Result<SmallSignalVec<Signal>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called periodically by the strategy engine to allow the strategy to perform time-based operations

§Parameters
  • timestamp_ns - The current timestamp in nanoseconds
§Returns

A SmallSignalVec of signals generated by the strategy

Source

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

Initializes the strategy with required resources

§Returns

Ok(()) if initialization was successful, an error otherwise

Source

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

Shuts down the strategy and cleans up resources

§Returns

Ok(()) if shutdown was successful, an error otherwise

Implementors§