nautilus_model/accounts/
stubs.rs1use rstest::fixture;
20
21use crate::{
22 accounts::{Account, AccountAny, BettingAccount, CashAccount, MarginAccount, WalletAccount},
23 enums::{AccountType, LiquiditySide},
24 events::account::{
25 state::AccountState,
26 stubs::{
27 betting_account_state, cash_account_state, cash_account_state_million_usd,
28 cash_account_state_million_usdt, cash_account_state_multi, margin_account_state,
29 wallet_account_state,
30 },
31 },
32 identifiers::stubs::{account_id, uuid4},
33 instruments::InstrumentAny,
34 types::{AccountBalance, Currency, Money, Price, Quantity},
35};
36
37impl Default for CashAccount {
38 fn default() -> Self {
40 let init_event = AccountState::new(
42 account_id(),
43 AccountType::Cash,
44 vec![AccountBalance::new(
45 Money::from("1000000 USD"),
46 Money::from("0 USD"),
47 Money::from("1000000 USD"),
48 )],
49 vec![],
50 true,
51 uuid4(),
52 0.into(),
53 0.into(),
54 Some(Currency::USD()),
55 );
56 Self::new(init_event, false, false)
57 }
58}
59
60impl Default for AccountAny {
61 fn default() -> Self {
63 Self::Cash(CashAccount::default())
64 }
65}
66
67#[fixture]
68pub fn margin_account(margin_account_state: AccountState) -> MarginAccount {
69 MarginAccount::new(margin_account_state, true)
70}
71
72#[fixture]
73pub fn cash_account(cash_account_state: AccountState) -> CashAccount {
74 CashAccount::new(cash_account_state, true, false)
75}
76
77#[fixture]
78pub fn betting_account(betting_account_state: AccountState) -> BettingAccount {
79 BettingAccount::new(betting_account_state, true)
80}
81
82#[fixture]
83pub fn wallet_account(wallet_account_state: AccountState) -> WalletAccount {
84 WalletAccount::new(wallet_account_state, true)
85}
86
87#[fixture]
88pub fn cash_account_million_usd(cash_account_state_million_usd: AccountState) -> CashAccount {
89 CashAccount::new(cash_account_state_million_usd, true, false)
90}
91
92#[fixture]
93pub fn cash_account_multi(cash_account_state_multi: AccountState) -> CashAccount {
94 CashAccount::new(cash_account_state_multi, true, false)
95}
96
97#[fixture]
98pub fn cash_account_borrowing(cash_account_state: AccountState) -> CashAccount {
99 CashAccount::new(cash_account_state, true, true)
100}
101
102#[fixture]
103pub fn cash_account_borrowing_million_usd(
104 cash_account_state_million_usd: AccountState,
105) -> CashAccount {
106 CashAccount::new(cash_account_state_million_usd, true, true)
107}
108
109#[must_use]
115pub fn calculate_commission(
116 instrument: &InstrumentAny,
117 quantity: Quantity,
118 price: Price,
119 currency: Option<Currency>,
120) -> Money {
121 let account_state = if Some(Currency::USDT()) == currency {
122 cash_account_state_million_usdt()
123 } else {
124 cash_account_state_million_usd("1000000 USD", "0 USD", "1000000 USD")
125 };
126 let account = cash_account_million_usd(account_state);
127 account
128 .calculate_commission(instrument, quantity, price, LiquiditySide::Taker, None)
129 .unwrap()
130}