pub fn build_account_from_balance(
account_id: &WalletAddress,
balance: &PortfolioBalance,
address: Option<WalletAddress>,
spot_prices: &HashMap<String, f64>,
) -> Result<Account, BuildAccountError>Expand description
Build a types::Account from PortfolioService’s internal state.
This converts executed positions (PortfolioBalance) into the format that SPAN/margin code expects (types::Account).
§Arguments
account_id- The wallet address / account identifierbalance- The internal PortfolioBalance from PortfolioServiceaddress- Optional on-chain address (for HyperCore lookups)spot_prices- Map of underlying -> current spot price (e.g., {“BTC”: 100000.0})
§Returns
Ok(Account)- A complete, trustworthy Account ready for SPAN margin calculationsErr(BuildAccountError)- If any position cannot be safely converted
§Fail-Closed Behavior
This function returns an error (rather than skipping) if:
- A symbol cannot be parsed
- A spot price is missing for an underlying with positions
- An instrument type is not supported