pub mod any;
pub mod base;
pub mod betting;
pub mod cash;
pub mod margin;
pub mod margin_model;
#[cfg(any(test, feature = "stubs"))]
pub mod stubs;
use ahash::AHashMap;
use enum_dispatch::enum_dispatch;
use nautilus_core::UnixNanos;
pub use crate::accounts::{
any::AccountAny, base::BaseAccount, betting::BettingAccount, cash::CashAccount,
margin::MarginAccount,
};
use crate::{
enums::{AccountType, LiquiditySide, OrderSide},
events::{AccountState, OrderFilled},
identifiers::AccountId,
instruments::InstrumentAny,
position::Position,
types::{AccountBalance, Currency, Money, Price, Quantity},
};
#[enum_dispatch]
pub trait Account: 'static + Send {
fn id(&self) -> AccountId;
fn account_type(&self) -> AccountType;
fn base_currency(&self) -> Option<Currency>;
fn is_cash_account(&self) -> bool;
fn is_margin_account(&self) -> bool;
fn calculated_account_state(&self) -> bool;
fn balance_total(&self, currency: Option<Currency>) -> Option<Money>;
fn balances_total(&self) -> AHashMap<Currency, Money>;
fn balance_free(&self, currency: Option<Currency>) -> Option<Money>;
fn balances_free(&self) -> AHashMap<Currency, Money>;
fn balance_locked(&self, currency: Option<Currency>) -> Option<Money>;
fn balances_locked(&self) -> AHashMap<Currency, Money>;
fn balance(&self, currency: Option<Currency>) -> Option<&AccountBalance>;
fn last_event(&self) -> Option<AccountState>;
fn events(&self) -> Vec<AccountState>;
fn event_count(&self) -> usize;
fn currencies(&self) -> Vec<Currency>;
fn starting_balances(&self) -> AHashMap<Currency, Money>;
fn balances(&self) -> AHashMap<Currency, AccountBalance>;
fn apply(&mut self, event: AccountState) -> anyhow::Result<()>;
fn purge_account_events(&mut self, ts_now: UnixNanos, lookback_secs: u64);
fn calculate_balance_locked(
&mut self,
instrument: &InstrumentAny,
side: OrderSide,
quantity: Quantity,
price: Price,
use_quote_for_inverse: Option<bool>,
) -> anyhow::Result<Money>;
fn calculate_pnls(
&self,
instrument: &InstrumentAny,
fill: &OrderFilled,
position: Option<Position>,
) -> anyhow::Result<Vec<Money>>;
fn calculate_commission(
&self,
instrument: &InstrumentAny,
last_qty: Quantity,
last_px: Price,
liquidity_side: LiquiditySide,
use_quote_for_inverse: Option<bool>,
) -> anyhow::Result<Money>;
}