pub fn parse_account_state(
subaccount: &DydxSubaccountInfo,
account_id: AccountId,
instruments: &HashMap<InstrumentId, InstrumentAny>,
oracle_prices: &HashMap<InstrumentId, Decimal>,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> Result<AccountState>Expand description
Parse a dYdX subaccount info into a Nautilus AccountState.
dYdX provides account-level balances with:
equity: Total account value (total balance)freeCollateral: Available for new orders (free balance)locked: equity - freeCollateral (calculated)
Margin calculations per position:
initial_margin = margin_init * abs(position_size) * oracle_pricemaintenance_margin = margin_maint * abs(position_size) * oracle_price
ยงErrors
Returns an error if balance fields cannot be parsed.