Multi-Leg Execution
Spread trades, hedged positions, and arbitrage strategies require multiple orders that must succeed or fail together. Horizon’s multi-leg module provides atomic execution with three fill policies, aggregate risk checks, and cross-exchange leg support. Type validation is in Rust; execution orchestration is in Python.Overview
Fill Policies
All-or-none, best-effort, and delta-neutral execution modes.
Aggregate Risk
hz.aggregate_leg_risk() sums notional across all legs before submission.Validation
hz.validate_legs() checks legs for completeness before execution.Cross-Exchange
Each leg can target a different exchange.
Core Types
FillPolicy
| Policy | Behavior |
|---|---|
AllOrNone | If any leg fails, cancel all previously submitted legs |
BestEffort | Submit all legs, continue on individual failures |
DeltaNeutral | If one side fails, cancel the paired leg |
Leg
| Field | Type | Description |
|---|---|---|
market_id | str | Target market |
side | str | "buy" or "sell" |
size | float | Order size |
price | float | Limit price |
exchange | str | Target exchange |
Core Functions
hz.validate_legs
Check legs for completeness (non-empty market_id, positive size).hz.aggregate_leg_risk
Sum risk metrics across all legs.hz.build_mock_result
Build a mock execution result for backtesting.Pipeline Function
hz.multi_leg
Execute multiple legs atomically each cycle.| Parameter | Type | Default | Description |
|---|---|---|---|
legs_config | list[dict] | None | Leg configurations (or read from ctx.params["legs"]) |
policy | str | "best_effort" | all_or_none, best_effort, or delta_neutral |