pub struct IndexedInstruments { /* private fields */ }Expand description
Indexed collection of exchanges, assets, and instruments.
Initialise incrementally via the IndexedInstrumentsBuilder, or all at once via the
constructor.
The indexed collection is useful for creating efficient O(1) constant lookup state management systems where the state is keyed on an instrument, asset, or exchange.
For example uses cases, see the central rustrade crate EngineState design.
§Index Relationships
ExchangeIndex: Unique index for eachExchangeIdadded during initialisation.InstrumentIndex: Unique identifier for eachInstrumentadded during initialisation.AssetIndex: Unique identifier for eachExchangeAssetadded during initialisation.
Implementations§
Source§impl IndexedInstruments
impl IndexedInstruments
Sourcepub fn new<Iter, I>(instruments: Iter) -> Self
pub fn new<Iter, I>(instruments: Iter) -> Self
Initialises a new IndexedInstruments from an iterator of Instruments.
This method indexes all unique exchanges, assets, and instruments, creating efficient lookup tables for each entity type.
Note that once an IndexedInstruments has been constructed, it cannot be mutated (this
could invalidate existing index lookup tables).
For incremental initialisation, see the IndexedInstrumentsBuilder.
Sourcepub fn builder() -> IndexedInstrumentsBuilder
pub fn builder() -> IndexedInstrumentsBuilder
Returns a new IndexedInstrumentsBuilder useful for incremental initialisation of
IndexedInstruments.
Sourcepub fn exchanges(&self) -> &[Keyed<ExchangeIndex, ExchangeId>]
pub fn exchanges(&self) -> &[Keyed<ExchangeIndex, ExchangeId>]
Returns a reference to the ExchangeIndex <–> ExchangeId associations.
Sourcepub fn assets(&self) -> &[Keyed<AssetIndex, ExchangeAsset<Asset>>]
pub fn assets(&self) -> &[Keyed<AssetIndex, ExchangeAsset<Asset>>]
Returns a reference to the AssetIndex <–> ExchangeAsset associations.
Sourcepub fn instruments(
&self,
) -> &[Keyed<InstrumentIndex, Instrument<Keyed<ExchangeIndex, ExchangeId>, AssetIndex>>]
pub fn instruments( &self, ) -> &[Keyed<InstrumentIndex, Instrument<Keyed<ExchangeIndex, ExchangeId>, AssetIndex>>]
Returns a reference to the InstrumentIndex <–> Instrument associations.
Sourcepub fn find_exchange_index(
&self,
exchange: ExchangeId,
) -> Result<ExchangeIndex, IndexError>
pub fn find_exchange_index( &self, exchange: ExchangeId, ) -> Result<ExchangeIndex, IndexError>
Finds the ExchangeIndex associated with the provided ExchangeId.
§Arguments
exchange- The exchange ID to look up
§Returns
Ok(ExchangeIndex)- exchange found.Err(IndexError)- exchange not found.
pub fn find_exchange( &self, index: ExchangeIndex, ) -> Result<ExchangeId, IndexError>
Sourcepub fn find_asset_index(
&self,
exchange: ExchangeId,
name: &AssetNameInternal,
) -> Result<AssetIndex, IndexError>
pub fn find_asset_index( &self, exchange: ExchangeId, name: &AssetNameInternal, ) -> Result<AssetIndex, IndexError>
Finds the AssetIndex associated with the provided ExchangeId and AssetNameInterval.
§Arguments
exchange- TheExchangeIdassociated with the asset.name- TheAssetNameInternalassociated with the asset (eg/ “btc”, “usdt”, etc).
§Returns
Ok(AssetIndex)- exchange asset found.Err(IndexError)- exchange asset not found.
pub fn find_asset( &self, index: AssetIndex, ) -> Result<&ExchangeAsset<Asset>, IndexError>
Sourcepub fn find_instrument_index(
&self,
exchange: ExchangeId,
name: &InstrumentNameInternal,
) -> Result<InstrumentIndex, IndexError>
pub fn find_instrument_index( &self, exchange: ExchangeId, name: &InstrumentNameInternal, ) -> Result<InstrumentIndex, IndexError>
Finds the InstrumentIndex associated with the provided ExchangeId and
InstrumentNameInternal.
§Arguments
exchange- TheExchangeIdassociated with the instrument.name- TheInstrumentNameInternalassociated with the instrument (eg/ binance_spot_btc_usdt).
§Returns
Ok(AssetIndex)- instrument found.Err(IndexError)- instrument not found.
pub fn find_instrument( &self, index: InstrumentIndex, ) -> Result<&Instrument<Keyed<ExchangeIndex, ExchangeId>, AssetIndex>, IndexError>
Trait Implementations§
Source§impl Clone for IndexedInstruments
impl Clone for IndexedInstruments
Source§fn clone(&self) -> IndexedInstruments
fn clone(&self) -> IndexedInstruments
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for IndexedInstruments
impl Debug for IndexedInstruments
Source§impl<'de> Deserialize<'de> for IndexedInstruments
impl<'de> Deserialize<'de> for IndexedInstruments
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<I> FromIterator<I> for IndexedInstruments
impl<I> FromIterator<I> for IndexedInstruments
Source§fn from_iter<Iter>(iter: Iter) -> Selfwhere
Iter: IntoIterator<Item = I>,
fn from_iter<Iter>(iter: Iter) -> Selfwhere
Iter: IntoIterator<Item = I>,
Source§impl PartialEq for IndexedInstruments
impl PartialEq for IndexedInstruments
Source§fn eq(&self, other: &IndexedInstruments) -> bool
fn eq(&self, other: &IndexedInstruments) -> bool
self and other values to be equal, and is used by ==.