Skip to main content
Horizon uses SQLite with WAL mode for crash recovery and an audit trail. All fills, order events, position snapshots, and risk events are persisted automatically.

Quick Start

Persistence is enabled by default. When you call hz.run(name="my_strategy"), a database is created at ./my_strategy.db.

Configuration

SQLite Schema

The database contains five tables:
Source of truth for position reconstruction. Uses INSERT OR IGNORE on fill_id for idempotent dedup.
One row per status change (append-only).
Periodic snapshots for fast recovery. Each snapshot is a batch of positions with a shared timestamp.
Kill switch activations, deactivations, and violations.
Records strategy run start/end with exchange info.

Crash Recovery

Recovery happens automatically on startup when persistence is enabled:
1

Load latest snapshot

The engine loads the most recent position snapshot from position_snapshots.
2

Replay fills

Fills from the fills table with timestamp >= snapshot_timestamp are replayed to update positions.
3

Detect orphaned orders

Orders that were open when the previous run ended are detected and logged as warnings.

Engine Persistence Methods

Automatic Behavior

When hz.run() manages the engine:

Performance

The database is configured for low-latency trading workloads:
Hot-path queries use prepare_cached for prepared statement reuse.

CLI Database Commands

Query the database from the command line: