diff --git a/nautilus_core/common/src/cache/core.rs b/nautilus_core/common/src/cache/core.rs index a12c6de1e308..a71b1919abda 100644 --- a/nautilus_core/common/src/cache/core.rs +++ b/nautilus_core/common/src/cache/core.rs @@ -38,11 +38,6 @@ use nautilus_model::{ instruments::{any::InstrumentAny, synthetic::SyntheticInstrument}, orderbook::book::OrderBook, orders::{any::OrderAny, list::OrderList}, - polymorphism::{ - GetClientOrderId, GetEmulationTrigger, GetExecAlgorithmId, GetExecSpawnId, GetInstrumentId, - GetOrderFilledQty, GetOrderLeavesQty, GetOrderQuantity, GetOrderSide, GetPositionId, - GetStrategyId, GetVenueOrderId, IsClosed, IsInflight, IsOpen, - }, position::Position, types::{currency::Currency, price::Price, quantity::Quantity}, }; @@ -2526,7 +2521,6 @@ mod tests { synthetic::SyntheticInstrument, }, orders::stubs::{TestOrderEventStubs, TestOrderStubs}, - polymorphism::{GetClientOrderId, GetOrderStatus, GetVenueOrderId, IsClosed, IsOpen}, types::{price::Price, quantity::Quantity}, }; use rstest::*; diff --git a/nautilus_core/common/src/factories.rs b/nautilus_core/common/src/factories.rs index fe281a3a7832..6569f0f6ebeb 100644 --- a/nautilus_core/common/src/factories.rs +++ b/nautilus_core/common/src/factories.rs @@ -149,9 +149,6 @@ pub mod tests { identifiers::{ client_order_id::ClientOrderId, instrument_id::InstrumentId, order_list_id::OrderListId, }, - polymorphism::{ - GetClientOrderId, GetExecAlgorithmId, GetInstrumentId, GetOrderQuantity, GetOrderSide, - }, }; use rstest::rstest; diff --git a/nautilus_core/execution/src/matching_core.rs b/nautilus_core/execution/src/matching_core.rs index 36852e6532f8..14ab3296e4e4 100644 --- a/nautilus_core/execution/src/matching_core.rs +++ b/nautilus_core/execution/src/matching_core.rs @@ -27,7 +27,6 @@ use nautilus_model::{ base::OrderError, market::MarketOrder, }, - polymorphism::{GetClientOrderId, GetLimitPrice, GetOrderSideSpecified, GetStopPrice}, types::price::Price, }; diff --git a/nautilus_core/infrastructure/tests/test_cache_database_postgres.rs b/nautilus_core/infrastructure/tests/test_cache_database_postgres.rs index 934a236f21b1..3343dc6e2d78 100644 --- a/nautilus_core/infrastructure/tests/test_cache_database_postgres.rs +++ b/nautilus_core/infrastructure/tests/test_cache_database_postgres.rs @@ -78,7 +78,6 @@ mod tests { Instrument, }, orders::stubs::{TestOrderEventStubs, TestOrderStubs}, - polymorphism::GetClientOrderId, types::{currency::Currency, price::Price, quantity::Quantity}, }; use serial_test::serial; diff --git a/nautilus_core/model/src/data/bar.rs b/nautilus_core/model/src/data/bar.rs index dd91adc35e8d..a3f45fd68c43 100644 --- a/nautilus_core/model/src/data/bar.rs +++ b/nautilus_core/model/src/data/bar.rs @@ -27,10 +27,10 @@ use indexmap::IndexMap; use nautilus_core::{nanos::UnixNanos, serialization::Serializable}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use super::GetTsInit; use crate::{ enums::{AggregationSource, BarAggregation, PriceType}, identifiers::instrument_id::InstrumentId, - polymorphism::GetTsInit, types::{price::Price, quantity::Quantity}, }; diff --git a/nautilus_core/model/src/data/delta.rs b/nautilus_core/model/src/data/delta.rs index 8380f5403a07..a253efe6ec82 100644 --- a/nautilus_core/model/src/data/delta.rs +++ b/nautilus_core/model/src/data/delta.rs @@ -25,11 +25,13 @@ use indexmap::IndexMap; use nautilus_core::{nanos::UnixNanos, serialization::Serializable}; use serde::{Deserialize, Serialize}; -use super::order::{BookOrder, NULL_ORDER}; +use super::{ + order::{BookOrder, NULL_ORDER}, + GetTsInit, +}; use crate::{ enums::{BookAction, RecordFlag}, identifiers::instrument_id::InstrumentId, - polymorphism::GetTsInit, }; /// Represents a single change/delta in an order book. diff --git a/nautilus_core/model/src/data/deltas.rs b/nautilus_core/model/src/data/deltas.rs index 702bd80fec68..f29923b51888 100644 --- a/nautilus_core/model/src/data/deltas.rs +++ b/nautilus_core/model/src/data/deltas.rs @@ -23,8 +23,8 @@ use std::{ use nautilus_core::nanos::UnixNanos; -use super::delta::OrderBookDelta; -use crate::{identifiers::instrument_id::InstrumentId, polymorphism::GetTsInit}; +use super::{delta::OrderBookDelta, GetTsInit}; +use crate::identifiers::instrument_id::InstrumentId; /// Represents a grouped batch of `OrderBookDelta` updates for an `OrderBook`. /// diff --git a/nautilus_core/model/src/data/depth.rs b/nautilus_core/model/src/data/depth.rs index 490c18800780..1dfc0118f1a7 100644 --- a/nautilus_core/model/src/data/depth.rs +++ b/nautilus_core/model/src/data/depth.rs @@ -24,8 +24,8 @@ use indexmap::IndexMap; use nautilus_core::{nanos::UnixNanos, serialization::Serializable}; use serde::{Deserialize, Serialize}; -use super::order::BookOrder; -use crate::{identifiers::instrument_id::InstrumentId, polymorphism::GetTsInit}; +use super::{order::BookOrder, GetTsInit}; +use crate::identifiers::instrument_id::InstrumentId; pub const DEPTH10_LEN: usize = 10; diff --git a/nautilus_core/model/src/data/mod.rs b/nautilus_core/model/src/data/mod.rs index 7d4936f772a4..118a5aa41999 100644 --- a/nautilus_core/model/src/data/mod.rs +++ b/nautilus_core/model/src/data/mod.rs @@ -31,7 +31,6 @@ use self::{ bar::Bar, delta::OrderBookDelta, deltas::OrderBookDeltas_API, depth::OrderBookDepth10, quote::QuoteTick, trade::TradeTick, }; -use crate::polymorphism::GetTsInit; /// A built-in Nautilus data type. /// @@ -49,6 +48,10 @@ pub enum Data { Bar(Bar), } +pub trait GetTsInit { + fn ts_init(&self) -> UnixNanos; +} + impl GetTsInit for Data { fn ts_init(&self) -> UnixNanos { match self { diff --git a/nautilus_core/model/src/data/quote.rs b/nautilus_core/model/src/data/quote.rs index 3bd2c63a924c..e24b5095a6aa 100644 --- a/nautilus_core/model/src/data/quote.rs +++ b/nautilus_core/model/src/data/quote.rs @@ -27,10 +27,10 @@ use indexmap::IndexMap; use nautilus_core::{correctness::check_equal_u8, nanos::UnixNanos, serialization::Serializable}; use serde::{Deserialize, Serialize}; +use super::GetTsInit; use crate::{ enums::PriceType, identifiers::instrument_id::InstrumentId, - polymorphism::GetTsInit, types::{fixed::FIXED_PRECISION, price::Price, quantity::Quantity}, }; diff --git a/nautilus_core/model/src/data/trade.rs b/nautilus_core/model/src/data/trade.rs index 5a995d06a09e..302b010d921d 100644 --- a/nautilus_core/model/src/data/trade.rs +++ b/nautilus_core/model/src/data/trade.rs @@ -26,10 +26,10 @@ use indexmap::IndexMap; use nautilus_core::{nanos::UnixNanos, serialization::Serializable}; use serde::{Deserialize, Serialize}; +use super::GetTsInit; use crate::{ enums::AggressorSide, identifiers::{instrument_id::InstrumentId, trade_id::TradeId}, - polymorphism::GetTsInit, types::{price::Price, quantity::Quantity}, }; diff --git a/nautilus_core/model/src/lib.rs b/nautilus_core/model/src/lib.rs index 52ae6ef1d9d4..b8448cb29ae2 100644 --- a/nautilus_core/model/src/lib.rs +++ b/nautilus_core/model/src/lib.rs @@ -37,7 +37,6 @@ pub mod instruments; pub mod macros; pub mod orderbook; pub mod orders; -pub mod polymorphism; pub mod position; pub mod types; pub mod venues; diff --git a/nautilus_core/model/src/orders/any.rs b/nautilus_core/model/src/orders/any.rs index d80f2c27d4d8..8cff68e1a171 100644 --- a/nautilus_core/model/src/orders/any.rs +++ b/nautilus_core/model/src/orders/any.rs @@ -38,13 +38,6 @@ use crate::{ instrument_id::InstrumentId, position_id::PositionId, strategy_id::StrategyId, trader_id::TraderId, venue_order_id::VenueOrderId, }, - polymorphism::{ - GetAccountId, GetClientOrderId, GetEmulationTrigger, GetExecAlgorithmId, GetExecSpawnId, - GetInstrumentId, GetLimitPrice, GetLiquiditySide, GetOrderFilledQty, GetOrderLeavesQty, - GetOrderQuantity, GetOrderSide, GetOrderSideSpecified, GetOrderStatus, GetOrderType, - GetPositionId, GetStopPrice, GetStrategyId, GetTraderId, GetVenueOrderId, IsClosed, - IsInflight, IsOpen, - }, types::{price::Price, quantity::Quantity}, }; @@ -190,36 +183,9 @@ impl OrderAny { } } } -} - -impl PartialEq for OrderAny { - fn eq(&self, other: &Self) -> bool { - self.client_order_id() == other.client_order_id() - } -} - -impl Display for OrderAny { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "{}", - match self { - Self::Limit(order) => order.to_string(), - Self::LimitIfTouched(order) => format!("{:?}", order), // TODO: Implement - Self::Market(order) => order.to_string(), - Self::MarketIfTouched(order) => format!("{:?}", order), // TODO: Implement - Self::MarketToLimit(order) => format!("{:?}", order), // TODO: Implement - Self::StopLimit(order) => order.to_string(), - Self::StopMarket(order) => format!("{:?}", order), // TODO: Implement - Self::TrailingStopLimit(order) => format!("{:?}", order), // TODO: Implement - Self::TrailingStopMarket(order) => format!("{:?}", order), // TODO: Implement - } - ) - } -} -impl GetTraderId for OrderAny { - fn trader_id(&self) -> TraderId { + #[must_use] + pub fn trader_id(&self) -> TraderId { match self { Self::Limit(order) => order.trader_id, Self::LimitIfTouched(order) => order.trader_id, @@ -232,10 +198,9 @@ impl GetTraderId for OrderAny { Self::TrailingStopMarket(order) => order.trader_id, } } -} -impl GetStrategyId for OrderAny { - fn strategy_id(&self) -> StrategyId { + #[must_use] + pub fn strategy_id(&self) -> StrategyId { match self { Self::Limit(order) => order.strategy_id, Self::LimitIfTouched(order) => order.strategy_id, @@ -248,10 +213,9 @@ impl GetStrategyId for OrderAny { Self::TrailingStopMarket(order) => order.strategy_id, } } -} -impl GetInstrumentId for OrderAny { - fn instrument_id(&self) -> InstrumentId { + #[must_use] + pub fn instrument_id(&self) -> InstrumentId { match self { Self::Limit(order) => order.instrument_id, Self::LimitIfTouched(order) => order.instrument_id, @@ -264,26 +228,9 @@ impl GetInstrumentId for OrderAny { Self::TrailingStopMarket(order) => order.instrument_id, } } -} - -impl GetAccountId for OrderAny { - fn account_id(&self) -> Option { - match self { - Self::Limit(order) => order.account_id, - Self::LimitIfTouched(order) => order.account_id, - Self::Market(order) => order.account_id, - Self::MarketIfTouched(order) => order.account_id, - Self::MarketToLimit(order) => order.account_id, - Self::StopLimit(order) => order.account_id, - Self::StopMarket(order) => order.account_id, - Self::TrailingStopLimit(order) => order.account_id, - Self::TrailingStopMarket(order) => order.account_id, - } - } -} -impl GetClientOrderId for OrderAny { - fn client_order_id(&self) -> ClientOrderId { + #[must_use] + pub fn client_order_id(&self) -> ClientOrderId { match self { Self::Limit(order) => order.client_order_id, Self::LimitIfTouched(order) => order.client_order_id, @@ -296,10 +243,24 @@ impl GetClientOrderId for OrderAny { Self::TrailingStopMarket(order) => order.client_order_id, } } -} -impl GetVenueOrderId for OrderAny { - fn venue_order_id(&self) -> Option { + #[must_use] + pub fn account_id(&self) -> Option { + match self { + Self::Limit(order) => order.account_id, + Self::LimitIfTouched(order) => order.account_id, + Self::Market(order) => order.account_id, + Self::MarketIfTouched(order) => order.account_id, + Self::MarketToLimit(order) => order.account_id, + Self::StopLimit(order) => order.account_id, + Self::StopMarket(order) => order.account_id, + Self::TrailingStopLimit(order) => order.account_id, + Self::TrailingStopMarket(order) => order.account_id, + } + } + + #[must_use] + pub fn venue_order_id(&self) -> Option { match self { Self::Limit(order) => order.venue_order_id, Self::LimitIfTouched(order) => order.venue_order_id, @@ -312,10 +273,9 @@ impl GetVenueOrderId for OrderAny { Self::TrailingStopMarket(order) => order.venue_order_id, } } -} -impl GetPositionId for OrderAny { - fn position_id(&self) -> Option { + #[must_use] + pub fn position_id(&self) -> Option { match self { Self::Limit(order) => order.position_id, Self::LimitIfTouched(order) => order.position_id, @@ -328,10 +288,9 @@ impl GetPositionId for OrderAny { Self::TrailingStopMarket(order) => order.position_id, } } -} -impl GetExecAlgorithmId for OrderAny { - fn exec_algorithm_id(&self) -> Option { + #[must_use] + pub fn exec_algorithm_id(&self) -> Option { match self { Self::Limit(order) => order.exec_algorithm_id, Self::LimitIfTouched(order) => order.exec_algorithm_id, @@ -344,10 +303,9 @@ impl GetExecAlgorithmId for OrderAny { Self::TrailingStopMarket(order) => order.exec_algorithm_id, } } -} -impl GetExecSpawnId for OrderAny { - fn exec_spawn_id(&self) -> Option { + #[must_use] + pub fn exec_spawn_id(&self) -> Option { match self { Self::Limit(order) => order.exec_spawn_id, Self::LimitIfTouched(order) => order.exec_spawn_id, @@ -360,10 +318,9 @@ impl GetExecSpawnId for OrderAny { Self::TrailingStopMarket(order) => order.exec_spawn_id, } } -} -impl GetOrderSide for OrderAny { - fn order_side(&self) -> OrderSide { + #[must_use] + pub fn order_side(&self) -> OrderSide { match self { Self::Limit(order) => order.side, Self::LimitIfTouched(order) => order.side, @@ -376,10 +333,9 @@ impl GetOrderSide for OrderAny { Self::TrailingStopMarket(order) => order.side, } } -} -impl GetOrderType for OrderAny { - fn order_type(&self) -> OrderType { + #[must_use] + pub fn order_type(&self) -> OrderType { match self { Self::Limit(order) => order.order_type, Self::LimitIfTouched(order) => order.order_type, @@ -392,10 +348,9 @@ impl GetOrderType for OrderAny { Self::TrailingStopMarket(order) => order.order_type, } } -} -impl GetOrderQuantity for OrderAny { - fn quantity(&self) -> Quantity { + #[must_use] + pub fn quantity(&self) -> Quantity { match self { Self::Limit(order) => order.quantity, Self::LimitIfTouched(order) => order.quantity, @@ -408,10 +363,9 @@ impl GetOrderQuantity for OrderAny { Self::TrailingStopMarket(order) => order.quantity, } } -} -impl GetOrderStatus for OrderAny { - fn status(&self) -> OrderStatus { + #[must_use] + pub fn status(&self) -> OrderStatus { match self { Self::Limit(order) => order.status, Self::LimitIfTouched(order) => order.status, @@ -424,10 +378,9 @@ impl GetOrderStatus for OrderAny { Self::TrailingStopMarket(order) => order.status, } } -} -impl GetOrderFilledQty for OrderAny { - fn filled_qty(&self) -> Quantity { + #[must_use] + pub fn filled_qty(&self) -> Quantity { match self { Self::Limit(order) => order.filled_qty(), Self::LimitIfTouched(order) => order.filled_qty(), @@ -440,10 +393,9 @@ impl GetOrderFilledQty for OrderAny { Self::TrailingStopMarket(order) => order.filled_qty(), } } -} -impl GetOrderLeavesQty for OrderAny { - fn leaves_qty(&self) -> Quantity { + #[must_use] + pub fn leaves_qty(&self) -> Quantity { match self { Self::Limit(order) => order.leaves_qty(), Self::LimitIfTouched(order) => order.leaves_qty(), @@ -456,10 +408,9 @@ impl GetOrderLeavesQty for OrderAny { Self::TrailingStopMarket(order) => order.leaves_qty(), } } -} -impl GetOrderSideSpecified for OrderAny { - fn order_side_specified(&self) -> OrderSideSpecified { + #[must_use] + pub fn order_side_specified(&self) -> OrderSideSpecified { match self { Self::Limit(order) => order.side.as_specified(), Self::LimitIfTouched(order) => order.side.as_specified(), @@ -472,10 +423,9 @@ impl GetOrderSideSpecified for OrderAny { Self::TrailingStopMarket(order) => order.side.as_specified(), } } -} -impl GetLiquiditySide for OrderAny { - fn liquidity_side(&self) -> Option { + #[must_use] + pub fn liquidity_side(&self) -> Option { match self { Self::Limit(order) => order.liquidity_side, Self::LimitIfTouched(order) => order.liquidity_side, @@ -488,10 +438,9 @@ impl GetLiquiditySide for OrderAny { Self::TrailingStopMarket(order) => order.liquidity_side, } } -} -impl GetEmulationTrigger for OrderAny { - fn emulation_trigger(&self) -> Option { + #[must_use] + pub fn emulation_trigger(&self) -> Option { match self { Self::Limit(order) => order.emulation_trigger, Self::LimitIfTouched(order) => order.emulation_trigger, @@ -504,10 +453,9 @@ impl GetEmulationTrigger for OrderAny { Self::TrailingStopMarket(order) => order.emulation_trigger, } } -} -impl IsOpen for OrderAny { - fn is_open(&self) -> bool { + #[must_use] + pub fn is_open(&self) -> bool { match self { Self::Limit(order) => order.is_open(), Self::LimitIfTouched(order) => order.is_open(), @@ -520,10 +468,9 @@ impl IsOpen for OrderAny { Self::TrailingStopMarket(order) => order.is_open(), } } -} -impl IsClosed for OrderAny { - fn is_closed(&self) -> bool { + #[must_use] + pub fn is_closed(&self) -> bool { match self { Self::Limit(order) => order.is_closed(), Self::LimitIfTouched(order) => order.is_closed(), @@ -536,10 +483,9 @@ impl IsClosed for OrderAny { Self::TrailingStopMarket(order) => order.is_closed(), } } -} -impl IsInflight for OrderAny { - fn is_inflight(&self) -> bool { + #[must_use] + pub fn is_inflight(&self) -> bool { match self { Self::Limit(order) => order.is_inflight(), Self::LimitIfTouched(order) => order.is_inflight(), @@ -554,6 +500,32 @@ impl IsInflight for OrderAny { } } +impl PartialEq for OrderAny { + fn eq(&self, other: &Self) -> bool { + self.client_order_id() == other.client_order_id() + } +} + +impl Display for OrderAny { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + Self::Limit(order) => order.to_string(), + Self::LimitIfTouched(order) => format!("{:?}", order), // TODO: Implement + Self::Market(order) => order.to_string(), + Self::MarketIfTouched(order) => format!("{:?}", order), // TODO: Implement + Self::MarketToLimit(order) => format!("{:?}", order), // TODO: Implement + Self::StopLimit(order) => order.to_string(), + Self::StopMarket(order) => format!("{:?}", order), // TODO: Implement + Self::TrailingStopLimit(order) => format!("{:?}", order), // TODO: Implement + Self::TrailingStopMarket(order) => format!("{:?}", order), // TODO: Implement + } + ) + } +} + #[derive(Clone, Debug)] pub enum PassiveOrderAny { Limit(LimitOrderAny), @@ -561,6 +533,22 @@ pub enum PassiveOrderAny { } impl PassiveOrderAny { + #[must_use] + pub fn client_order_id(&self) -> ClientOrderId { + match self { + Self::Limit(order) => order.client_order_id(), + Self::Stop(order) => order.client_order_id(), + } + } + + #[must_use] + pub fn order_side_specified(&self) -> OrderSideSpecified { + match self { + Self::Limit(order) => order.order_side_specified(), + Self::Stop(order) => order.order_side_specified(), + } + } + #[must_use] pub fn is_closed(&self) -> bool { match self { @@ -596,6 +584,36 @@ pub enum LimitOrderAny { } impl LimitOrderAny { + #[must_use] + pub fn client_order_id(&self) -> ClientOrderId { + match self { + Self::Limit(order) => order.client_order_id, + Self::MarketToLimit(order) => order.client_order_id, + Self::StopLimit(order) => order.client_order_id, + Self::TrailingStopLimit(order) => order.client_order_id, + } + } + + #[must_use] + pub fn order_side_specified(&self) -> OrderSideSpecified { + match self { + Self::Limit(order) => order.side.as_specified(), + Self::MarketToLimit(order) => order.side.as_specified(), + Self::StopLimit(order) => order.side.as_specified(), + Self::TrailingStopLimit(order) => order.side.as_specified(), + } + } + + #[must_use] + pub fn limit_px(&self) -> Price { + match self { + Self::Limit(order) => order.price, + Self::MarketToLimit(order) => order.price.expect("No price for order"), // TBD + Self::StopLimit(order) => order.price, + Self::TrailingStopLimit(order) => order.price, + } + } + #[must_use] pub fn is_closed(&self) -> bool { match self { @@ -639,6 +657,42 @@ pub enum StopOrderAny { } impl StopOrderAny { + #[must_use] + pub fn client_order_id(&self) -> ClientOrderId { + match self { + Self::LimitIfTouched(order) => order.client_order_id, + Self::MarketIfTouched(order) => order.client_order_id, + Self::StopLimit(order) => order.client_order_id, + Self::StopMarket(order) => order.client_order_id, + Self::TrailingStopLimit(order) => order.client_order_id, + Self::TrailingStopMarket(order) => order.client_order_id, + } + } + + #[must_use] + pub fn order_side_specified(&self) -> OrderSideSpecified { + match self { + Self::LimitIfTouched(order) => order.side.as_specified(), + Self::MarketIfTouched(order) => order.side.as_specified(), + Self::StopLimit(order) => order.side.as_specified(), + Self::StopMarket(order) => order.side.as_specified(), + Self::TrailingStopLimit(order) => order.side.as_specified(), + Self::TrailingStopMarket(order) => order.side.as_specified(), + } + } + + #[must_use] + pub fn stop_px(&self) -> Price { + match self { + Self::LimitIfTouched(order) => order.trigger_price, + Self::MarketIfTouched(order) => order.trigger_price, + Self::StopLimit(order) => order.trigger_price, + Self::StopMarket(order) => order.trigger_price, + Self::TrailingStopLimit(order) => order.trigger_price, + Self::TrailingStopMarket(order) => order.trigger_price, + } + } + #[must_use] pub fn is_closed(&self) -> bool { match self { @@ -676,93 +730,3 @@ impl PartialEq for StopOrderAny { } } } - -impl GetClientOrderId for PassiveOrderAny { - fn client_order_id(&self) -> ClientOrderId { - match self { - Self::Limit(order) => order.client_order_id(), - Self::Stop(order) => order.client_order_id(), - } - } -} - -impl GetOrderSideSpecified for PassiveOrderAny { - fn order_side_specified(&self) -> OrderSideSpecified { - match self { - Self::Limit(order) => order.order_side_specified(), - Self::Stop(order) => order.order_side_specified(), - } - } -} - -impl GetClientOrderId for LimitOrderAny { - fn client_order_id(&self) -> ClientOrderId { - match self { - Self::Limit(order) => order.client_order_id, - Self::MarketToLimit(order) => order.client_order_id, - Self::StopLimit(order) => order.client_order_id, - Self::TrailingStopLimit(order) => order.client_order_id, - } - } -} - -impl GetOrderSideSpecified for LimitOrderAny { - fn order_side_specified(&self) -> OrderSideSpecified { - match self { - Self::Limit(order) => order.side.as_specified(), - Self::MarketToLimit(order) => order.side.as_specified(), - Self::StopLimit(order) => order.side.as_specified(), - Self::TrailingStopLimit(order) => order.side.as_specified(), - } - } -} - -impl GetLimitPrice for LimitOrderAny { - fn limit_px(&self) -> Price { - match self { - Self::Limit(order) => order.price, - Self::MarketToLimit(order) => order.price.expect("No price for order"), // TBD - Self::StopLimit(order) => order.price, - Self::TrailingStopLimit(order) => order.price, - } - } -} - -impl GetClientOrderId for StopOrderAny { - fn client_order_id(&self) -> ClientOrderId { - match self { - Self::LimitIfTouched(order) => order.client_order_id, - Self::MarketIfTouched(order) => order.client_order_id, - Self::StopLimit(order) => order.client_order_id, - Self::StopMarket(order) => order.client_order_id, - Self::TrailingStopLimit(order) => order.client_order_id, - Self::TrailingStopMarket(order) => order.client_order_id, - } - } -} - -impl GetOrderSideSpecified for StopOrderAny { - fn order_side_specified(&self) -> OrderSideSpecified { - match self { - Self::LimitIfTouched(order) => order.side.as_specified(), - Self::MarketIfTouched(order) => order.side.as_specified(), - Self::StopLimit(order) => order.side.as_specified(), - Self::StopMarket(order) => order.side.as_specified(), - Self::TrailingStopLimit(order) => order.side.as_specified(), - Self::TrailingStopMarket(order) => order.side.as_specified(), - } - } -} - -impl GetStopPrice for StopOrderAny { - fn stop_px(&self) -> Price { - match self { - Self::LimitIfTouched(order) => order.trigger_price, - Self::MarketIfTouched(order) => order.trigger_price, - Self::StopLimit(order) => order.trigger_price, - Self::StopMarket(order) => order.trigger_price, - Self::TrailingStopLimit(order) => order.trigger_price, - Self::TrailingStopMarket(order) => order.trigger_price, - } - } -} diff --git a/nautilus_core/model/src/orders/list.rs b/nautilus_core/model/src/orders/list.rs index 300d0a630b76..58576079c6ce 100644 --- a/nautilus_core/model/src/orders/list.rs +++ b/nautilus_core/model/src/orders/list.rs @@ -19,11 +19,8 @@ use nautilus_core::{correctness::check_slice_not_empty, nanos::UnixNanos}; use serde::{Deserialize, Serialize}; use super::any::OrderAny; -use crate::{ - identifiers::{ - instrument_id::InstrumentId, order_list_id::OrderListId, strategy_id::StrategyId, - }, - polymorphism::{GetInstrumentId, GetStrategyId}, +use crate::identifiers::{ + instrument_id::InstrumentId, order_list_id::OrderListId, strategy_id::StrategyId, }; #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/nautilus_core/model/src/orders/stubs.rs b/nautilus_core/model/src/orders/stubs.rs index d173de87b18b..22b4be9e818e 100644 --- a/nautilus_core/model/src/orders/stubs.rs +++ b/nautilus_core/model/src/orders/stubs.rs @@ -28,10 +28,6 @@ use crate::{ }, instruments::any::InstrumentAny, orders::market::MarketOrder, - polymorphism::{ - GetAccountId, GetClientOrderId, GetInstrumentId, GetLiquiditySide, GetOrderQuantity, - GetOrderSide, GetOrderType, GetPositionId, GetStrategyId, GetTraderId, GetVenueOrderId, - }, types::{money::Money, price::Price, quantity::Quantity}, }; diff --git a/nautilus_core/model/src/polymorphism.rs b/nautilus_core/model/src/polymorphism.rs deleted file mode 100644 index 490e361c42b1..000000000000 --- a/nautilus_core/model/src/polymorphism.rs +++ /dev/null @@ -1,124 +0,0 @@ -// ------------------------------------------------------------------------------------------------- -// Copyright (C) 2015-2024 Nautech Systems Pty Ltd. All rights reserved. -// https://nautechsystems.io -// -// Licensed under the GNU Lesser General Public License Version 3.0 (the "License"); -// You may not use this file except in compliance with the License. -// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ------------------------------------------------------------------------------------------------- - -//! Traits to faciliate polymorphism. - -use nautilus_core::nanos::UnixNanos; - -use crate::{ - enums::{LiquiditySide, OrderSide, OrderSideSpecified, OrderStatus, OrderType, TriggerType}, - identifiers::{ - account_id::AccountId, client_order_id::ClientOrderId, exec_algorithm_id::ExecAlgorithmId, - instrument_id::InstrumentId, position_id::PositionId, strategy_id::StrategyId, - trader_id::TraderId, venue_order_id::VenueOrderId, - }, - types::{price::Price, quantity::Quantity}, -}; - -pub trait GetTsInit { - fn ts_init(&self) -> UnixNanos; -} - -pub trait GetTraderId { - fn trader_id(&self) -> TraderId; -} - -pub trait GetStrategyId { - fn strategy_id(&self) -> StrategyId; -} - -pub trait GetInstrumentId { - fn instrument_id(&self) -> InstrumentId; -} - -pub trait GetClientOrderId { - fn client_order_id(&self) -> ClientOrderId; -} - -pub trait GetAccountId { - fn account_id(&self) -> Option; -} - -pub trait GetVenueOrderId { - fn venue_order_id(&self) -> Option; -} - -pub trait GetPositionId { - fn position_id(&self) -> Option; -} - -pub trait GetExecAlgorithmId { - fn exec_algorithm_id(&self) -> Option; -} - -pub trait GetExecSpawnId { - fn exec_spawn_id(&self) -> Option; -} - -pub trait GetOrderSide { - fn order_side(&self) -> OrderSide; -} - -pub trait GetOrderType { - fn order_type(&self) -> OrderType; -} - -pub trait GetOrderQuantity { - fn quantity(&self) -> Quantity; -} - -pub trait GetOrderStatus { - fn status(&self) -> OrderStatus; -} - -pub trait GetOrderFilledQty { - fn filled_qty(&self) -> Quantity; -} - -pub trait GetOrderLeavesQty { - fn leaves_qty(&self) -> Quantity; -} - -pub trait GetOrderSideSpecified { - fn order_side_specified(&self) -> OrderSideSpecified; -} - -pub trait GetLiquiditySide { - fn liquidity_side(&self) -> Option; -} - -pub trait GetEmulationTrigger { - fn emulation_trigger(&self) -> Option; -} - -pub trait GetLimitPrice { - fn limit_px(&self) -> Price; -} - -pub trait GetStopPrice { - fn stop_px(&self) -> Price; -} - -pub trait IsOpen { - fn is_open(&self) -> bool; -} - -pub trait IsClosed { - fn is_closed(&self) -> bool; -} - -pub trait IsInflight { - fn is_inflight(&self) -> bool; -} diff --git a/nautilus_core/model/src/position.rs b/nautilus_core/model/src/position.rs index 8a0bfb67f15a..0942fb92673f 100644 --- a/nautilus_core/model/src/position.rs +++ b/nautilus_core/model/src/position.rs @@ -534,10 +534,6 @@ mod tests { stubs::*, }, orders::stubs::{TestOrderEventStubs, TestOrderStubs}, - polymorphism::{ - GetAccountId, GetClientOrderId, GetInstrumentId, GetOrderQuantity, GetStrategyId, - GetTraderId, - }, position::Position, stubs::*, types::{money::Money, price::Price, quantity::Quantity}, diff --git a/nautilus_core/persistence/src/backend/session.rs b/nautilus_core/persistence/src/backend/session.rs index 8360877e593e..d4774a4f7c51 100644 --- a/nautilus_core/persistence/src/backend/session.rs +++ b/nautilus_core/persistence/src/backend/session.rs @@ -21,7 +21,7 @@ use datafusion::{ }; use futures::StreamExt; use nautilus_core::ffi::cvec::CVec; -use nautilus_model::{data::Data, polymorphism::GetTsInit}; +use nautilus_model::data::{Data, GetTsInit}; use super::kmerge_batch::{EagerStream, ElementBatchIter, KMerge}; use crate::arrow::{