use nautilus_core::{UUID4, python::IntoPyObjectNautilusExt};
use pyo3::{basic::CompareOp, prelude::*};
use crate::{
enums::AccountType,
events::PortfolioSnapshot,
identifiers::{AccountId, InstrumentId},
types::{AccountBalance, Currency, MarginBalance, Money},
};
#[pymethods]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
impl PortfolioSnapshot {
#[expect(clippy::too_many_arguments)]
#[new]
#[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))]
fn py_new(
account_id: AccountId,
account_type: AccountType,
balances: Vec<AccountBalance>,
margins: Vec<MarginBalance>,
unrealized_pnls: Vec<Money>,
realized_pnls: Vec<Money>,
total_equity: Vec<Money>,
event_id: UUID4,
ts_event: u64,
ts_init: u64,
base_currency: Option<Currency>,
base_currency_equity: Option<Money>,
is_stale: bool,
stale_instruments: Option<Vec<InstrumentId>>,
stale_currencies: Option<Vec<Currency>>,
unpriced_instruments: Option<Vec<InstrumentId>>,
) -> Self {
Self::new(
account_id,
account_type,
base_currency,
balances,
margins,
unrealized_pnls,
realized_pnls,
total_equity,
base_currency_equity,
is_stale,
stale_instruments.unwrap_or_default(),
stale_currencies.unwrap_or_default(),
unpriced_instruments.unwrap_or_default(),
event_id,
ts_event.into(),
ts_init.into(),
)
}
#[getter]
fn account_id(&self) -> AccountId {
self.account_id
}
#[getter]
fn account_type(&self) -> AccountType {
self.account_type
}
#[getter]
fn base_currency(&self) -> Option<Currency> {
self.base_currency
}
#[getter]
fn balances(&self) -> Vec<AccountBalance> {
self.balances.clone()
}
#[getter]
fn margins(&self) -> Vec<MarginBalance> {
self.margins.clone()
}
#[getter]
fn unrealized_pnls(&self) -> Vec<Money> {
self.unrealized_pnls.clone()
}
#[getter]
fn realized_pnls(&self) -> Vec<Money> {
self.realized_pnls.clone()
}
#[getter]
fn total_equity(&self) -> Vec<Money> {
self.total_equity.clone()
}
#[getter]
fn base_currency_equity(&self) -> Option<Money> {
self.base_currency_equity
}
#[getter]
fn is_stale(&self) -> bool {
self.is_stale
}
#[getter]
fn stale_instruments(&self) -> Vec<InstrumentId> {
self.stale_instruments.clone()
}
#[getter]
fn stale_currencies(&self) -> Vec<Currency> {
self.stale_currencies.clone()
}
#[getter]
fn unpriced_instruments(&self) -> Vec<InstrumentId> {
self.unpriced_instruments.clone()
}
#[getter]
fn event_id(&self) -> UUID4 {
self.event_id
}
#[getter]
fn ts_event(&self) -> u64 {
self.ts_event.as_u64()
}
#[getter]
fn ts_init(&self) -> u64 {
self.ts_init.as_u64()
}
fn __richcmp__(&self, other: &Self, op: CompareOp, py: Python<'_>) -> Py<PyAny> {
match op {
CompareOp::Eq => self.eq(other).into_py_any_unwrap(py),
CompareOp::Ne => self.ne(other).into_py_any_unwrap(py),
_ => py.NotImplemented(),
}
}
fn __repr__(&self) -> String {
format!("{self:?}")
}
fn __str__(&self) -> String {
self.to_string()
}
}