OrderBook

Struct OrderBook 

Source
pub struct OrderBook {
Show 13 fields pub symbol: String, pub timestamp: i64, pub datetime: Option<String>, pub nonce: Option<i64>, pub bids: Vec<OrderBookEntry>, pub asks: Vec<OrderBookEntry>, pub info: HashMap<String, Value>, pub buffered_deltas: VecDeque<OrderBookDelta>, pub bids_map: BTreeMap<String, Decimal>, pub asks_map: BTreeMap<String, Decimal>, pub is_synced: bool, pub needs_resync: bool, pub last_resync_time: i64,
}
Expand description

Complete order book structure

Fields§

§symbol: String

Exchange symbol

§timestamp: i64

Timestamp in milliseconds

§datetime: Option<String>

ISO8601 datetime string

§nonce: Option<i64>

Nonce/sequence number for updates

§bids: Vec<OrderBookEntry>

Bid side (buyers) - sorted descending by price

§asks: Vec<OrderBookEntry>

Ask side (sellers) - sorted ascending by price

§info: HashMap<String, Value>

Raw exchange info

§buffered_deltas: VecDeque<OrderBookDelta>

Buffered delta messages waiting for snapshot

§bids_map: BTreeMap<String, Decimal>

BTree map for efficient bid updates (price -> amount)

§asks_map: BTreeMap<String, Decimal>

BTree map for efficient ask updates (price -> amount)

§is_synced: bool

Whether orderbook is synchronized

§needs_resync: bool

Request resync flag (set when sequence gap detected)

§last_resync_time: i64

Last resync timestamp (for rate limiting resync attempts)

Implementations§

Source§

impl OrderBook

Source

pub fn new(symbol: String, timestamp: i64) -> OrderBook

Create a new empty order book

Source

pub fn best_bid(&self) -> Option<&OrderBookEntry>

Get best bid (highest buy price)

Source

pub fn best_ask(&self) -> Option<&OrderBookEntry>

Get best ask (lowest sell price)

Source

pub fn spread(&self) -> Option<Price>

Calculate bid-ask spread

Source

pub fn spread_percentage(&self) -> Option<Decimal>

Calculate spread percentage

Source

pub fn mid_price(&self) -> Option<Price>

Calculate mid price (average of best bid and ask)

Source

pub fn bid_volume(&self) -> Amount

Get total bid volume

Source

pub fn ask_volume(&self) -> Amount

Get total ask volume

Source

pub fn sort_bids(&mut self)

Sort bids in descending order (highest price first)

Source

pub fn sort_asks(&mut self)

Sort asks in ascending order (lowest price first)

Source

pub fn sort(&mut self)

Sort both sides

Source

pub fn limit(&mut self, depth: usize)

Limit order book to specified depth per side

Source

pub fn update( &mut self, bids: Vec<OrderBookEntry>, asks: Vec<OrderBookEntry>, timestamp: i64, )

Update order book with new entries

Source

pub fn reset_from_snapshot( &mut self, bids: Vec<OrderBookEntry>, asks: Vec<OrderBookEntry>, timestamp: i64, nonce: Option<i64>, )

Reset orderbook from snapshot

Source

pub fn buffer_delta(&mut self, delta: OrderBookDelta)

Buffer a delta update for later processing

Source

pub fn apply_delta( &mut self, delta: &OrderBookDelta, is_futures: bool, ) -> Result<(), String>

Apply a delta update (incremental update)

Source

pub fn process_buffered_deltas( &mut self, is_futures: bool, ) -> Result<usize, String>

Process buffered deltas after receiving snapshot

Source

pub fn clear_buffer(&mut self)

Clear all buffered deltas

Source

pub fn buffered_count(&self) -> usize

Get number of buffered deltas

Source

pub fn reset_for_resync(&mut self)

Reset orderbook state for resync Clears all data but keeps symbol and preserves buffered deltas

Source

pub fn should_resync(&self, current_time: i64) -> bool

Check if resync is needed and rate limit is satisfied Rate limit: minimum 1 second between resyncs

Source

pub fn mark_resync_initiated(&mut self, current_time: i64)

Mark that resync has been initiated

Trait Implementations§

Source§

impl Clone for OrderBook

Source§

fn clone(&self) -> OrderBook

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OrderBook

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for OrderBook

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<OrderBook, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for OrderBook

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,