nautilus_model/instruments/
any.rs1use enum_dispatch::enum_dispatch;
17use serde::{Deserialize, Serialize};
18
19use super::{
20 Instrument, betting::BettingInstrument, binary_option::BinaryOption,
21 crypto_future::CryptoFuture, crypto_option::CryptoOption, crypto_perpetual::CryptoPerpetual,
22 currency_pair::CurrencyPair, equity::Equity, futures_contract::FuturesContract,
23 futures_spread::FuturesSpread, option_contract::OptionContract, option_spread::OptionSpread,
24};
25use crate::types::{Price, Quantity};
26
27#[derive(Clone, Debug, Serialize, Deserialize)]
28#[enum_dispatch(Instrument)]
29pub enum InstrumentAny {
30 Betting(BettingInstrument),
31 BinaryOption(BinaryOption),
32 CryptoFuture(CryptoFuture),
33 CryptoOption(CryptoOption),
34 CryptoPerpetual(CryptoPerpetual),
35 CurrencyPair(CurrencyPair),
36 Equity(Equity),
37 FuturesContract(FuturesContract),
38 FuturesSpread(FuturesSpread),
39 OptionContract(OptionContract),
40 OptionSpread(OptionSpread),
41}
42
43impl InstrumentAny {
45 #[must_use]
46 pub fn get_base_quantity(&self, quantity: Quantity, last_px: Price) -> Quantity {
47 match self {
48 Self::Betting(inst) => inst.calculate_base_quantity(quantity, last_px),
49 Self::BinaryOption(inst) => inst.calculate_base_quantity(quantity, last_px),
50 Self::CryptoFuture(inst) => inst.calculate_base_quantity(quantity, last_px),
51 Self::CryptoOption(inst) => inst.calculate_base_quantity(quantity, last_px),
52 Self::CryptoPerpetual(inst) => inst.calculate_base_quantity(quantity, last_px),
53 Self::CurrencyPair(inst) => inst.calculate_base_quantity(quantity, last_px),
54 Self::Equity(inst) => inst.calculate_base_quantity(quantity, last_px),
55 Self::FuturesContract(inst) => inst.calculate_base_quantity(quantity, last_px),
56 Self::FuturesSpread(inst) => inst.calculate_base_quantity(quantity, last_px),
57 Self::OptionContract(inst) => inst.calculate_base_quantity(quantity, last_px),
58 Self::OptionSpread(inst) => inst.calculate_base_quantity(quantity, last_px),
59 }
60 }
61}
62
63impl PartialEq for InstrumentAny {
64 fn eq(&self, other: &Self) -> bool {
65 self.id() == other.id()
66 }
67}