pub struct OrderBook {
pub symbol: SmartString,
pub tick_size: Decimal,
pub lot_size: Decimal,
/* private fields */
}Expand description
L2 Order Book maintaining bid/ask levels
Fields§
§symbol: SmartStringSymbol/asset identifier
tick_size: DecimalTick size for price rounding
lot_size: DecimalLot size for quantity rounding
Implementations§
Source§impl OrderBook
impl OrderBook
Sourcepub fn new(symbol: SmartString, tick_size: Decimal, lot_size: Decimal) -> Self
pub fn new(symbol: SmartString, tick_size: Decimal, lot_size: Decimal) -> Self
Create a new L2 order book
Sourcepub fn price_to_tick(&self, price: Decimal) -> i64
pub fn price_to_tick(&self, price: Decimal) -> i64
Convert price to tick
Sourcepub fn tick_to_price(&self, tick: i64) -> Decimal
pub fn tick_to_price(&self, tick: i64) -> Decimal
Convert tick to price
Sourcepub fn round_quantity(&self, quantity: Decimal) -> Decimal
pub fn round_quantity(&self, quantity: Decimal) -> Decimal
Round quantity to lot size
Sourcepub fn update_bid(
&self,
price: Decimal,
quantity: Decimal,
order_count: u32,
timestamp_ns: u64,
)
pub fn update_bid( &self, price: Decimal, quantity: Decimal, order_count: u32, timestamp_ns: u64, )
Update a bid level
Sourcepub fn update_ask(
&self,
price: Decimal,
quantity: Decimal,
order_count: u32,
timestamp_ns: u64,
)
pub fn update_ask( &self, price: Decimal, quantity: Decimal, order_count: u32, timestamp_ns: u64, )
Update an ask level
Sourcepub fn bid_qty_at_tick(&self, tick: i64) -> Decimal
pub fn bid_qty_at_tick(&self, tick: i64) -> Decimal
Get bid quantity at price tick
Sourcepub fn ask_qty_at_tick(&self, tick: i64) -> Decimal
pub fn ask_qty_at_tick(&self, tick: i64) -> Decimal
Get ask quantity at price tick
Sourcepub fn update_last_price(&self, price: Decimal, timestamp_ns: u64)
pub fn update_last_price(&self, price: Decimal, timestamp_ns: u64)
Update last trade price
Sourcepub fn last_price(&self) -> Option<Decimal>
pub fn last_price(&self) -> Option<Decimal>
Get last trade price
Sourcepub fn bid_liquidity_within(&self, ticks: i64) -> Decimal
pub fn bid_liquidity_within(&self, ticks: i64) -> Decimal
Get total bid liquidity within N ticks from best
Sourcepub fn ask_liquidity_within(&self, ticks: i64) -> Decimal
pub fn ask_liquidity_within(&self, ticks: i64) -> Decimal
Get total ask liquidity within N ticks from best
Sourcepub fn impact_bid(&self, quantity: Decimal) -> Option<Decimal>
pub fn impact_bid(&self, quantity: Decimal) -> Option<Decimal>
Calculate weighted average price for a market buy
Sourcepub fn impact_ask(&self, quantity: Decimal) -> Option<Decimal>
pub fn impact_ask(&self, quantity: Decimal) -> Option<Decimal>
Calculate weighted average price for a market sell
Sourcepub fn total_volume(&self) -> Decimal
pub fn total_volume(&self) -> Decimal
Get total volume across all levels
Auto Trait Implementations§
impl Freeze for OrderBook
impl !RefUnwindSafe for OrderBook
impl Send for OrderBook
impl Sync for OrderBook
impl Unpin for OrderBook
impl !UnwindSafe for OrderBook
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more