pub struct InstrumentCache { /* private fields */ }Expand description
Thread-safe instrument cache with multiple lookup indices.
Shared between HTTP client, WebSocket client, and execution client via Arc.
Provides O(1) lookups by InstrumentId, market ticker, or clob_pair_id.
Implementations§
Source§impl InstrumentCache
impl InstrumentCache
Sourcepub fn insert(&self, instrument: InstrumentAny, market: PerpetualMarket)
pub fn insert(&self, instrument: InstrumentAny, market: PerpetualMarket)
Inserts an instrument with its market data.
This populates the primary storage and all lookup indices.
Sourcepub fn insert_many(&self, items: Vec<(InstrumentAny, PerpetualMarket)>)
pub fn insert_many(&self, items: Vec<(InstrumentAny, PerpetualMarket)>)
Bulk inserts instruments with their market data.
Marks the cache as initialized after insertion.
Sourcepub fn insert_instrument_only(&self, instrument: InstrumentAny)
pub fn insert_instrument_only(&self, instrument: InstrumentAny)
Inserts an instrument without market data (InstrumentId lookup only).
Use this for caching instruments when market params are not available.
Note: get_by_clob_id() and get_by_market() won’t work for instruments
inserted this way - only get() by InstrumentId will work.
Sourcepub fn insert_instruments_only(&self, instruments: Vec<InstrumentAny>)
pub fn insert_instruments_only(&self, instruments: Vec<InstrumentAny>)
Bulk inserts instruments without market data.
Marks the cache as initialized after insertion.
Sourcepub fn get(&self, instrument_id: &InstrumentId) -> Option<InstrumentAny>
pub fn get(&self, instrument_id: &InstrumentId) -> Option<InstrumentAny>
Gets an instrument by InstrumentId.
Sourcepub fn get_by_market(&self, ticker: &str) -> Option<InstrumentAny>
pub fn get_by_market(&self, ticker: &str) -> Option<InstrumentAny>
Gets an instrument by market ticker (e.g., “BTC-USD”).
This is the identifier used in public WebSocket channels.
Sourcepub fn get_by_clob_id(&self, clob_pair_id: u32) -> Option<InstrumentAny>
pub fn get_by_clob_id(&self, clob_pair_id: u32) -> Option<InstrumentAny>
Gets an instrument by clob_pair_id (e.g., 0, 1, 2).
This is the identifier used in blockchain transactions and order messages.
Sourcepub fn get_id_by_clob_id(&self, clob_pair_id: u32) -> Option<InstrumentId>
pub fn get_id_by_clob_id(&self, clob_pair_id: u32) -> Option<InstrumentId>
Gets an InstrumentId by clob_pair_id.
Returns directly from index without cloning full instrument.
Sourcepub fn get_id_by_market(&self, ticker: &str) -> Option<InstrumentId>
pub fn get_id_by_market(&self, ticker: &str) -> Option<InstrumentId>
Gets an InstrumentId by market ticker.
Returns directly from index without cloning full instrument.
Sourcepub fn get_market_params(
&self,
instrument_id: &InstrumentId,
) -> Option<PerpetualMarket>
pub fn get_market_params( &self, instrument_id: &InstrumentId, ) -> Option<PerpetualMarket>
Gets full market parameters by InstrumentId.
Returns the complete PerpetualMarket data including margin requirements,
quantization parameters, and current oracle price.
Sourcepub fn get_order_market_params(
&self,
instrument_id: &InstrumentId,
) -> Option<OrderMarketParams>
pub fn get_order_market_params( &self, instrument_id: &InstrumentId, ) -> Option<OrderMarketParams>
Gets order market parameters for order building.
Returns the subset of market data needed for constructing orders (quantization, clob_pair_id, etc.).
Sourcepub fn update_oracle_price(&self, ticker: &str, oracle_price: Decimal)
pub fn update_oracle_price(&self, ticker: &str, oracle_price: Decimal)
Updates oracle price for a market.
Called when receiving price updates via WebSocket v4_markets channel.
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Returns whether the cache has been initialized with instrument data.
Sourcepub fn all_instruments(&self) -> Vec<InstrumentAny>
pub fn all_instruments(&self) -> Vec<InstrumentAny>
Returns all cached instruments.
Useful for WebSocket handler initialization and instrument replay.
Sourcepub fn all_instrument_ids(&self) -> Vec<InstrumentId>
pub fn all_instrument_ids(&self) -> Vec<InstrumentId>
Returns all InstrumentIds.
Sourcepub fn contains(&self, instrument_id: &InstrumentId) -> bool
pub fn contains(&self, instrument_id: &InstrumentId) -> bool
Checks if an instrument exists by InstrumentId.
Sourcepub fn contains_clob_id(&self, clob_pair_id: u32) -> bool
pub fn contains_clob_id(&self, clob_pair_id: u32) -> bool
Checks if an instrument exists by clob_pair_id.
Sourcepub fn contains_market(&self, ticker: &str) -> bool
pub fn contains_market(&self, ticker: &str) -> bool
Checks if an instrument exists by market ticker (e.g., “BTC-USD”).
Sourcepub fn to_instrument_id_map(&self) -> HashMap<InstrumentId, InstrumentAny>
pub fn to_instrument_id_map(&self) -> HashMap<InstrumentId, InstrumentAny>
Returns a HashMap of all instruments keyed by InstrumentId.
This is useful for parsing functions that expect HashMap<InstrumentId, InstrumentAny>.
Note: Creates a snapshot copy, so frequent calls should be avoided.
Sourcepub fn to_oracle_prices_map(&self) -> HashMap<InstrumentId, Decimal>
pub fn to_oracle_prices_map(&self) -> HashMap<InstrumentId, Decimal>
Returns a HashMap of oracle prices keyed by InstrumentId.
This is useful for parsing functions like parse_account_state that need oracle prices.
Note: Creates a snapshot copy, so frequent calls should be avoided.
Sourcepub fn log_missing_clob_pair_id(&self, clob_pair_id: u32)
pub fn log_missing_clob_pair_id(&self, clob_pair_id: u32)
Logs a warning about a missing instrument for a clob_pair_id, listing known mappings.
Trait Implementations§
Source§impl Debug for InstrumentCache
impl Debug for InstrumentCache
Source§impl Default for InstrumentCache
impl Default for InstrumentCache
Source§fn default() -> InstrumentCache
fn default() -> InstrumentCache
Auto Trait Implementations§
impl !Freeze for InstrumentCache
impl !RefUnwindSafe for InstrumentCache
impl Send for InstrumentCache
impl Sync for InstrumentCache
impl Unpin for InstrumentCache
impl UnsafeUnpin for InstrumentCache
impl UnwindSafe for InstrumentCache
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
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
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>,
Layered].