1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
1516pub mod cash;
17pub mod margin;
18pub mod transformer;
1920use nautilus_core::python::to_pyvalue_err;
21use pyo3::{PyObject, PyResult, Python, conversion::IntoPyObjectExt};
2223use crate::{
24 accounts::{AccountAny, CashAccount, MarginAccount},
25 enums::AccountType,
26};
2728pub fn pyobject_to_account_any(py: Python, account: PyObject) -> PyResult<AccountAny> {
29let account_type = account
30 .getattr(py, "account_type")?
31.extract::<AccountType>(py)?;
32if account_type == AccountType::Cash {
33let cash = account.extract::<CashAccount>(py)?;
34Ok(AccountAny::Cash(cash))
35 } else if account_type == AccountType::Margin {
36let margin = account.extract::<MarginAccount>(py)?;
37Ok(AccountAny::Margin(margin))
38 } else {
39Err(to_pyvalue_err("Unsupported account type"))
40 }
41}
4243pub fn account_any_to_pyobject(py: Python, account: AccountAny) -> PyResult<PyObject> {
44match account {
45 AccountAny::Cash(account) => account.into_py_any(py),
46 AccountAny::Margin(account) => account.into_py_any(py),
47 }
48}