hz.run() is the single entry point for running a strategy. It creates the engine, starts feeds, recovers state, syncs positions, and enters the main loop.
Full Signature
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | required | Strategy name (shown in logs and dashboard) |
exchange | Exchange or None | None | Single exchange config: Polymarket(...), Kalshi(...), Alpaca(...), IBKR(...), Coinbase(...), Robinhood(...) |
exchanges | list | None | Multi-exchange configs, e.g. [Polymarket(...), Alpaca(...)] |
markets | list[str] | [] | Market slugs or tickers to trade |
feeds | dict[str, Feed] | {} | Named feeds, e.g. {"btc": BinanceWS("btcusdt")} |
pipeline | list[Callable] | required | Pipeline functions. Final fn must return list[Quote] |
risk | Risk or RiskConfig | defaults | Risk configuration |
interval | float | 0.5 | Seconds between strategy cycles |
mode | str | "paper" | "paper" for simulation, "live" for real trading |
dashboard | bool | False | Enable TUI dashboard |
params | dict | {} | Custom params accessible via ctx.params |
db_path | str or None | auto | SQLite path. Default: HORIZON_DB env or ./{name}.db. Set None to disable. |
events | list[Event] | None | Multi-outcome events (each outcome becomes a market). See Multi-Outcome Events. |
netting_pairs | list[tuple] | None | Market pairs whose positions offset for risk |
api_key | str or None | None | Horizon API key. Falls back to HORIZON_API_KEY env var. See Authentication. |
Lifecycle
Validate API key
Validates the Horizon API key (from
api_key param or HORIZON_API_KEY env var). Uses a local cache at ~/.horizon/license.json - only makes a network call if the cache is expired or missing. See Authentication.Build engine
Creates the Engine with exchange backend(s) and risk config. For multi-exchange, the first exchange in the list becomes the primary.
Register events and netting pairs
If
events is provided, each event is registered on the engine and its outcomes are expanded into markets. If netting_pairs is provided, registers each pair on the engine for cross-exchange hedging.Recover state
If persistence is enabled, loads the latest position snapshot and replays fills since that snapshot. Detects orphaned orders from previous runs.
Resolve markets
In live mode, fetches market metadata from exchange APIs. For Polymarket, queries the Gamma API for token IDs and condition IDs. For Kalshi, sets the ticker. For Alpaca/IBKR, resolves symbols directly.
Start feeds
Starts all configured feeds (WebSocket connections, REST pollers) on the engine’s feed manager.
Main loop
Each cycle:
- Poll fills from live exchanges
- Update daily P&L for drawdown tracking
- For each market: build context → run pipeline → process result
- Cancel stale orders → submit new quotes
- Snapshot positions to DB every 50 cycles
- Evict terminal orders every 100 cycles
Persistence Defaults
Thedb_path parameter uses a sentinel value (...) to distinguish between “use default” and “explicitly disabled”:
| Value | Behavior |
|---|---|
... (default) | Use HORIZON_DB env var, or ./{name}.db |
"/path/to/db" | Use the specified path |
None | Disable persistence entirely |