Skip to main content
Strategies are built by chaining pipeline functions. Each function receives the Context plus the outputs of previous functions. The final function must return list[Quote].

Basic Example

How It Works

Horizon inspects each function’s signature to determine how many arguments it expects. Previous outputs are passed in order: This means you can insert or remove pipeline stages without changing downstream functions.

Signature Introspection

The pipeline runner uses inspect.signature() to count parameters:
The first parameter is always ctx: hz.Context. Additional parameters receive outputs from previous pipeline stages, most recent last.

Pipeline Rules

  1. At least one function is required in the pipeline
  2. The final function must return list[Quote] (or a single Quote)
  3. Each function runs once per market per cycle
  4. If a function raises an exception, the error is logged and that market is skipped for the cycle
  5. The pipeline runs for every market in the markets list

Result Processing

After the pipeline runs, _process_result() handles the output:
  1. Cancel existing orders for the market (cancel_market())
  2. Tick the paper exchange with the feed mid price (or quote mid as fallback)
  3. Update mark prices for unrealized P&L tracking
  4. Submit new quotes, routed to the correct exchange based on market.exchange
Risk rejections during quote submission are logged at debug level (not warning), since they’re expected during normal operation (e.g., position limits hit).

Composability Examples

Adding a stage

You can add an intermediate stage without modifying existing functions:

Multiple data sources

The hz.quotes() Helper

A convenience function to create quotes from a fair value and spread:
Bid and ask are automatically clamped to [0.01, 0.99] for prediction markets. If the spread is too wide for the fair value (resulting in a crossed or invalid quote), an empty list is returned instead of raising an error:
Or create quotes manually:

Built-in Pipeline Functions

Horizon provides several ready-to-use pipeline functions that can be composed together:

Example: Signal → Kelly → Market Maker

See Market Making, Signal Combiner, Kelly Criterion, and Arbitrage Executor for detailed documentation.