Skip to main content

IndexedInstruments

Struct IndexedInstruments 

Source
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 each ExchangeId added during initialisation.
  • InstrumentIndex: Unique identifier for each Instrument added during initialisation.
  • AssetIndex: Unique identifier for each ExchangeAsset added during initialisation.

Implementations§

Source§

impl IndexedInstruments

Source

pub fn new<Iter, I>(instruments: Iter) -> Self
where Iter: IntoIterator<Item = I>, I: Into<Instrument<ExchangeId, Asset>>,

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.

Source

pub fn builder() -> IndexedInstrumentsBuilder

Returns a new IndexedInstrumentsBuilder useful for incremental initialisation of IndexedInstruments.

Source

pub fn exchanges(&self) -> &[Keyed<ExchangeIndex, ExchangeId>]

Returns a reference to the ExchangeIndex <–> ExchangeId associations.

Source

pub fn assets(&self) -> &[Keyed<AssetIndex, ExchangeAsset<Asset>>]

Returns a reference to the AssetIndex <–> ExchangeAsset associations.

Source

pub fn instruments( &self, ) -> &[Keyed<InstrumentIndex, Instrument<Keyed<ExchangeIndex, ExchangeId>, AssetIndex>>]

Returns a reference to the InstrumentIndex <–> Instrument associations.

Source

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.
Source

pub fn find_exchange( &self, index: ExchangeIndex, ) -> Result<ExchangeId, IndexError>

Source

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 - The ExchangeId associated with the asset.
  • name - The AssetNameInternal associated with the asset (eg/ “btc”, “usdt”, etc).
§Returns
  • Ok(AssetIndex) - exchange asset found.
  • Err(IndexError) - exchange asset not found.
Source

pub fn find_asset( &self, index: AssetIndex, ) -> Result<&ExchangeAsset<Asset>, IndexError>

Source

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 - The ExchangeId associated with the instrument.
  • name - The InstrumentNameInternal associated with the instrument (eg/ binance_spot_btc_usdt).
§Returns
  • Ok(AssetIndex) - instrument found.
  • Err(IndexError) - instrument not found.
Source

pub fn find_instrument( &self, index: InstrumentIndex, ) -> Result<&Instrument<Keyed<ExchangeIndex, ExchangeId>, AssetIndex>, IndexError>

Trait Implementations§

Source§

impl Clone for IndexedInstruments

Source§

fn clone(&self) -> IndexedInstruments

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for IndexedInstruments

Source§

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

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

impl<'de> Deserialize<'de> for IndexedInstruments

Source§

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

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

impl<I> FromIterator<I> for IndexedInstruments

Source§

fn from_iter<Iter>(iter: Iter) -> Self
where Iter: IntoIterator<Item = I>,

Creates a value from an iterator. Read more
Source§

impl PartialEq for IndexedInstruments

Source§

fn eq(&self, other: &IndexedInstruments) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for IndexedInstruments

Source§

fn partial_cmp(&self, other: &IndexedInstruments) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for IndexedInstruments

Source§

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

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for IndexedInstruments

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, 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> 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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,