nautilus_model/python/account/
mod.rs1pub mod betting;
17pub mod cash;
18pub mod margin;
19pub mod margin_model;
20pub mod transformer;
21pub mod wallet;
22
23use nautilus_core::python::to_pyvalue_err;
24use pyo3::{Py, PyAny, PyResult, Python, conversion::IntoPyObjectExt};
25
26use crate::{
27 accounts::{AccountAny, BettingAccount, CashAccount, MarginAccount, WalletAccount},
28 enums::AccountType,
29};
30
31#[expect(clippy::needless_pass_by_value)]
40pub fn pyobject_to_account_any(py: Python, account: Py<PyAny>) -> PyResult<AccountAny> {
41 let account_type = account
42 .getattr(py, "account_type")?
43 .extract::<AccountType>(py)?;
44 if account_type == AccountType::Margin {
45 let margin = account.extract::<MarginAccount>(py)?;
46 Ok(AccountAny::Margin(margin))
47 } else if account_type == AccountType::Cash {
48 let cash = account.extract::<CashAccount>(py)?;
49 Ok(AccountAny::Cash(cash))
50 } else if account_type == AccountType::Betting {
51 let betting = account.extract::<BettingAccount>(py)?;
52 Ok(AccountAny::Betting(betting))
53 } else if account_type == AccountType::Wallet {
54 let wallet = account.extract::<WalletAccount>(py)?;
55 Ok(AccountAny::Wallet(wallet))
56 } else {
57 Err(to_pyvalue_err("Unsupported account type"))
58 }
59}
60
61pub fn account_any_to_pyobject(py: Python, account: AccountAny) -> PyResult<Py<PyAny>> {
67 match account {
68 AccountAny::Margin(account) => account.into_py_any(py),
69 AccountAny::Cash(account) => account.into_py_any(py),
70 AccountAny::Betting(account) => account.into_py_any(py),
71 AccountAny::Wallet(account) => account.into_py_any(py),
72 }
73}