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