Quick Start
Persistence is enabled by default. When you callhz.run(name="my_strategy"), a database is created at ./my_strategy.db.
Configuration
SQLite Schema
The database contains five tables:fills - Append-only fill journal
fills - Append-only fill journal
Source of truth for position reconstruction. Uses
INSERT OR IGNORE on fill_id for idempotent dedup.order_events - Order lifecycle log
order_events - Order lifecycle log
One row per status change (append-only).
position_snapshots - Periodic snapshots
position_snapshots - Periodic snapshots
Periodic snapshots for fast recovery. Each snapshot is a batch of positions with a shared timestamp.
risk_events - Risk event log
risk_events - Risk event log
Kill switch activations, deactivations, and violations.
strategy_runs - Run audit trail
strategy_runs - Run audit trail
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
Whenhz.run() manages the engine:
Performance
The database is configured for low-latency trading workloads:prepare_cached for prepared statement reuse.