nautilus_common/messages/
system.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 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")
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 struct was initialized.
45    pub ts_init: UnixNanos,
46}
47
48impl ShutdownSystem {
49    /// Creates a new [`ShutdownSystem`] instance.
50    #[must_use]
51    pub fn new(
52        trader_id: TraderId,
53        component_id: Ustr,
54        reason: Option<String>,
55        command_id: UUID4,
56        ts_init: UnixNanos,
57    ) -> Self {
58        Self {
59            trader_id,
60            component_id,
61            reason,
62            command_id,
63            ts_init,
64        }
65    }
66
67    pub fn as_any(&self) -> &dyn Any {
68        self
69    }
70}
71
72impl Display for ShutdownSystem {
73    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74        write!(
75            f,
76            "{}(trader_id={}, component_id={}, reason={:?}, command_id={})",
77            stringify!(ShutdownSystem),
78            self.trader_id,
79            self.component_id,
80            self.reason,
81            self.command_id,
82        )
83    }
84}