pub struct AccountsManager { /* private fields */ }Expand description
Manages account balance updates and calculations for portfolio management.
The accounts manager handles balance updates for different account types, including cash and margin accounts, based on order fills and position changes.
Implementations§
Source§impl AccountsManager
impl AccountsManager
Sourcepub fn new(clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>) -> Self
pub fn new(clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>) -> Self
Creates a new AccountsManager instance.
Sourcepub fn update_balances(
&self,
account: AccountAny,
instrument: &InstrumentAny,
fill: OrderFilled,
) -> (AccountAny, AccountState)
pub fn update_balances( &self, account: AccountAny, instrument: &InstrumentAny, fill: OrderFilled, ) -> (AccountAny, AccountState)
Updates the given account state based on a filled order.
Mutations are applied to account in place so the caller can persist
the recalculated balances and commissions back to the cache.
§Panics
Panics if the position list for the filled instrument is empty.
Sourcepub fn update_orders(
&self,
account: &AccountAny,
instrument: &InstrumentAny,
orders_open: &[&OrderAny],
ts_event: UnixNanos,
) -> Option<(AccountAny, AccountState)>
pub fn update_orders( &self, account: &AccountAny, instrument: &InstrumentAny, orders_open: &[&OrderAny], ts_event: UnixNanos, ) -> Option<(AccountAny, AccountState)>
Updates account balances based on open orders.
For cash accounts, updates the balance locked by open orders. For margin accounts, updates the initial margin requirements.
Sourcepub fn update_orders_in_place(
&self,
account: &mut AccountAny,
instrument: &InstrumentAny,
orders_open: &[&OrderAny],
ts_event: UnixNanos,
) -> Option<AccountState>
pub fn update_orders_in_place( &self, account: &mut AccountAny, instrument: &InstrumentAny, orders_open: &[&OrderAny], ts_event: UnixNanos, ) -> Option<AccountState>
Updates account balances based on open orders in place.
For cash accounts, updates the balance locked by open orders. For margin accounts, updates the initial margin requirements.
Sourcepub fn update_positions(
&self,
account: &MarginAccount,
instrument: &InstrumentAny,
positions: Vec<&Position>,
ts_event: UnixNanos,
) -> Option<(MarginAccount, AccountState)>
pub fn update_positions( &self, account: &MarginAccount, instrument: &InstrumentAny, positions: Vec<&Position>, ts_event: UnixNanos, ) -> Option<(MarginAccount, AccountState)>
Updates the account based on current open positions.
§Panics
Panics if any position’s instrument_id does not match the provided instrument.
Sourcepub fn update_positions_in_place(
&self,
account: &mut MarginAccount,
instrument: &InstrumentAny,
positions: Vec<&Position>,
ts_event: UnixNanos,
) -> Option<AccountState>
pub fn update_positions_in_place( &self, account: &mut MarginAccount, instrument: &InstrumentAny, positions: Vec<&Position>, ts_event: UnixNanos, ) -> Option<AccountState>
Updates the account based on current open positions in place.
Maintenance margin is computed on the net per-instrument exposure: open positions are folded into a NETTING-equivalent state and the margin model runs once on the result.
§Panics
Panics if any position’s instrument_id does not match the provided instrument.