nautilus_execution/messages/
submit.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::fmt::Display;
17
18use nautilus_core::{UnixNanos, UUID4};
19use nautilus_model::{
20    identifiers::{
21        ClientId, ClientOrderId, ExecAlgorithmId, InstrumentId, PositionId, StrategyId, TraderId,
22        VenueOrderId,
23    },
24    orders::OrderAny,
25};
26use serde::{Deserialize, Serialize};
27
28// Fix: equality and default and builder
29#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
30// #[builder(default)]
31#[serde(tag = "type")]
32pub struct SubmitOrder {
33    pub trader_id: TraderId,
34    pub client_id: ClientId,
35    pub strategy_id: StrategyId,
36    pub instrument_id: InstrumentId,
37    pub client_order_id: ClientOrderId,
38    pub venue_order_id: VenueOrderId,
39    pub order: OrderAny,
40    pub exec_algorith_id: Option<ExecAlgorithmId>,
41    pub position_id: Option<PositionId>,
42    pub command_id: UUID4,
43    pub ts_init: UnixNanos,
44}
45
46impl SubmitOrder {
47    /// Creates a new [`SubmitOrder`] instance.
48    #[allow(clippy::too_many_arguments)]
49    pub const fn new(
50        trader_id: TraderId,
51        client_id: ClientId,
52        strategy_id: StrategyId,
53        instrument_id: InstrumentId,
54        client_order_id: ClientOrderId,
55        venue_order_id: VenueOrderId,
56        order: OrderAny,
57        exec_algorith_id: Option<ExecAlgorithmId>,
58        position_id: Option<PositionId>,
59        command_id: UUID4,
60        ts_init: UnixNanos,
61    ) -> anyhow::Result<Self> {
62        Ok(Self {
63            trader_id,
64            client_id,
65            strategy_id,
66            instrument_id,
67            client_order_id,
68            venue_order_id,
69            order,
70            exec_algorith_id,
71            position_id,
72            command_id,
73            ts_init,
74        })
75    }
76}
77
78impl Display for SubmitOrder {
79    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80        write!(
81            f,
82            "SubmitOrder(instrument_id={}, order=TBD, position_id={})",
83            self.instrument_id,
84            self.position_id
85                .map_or("None".to_string(), |position_id| format!("{position_id}")),
86        )
87    }
88}
89
90////////////////////////////////////////////////////////////////////////////////
91// Tests
92////////////////////////////////////////////////////////////////////////////////
93#[cfg(test)]
94mod tests {}