Single entry point for feeding trades into the risk engine.
submit/1 is the boundary between the outside world (a market data feed,
an API endpoint, RiskEngine.Simulator, ...) and the rest of the system.
It validates the trade, makes sure a RiskEngine.Portfolio process exists
for the portfolio, forwards the trade to it, and broadcasts the raw trade
on the "trades" PubSub topic for any interested observers.
Summary
Functions
Submits a trade for a portfolio.
Types
@type trade() :: %{ portfolio_id: String.t(), symbol: String.t(), side: :buy | :sell, qty: number(), price: number() }
A single buy or sell order for a portfolio.
:portfolio_id— identifies whichRiskEngine.Portfoliothe trade belongs to. A new portfolio process is started automatically the first time an id is seen.:symbol— the ticker traded, e.g."AAPL".:side—:buyor:sell.:qty— number of units traded. Must be a positive number.:price— price per unit. Must be a positive number.
Functions
@spec submit(trade()) :: :ok | {:error, :invalid_trade}
Submits a trade for a portfolio.
Ensures the portfolio process exists, forwards the trade to it, and
broadcasts it on the "trades" topic for observers.
Returns :ok on success, or {:error, :invalid_trade} if trade is
missing required fields or has a value outside its valid range (e.g. a
non-positive :qty or :price, or a :side other than :buy/:sell).