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