Skip to main content

Module account_builder

Module account_builder 

Source
Expand description

Account builder for converting PortfolioBalance to types::Account.

This module provides the translation layer between:

  • PortfolioBalance (PortfolioService’s internal state for executed positions)
  • types::Account (SPAN/margin calculation input)

The key insight is that PortfolioBalance stores positions keyed by full symbol (e.g., “BTC-20250131-100000-C”), while Account groups by underlying (e.g., “BTC”).

§Fail-Closed Design

This builder returns Result<Account, BuildAccountError> rather than silently skipping unknown or missing data. If we cannot safely construct a complete risk view, we return an error so callers can reject margin-sensitive operations.

Enums§

BuildAccountError
Error type for account construction failures.

Functions§

build_account_from_balance
Build a types::Account from PortfolioService’s internal state.
expiry_to_years
Convert YYYYMMDD expiry to years-to-expiry from now.