pub struct QuoteCache { /* private fields */ }Expand description
A cache for storing the last known quote per instrument.
This is particularly useful for handling partial quote updates from exchange WebSocket feeds, where updates may only include one side of the market (bid or ask). The cache maintains the most recent complete quote for each instrument, allowing adapters to fill in missing information when processing partial updates.
§Thread Safety
This cache is not thread-safe. If shared across threads, wrap it in an appropriate
synchronization primitive such as Arc<RwLock<QuoteCache>> or Arc<Mutex<QuoteCache>>.
Implementations§
Source§impl QuoteCache
impl QuoteCache
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty QuoteCache.
Sourcepub fn get(&self, instrument_id: &InstrumentId) -> Option<&QuoteTick>
pub fn get(&self, instrument_id: &InstrumentId) -> Option<&QuoteTick>
Returns the cached quote for the given instrument, if available.
Sourcepub fn insert(
&mut self,
instrument_id: InstrumentId,
quote: QuoteTick,
) -> Option<QuoteTick>
pub fn insert( &mut self, instrument_id: InstrumentId, quote: QuoteTick, ) -> Option<QuoteTick>
Inserts or updates a quote in the cache for the given instrument.
Returns the previously cached quote if one existed.
Sourcepub fn remove(&mut self, instrument_id: &InstrumentId) -> Option<QuoteTick>
pub fn remove(&mut self, instrument_id: &InstrumentId) -> Option<QuoteTick>
Removes the cached quote for the given instrument.
Returns the removed quote if one existed.
Sourcepub fn contains(&self, instrument_id: &InstrumentId) -> bool
pub fn contains(&self, instrument_id: &InstrumentId) -> bool
Returns true if the cache contains a quote for the given instrument.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears all cached quotes.
This is typically called after a reconnection to ensure stale quotes from before the disconnect are not used.
Sourcepub fn process(
&mut self,
instrument_id: InstrumentId,
bid_price: Option<Price>,
ask_price: Option<Price>,
bid_size: Option<Quantity>,
ask_size: Option<Quantity>,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> Result<QuoteTick>
pub fn process( &mut self, instrument_id: InstrumentId, bid_price: Option<Price>, ask_price: Option<Price>, bid_size: Option<Quantity>, ask_size: Option<Quantity>, ts_event: UnixNanos, ts_init: UnixNanos, ) -> Result<QuoteTick>
Processes a partial quote update, merging with cached values when needed.
This method handles partial quote updates where some fields may be missing.
If any field is None, it will use the corresponding field from the cached quote.
If there is no cached quote and any field is missing, an error is returned.
§Errors
Returns an error if:
- Any required field is
Noneand there is no cached quote. - The first quote received is incomplete (no cached values to merge with).
Trait Implementations§
Source§impl Clone for QuoteCache
impl Clone for QuoteCache
Source§fn clone(&self) -> QuoteCache
fn clone(&self) -> QuoteCache
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for QuoteCache
impl Debug for QuoteCache
Auto Trait Implementations§
impl Freeze for QuoteCache
impl RefUnwindSafe for QuoteCache
impl Send for QuoteCache
impl Sync for QuoteCache
impl Unpin for QuoteCache
impl UnwindSafe for QuoteCache
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)§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>
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>
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