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#![warn(clippy::clone_on_ref_ptr)]
44#![deny(unsafe_code)]
45#![deny(unsafe_op_in_unsafe_fn)]
46#![deny(nonstandard_style)]
47#![deny(missing_debug_implementations)]
48#![deny(clippy::missing_errors_doc)]
49#![deny(clippy::missing_panics_doc)]
50#![deny(rustdoc::broken_intra_doc_links)]
51#![allow(
52    clippy::assert_is_empty,
53    reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
54)]
55
56pub mod backend;
57pub mod capture;
58pub mod codec;
59pub mod entry;
60pub mod error;
61pub mod hash;
62pub mod headers;
63pub mod kernel;
64pub mod manifest;
65pub mod markers;
66pub mod reader;
67pub mod replay;
68pub mod retention;
69pub mod snapshot;
70pub mod verifier;
71pub mod writer;
72
73mod format;
74mod wire;
75
76pub use backend::{
77    AppendEntry, EventStore, IndexKey, IndexKind, MemoryBackend, RedbBackend, ScanDirection,
78};
79pub use capture::{
80    BusCaptureAdapter, CaptureError, Encode, EncodeError, EncodedPayload, EncoderRegistry,
81    PAYLOAD_TYPE_ACCOUNT_STATE, PAYLOAD_TYPE_FILL_REPORT, PAYLOAD_TYPE_ORDER_FILLED,
82    PAYLOAD_TYPE_ORDER_STATUS_REPORT, PAYLOAD_TYPE_POSITION_STATUS_REPORT,
83    PAYLOAD_TYPE_SUBMIT_ORDER, TypedEncoder, default_registry, encode_account_state,
84    encode_fill_report, encode_order_filled, encode_order_status_report,
85    encode_position_status_report, encode_submit_order, register_default,
86};
87pub use entry::{EventStoreEntry, PayloadType, Topic};
88pub use error::EventStoreError;
89pub use hash::{EntryHash, compute_entry_hash};
90pub use headers::Headers;
91pub use kernel::{
92    BootError, EventStoreLifecycle, EventStoreLifecycleOptions, EventStoreSession, HaltSignal,
93    KernelError, RecoveredRun, RecoveryOutcome, build_run_id, open_run, open_run_with_options,
94    recover_predecessors,
95};
96pub use manifest::{RunId, RunManifest, RunStatus};
97pub use markers::{
98    CursorState, DEFAULT_MARKER_CHANNEL_CAPACITY, DEFAULT_MARKER_MAX_BATCH,
99    DEFAULT_MARKER_MAX_LATENCY, DataClass, DataCursorSnapshot, DataMarkerCapture,
100    DataMarkerExtractor, DataMarkerExtractorRegistry, HiFiMarker, MarkerBackend, MarkerCountKind,
101    MarkerFinding, MarkerGap, MarkerGapReason, MarkerManifest, MarkerMsg, MarkerReader,
102    MarkerRecordKind, MarkerVerifier, MarkerVerifyReport, MarkerWriter, MarkerWriterConfig,
103    MemoryMarkerBackend, RedbMarkerBackend, StoredMarkerRecord, StreamCursor, StreamDictEntry,
104    StreamSlot, compute_dict_hash, compute_gap_hash, compute_hifi_hash, compute_marker_hash,
105};
106#[cfg(feature = "persistence")]
107pub use markers::{JoinedStream, join_at_entry};
108pub use nautilus_system::{
109    RegisteredComponents,
110    event_store::{
111        DEFAULT_DATA_MARKER_CHANNEL_CAPACITY, DEFAULT_DATA_MARKER_SAFETY_FLUSH_INTERVAL,
112        DataMarkerClass, DataMarkerConfig, EventStoreConfig, RetentionMode, RunIdentity,
113    },
114};
115pub use reader::{DEFAULT_SCAN_CHUNK_SIZE, EventStoreReader, RangeScan, SnapshotReplayPlan};
116#[cfg(feature = "persistence")]
117pub use replay::ParquetReplayCatalog;
118pub use replay::{
119    CacheReplayError, CacheReplayReport, CatalogReplayData, CatalogReplayRecord,
120    CatalogReplaySlice, CatalogSliceCoverage, CatalogSlicePlan, CatalogSliceQuery,
121    CatalogSliceSelector, EventStoreReplayReport, ReplayCatalog, ReplayInputError, ReplayInputPlan,
122    ReplayInputs, ReplaySeqRange, ReplayTimeRange, apply_cache_replay_entry,
123    load_catalog_replay_inputs, load_forensics_replay_inputs, open_event_store_replay_source,
124    plan_catalog_replay_inputs, plan_forensics_replay_inputs, replay_cache_snapshot_tail,
125    restore_cache_from_sealed_run, restore_cache_snapshot_and_replay_tail,
126    restore_cache_snapshot_blob, validate_event_store_replay_source,
127};
128pub use retention::{
129    RetentionPlan, RetentionRun, SnapshotAnchorStatus, list_redb_sealed_runs, plan_redb_retention,
130    plan_retention,
131};
132pub use snapshot::{SnapshotAnchor, compute_snapshot_content_hash};
133pub use verifier::{
134    GapRange, IndexDrift, ManifestField, Verifier, VerifyError, VerifyFinding, VerifyReport,
135};
136pub use writer::{
137    DEFAULT_CHANNEL_CAPACITY, DEFAULT_HALT_THRESHOLD, DEFAULT_MAX_BATCH_ENTRIES,
138    DEFAULT_MAX_BATCH_LATENCY, EntryDraft, EventStoreWriter, HaltCallback, HaltReason, SubmitError,
139    WriterConfig, noop_halt,
140};