RiskEngine.TradeIngestion (risk_engine v0.1.0)

Copy Markdown View Source

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

Types

A single buy or sell order for a portfolio.

Functions

Submits a trade for a portfolio.

Types

trade()

@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 which RiskEngine.Portfolio the 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:buy or :sell.
  • :qty — number of units traded. Must be a positive number.
  • :price — price per unit. Must be a positive number.

Functions

submit(trade)

@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).