Skip to main content

Horizon Monitoring

Horizon provides monitoring with three components: metrics for observability, alerts for real-time notifications, and calibration tracking for model evaluation.

Metrics

Thread-safe counters, gauges, and histograms with Prometheus text export.

Alerts

Alerting with throttling per time window and structured alert payloads.

Calibration

Track prediction accuracy with Brier scores and calibration curves across markets.

Metrics

MetricsCollector

The MetricsCollector provides thread-safe metric primitives that render to Prometheus text format.

Counter

A monotonically increasing counter. Use for event counts (orders submitted, fills received, errors).

Gauge

A value that can go up and down. Use for current state (position size, PnL, active orders).

Histogram

Records observations and computes distribution statistics. Use for latencies, fill sizes, spreads.

Rendering

All metrics render to Prometheus text exposition format:

Tracking Engine Status

Use the collector’s gauge primitives to record engine status each tick:

Alerts

AlertManager

The AlertManager routes alerts to channels with time-window throttling. By default, alerts are logged via the Python logger.
The constructor accepts optional channels and throttling configuration:

AlertType

Sending Alerts

Use the .alert() method to send an alert to all configured channels:
The .alert() method returns True if the alert was sent, or False if it was throttled.

Throttling

Alerts are throttled based on the max_alerts_per_window and window_secs parameters set in the constructor. Once the limit is reached within the sliding window, subsequent alerts are suppressed until the window advances.
Throttling is global across all alert types (not per-type). If you need higher throughput for certain alerts, create a separate AlertManager instance with a larger max_alerts_per_window.

Calibration Tracking

CalibrationTracker

Track prediction accuracy over time to evaluate your model’s calibration. Uses SQLite for persistence.

Recording Predictions

Log predictions and resolve markets separately. This supports the typical workflow where you make predictions first and learn outcomes later.

Brier Score

The Brier score measures the accuracy of probabilistic predictions. Range is 0.0 (perfect) to 1.0 (worst).

Log Loss

Log loss (cross-entropy) provides another measure of prediction quality, penalizing confident wrong predictions more heavily.

Calibration Curve

Compute a calibration curve to visualize reliability. Returns a list of CalibrationBucket objects.
Each CalibrationBucket has: The calibration curve groups predictions into bins and compares the average predicted probability against the actual outcome frequency. A perfectly calibrated model produces points along the diagonal (predicted == actual).

Suggest Adjustment

Get a calibration-adjusted probability based on historical data:

Calibration Report

Generate a full calibration report with all metrics:

Cleanup


Full Examples

Production Monitoring Setup

1

Initialize monitoring components

2

Create custom metrics

3

Wire into the pipeline

4

Run the strategy

Alert-Driven Risk Management

Calibration Tracking Over Time

Integrated Monitoring with Backtesting


Grafana Dashboard

Use collector.render() to expose metrics in Prometheus text format, then scrape them with Prometheus:
Suggested panels:
  • PnL Over Time: horizon_total_realized_pnl + horizon_total_unrealized_pnl
  • Order Rate: rate(horizon_orders_submitted_total[1m])
  • Position Count: horizon_active_positions
  • Tick Latency: histogram_quantile(0.95, horizon_tick_latency_seconds_bucket)
  • Fill Size Distribution: horizon_fill_size_bucket
  • Kill Switch Status: horizon_kill_switch (alert on value == 1)
If you serve metrics over HTTP, never expose the endpoint to the public internet. Use a reverse proxy with authentication or bind only to localhost.