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