pub struct BookState { /* private fields */ }Expand description
Local order book rebuilt from Finam’s snapshot + action rows.
§Examples
use brokapi_finam::map::market::{ApplyOutcome, BookState, RowAction, RowView};
let row = |price: &str, is_ask, size: &str, action| RowView {
price: price.parse().unwrap(),
is_ask,
size: size.parse().unwrap(),
action,
ts: None,
};
let mut book = BookState::default();
// An increment with no snapshot under it is refused: the stream must be reopened.
let late = [row("100", false, "5", RowAction::Set)];
assert_eq!(book.apply(&late, false), ApplyOutcome::NeedSnapshot);
// A snapshot replaces the book, then rows change single levels.
let snapshot = [row("100", false, "5", RowAction::Set), row("101", true, "3", RowAction::Set)];
assert_eq!(book.apply(&snapshot, true), ApplyOutcome::Applied);
assert!(book.has_snapshot());
book.apply(&[row("100", false, "0", RowAction::Remove), row("99", false, "7", RowAction::Set)], false);
let (bids, asks) = book.levels(10);
assert_eq!(bids.len(), 1);
assert_eq!(bids[0].price, "99".parse()?);
assert_eq!(asks[0].qty, "3".parse()?);Implementations§
Source§impl BookState
impl BookState
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Forgets the whole book, including the snapshot. The next increment is refused until a new snapshot.
Sourcepub fn has_snapshot(&self) -> bool
pub fn has_snapshot(&self) -> bool
true once a snapshot was applied since creation or the last reset.
Sourcepub fn apply(&mut self, rows: &[RowView], is_snapshot: bool) -> ApplyOutcome
pub fn apply(&mut self, rows: &[RowView], is_snapshot: bool) -> ApplyOutcome
is_snapshot replaces the whole book (a snapshot message is assumed to carry all levels).
Without a snapshot an increment is not applied and the result is ApplyOutcome::NeedSnapshot.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BookState
impl RefUnwindSafe for BookState
impl Send for BookState
impl Sync for BookState
impl Unpin for BookState
impl UnsafeUnpin for BookState
impl UnwindSafe for BookState
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered].