nautilus_model/events/account/
stubs.rs

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// -------------------------------------------------------------------------------------------------
15
16use nautilus_core::UUID4;
17use rstest::fixture;
18
19use crate::{
20    enums::AccountType,
21    events::AccountState,
22    identifiers::stubs::{account_id, uuid4},
23    types::{
24        stubs::{stub_account_balance, stub_margin_balance},
25        AccountBalance, Currency, Money,
26    },
27};
28
29#[fixture]
30pub fn cash_account_state() -> AccountState {
31    AccountState::new(
32        account_id(),
33        AccountType::Cash,
34        vec![stub_account_balance()],
35        vec![],
36        true,
37        uuid4(),
38        0.into(),
39        0.into(),
40        Some(Currency::USD()),
41    )
42}
43
44#[fixture]
45pub fn cash_account_state_million_usd(
46    #[default("1000000 USD")] total: &str,
47    #[default("0 USD")] locked: &str,
48    #[default("1000000 USD")] free: &str,
49) -> AccountState {
50    AccountState::new(
51        account_id(),
52        AccountType::Cash,
53        vec![AccountBalance::new(
54            Money::from(total),
55            Money::from(locked),
56            Money::from(free),
57        )],
58        vec![],
59        true,
60        UUID4::new(),
61        0.into(),
62        0.into(),
63        Some(Currency::USD()),
64    )
65}
66
67#[fixture]
68pub fn cash_account_state_million_usdt() -> AccountState {
69    AccountState::new(
70        account_id(),
71        AccountType::Cash,
72        vec![AccountBalance::new(
73            Money::from("1000000 USD"),
74            Money::from("0 USD"),
75            Money::from("1000000 USD"),
76        )],
77        vec![],
78        true,
79        uuid4(),
80        0.into(),
81        0.into(),
82        Some(Currency::USD()),
83    )
84}
85
86#[fixture]
87pub fn cash_account_state_multi() -> AccountState {
88    let btc_account_balance = AccountBalance::new(
89        Money::from("10 BTC"),
90        Money::from("0 BTC"),
91        Money::from("10 BTC"),
92    );
93    let eth_account_balance = AccountBalance::new(
94        Money::from("20 ETH"),
95        Money::from("0 ETH"),
96        Money::from("20 ETH"),
97    );
98    AccountState::new(
99        account_id(),
100        AccountType::Cash,
101        vec![btc_account_balance, eth_account_balance],
102        vec![],
103        true,
104        uuid4(),
105        0.into(),
106        0.into(),
107        None, // multi cash account
108    )
109}
110
111#[fixture]
112pub fn cash_account_state_multi_changed_btc() -> AccountState {
113    let btc_account_balance = AccountBalance::new(
114        Money::from("9 BTC"),
115        Money::from("0.5 BTC"),
116        Money::from("8.5 BTC"),
117    );
118    let eth_account_balance = AccountBalance::new(
119        Money::from("20 ETH"),
120        Money::from("0 ETH"),
121        Money::from("20 ETH"),
122    );
123    AccountState::new(
124        account_id(),
125        AccountType::Cash,
126        vec![btc_account_balance, eth_account_balance],
127        vec![],
128        true,
129        uuid4(),
130        0.into(),
131        0.into(),
132        None, // multi cash account
133    )
134}
135
136#[fixture]
137pub fn margin_account_state() -> AccountState {
138    AccountState::new(
139        account_id(),
140        AccountType::Margin,
141        vec![stub_account_balance()],
142        vec![stub_margin_balance()],
143        true,
144        uuid4(),
145        0.into(),
146        0.into(),
147        Some(Currency::USD()),
148    )
149}