nautilus_model/accounts/
mod.rs1pub mod any;
19pub mod base;
20pub mod betting;
21pub mod cash;
22pub mod margin;
23pub mod margin_model;
24pub mod wallet;
25
26#[cfg(any(test, feature = "test-support"))]
27pub mod stubs;
28
29use enum_dispatch::enum_dispatch;
30use indexmap::IndexMap;
31use nautilus_core::UnixNanos;
32
33pub use crate::accounts::{
35 any::AccountAny, base::BaseAccount, betting::BettingAccount, cash::CashAccount,
36 margin::MarginAccount, wallet::WalletAccount,
37};
38use crate::{
39 enums::{AccountType, LiquiditySide, OrderSide},
40 events::{AccountState, OrderFilled},
41 identifiers::AccountId,
42 instruments::InstrumentAny,
43 position::Position,
44 types::{AccountBalance, Currency, Money, Price, Quantity},
45};
46
47#[enum_dispatch]
48pub trait Account: 'static + Send {
49 fn id(&self) -> AccountId;
50 fn account_type(&self) -> AccountType;
51 fn base_currency(&self) -> Option<Currency>;
52 fn is_cash_account(&self) -> bool;
53 fn is_margin_account(&self) -> bool;
54 fn calculated_account_state(&self) -> bool;
55 fn balance_total(&self, currency: Option<Currency>) -> Option<Money>;
56 fn balances_total(&self) -> IndexMap<Currency, Money>;
57 fn balance_free(&self, currency: Option<Currency>) -> Option<Money>;
58 fn balances_free(&self) -> IndexMap<Currency, Money>;
59 fn balance_locked(&self, currency: Option<Currency>) -> Option<Money>;
60 fn balances_locked(&self) -> IndexMap<Currency, Money>;
61 fn balance(&self, currency: Option<Currency>) -> Option<&AccountBalance>;
62 fn last_event(&self) -> Option<AccountState>;
63 fn events(&self) -> Vec<AccountState>;
64 fn event_count(&self) -> usize;
65 fn currencies(&self) -> Vec<Currency>;
66 fn starting_balances(&self) -> IndexMap<Currency, Money>;
67 fn balances(&self) -> IndexMap<Currency, AccountBalance>;
68 fn apply(&mut self, event: AccountState) -> anyhow::Result<()>;
75 fn purge_account_events(&mut self, ts_now: UnixNanos, lookback_secs: u64);
76
77 fn calculate_balance_locked(
83 &mut self,
84 instrument: &InstrumentAny,
85 side: OrderSide,
86 quantity: Quantity,
87 price: Price,
88 use_quote_for_inverse: Option<bool>,
89 ) -> anyhow::Result<Money>;
90
91 fn calculate_pnls(
97 &self,
98 instrument: &InstrumentAny,
99 fill: &OrderFilled,
100 position: Option<Position>,
101 ) -> anyhow::Result<Vec<Money>>;
102
103 fn calculate_commission(
109 &self,
110 instrument: &InstrumentAny,
111 last_qty: Quantity,
112 last_px: Price,
113 liquidity_side: LiquiditySide,
114 use_quote_for_inverse: Option<bool>,
115 ) -> anyhow::Result<Money>;
116}