1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
1516use enum_dispatch::enum_dispatch;
17use serde::{Deserialize, Serialize};
1819use 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};
2627#[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}
4243// TODO: Probably move this to the `Instrument` trait too
44impl InstrumentAny {
45#[must_use]
46pub fn get_base_quantity(&self, quantity: Quantity, last_px: Price) -> Quantity {
47match self {
48Self::Betting(inst) => inst.calculate_base_quantity(quantity, last_px),
49Self::BinaryOption(inst) => inst.calculate_base_quantity(quantity, last_px),
50Self::CryptoFuture(inst) => inst.calculate_base_quantity(quantity, last_px),
51Self::CryptoOption(inst) => inst.calculate_base_quantity(quantity, last_px),
52Self::CryptoPerpetual(inst) => inst.calculate_base_quantity(quantity, last_px),
53Self::CurrencyPair(inst) => inst.calculate_base_quantity(quantity, last_px),
54Self::Equity(inst) => inst.calculate_base_quantity(quantity, last_px),
55Self::FuturesContract(inst) => inst.calculate_base_quantity(quantity, last_px),
56Self::FuturesSpread(inst) => inst.calculate_base_quantity(quantity, last_px),
57Self::OptionContract(inst) => inst.calculate_base_quantity(quantity, last_px),
58Self::OptionSpread(inst) => inst.calculate_base_quantity(quantity, last_px),
59 }
60 }
61}
6263impl PartialEq for InstrumentAny {
64fn eq(&self, other: &Self) -> bool {
65self.id() == other.id()
66 }
67}