nautilus_model/python/orders/
trailing_stop_limit.rsuse std::collections::HashMap;
use nautilus_core::{python::to_pyruntime_err, uuid::UUID4};
use pyo3::prelude::*;
use ustr::Ustr;
use crate::{
enums::{ContingencyType, OrderSide, OrderType, TimeInForce, TrailingOffsetType, TriggerType},
events::order::initialized::OrderInitialized,
identifiers::{
ClientOrderId, ExecAlgorithmId, InstrumentId, OrderListId, StrategyId, TraderId,
},
orders::{
base::{str_hashmap_to_ustr, Order},
trailing_stop_limit::TrailingStopLimitOrder,
},
python::events::order::{order_event_to_pyobject, pyobject_to_order_event},
types::{price::Price, quantity::Quantity},
};
#[pymethods]
impl TrailingStopLimitOrder {
#[new]
#[allow(clippy::too_many_arguments)]
#[pyo3(signature = (trader_id, strategy_id, instrument_id, client_order_id, order_side, quantity, price, trigger_price, trigger_type, limit_offset, trailing_offset, trailing_offset_type, time_in_force, post_only, reduce_only, quote_quantity, init_id, ts_init, expire_time=None, display_qty=None, emulation_trigger=None, trigger_instrument_id=None, contingency_type=None, order_list_id=None, linked_order_ids=None, parent_order_id=None, exec_algorithm_id=None, exec_algorithm_params=None, exec_spawn_id=None, tags=None))]
fn py_new(
trader_id: TraderId,
strategy_id: StrategyId,
instrument_id: InstrumentId,
client_order_id: ClientOrderId,
order_side: OrderSide,
quantity: Quantity,
price: Price,
trigger_price: Price,
trigger_type: TriggerType,
limit_offset: Price,
trailing_offset: Price,
trailing_offset_type: TrailingOffsetType,
time_in_force: TimeInForce,
post_only: bool,
reduce_only: bool,
quote_quantity: bool,
init_id: UUID4,
ts_init: u64,
expire_time: Option<u64>,
display_qty: Option<Quantity>,
emulation_trigger: Option<TriggerType>,
trigger_instrument_id: Option<InstrumentId>,
contingency_type: Option<ContingencyType>,
order_list_id: Option<OrderListId>,
linked_order_ids: Option<Vec<ClientOrderId>>,
parent_order_id: Option<ClientOrderId>,
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<String, String>>,
exec_spawn_id: Option<ClientOrderId>,
tags: Option<Vec<String>>,
) -> Self {
let exec_algorithm_params = exec_algorithm_params.map(str_hashmap_to_ustr);
Self::new(
trader_id,
strategy_id,
instrument_id,
client_order_id,
order_side,
quantity,
price,
trigger_price,
trigger_type,
limit_offset,
trailing_offset,
trailing_offset_type,
time_in_force,
expire_time.map(std::convert::Into::into),
post_only,
reduce_only,
quote_quantity,
display_qty,
emulation_trigger,
trigger_instrument_id,
contingency_type,
order_list_id,
linked_order_ids,
parent_order_id,
exec_algorithm_id,
exec_algorithm_params,
exec_spawn_id,
tags.map(|vec| vec.into_iter().map(|s| Ustr::from(s.as_str())).collect()),
init_id,
ts_init.into(),
)
}
#[getter]
#[pyo3(name = "order_type")]
fn py_order_type(&self) -> OrderType {
self.order_type
}
#[getter]
#[pyo3(name = "events")]
fn py_events(&self, py: Python<'_>) -> PyResult<Vec<PyObject>> {
self.events()
.into_iter()
.map(|event| order_event_to_pyobject(py, event.clone()))
.collect()
}
#[staticmethod]
#[pyo3(name = "create")]
fn py_create(init: OrderInitialized) -> PyResult<Self> {
Ok(TrailingStopLimitOrder::from(init))
}
#[pyo3(name = "apply")]
fn py_apply(&mut self, event: PyObject, py: Python<'_>) -> PyResult<()> {
let event_any = pyobject_to_order_event(py, event).unwrap();
self.apply(event_any).map(|_| ()).map_err(to_pyruntime_err)
}
}