Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor create method method in orders for Cython and Rust #1598

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions nautilus_core/model/src/python/orders/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -118,6 +119,12 @@ impl LimitOrder {
self.to_string()
}

#[staticmethod]
#[pyo3(name = "create")]
fn py_create(init: OrderInitialized) -> PyResult<Self> {
Ok(LimitOrder::from(init))
}

#[getter]
#[pyo3(name = "trader_id")]
fn py_trader_id(&self) -> TraderId {
Expand Down
7 changes: 7 additions & 0 deletions nautilus_core/model/src/python/orders/limit_if_touched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -95,4 +96,10 @@ impl LimitIfTouchedOrder {
)
.unwrap())
}

#[staticmethod]
#[pyo3(name = "create")]
fn py_create(init: OrderInitialized) -> PyResult<Self> {
Ok(LimitIfTouchedOrder::from(init))
}
}
7 changes: 7 additions & 0 deletions nautilus_core/model/src/python/orders/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -105,6 +106,12 @@ impl MarketOrder {
self.to_string()
}

#[staticmethod]
#[pyo3(name = "create")]
fn py_create(init: OrderInitialized) -> PyResult<Self> {
Ok(MarketOrder::from(init))
}

#[pyo3(name = "signed_decimal_qty")]
fn py_signed_decimal_qty(&self) -> Decimal {
self.signed_decimal_qty()
Expand Down
7 changes: 7 additions & 0 deletions nautilus_core/model/src/python/orders/market_if_touched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -91,4 +92,10 @@ impl MarketIfTouchedOrder {
)
.unwrap())
}

#[staticmethod]
#[pyo3(name = "create")]
fn py_create(init: OrderInitialized) -> PyResult<Self> {
Ok(MarketIfTouchedOrder::from(init))
}
}
7 changes: 7 additions & 0 deletions nautilus_core/model/src/python/orders/market_to_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -85,4 +86,10 @@ impl MarketToLimitOrder {
)
.unwrap())
}

#[staticmethod]
#[pyo3(name = "create")]
fn py_create(init: OrderInitialized) -> PyResult<Self> {
Ok(MarketToLimitOrder::from(init))
}
}
7 changes: 7 additions & 0 deletions nautilus_core/model/src/python/orders/stop_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -115,6 +116,12 @@ impl StopLimitOrder {
self.to_string()
}

#[staticmethod]
#[pyo3(name = "create")]
fn py_create(init: OrderInitialized) -> PyResult<Self> {
Ok(StopLimitOrder::from(init))
}

#[getter]
#[pyo3(name = "trader_id")]
fn py_trader_id(&self) -> TraderId {
Expand Down
7 changes: 7 additions & 0 deletions nautilus_core/model/src/python/orders/stop_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -91,4 +92,10 @@ impl StopMarketOrder {
)
.unwrap())
}

#[staticmethod]
#[pyo3(name = "create")]
fn py_create(init: OrderInitialized) -> PyResult<Self> {
Ok(StopMarketOrder::from(init))
}
}
7 changes: 7 additions & 0 deletions nautilus_core/model/src/python/orders/trailing_stop_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -101,4 +102,10 @@ impl TrailingStopLimitOrder {
)
.unwrap())
}

#[staticmethod]
#[pyo3(name = "create")]
fn py_create(init: OrderInitialized) -> PyResult<Self> {
Ok(TrailingStopLimitOrder::from(init))
}
}
7 changes: 7 additions & 0 deletions nautilus_core/model/src/python/orders/trailing_stop_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -95,4 +96,10 @@ impl TrailingStopMarketOrder {
)
.unwrap())
}

#[staticmethod]
#[pyo3(name = "create")]
fn py_create(init: OrderInitialized) -> PyResult<Self> {
Ok(TrailingStopMarketOrder::from(init))
}
}
19 changes: 19 additions & 0 deletions nautilus_trader/core/nautilus_pyo3.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down Expand Up @@ -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__(
Expand All @@ -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: ...
Expand Down Expand Up @@ -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__(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1282,6 +1299,8 @@ class TrailingStopMarketOrder:
exec_spawn_id: ClientOrderId | None = None,
tags: str | None = None,
): ...
@classmethod
def create(cls, init: OrderInitialized) -> TrailingStopMarketOrder: ...

### Objects

Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/model/orders/limit.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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=*)
Expand Down
6 changes: 5 additions & 1 deletion nautilus_trader/model/orders/limit.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/model/orders/limit_if_touched.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 5 additions & 1 deletion nautilus_trader/model/orders/limit_if_touched.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion nautilus_trader/model/orders/market.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion nautilus_trader/model/orders/market.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/model/orders/market_if_touched.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 5 additions & 1 deletion nautilus_trader/model/orders/market_if_touched.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion nautilus_trader/model/orders/market_to_limit.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 5 additions & 1 deletion nautilus_trader/model/orders/market_to_limit.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion nautilus_trader/model/orders/stop_limit.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading