nautilus_common/messages/system/shutdown.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
16use std::{
17 any::Any,
18 fmt::{Debug, Display},
19 hash::Hash,
20};
21
22use nautilus_core::{UUID4, UnixNanos};
23use nautilus_model::identifiers::TraderId;
24use serde::{Deserialize, Serialize};
25use ustr::Ustr;
26
27/// Represents a command to shut down a system and terminate the process.
28#[repr(C)]
29#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
30#[serde(tag = "type")]
31#[cfg_attr(
32 feature = "python",
33 pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.model", from_py_object)
34)]
35pub struct ShutdownSystem {
36 /// The trader ID associated with the command.
37 pub trader_id: TraderId,
38 /// The component ID associated with the command.
39 pub component_id: Ustr,
40 /// The reason for the shutdown command.
41 pub reason: Option<String>,
42 /// The command ID.
43 pub command_id: UUID4,
44 /// UNIX timestamp (nanoseconds) when the instance was created.
45 pub ts_init: UnixNanos,
46 /// The correlation ID, set when this command is correlated to another command or request.
47 pub correlation_id: Option<UUID4>,
48}
49
50impl ShutdownSystem {
51 /// Creates a new [`ShutdownSystem`] instance.
52 #[must_use]
53 pub fn new(
54 trader_id: TraderId,
55 component_id: Ustr,
56 reason: Option<String>,
57 command_id: UUID4,
58 ts_init: UnixNanos,
59 correlation_id: Option<UUID4>,
60 ) -> Self {
61 Self {
62 trader_id,
63 component_id,
64 reason,
65 command_id,
66 ts_init,
67 correlation_id,
68 }
69 }
70
71 pub fn as_any(&self) -> &dyn Any {
72 self
73 }
74}
75
76impl Display for ShutdownSystem {
77 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78 write!(
79 f,
80 "{}(trader_id={}, component_id={}, reason={:?}, command_id={}, correlation_id={:?})",
81 stringify!(ShutdownSystem),
82 self.trader_id,
83 self.component_id,
84 self.reason,
85 self.command_id,
86 self.correlation_id,
87 )
88 }
89}