nautilus_common/messages/mod.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//! Message types for system communication.
17//!
18//! This module provides message types used for communication between different
19//! parts of the NautilusTrader system, including data requests, execution commands,
20//! and system control messages.
21
22use nautilus_model::{
23 data::{Data, FundingRateUpdate, InstrumentStatus, option_chain::OptionGreeks},
24 events::{
25 AccountState, OrderAcceptedBatch, OrderCanceledBatch, OrderEventAny, OrderSubmittedBatch,
26 },
27 instruments::InstrumentAny,
28};
29use strum::Display;
30
31pub mod data;
32pub mod execution;
33pub mod system;
34
35#[cfg(feature = "defi")]
36pub mod defi;
37
38// Re-exports
39pub use data::{DataResponse, SubscribeCommand, UnsubscribeCommand};
40pub use execution::ExecutionReport;
41
42// TODO: Refine this to reduce disparity between enum sizes
43#[allow(
44 clippy::large_enum_variant,
45 reason = "event enum keeps all data variants in one routing type"
46)]
47#[derive(Debug, Display)]
48pub enum DataEvent {
49 Response(DataResponse),
50 Data(Data),
51 // Kept separate from `Data` pending the decision on generic dispatch versus this routing enum
52 Instrument(InstrumentAny),
53 FundingRate(FundingRateUpdate),
54 InstrumentStatus(InstrumentStatus),
55 OptionGreeks(OptionGreeks),
56 // nautilus-import-ok: conditional compilation import
57 #[cfg(feature = "defi")]
58 DeFi(nautilus_model::defi::data::DefiData),
59}
60
61/// System command variants routed to a live node.
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Display)]
63pub enum SystemCommand {
64 ReconnectSocket(system::ReconnectSocket),
65}
66
67/// System event variants routed to a live node.
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Display)]
69pub enum SystemEvent {
70 SocketState(system::SocketStateChange),
71}
72
73/// Execution event variants for order events and reports.
74#[allow(clippy::large_enum_variant)]
75#[derive(Debug, Display)]
76pub enum ExecutionEvent {
77 Order(OrderEventAny),
78 OrderSubmittedBatch(OrderSubmittedBatch),
79 OrderAcceptedBatch(OrderAcceptedBatch),
80 OrderCanceledBatch(OrderCanceledBatch),
81 Report(ExecutionReport),
82 Account(AccountState),
83}