nautilus_model/python/account/
mod.rs1pub mod cash;
17pub mod margin;
18pub mod transformer;
19
20use nautilus_core::python::to_pyvalue_err;
21use pyo3::{IntoPy, PyObject, PyResult, Python};
22
23use crate::{
24 accounts::{any::AccountAny, cash::CashAccount, margin::MarginAccount},
25 enums::AccountType,
26};
27
28pub fn convert_pyobject_to_account_any(py: Python, account: PyObject) -> PyResult<AccountAny> {
29 let account_type = account
30 .getattr(py, "account_type")?
31 .extract::<AccountType>(py)?;
32 if account_type == AccountType::Cash {
33 let cash = account.extract::<CashAccount>(py)?;
34 Ok(AccountAny::Cash(cash))
35 } else if account_type == AccountType::Margin {
36 let margin = account.extract::<MarginAccount>(py)?;
37 Ok(AccountAny::Margin(margin))
38 } else {
39 Err(to_pyvalue_err("Unsupported account type"))
40 }
41}
42
43pub fn convert_account_any_to_pyobject(py: Python, account: AccountAny) -> PyResult<PyObject> {
44 match account {
45 AccountAny::Cash(account) => Ok(account.into_py(py)),
46 AccountAny::Margin(account) => Ok(account.into_py(py)),
47 }
48}