nautilus_model/python/events/position/
opened.rs1use nautilus_core::{UUID4, python::IntoPyObjectNautilusExt};
17use pyo3::{basic::CompareOp, prelude::*};
18
19use crate::{
20 enums::{OrderSide, PositionSide},
21 events::{OrderFilled, PositionOpened},
22 identifiers::{AccountId, ClientOrderId, InstrumentId, PositionId, StrategyId, TraderId},
23 position::Position,
24 types::{Currency, Price, Quantity},
25};
26
27#[pymethods]
28#[pyo3_stub_gen::derive::gen_stub_pymethods]
29impl PositionOpened {
30 #[staticmethod]
31 #[pyo3(name = "create")]
32 fn py_create(position: &Position, fill: &OrderFilled, event_id: UUID4, ts_init: u64) -> Self {
33 Self::create(position, fill, event_id, ts_init.into())
34 }
35
36 fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
37 match op {
38 CompareOp::Eq => self.eq(other).into_py_any_unwrap(py),
39 CompareOp::Ne => self.ne(other).into_py_any_unwrap(py),
40 _ => py.NotImplemented(),
41 }
42 }
43
44 fn __repr__(&self) -> String {
45 format!("{self:?}")
46 }
47
48 #[getter]
49 #[pyo3(name = "trader_id")]
50 fn py_trader_id(&self) -> TraderId {
51 self.trader_id
52 }
53
54 #[getter]
55 #[pyo3(name = "strategy_id")]
56 fn py_strategy_id(&self) -> StrategyId {
57 self.strategy_id
58 }
59
60 #[getter]
61 #[pyo3(name = "instrument_id")]
62 fn py_instrument_id(&self) -> InstrumentId {
63 self.instrument_id
64 }
65
66 #[getter]
67 #[pyo3(name = "position_id")]
68 fn py_position_id(&self) -> PositionId {
69 self.position_id
70 }
71
72 #[getter]
73 #[pyo3(name = "account_id")]
74 fn py_account_id(&self) -> AccountId {
75 self.account_id
76 }
77
78 #[getter]
79 #[pyo3(name = "opening_order_id")]
80 fn py_opening_order_id(&self) -> ClientOrderId {
81 self.opening_order_id
82 }
83
84 #[getter]
85 #[pyo3(name = "entry")]
86 fn py_entry(&self) -> OrderSide {
87 self.entry
88 }
89
90 #[getter]
91 #[pyo3(name = "side")]
92 fn py_side(&self) -> PositionSide {
93 self.side
94 }
95
96 #[getter]
97 #[pyo3(name = "signed_qty")]
98 fn py_signed_qty(&self) -> f64 {
99 self.signed_qty
100 }
101
102 #[getter]
103 #[pyo3(name = "quantity")]
104 fn py_quantity(&self) -> Quantity {
105 self.quantity
106 }
107
108 #[getter]
109 #[pyo3(name = "last_qty")]
110 fn py_last_qty(&self) -> Quantity {
111 self.last_qty
112 }
113
114 #[getter]
115 #[pyo3(name = "last_px")]
116 fn py_last_px(&self) -> Price {
117 self.last_px
118 }
119
120 #[getter]
121 #[pyo3(name = "currency")]
122 fn py_currency(&self) -> Currency {
123 self.currency
124 }
125
126 #[getter]
127 #[pyo3(name = "avg_px_open")]
128 fn py_avg_px_open(&self) -> f64 {
129 self.avg_px_open
130 }
131
132 #[getter]
133 #[pyo3(name = "event_id")]
134 fn py_event_id(&self) -> UUID4 {
135 self.event_id
136 }
137
138 #[getter]
139 #[pyo3(name = "ts_event")]
140 fn py_ts_event(&self) -> u64 {
141 self.ts_event.as_u64()
142 }
143
144 #[getter]
145 #[pyo3(name = "ts_init")]
146 fn py_ts_init(&self) -> u64 {
147 self.ts_init.as_u64()
148 }
149}