Skip to main content

nautilus_event_store/
lib.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Event store and authoritative log of state-affecting messages for [NautilusTrader](https://nautilustrader.io).
17//!
18//! The `nautilus-event-store` crate provides an embedded, append-only event store that captures
19//! commands, events, venue reports, and correlations flowing across the message bus. Combined with
20//! cache snapshots, it provides stable restarts via tail-replay, deterministic incident replay,
21//! end-to-end audit of agent decisions, and counterfactual research.
22//!
23//! See `README.md` for the high-level specification.
24//!
25//! # NautilusTrader
26//!
27//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native
28//! engine for multi-asset, multi-venue trading systems.
29//!
30//! The system spans research, deterministic simulation, and live execution within a single
31//! event-driven architecture, providing research-to-live semantic parity.
32//!
33//! # Feature Flags
34//!
35//! This crate provides feature flags to control source code inclusion during compilation:
36//!
37//! - `defi`: Enables DeFi (Decentralized Finance) support.
38//! - `live`: Enables live-runtime support through `nautilus-common`.
39//! - `persistence`: Enables Parquet catalog replay support through `nautilus-persistence`.
40
41#![warn(rustc::all)]
42#![warn(clippy::pedantic)]
43#![allow(
44    clippy::manual_let_else,
45    clippy::option_if_let_else,
46    clippy::or_fun_call,
47    clippy::redundant_else,
48    clippy::similar_names,
49    clippy::single_match_else,
50    reason = "workspace policy; generated by scripts/update-clippy-allowances.py"
51)]
52#![warn(clippy::clone_on_ref_ptr)]
53#![deny(unsafe_code)]
54#![deny(unsafe_op_in_unsafe_fn)]
55#![deny(nonstandard_style)]
56#![deny(missing_debug_implementations)]
57#![deny(clippy::missing_errors_doc)]
58#![deny(clippy::missing_panics_doc)]
59#![deny(rustdoc::broken_intra_doc_links)]
60#![allow(
61    clippy::assert_is_empty,
62    reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
63)]
64
65pub mod backend;
66pub mod capture;
67pub mod codec;
68pub mod entry;
69pub mod error;
70pub mod hash;
71pub mod headers;
72pub mod kernel;
73pub mod manifest;
74pub mod markers;
75pub mod reader;
76pub mod replay;
77pub mod retention;
78pub mod snapshot;
79pub mod verifier;
80pub mod writer;
81
82mod format;
83mod wire;
84
85pub use backend::{
86    AppendEntry, EventStore, IndexKey, IndexKind, MemoryBackend, RedbBackend, ScanDirection,
87};
88pub use capture::{
89    BusCaptureAdapter, CaptureError, Encode, EncodeError, EncodedPayload, EncoderRegistry,
90    PAYLOAD_TYPE_ACCOUNT_STATE, PAYLOAD_TYPE_FILL_REPORT, PAYLOAD_TYPE_ORDER_FILLED,
91    PAYLOAD_TYPE_ORDER_STATUS_REPORT, PAYLOAD_TYPE_POSITION_STATUS_REPORT,
92    PAYLOAD_TYPE_SUBMIT_ORDER, TypedEncoder, default_registry, encode_account_state,
93    encode_fill_report, encode_order_filled, encode_order_status_report,
94    encode_position_status_report, encode_submit_order, register_default,
95};
96pub use entry::{EventStoreEntry, PayloadType, Topic};
97pub use error::EventStoreError;
98pub use hash::{EntryHash, compute_entry_hash};
99pub use headers::Headers;
100pub use kernel::{
101    BootError, EventStoreLifecycle, EventStoreLifecycleOptions, EventStoreSession, HaltSignal,
102    KernelError, RecoveredRun, RecoveryOutcome, build_run_id, open_run, open_run_with_options,
103    recover_predecessors,
104};
105pub use manifest::{RunId, RunManifest, RunStatus};
106pub use markers::{
107    CursorState, DEFAULT_MARKER_CHANNEL_CAPACITY, DEFAULT_MARKER_MAX_BATCH,
108    DEFAULT_MARKER_MAX_LATENCY, DataClass, DataCursorSnapshot, DataMarkerCapture,
109    DataMarkerExtractor, DataMarkerExtractorRegistry, HiFiMarker, MarkerBackend, MarkerCountKind,
110    MarkerFinding, MarkerGap, MarkerGapReason, MarkerManifest, MarkerMsg, MarkerReader,
111    MarkerRecordKind, MarkerVerifier, MarkerVerifyReport, MarkerWriter, MarkerWriterConfig,
112    MemoryMarkerBackend, RedbMarkerBackend, StoredMarkerRecord, StreamCursor, StreamDictEntry,
113    StreamSlot, compute_dict_hash, compute_gap_hash, compute_hifi_hash, compute_marker_hash,
114};
115#[cfg(feature = "persistence")]
116pub use markers::{JoinedStream, join_at_entry};
117pub use nautilus_system::{
118    RegisteredComponents,
119    event_store::{
120        DEFAULT_DATA_MARKER_CHANNEL_CAPACITY, DEFAULT_DATA_MARKER_SAFETY_FLUSH_INTERVAL,
121        DataMarkerClass, DataMarkerConfig, EventStoreConfig, RetentionMode, RunIdentity,
122    },
123};
124pub use reader::{DEFAULT_SCAN_CHUNK_SIZE, EventStoreReader, RangeScan, SnapshotReplayPlan};
125#[cfg(feature = "persistence")]
126pub use replay::ParquetReplayCatalog;
127pub use replay::{
128    CacheReplayError, CacheReplayReport, CatalogReplayData, CatalogReplayRecord,
129    CatalogReplaySlice, CatalogSliceCoverage, CatalogSlicePlan, CatalogSliceQuery,
130    CatalogSliceSelector, EventStoreReplayReport, ReplayCatalog, ReplayInputError, ReplayInputPlan,
131    ReplayInputs, ReplaySeqRange, ReplayTimeRange, apply_cache_replay_entry,
132    load_catalog_replay_inputs, load_forensics_replay_inputs, open_event_store_replay_source,
133    plan_catalog_replay_inputs, plan_forensics_replay_inputs, replay_cache_snapshot_tail,
134    restore_cache_from_sealed_run, restore_cache_snapshot_and_replay_tail,
135    restore_cache_snapshot_blob, validate_event_store_replay_source,
136};
137pub use retention::{
138    RetentionPlan, RetentionRun, SnapshotAnchorStatus, list_redb_sealed_runs, plan_redb_retention,
139    plan_retention,
140};
141pub use snapshot::{SnapshotAnchor, compute_snapshot_content_hash};
142pub use verifier::{
143    GapRange, IndexDrift, ManifestField, Verifier, VerifyError, VerifyFinding, VerifyReport,
144};
145pub use writer::{
146    DEFAULT_CHANNEL_CAPACITY, DEFAULT_HALT_THRESHOLD, DEFAULT_MAX_BATCH_ENTRIES,
147    DEFAULT_MAX_BATCH_LATENCY, EntryDraft, EventStoreWriter, HaltCallback, HaltReason, SubmitError,
148    WriterConfig, noop_halt,
149};