From 8769dae920ca43454612b328613b59464e186a31 Mon Sep 17 00:00:00 2001 From: Filip Macek Date: Sat, 20 Apr 2024 23:06:50 +0200 Subject: [PATCH] Refactor order create method for Cython and Rust (#1598) --- .../model/src/python/orders/limit.rs | 7 +++++++ .../src/python/orders/limit_if_touched.rs | 7 +++++++ .../model/src/python/orders/market.rs | 7 +++++++ .../src/python/orders/market_if_touched.rs | 7 +++++++ .../src/python/orders/market_to_limit.rs | 7 +++++++ .../model/src/python/orders/stop_limit.rs | 7 +++++++ .../model/src/python/orders/stop_market.rs | 7 +++++++ .../src/python/orders/trailing_stop_limit.rs | 7 +++++++ .../src/python/orders/trailing_stop_market.rs | 7 +++++++ nautilus_trader/core/nautilus_pyo3.pyi | 19 +++++++++++++++++++ nautilus_trader/model/orders/limit.pxd | 2 +- nautilus_trader/model/orders/limit.pyx | 6 +++++- .../model/orders/limit_if_touched.pxd | 2 +- .../model/orders/limit_if_touched.pyx | 6 +++++- nautilus_trader/model/orders/market.pxd | 2 +- nautilus_trader/model/orders/market.pyx | 6 +++++- .../model/orders/market_if_touched.pxd | 2 +- .../model/orders/market_if_touched.pyx | 6 +++++- .../model/orders/market_to_limit.pxd | 2 +- .../model/orders/market_to_limit.pyx | 6 +++++- nautilus_trader/model/orders/stop_limit.pxd | 2 +- nautilus_trader/model/orders/stop_limit.pyx | 6 +++++- nautilus_trader/model/orders/stop_market.pxd | 2 +- nautilus_trader/model/orders/stop_market.pyx | 6 +++++- .../model/orders/trailing_stop_limit.pxd | 2 +- .../model/orders/trailing_stop_limit.pyx | 6 +++++- .../model/orders/trailing_stop_market.pxd | 2 +- .../model/orders/trailing_stop_market.pyx | 6 +++++- nautilus_trader/model/orders/unpacker.pyx | 18 +++++++++--------- 29 files changed, 145 insertions(+), 27 deletions(-) diff --git a/nautilus_core/model/src/python/orders/limit.rs b/nautilus_core/model/src/python/orders/limit.rs index ca892e1f9a06..0c22d1627333 100644 --- a/nautilus_core/model/src/python/orders/limit.rs +++ b/nautilus_core/model/src/python/orders/limit.rs @@ -28,6 +28,7 @@ use crate::{ ContingencyType, LiquiditySide, OrderSide, OrderStatus, OrderType, PositionSide, TimeInForce, TriggerType, }, + events::order::initialized::OrderInitialized, identifiers::{ client_order_id::ClientOrderId, exec_algorithm_id::ExecAlgorithmId, instrument_id::InstrumentId, order_list_id::OrderListId, strategy_id::StrategyId, @@ -118,6 +119,12 @@ impl LimitOrder { self.to_string() } + #[staticmethod] + #[pyo3(name = "create")] + fn py_create(init: OrderInitialized) -> PyResult { + Ok(LimitOrder::from(init)) + } + #[getter] #[pyo3(name = "trader_id")] fn py_trader_id(&self) -> TraderId { diff --git a/nautilus_core/model/src/python/orders/limit_if_touched.rs b/nautilus_core/model/src/python/orders/limit_if_touched.rs index 8f966d82f455..2dd5dc2ee300 100644 --- a/nautilus_core/model/src/python/orders/limit_if_touched.rs +++ b/nautilus_core/model/src/python/orders/limit_if_touched.rs @@ -21,6 +21,7 @@ use ustr::Ustr; use crate::{ enums::{ContingencyType, OrderSide, TimeInForce, TriggerType}, + events::order::initialized::OrderInitialized, identifiers::{ client_order_id::ClientOrderId, exec_algorithm_id::ExecAlgorithmId, instrument_id::InstrumentId, order_list_id::OrderListId, strategy_id::StrategyId, @@ -95,4 +96,10 @@ impl LimitIfTouchedOrder { ) .unwrap()) } + + #[staticmethod] + #[pyo3(name = "create")] + fn py_create(init: OrderInitialized) -> PyResult { + Ok(LimitIfTouchedOrder::from(init)) + } } diff --git a/nautilus_core/model/src/python/orders/market.rs b/nautilus_core/model/src/python/orders/market.rs index f74a8ad53d68..9f12849dfbcd 100644 --- a/nautilus_core/model/src/python/orders/market.rs +++ b/nautilus_core/model/src/python/orders/market.rs @@ -27,6 +27,7 @@ use ustr::Ustr; use crate::{ enums::{ContingencyType, OrderSide, OrderType, PositionSide, TimeInForce}, + events::order::initialized::OrderInitialized, identifiers::{ account_id::AccountId, client_order_id::ClientOrderId, exec_algorithm_id::ExecAlgorithmId, instrument_id::InstrumentId, order_list_id::OrderListId, strategy_id::StrategyId, @@ -105,6 +106,12 @@ impl MarketOrder { self.to_string() } + #[staticmethod] + #[pyo3(name = "create")] + fn py_create(init: OrderInitialized) -> PyResult { + Ok(MarketOrder::from(init)) + } + #[pyo3(name = "signed_decimal_qty")] fn py_signed_decimal_qty(&self) -> Decimal { self.signed_decimal_qty() diff --git a/nautilus_core/model/src/python/orders/market_if_touched.rs b/nautilus_core/model/src/python/orders/market_if_touched.rs index 97db84845029..5a1c0ddd6a96 100644 --- a/nautilus_core/model/src/python/orders/market_if_touched.rs +++ b/nautilus_core/model/src/python/orders/market_if_touched.rs @@ -21,6 +21,7 @@ use ustr::Ustr; use crate::{ enums::{ContingencyType, OrderSide, TimeInForce, TriggerType}, + events::order::initialized::OrderInitialized, identifiers::{ client_order_id::ClientOrderId, exec_algorithm_id::ExecAlgorithmId, instrument_id::InstrumentId, order_list_id::OrderListId, strategy_id::StrategyId, @@ -91,4 +92,10 @@ impl MarketIfTouchedOrder { ) .unwrap()) } + + #[staticmethod] + #[pyo3(name = "create")] + fn py_create(init: OrderInitialized) -> PyResult { + Ok(MarketIfTouchedOrder::from(init)) + } } diff --git a/nautilus_core/model/src/python/orders/market_to_limit.rs b/nautilus_core/model/src/python/orders/market_to_limit.rs index 211d7915bd71..ac82db96672e 100644 --- a/nautilus_core/model/src/python/orders/market_to_limit.rs +++ b/nautilus_core/model/src/python/orders/market_to_limit.rs @@ -21,6 +21,7 @@ use ustr::Ustr; use crate::{ enums::{ContingencyType, OrderSide, TimeInForce}, + events::order::initialized::OrderInitialized, identifiers::{ client_order_id::ClientOrderId, exec_algorithm_id::ExecAlgorithmId, instrument_id::InstrumentId, order_list_id::OrderListId, strategy_id::StrategyId, @@ -85,4 +86,10 @@ impl MarketToLimitOrder { ) .unwrap()) } + + #[staticmethod] + #[pyo3(name = "create")] + fn py_create(init: OrderInitialized) -> PyResult { + Ok(MarketToLimitOrder::from(init)) + } } diff --git a/nautilus_core/model/src/python/orders/stop_limit.rs b/nautilus_core/model/src/python/orders/stop_limit.rs index b69bec23ccf5..7ca513cda729 100644 --- a/nautilus_core/model/src/python/orders/stop_limit.rs +++ b/nautilus_core/model/src/python/orders/stop_limit.rs @@ -21,6 +21,7 @@ use ustr::Ustr; use crate::{ enums::{ContingencyType, OrderSide, OrderStatus, OrderType, TimeInForce, TriggerType}, + events::order::initialized::OrderInitialized, identifiers::{ client_order_id::ClientOrderId, exec_algorithm_id::ExecAlgorithmId, instrument_id::InstrumentId, order_list_id::OrderListId, strategy_id::StrategyId, @@ -115,6 +116,12 @@ impl StopLimitOrder { self.to_string() } + #[staticmethod] + #[pyo3(name = "create")] + fn py_create(init: OrderInitialized) -> PyResult { + Ok(StopLimitOrder::from(init)) + } + #[getter] #[pyo3(name = "trader_id")] fn py_trader_id(&self) -> TraderId { diff --git a/nautilus_core/model/src/python/orders/stop_market.rs b/nautilus_core/model/src/python/orders/stop_market.rs index b438f35cf987..964463797590 100644 --- a/nautilus_core/model/src/python/orders/stop_market.rs +++ b/nautilus_core/model/src/python/orders/stop_market.rs @@ -21,6 +21,7 @@ use ustr::Ustr; use crate::{ enums::{ContingencyType, OrderSide, TimeInForce, TriggerType}, + events::order::initialized::OrderInitialized, identifiers::{ client_order_id::ClientOrderId, exec_algorithm_id::ExecAlgorithmId, instrument_id::InstrumentId, order_list_id::OrderListId, strategy_id::StrategyId, @@ -91,4 +92,10 @@ impl StopMarketOrder { ) .unwrap()) } + + #[staticmethod] + #[pyo3(name = "create")] + fn py_create(init: OrderInitialized) -> PyResult { + Ok(StopMarketOrder::from(init)) + } } diff --git a/nautilus_core/model/src/python/orders/trailing_stop_limit.rs b/nautilus_core/model/src/python/orders/trailing_stop_limit.rs index ff1254c1a3e3..a117a0787dfc 100644 --- a/nautilus_core/model/src/python/orders/trailing_stop_limit.rs +++ b/nautilus_core/model/src/python/orders/trailing_stop_limit.rs @@ -21,6 +21,7 @@ use ustr::Ustr; use crate::{ enums::{ContingencyType, OrderSide, TimeInForce, TrailingOffsetType, TriggerType}, + events::order::initialized::OrderInitialized, identifiers::{ client_order_id::ClientOrderId, exec_algorithm_id::ExecAlgorithmId, instrument_id::InstrumentId, order_list_id::OrderListId, strategy_id::StrategyId, @@ -101,4 +102,10 @@ impl TrailingStopLimitOrder { ) .unwrap()) } + + #[staticmethod] + #[pyo3(name = "create")] + fn py_create(init: OrderInitialized) -> PyResult { + Ok(TrailingStopLimitOrder::from(init)) + } } diff --git a/nautilus_core/model/src/python/orders/trailing_stop_market.rs b/nautilus_core/model/src/python/orders/trailing_stop_market.rs index f08d29f7af27..93e41bef8f77 100644 --- a/nautilus_core/model/src/python/orders/trailing_stop_market.rs +++ b/nautilus_core/model/src/python/orders/trailing_stop_market.rs @@ -21,6 +21,7 @@ use ustr::Ustr; use crate::{ enums::{ContingencyType, OrderSide, TimeInForce, TrailingOffsetType, TriggerType}, + events::order::initialized::OrderInitialized, identifiers::{ client_order_id::ClientOrderId, exec_algorithm_id::ExecAlgorithmId, instrument_id::InstrumentId, order_list_id::OrderListId, strategy_id::StrategyId, @@ -95,4 +96,10 @@ impl TrailingStopMarketOrder { ) .unwrap()) } + + #[staticmethod] + #[pyo3(name = "create")] + fn py_create(init: OrderInitialized) -> PyResult { + Ok(TrailingStopMarketOrder::from(init)) + } } diff --git a/nautilus_trader/core/nautilus_pyo3.pyi b/nautilus_trader/core/nautilus_pyo3.pyi index 79dab082e247..bdbe7bc6b46d 100644 --- a/nautilus_trader/core/nautilus_pyo3.pyi +++ b/nautilus_trader/core/nautilus_pyo3.pyi @@ -909,6 +909,8 @@ class LimitOrder: exec_spawn_id: ClientOrderId | None = None, tags: str | None = None, ): ... + @classmethod + def create(cls, init: OrderInitialized) -> LimitOrder: ... def to_dict(self) -> dict[str, str]: ... @property def trader_id(self) -> TraderId: ... @@ -993,6 +995,8 @@ class LimitIfTouchedOrder: exec_spawn_id: ClientOrderId | None = None, tags: str | None = None, ) -> None: ... + @classmethod + def create(cls, init: OrderInitialized) -> LimitIfTouchedOrder: ... class MarketOrder: def __init__( @@ -1017,6 +1021,8 @@ class MarketOrder: exec_spawn_id: ClientOrderId | None = None, tags: str | None = None, ) -> None: ... + @classmethod + def create(cls, init: OrderInitialized) -> MarketOrder: ... def to_dict(self) -> dict[str, str]: ... @classmethod def from_dict(cls, values: dict[str, str]) -> MarketOrder: ... @@ -1079,6 +1085,8 @@ class MarketToLimitOrder: exec_spawn_id: ClientOrderId | None = None, tags: str | None = None, ): ... + @classmethod + def create(cls, init: OrderInitialized) -> MarketToLimitOrder: ... class MarketIfTouchedOrder: def __init__( @@ -1109,6 +1117,9 @@ class MarketIfTouchedOrder: exec_spawn_id: ClientOrderId | None = None, tags: str | None = None, ): ... + @classmethod + def create(cls, init: OrderInitialized) -> MarketIfTouchedOrder: ... + class StopLimitOrder: def __init__( self, @@ -1141,6 +1152,8 @@ class StopLimitOrder: tags: str | None = None, ): ... @classmethod + def create(cls, init: OrderInitialized) -> StopLimitOrder: ... + @classmethod def from_dict(cls, values: dict[str, str]) -> StopLimitOrder: ... def to_dict(self) -> dict[str, str]: ... @property @@ -1217,6 +1230,8 @@ class StopMarketOrder: exec_spawn_id: ClientOrderId | None = None, tags: str | None = None, ): ... + @classmethod + def create(cls, init: OrderInitialized) -> StopMarketOrder: ... class TrailingStopLimitOrder: def __init__( self, @@ -1251,6 +1266,8 @@ class TrailingStopLimitOrder: exec_spawn_id: ClientOrderId | None = None, tags: str | None = None, ): ... + @classmethod + def create(cls, init: OrderInitialized) -> TrailingStopLimitOrder: ... class TrailingStopMarketOrder: def __init__( self, @@ -1282,6 +1299,8 @@ class TrailingStopMarketOrder: exec_spawn_id: ClientOrderId | None = None, tags: str | None = None, ): ... + @classmethod + def create(cls, init: OrderInitialized) -> TrailingStopMarketOrder: ... ### Objects diff --git a/nautilus_trader/model/orders/limit.pxd b/nautilus_trader/model/orders/limit.pxd index 7b4c03c620da..b87bd5281a3b 100644 --- a/nautilus_trader/model/orders/limit.pxd +++ b/nautilus_trader/model/orders/limit.pxd @@ -30,7 +30,7 @@ cdef class LimitOrder(Order): """The quantity of the order to display on the public book (iceberg).\n\n:returns: `Quantity` or ``None``""" @staticmethod - cdef LimitOrder create(OrderInitialized init) + cdef LimitOrder create_c(OrderInitialized init) @staticmethod cdef LimitOrder transform(Order order, uint64_t ts_init, Price price=*) diff --git a/nautilus_trader/model/orders/limit.pyx b/nautilus_trader/model/orders/limit.pyx index 92a2d6c3cb0f..5b309f32852d 100644 --- a/nautilus_trader/model/orders/limit.pyx +++ b/nautilus_trader/model/orders/limit.pyx @@ -346,7 +346,7 @@ cdef class LimitOrder(Order): } @staticmethod - cdef LimitOrder create(OrderInitialized init): + cdef LimitOrder create_c(OrderInitialized init): """ Return a `Limit` order from the given initialized event. @@ -398,6 +398,10 @@ cdef class LimitOrder(Order): tags=init.tags, ) + @staticmethod + def create(OrderInitialized init): + return LimitOrder.create_c(init) + @staticmethod cdef LimitOrder transform(Order order, uint64_t ts_init, Price price = None): """ diff --git a/nautilus_trader/model/orders/limit_if_touched.pxd b/nautilus_trader/model/orders/limit_if_touched.pxd index 79664cddae37..e1481e29db87 100644 --- a/nautilus_trader/model/orders/limit_if_touched.pxd +++ b/nautilus_trader/model/orders/limit_if_touched.pxd @@ -39,4 +39,4 @@ cdef class LimitIfTouchedOrder(Order): """The UNIX timestamp (nanoseconds) when the order was triggered (0 if not triggered).\n\n:returns: `uint64_t`""" @staticmethod - cdef LimitIfTouchedOrder create(OrderInitialized init) + cdef LimitIfTouchedOrder create_c(OrderInitialized init) diff --git a/nautilus_trader/model/orders/limit_if_touched.pyx b/nautilus_trader/model/orders/limit_if_touched.pyx index b342b8dcd3de..dddbf7c6a6ac 100644 --- a/nautilus_trader/model/orders/limit_if_touched.pyx +++ b/nautilus_trader/model/orders/limit_if_touched.pyx @@ -339,7 +339,7 @@ cdef class LimitIfTouchedOrder(Order): } @staticmethod - cdef LimitIfTouchedOrder create(OrderInitialized init): + cdef LimitIfTouchedOrder create_c(OrderInitialized init): """ Return a `Limit-If-Touched` order from the given initialized event. @@ -392,3 +392,7 @@ cdef class LimitIfTouchedOrder(Order): exec_spawn_id=init.exec_spawn_id, tags=init.tags, ) + + @staticmethod + def create(init): + return LimitIfTouchedOrder.create_c(init) diff --git a/nautilus_trader/model/orders/market.pxd b/nautilus_trader/model/orders/market.pxd index 96e89d71d120..ef48f030f9a9 100644 --- a/nautilus_trader/model/orders/market.pxd +++ b/nautilus_trader/model/orders/market.pxd @@ -21,7 +21,7 @@ from nautilus_trader.model.orders.base cimport Order cdef class MarketOrder(Order): @staticmethod - cdef MarketOrder create(OrderInitialized init) + cdef MarketOrder create_c(OrderInitialized init) @staticmethod cdef MarketOrder transform(Order order, uint64_t ts_init) diff --git a/nautilus_trader/model/orders/market.pyx b/nautilus_trader/model/orders/market.pyx index fc5532193064..48f03e1b43ea 100644 --- a/nautilus_trader/model/orders/market.pyx +++ b/nautilus_trader/model/orders/market.pyx @@ -266,7 +266,7 @@ cdef class MarketOrder(Order): } @staticmethod - cdef MarketOrder create(OrderInitialized init): + cdef MarketOrder create_c(OrderInitialized init): """ Return a `market` order from the given initialized event. @@ -310,6 +310,10 @@ cdef class MarketOrder(Order): tags=init.tags, ) + @staticmethod + def create(init): + return MarketOrder.create_c(init) + @staticmethod cdef MarketOrder transform(Order order, uint64_t ts_init): """ diff --git a/nautilus_trader/model/orders/market_if_touched.pxd b/nautilus_trader/model/orders/market_if_touched.pxd index 517c64ae4d5a..5233bb2de2db 100644 --- a/nautilus_trader/model/orders/market_if_touched.pxd +++ b/nautilus_trader/model/orders/market_if_touched.pxd @@ -30,4 +30,4 @@ cdef class MarketIfTouchedOrder(Order): """The order expiration (UNIX epoch nanoseconds), zero for no expiration.\n\n:returns: `uint64_t`""" @staticmethod - cdef MarketIfTouchedOrder create(OrderInitialized init) + cdef MarketIfTouchedOrder create_c(OrderInitialized init) diff --git a/nautilus_trader/model/orders/market_if_touched.pyx b/nautilus_trader/model/orders/market_if_touched.pyx index 8a790438b244..72569dfe5ac6 100644 --- a/nautilus_trader/model/orders/market_if_touched.pyx +++ b/nautilus_trader/model/orders/market_if_touched.pyx @@ -305,7 +305,7 @@ cdef class MarketIfTouchedOrder(Order): } @staticmethod - cdef MarketIfTouchedOrder create(OrderInitialized init): + cdef MarketIfTouchedOrder create_c(OrderInitialized init): """ Return a `Market-If-Touched` order from the given initialized event. @@ -353,3 +353,7 @@ cdef class MarketIfTouchedOrder(Order): exec_spawn_id=init.exec_spawn_id, tags=init.tags, ) + + @staticmethod + def create(init): + return MarketIfTouchedOrder.create_c(init) diff --git a/nautilus_trader/model/orders/market_to_limit.pxd b/nautilus_trader/model/orders/market_to_limit.pxd index 029011dbeae2..2b2acf4cb217 100644 --- a/nautilus_trader/model/orders/market_to_limit.pxd +++ b/nautilus_trader/model/orders/market_to_limit.pxd @@ -30,4 +30,4 @@ cdef class MarketToLimitOrder(Order): """The quantity of the limit order to display on the public book (iceberg).\n\n:returns: `Quantity` or ``None``""" @staticmethod - cdef MarketToLimitOrder create(OrderInitialized init) + cdef MarketToLimitOrder create_c(OrderInitialized init) diff --git a/nautilus_trader/model/orders/market_to_limit.pyx b/nautilus_trader/model/orders/market_to_limit.pyx index 4d370f4ef874..ff290b6d80b5 100644 --- a/nautilus_trader/model/orders/market_to_limit.pyx +++ b/nautilus_trader/model/orders/market_to_limit.pyx @@ -282,7 +282,7 @@ cdef class MarketToLimitOrder(Order): } @staticmethod - cdef MarketToLimitOrder create(OrderInitialized init): + cdef MarketToLimitOrder create_c(OrderInitialized init): """ Return a `Market-To-Limit` order from the given initialized event. @@ -329,3 +329,7 @@ cdef class MarketToLimitOrder(Order): exec_spawn_id=init.exec_spawn_id, tags=init.tags, ) + + @staticmethod + def create(init): + return MarketToLimitOrder.create_c(init) diff --git a/nautilus_trader/model/orders/stop_limit.pxd b/nautilus_trader/model/orders/stop_limit.pxd index ec00bde6b4be..898be78eab59 100644 --- a/nautilus_trader/model/orders/stop_limit.pxd +++ b/nautilus_trader/model/orders/stop_limit.pxd @@ -39,7 +39,7 @@ cdef class StopLimitOrder(Order): """The UNIX timestamp (nanoseconds) when the order was triggered (0 if not triggered).\n\n:returns: `uint64_t`""" @staticmethod - cdef StopLimitOrder create(OrderInitialized init) + cdef StopLimitOrder create_c(OrderInitialized init) @staticmethod cdef StopLimitOrder from_pyo3_c(pyo3_order) diff --git a/nautilus_trader/model/orders/stop_limit.pyx b/nautilus_trader/model/orders/stop_limit.pyx index 24d596d3e9a8..07c56a46d393 100644 --- a/nautilus_trader/model/orders/stop_limit.pyx +++ b/nautilus_trader/model/orders/stop_limit.pyx @@ -381,7 +381,7 @@ cdef class StopLimitOrder(Order): } @staticmethod - cdef StopLimitOrder create(OrderInitialized init): + cdef StopLimitOrder create_c(OrderInitialized init): """ Return a `Stop-Limit` order from the given initialized event. @@ -434,3 +434,7 @@ cdef class StopLimitOrder(Order): exec_spawn_id=init.exec_spawn_id, tags=init.tags, ) + + @staticmethod + def create(init): + return StopLimitOrder.create_c(init) diff --git a/nautilus_trader/model/orders/stop_market.pxd b/nautilus_trader/model/orders/stop_market.pxd index 83b2ded2f7ca..600a1a44ff98 100644 --- a/nautilus_trader/model/orders/stop_market.pxd +++ b/nautilus_trader/model/orders/stop_market.pxd @@ -30,4 +30,4 @@ cdef class StopMarketOrder(Order): """The order expiration (UNIX epoch nanoseconds), zero for no expiration.\n\n:returns: `uint64_t`""" @staticmethod - cdef StopMarketOrder create(OrderInitialized init) + cdef StopMarketOrder create_c(OrderInitialized init) diff --git a/nautilus_trader/model/orders/stop_market.pyx b/nautilus_trader/model/orders/stop_market.pyx index 1dc1c5771a3c..90ed019161e9 100644 --- a/nautilus_trader/model/orders/stop_market.pyx +++ b/nautilus_trader/model/orders/stop_market.pyx @@ -310,7 +310,7 @@ cdef class StopMarketOrder(Order): } @staticmethod - cdef StopMarketOrder create(OrderInitialized init): + cdef StopMarketOrder create_c(OrderInitialized init): """ Return a `Stop-Market` order from the given initialized event. @@ -358,3 +358,7 @@ cdef class StopMarketOrder(Order): exec_spawn_id=init.exec_spawn_id, tags=init.tags, ) + + @staticmethod + def create(init): + return StopMarketOrder.create_c(init) diff --git a/nautilus_trader/model/orders/trailing_stop_limit.pxd b/nautilus_trader/model/orders/trailing_stop_limit.pxd index c62dd0adade6..4d2549be072d 100644 --- a/nautilus_trader/model/orders/trailing_stop_limit.pxd +++ b/nautilus_trader/model/orders/trailing_stop_limit.pxd @@ -46,4 +46,4 @@ cdef class TrailingStopLimitOrder(Order): """The UNIX timestamp (nanoseconds) when the order was triggered (0 if not triggered).\n\n:returns: `uint64_t`""" @staticmethod - cdef TrailingStopLimitOrder create(OrderInitialized init) + cdef TrailingStopLimitOrder create_c(OrderInitialized init) diff --git a/nautilus_trader/model/orders/trailing_stop_limit.pyx b/nautilus_trader/model/orders/trailing_stop_limit.pyx index dcd027e2bc5e..6e5b9cbe0c23 100644 --- a/nautilus_trader/model/orders/trailing_stop_limit.pyx +++ b/nautilus_trader/model/orders/trailing_stop_limit.pyx @@ -356,7 +356,7 @@ cdef class TrailingStopLimitOrder(Order): } @staticmethod - cdef TrailingStopLimitOrder create(OrderInitialized init): + cdef TrailingStopLimitOrder create_c(OrderInitialized init): """ Return a `Trailing-Stop-Limit` order from the given initialized event. @@ -414,3 +414,7 @@ cdef class TrailingStopLimitOrder(Order): exec_spawn_id=init.exec_spawn_id, tags=init.tags, ) + + @staticmethod + def create(init): + return TrailingStopLimitOrder.create_c(init) diff --git a/nautilus_trader/model/orders/trailing_stop_market.pxd b/nautilus_trader/model/orders/trailing_stop_market.pxd index 9e20d1f34e66..4d6d91c7d669 100644 --- a/nautilus_trader/model/orders/trailing_stop_market.pxd +++ b/nautilus_trader/model/orders/trailing_stop_market.pxd @@ -35,4 +35,4 @@ cdef class TrailingStopMarketOrder(Order): """The order expiration (UNIX epoch nanoseconds), zero for no expiration.\n\n:returns: `uint64_t`""" @staticmethod - cdef TrailingStopMarketOrder create(OrderInitialized init) + cdef TrailingStopMarketOrder create_c(OrderInitialized init) diff --git a/nautilus_trader/model/orders/trailing_stop_market.pyx b/nautilus_trader/model/orders/trailing_stop_market.pyx index af4c5821022e..330b471f3cea 100644 --- a/nautilus_trader/model/orders/trailing_stop_market.pyx +++ b/nautilus_trader/model/orders/trailing_stop_market.pyx @@ -319,7 +319,7 @@ cdef class TrailingStopMarketOrder(Order): } @staticmethod - cdef TrailingStopMarketOrder create(OrderInitialized init): + cdef TrailingStopMarketOrder create_c(OrderInitialized init): """ Return a `Trailing-Stop-Market` order from the given initialized event. @@ -371,3 +371,7 @@ cdef class TrailingStopMarketOrder(Order): exec_spawn_id=init.exec_spawn_id, tags=init.tags, ) + + @staticmethod + def create(init): + return TrailingStopMarketOrder.create_c(init) diff --git a/nautilus_trader/model/orders/unpacker.pyx b/nautilus_trader/model/orders/unpacker.pyx index f0c3144837cc..554fc7b13f9c 100644 --- a/nautilus_trader/model/orders/unpacker.pyx +++ b/nautilus_trader/model/orders/unpacker.pyx @@ -42,23 +42,23 @@ cdef class OrderUnpacker: @staticmethod cdef Order from_init_c(OrderInitialized init): if init.order_type == OrderType.MARKET: - return MarketOrder.create(init=init) + return MarketOrder.create_c(init=init) elif init.order_type == OrderType.LIMIT: - return LimitOrder.create(init=init) + return LimitOrder.create_c(init=init) elif init.order_type == OrderType.STOP_MARKET: - return StopMarketOrder.create(init=init) + return StopMarketOrder.create_c(init=init) elif init.order_type == OrderType.STOP_LIMIT: - return StopLimitOrder.create(init=init) + return StopLimitOrder.create_c(init=init) elif init.order_type == OrderType.MARKET_TO_LIMIT: - return MarketToLimitOrder.create(init=init) + return MarketToLimitOrder.create_c(init=init) elif init.order_type == OrderType.MARKET_IF_TOUCHED: - return MarketIfTouchedOrder.create(init=init) + return MarketIfTouchedOrder.create_c(init=init) elif init.order_type == OrderType.LIMIT_IF_TOUCHED: - return LimitIfTouchedOrder.create(init=init) + return LimitIfTouchedOrder.create_c(init=init) elif init.order_type == OrderType.TRAILING_STOP_MARKET: - return TrailingStopMarketOrder.create(init=init) + return TrailingStopMarketOrder.create_c(init=init) elif init.order_type == OrderType.TRAILING_STOP_LIMIT: - return TrailingStopLimitOrder.create(init=init) + return TrailingStopLimitOrder.create_c(init=init) else: raise RuntimeError("invalid `OrderType`") # pragma: no cover (design-time error)