nautilus_model/python/events/portfolio/
snapshot.rs1use nautilus_core::{UUID4, python::IntoPyObjectNautilusExt};
17use pyo3::{basic::CompareOp, prelude::*};
18
19use crate::{
20 enums::AccountType,
21 events::PortfolioSnapshot,
22 identifiers::{AccountId, InstrumentId},
23 types::{AccountBalance, Currency, MarginBalance, Money},
24};
25
26#[pymethods]
27#[pyo3_stub_gen::derive::gen_stub_pymethods]
28impl PortfolioSnapshot {
29 #[expect(clippy::too_many_arguments)]
41 #[new]
42 #[pyo3(signature = (account_id, account_type, balances, margins, unrealized_pnls, realized_pnls, total_equity, event_id, ts_event, ts_init, base_currency=None, base_currency_equity=None, is_stale=false, stale_instruments=None, stale_currencies=None, unpriced_instruments=None))]
43 fn py_new(
44 account_id: AccountId,
45 account_type: AccountType,
46 balances: Vec<AccountBalance>,
47 margins: Vec<MarginBalance>,
48 unrealized_pnls: Vec<Money>,
49 realized_pnls: Vec<Money>,
50 total_equity: Vec<Money>,
51 event_id: UUID4,
52 ts_event: u64,
53 ts_init: u64,
54 base_currency: Option<Currency>,
55 base_currency_equity: Option<Money>,
56 is_stale: bool,
57 stale_instruments: Option<Vec<InstrumentId>>,
58 stale_currencies: Option<Vec<Currency>>,
59 unpriced_instruments: Option<Vec<InstrumentId>>,
60 ) -> Self {
61 Self::new(
62 account_id,
63 account_type,
64 base_currency,
65 balances,
66 margins,
67 unrealized_pnls,
68 realized_pnls,
69 total_equity,
70 base_currency_equity,
71 is_stale,
72 stale_instruments.unwrap_or_default(),
73 stale_currencies.unwrap_or_default(),
74 unpriced_instruments.unwrap_or_default(),
75 event_id,
76 ts_event.into(),
77 ts_init.into(),
78 )
79 }
80
81 #[getter]
82 fn account_id(&self) -> AccountId {
83 self.account_id
84 }
85
86 #[getter]
87 fn account_type(&self) -> AccountType {
88 self.account_type
89 }
90
91 #[getter]
92 fn base_currency(&self) -> Option<Currency> {
93 self.base_currency
94 }
95
96 #[getter]
97 fn balances(&self) -> Vec<AccountBalance> {
98 self.balances.clone()
99 }
100
101 #[getter]
102 fn margins(&self) -> Vec<MarginBalance> {
103 self.margins.clone()
104 }
105
106 #[getter]
107 fn unrealized_pnls(&self) -> Vec<Money> {
108 self.unrealized_pnls.clone()
109 }
110
111 #[getter]
112 fn realized_pnls(&self) -> Vec<Money> {
113 self.realized_pnls.clone()
114 }
115
116 #[getter]
117 fn total_equity(&self) -> Vec<Money> {
118 self.total_equity.clone()
119 }
120
121 #[getter]
122 fn base_currency_equity(&self) -> Option<Money> {
123 self.base_currency_equity
124 }
125
126 #[getter]
127 fn is_stale(&self) -> bool {
128 self.is_stale
129 }
130
131 #[getter]
132 fn stale_instruments(&self) -> Vec<InstrumentId> {
133 self.stale_instruments.clone()
134 }
135
136 #[getter]
137 fn stale_currencies(&self) -> Vec<Currency> {
138 self.stale_currencies.clone()
139 }
140
141 #[getter]
142 fn unpriced_instruments(&self) -> Vec<InstrumentId> {
143 self.unpriced_instruments.clone()
144 }
145
146 #[getter]
147 fn event_id(&self) -> UUID4 {
148 self.event_id
149 }
150
151 #[getter]
152 fn ts_event(&self) -> u64 {
153 self.ts_event.as_u64()
154 }
155
156 #[getter]
157 fn ts_init(&self) -> u64 {
158 self.ts_init.as_u64()
159 }
160
161 fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
162 match op {
163 CompareOp::Eq => self.eq(other).into_py_any_unwrap(py),
164 CompareOp::Ne => self.ne(other).into_py_any_unwrap(py),
165 _ => py.NotImplemented(),
166 }
167 }
168
169 fn __repr__(&self) -> String {
170 format!("{self:?}")
171 }
172
173 fn __str__(&self) -> String {
174 self.to_string()
175 }
176}