RiskEngine

class RiskEngine(rules: List<RiskRule>, haltRules: List<HaltRule>, positions: PositionProvider, riskState: RiskState)

Pre-trade risk gate. Every OrderRequest flowing from the strategy layer to the broker goes through approve; rejected requests never reach the venue.

Two rule lists run independently:

  • Per-request rules (RiskRule) — evaluated on every order, short-circuit on the first rejection. Used for caps (max position size, max open positions, etc).

  • Halt rules (HaltRule) — evaluated against running state by RiskState; can put a strategy into a halted state where every subsequent submission auto-rejects without consulting the per-request rules.

The engine is single-threaded by design — call approve from the same thread that publishes order events onto the bus so the halt-vs-approve decision stays consistent with the order book state.

Constructors

Link copied to clipboard
constructor(rules: List<RiskRule>, positions: PositionProvider)

Convenience constructor for tests / single-strategy setups with no halt rules.

constructor(rules: List<RiskRule>, haltRules: List<HaltRule>, positions: PositionProvider, riskState: RiskState)

Functions

Link copied to clipboard

Run the rules over request and return whether the venue should see it.

Link copied to clipboard

Run the rules over requests as one position (an option structure's legs): a halted strategy may only send a group of risk-reducing legs; a GroupAwareRule judges the legs together and every other rule judges each leg; the first refusal refuses the whole group.

Link copied to clipboard