Skip to main content

nautilus_common/messages/execution/
query.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::fmt::Display;
17
18use derive_builder::Builder;
19use nautilus_core::{Params, UUID4, UnixNanos};
20use nautilus_model::identifiers::{
21    AccountId, ClientId, ClientOrderId, InstrumentId, StrategyId, TraderId, VenueOrderId,
22};
23use serde::{Deserialize, Serialize};
24
25#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Builder)]
26#[serde(tag = "type")]
27pub struct QueryAccount {
28    pub trader_id: TraderId,
29    pub client_id: Option<ClientId>,
30    pub account_id: AccountId,
31    pub command_id: UUID4,
32    pub ts_init: UnixNanos,
33    pub params: Option<Params>,
34    #[builder(default)]
35    pub correlation_id: Option<UUID4>,
36    #[builder(default)]
37    #[serde(default, skip_serializing_if = "Option::is_none")]
38    pub causation_id: Option<UUID4>,
39}
40
41impl QueryAccount {
42    /// Creates a new [`QueryAccount`] instance.
43    #[must_use]
44    pub const fn new(
45        trader_id: TraderId,
46        client_id: Option<ClientId>,
47        account_id: AccountId,
48        command_id: UUID4,
49        ts_init: UnixNanos,
50        params: Option<Params>,
51        correlation_id: Option<UUID4>,
52    ) -> Self {
53        Self {
54            trader_id,
55            client_id,
56            account_id,
57            command_id,
58            ts_init,
59            params,
60            correlation_id,
61            causation_id: None,
62        }
63    }
64}
65
66impl Display for QueryAccount {
67    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68        write!(
69            f,
70            "QueryAccount(client_id={:?}, account_id={})",
71            self.client_id, self.account_id,
72        )
73    }
74}
75
76#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize, Builder)]
77#[serde(tag = "type")]
78pub struct QueryOrder {
79    pub trader_id: TraderId,
80    pub client_id: Option<ClientId>,
81    pub strategy_id: StrategyId,
82    pub instrument_id: InstrumentId,
83    pub client_order_id: ClientOrderId,
84    pub venue_order_id: Option<VenueOrderId>,
85    pub command_id: UUID4,
86    pub ts_init: UnixNanos,
87    pub params: Option<Params>,
88    #[builder(default)]
89    pub correlation_id: Option<UUID4>,
90    #[builder(default)]
91    #[serde(default, skip_serializing_if = "Option::is_none")]
92    pub causation_id: Option<UUID4>,
93}
94
95impl QueryOrder {
96    /// Creates a new [`QueryOrder`] instance.
97    #[expect(clippy::too_many_arguments)]
98    #[must_use]
99    pub const fn new(
100        trader_id: TraderId,
101        client_id: Option<ClientId>,
102        strategy_id: StrategyId,
103        instrument_id: InstrumentId,
104        client_order_id: ClientOrderId,
105        venue_order_id: Option<VenueOrderId>,
106        command_id: UUID4,
107        ts_init: UnixNanos,
108        params: Option<Params>,
109        correlation_id: Option<UUID4>,
110    ) -> Self {
111        Self {
112            trader_id,
113            client_id,
114            strategy_id,
115            instrument_id,
116            client_order_id,
117            venue_order_id,
118            command_id,
119            ts_init,
120            params,
121            correlation_id,
122            causation_id: None,
123        }
124    }
125}
126
127impl Display for QueryOrder {
128    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
129        write!(
130            f,
131            "QueryOrder(instrument_id={}, client_order_id={}, venue_order_id={:?})",
132            self.instrument_id, self.client_order_id, self.venue_order_id,
133        )
134    }
135}
136
137#[cfg(test)]
138mod tests {}