Skip to content

Commit

Permalink
Add InstrumentAny methods in Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Apr 15, 2024
1 parent 98021a3 commit 240cb7d
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions nautilus_core/model/src/instruments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,88 @@ impl InstrumentAny {
}
}

#[must_use]
pub fn price_precision(&self) -> u8 {
match self {
Self::CryptoFuture(inst) => inst.price_precision(),
Self::CryptoPerpetual(inst) => inst.price_precision(),
Self::CurrencyPair(inst) => inst.price_precision(),
Self::Equity(inst) => inst.price_precision(),
Self::FuturesContract(inst) => inst.price_precision(),
Self::FuturesSpread(inst) => inst.price_precision(),
Self::OptionsContract(inst) => inst.price_precision(),
Self::OptionsSpread(inst) => inst.price_precision(),
}
}

#[must_use]
pub fn size_precision(&self) -> u8 {
match self {
Self::CryptoFuture(inst) => inst.size_precision(),
Self::CryptoPerpetual(inst) => inst.size_precision(),
Self::CurrencyPair(inst) => inst.size_precision(),
Self::Equity(inst) => inst.size_precision(),
Self::FuturesContract(inst) => inst.size_precision(),
Self::FuturesSpread(inst) => inst.size_precision(),
Self::OptionsContract(inst) => inst.size_precision(),
Self::OptionsSpread(inst) => inst.size_precision(),
}
}

#[must_use]
pub fn price_increment(&self) -> Price {
match self {
Self::CryptoFuture(inst) => inst.price_increment(),
Self::CryptoPerpetual(inst) => inst.price_increment(),
Self::CurrencyPair(inst) => inst.price_increment(),
Self::Equity(inst) => inst.price_increment(),
Self::FuturesContract(inst) => inst.price_increment(),
Self::FuturesSpread(inst) => inst.price_increment(),
Self::OptionsContract(inst) => inst.price_increment(),
Self::OptionsSpread(inst) => inst.price_increment(),
}
}

#[must_use]
pub fn size_increment(&self) -> Quantity {
match self {
Self::CryptoFuture(inst) => inst.size_increment(),
Self::CryptoPerpetual(inst) => inst.size_increment(),
Self::CurrencyPair(inst) => inst.size_increment(),
Self::Equity(inst) => inst.size_increment(),
Self::FuturesContract(inst) => inst.size_increment(),
Self::FuturesSpread(inst) => inst.size_increment(),
Self::OptionsContract(inst) => inst.size_increment(),
Self::OptionsSpread(inst) => inst.size_increment(),
}
}

pub fn make_price(&self, value: f64) -> anyhow::Result<Price> {
match self {
Self::CryptoFuture(inst) => inst.make_price(value),
Self::CryptoPerpetual(inst) => inst.make_price(value),
Self::CurrencyPair(inst) => inst.make_price(value),
Self::Equity(inst) => inst.make_price(value),
Self::FuturesContract(inst) => inst.make_price(value),
Self::FuturesSpread(inst) => inst.make_price(value),
Self::OptionsContract(inst) => inst.make_price(value),
Self::OptionsSpread(inst) => inst.make_price(value),
}
}

pub fn make_qty(&self, value: f64) -> anyhow::Result<Quantity> {
match self {
Self::CryptoFuture(inst) => inst.make_qty(value),
Self::CryptoPerpetual(inst) => inst.make_qty(value),
Self::CurrencyPair(inst) => inst.make_qty(value),
Self::Equity(inst) => inst.make_qty(value),
Self::FuturesContract(inst) => inst.make_qty(value),
Self::FuturesSpread(inst) => inst.make_qty(value),
Self::OptionsContract(inst) => inst.make_qty(value),
Self::OptionsSpread(inst) => inst.make_qty(value),
}
}

#[must_use]
pub fn calculate_notional_value(
&self,
Expand Down

0 comments on commit 240cb7d

Please sign in to comment.