Trait obrewin_data_structures::market::Orderbook

source ·
pub trait Orderbook {
    // Required methods
    fn iter_ask<'s>(&'s self) -> WrappedIterator<'s, (&'s Price, &'s Quantity)> ;
    fn iter_bid<'s>(&'s self) -> WrappedIterator<'s, (&'s Price, &'s Quantity)> ;
    fn apply_change(&mut self, change: &DirectOrderbookChange, is_ask: bool);

    // Provided methods
    fn best_ask<'s>(
        &'s self,
    ) -> (&'s Price, &'s Quantity, WrappedIterator<'s, (&'s Price, &'s Quantity)>) { ... }
    fn best_bid<'s>(
        &'s self,
    ) -> (&'s Price, &'s Quantity, WrappedIterator<'s, (&'s Price, &'s Quantity)>) { ... }
    fn validate(&self) -> bool { ... }
}
Expand description

Trait for orderbook. The reason why I made a trait for this is because there can be several different structs of an Orderbook.

Following list contains variations on level;

  • L1: Best ask/bid
  • L2: Aggregated asks/bids
  • L3: Non-aggregated asks/bids (Currently not supported)

And also an orderbook can be unsized or have fixed size.

Required Methods§

source

fn iter_ask<'s>(&'s self) -> WrappedIterator<'s, (&'s Price, &'s Quantity)>

Return an iterator that yields asks from the best to the worst.

source

fn iter_bid<'s>(&'s self) -> WrappedIterator<'s, (&'s Price, &'s Quantity)>

Return an iterator that yields bids from the best to the worst.

source

fn apply_change(&mut self, change: &DirectOrderbookChange, is_ask: bool)

Apply change on current orderbook. This method does not guarantee that the modified state is valid.

Provided Methods§

source

fn best_ask<'s>( &'s self, ) -> (&'s Price, &'s Quantity, WrappedIterator<'s, (&'s Price, &'s Quantity)>)

Return first ask price, first ask quantity, and iterator of remaining ask levels. If there is no ask, return Price::MIN as price and Quantity::ZERO as quantity. You can safely drop iterator if there is no needs.

source

fn best_bid<'s>( &'s self, ) -> (&'s Price, &'s Quantity, WrappedIterator<'s, (&'s Price, &'s Quantity)>)

Return first bid price, first bid quantity, and iterator of remaining bid levels. If there is no bid, return Price::MAX as price and Quantity::ZERO as quantity. You can safely drop iterator if there is no needs.

source

fn validate(&self) -> bool

Validate if current state of this orderbook is valid.

Implementors§