Client API for interacting with a portfolio process.
Each portfolio is a GenServer (see RiskEngine.Portfolio.Server)
started under RiskEngine.PortfolioSupervisor and registered in
RiskEngine.PortfolioRegistry under its portfolio_id. This module never
holds a pid directly — every call is routed through the registry via
via/1, so callers only ever need to know a portfolio's id.
Summary
Types
Identifies a portfolio, and the process that owns its state.
Functions
Builds a child specification for starting a portfolio under a supervisor.
Fetches the current state of the portfolio identified by portfolio_id.
Starts a portfolio process for portfolio_id, registering it in
RiskEngine.PortfolioRegistry.
Asynchronously submits a trade to the portfolio identified by
portfolio_id.
Types
@type portfolio_id() :: String.t()
Identifies a portfolio, and the process that owns its state.
Functions
@spec child_spec(portfolio_id()) :: Supervisor.child_spec()
Builds a child specification for starting a portfolio under a supervisor.
Uses a :transient restart strategy: the process is restarted if it
crashes, but not if it exits normally.
@spec get_state(portfolio_id()) :: RiskEngine.Portfolio.Server.t()
Fetches the current state of the portfolio identified by portfolio_id.
@spec start_link(portfolio_id()) :: GenServer.on_start()
Starts a portfolio process for portfolio_id, registering it in
RiskEngine.PortfolioRegistry.
Not usually called directly — use
RiskEngine.PortfolioSupervisor.ensure_started/1 instead, which starts
the process under supervision and is safe to call even if one is already
running.
@spec submit_trade(portfolio_id(), RiskEngine.TradeIngestion.trade()) :: :ok
Asynchronously submits a trade to the portfolio identified by
portfolio_id.
Returns :ok immediately; the portfolio's exposure, volatility, and
drawdown are recomputed and broadcast once the cast is processed.