Skip to main content

nautilus_live/execution/
submission.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
16//! Native policy and diagnostics for exhausted submission recovery.
17
18use nautilus_core::UnixNanos;
19use nautilus_model::identifiers::{ClientId, ClientOrderId, InstrumentId, StrategyId, TraderId};
20use serde::{Deserialize, Serialize};
21
22/// Policy when recovery queries cannot establish a submission's venue outcome.
23///
24/// When a registered client's `ExecutionClient::retain_unresolved_submissions` returns `true`,
25/// the manager retains its unacknowledged orders regardless of this setting. `LiveNode` registers
26/// this requirement automatically. Retention stops the manager's automatic per-order recovery
27/// queries; later venue events and reports can still resolve the order.
28#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
29#[serde(rename_all = "snake_case")]
30#[cfg_attr(
31    feature = "python",
32    pyo3::pyclass(
33        frozen,
34        eq,
35        eq_int,
36        module = "nautilus_trader.live",
37        from_py_object,
38        rename_all = "SCREAMING_SNAKE_CASE",
39    )
40)]
41#[cfg_attr(
42    feature = "python",
43    pyo3_stub_gen::derive::gen_stub_pyclass_enum(module = "nautilus_trader.live")
44)]
45pub enum SubmissionRecoveryPolicy {
46    /// Selects local resolution using the existing timeout and missing-order policies.
47    ResolveLocally,
48    /// Retains unacknowledged orders without further automatic per-order recovery queries, and
49    /// restores an accepted order's prior status when a pending cancel or update times out.
50    #[default]
51    RetainUnresolved,
52}
53
54/// Recovery path which exhausted its query budget.
55#[derive(Clone, Copy, Debug, PartialEq, Eq)]
56pub enum SubmissionRecoverySource {
57    /// The scheduled inflight checker exhausted its retry limit.
58    Inflight,
59    /// Full-history reconciliation and its targeted query found no definitive outcome.
60    MissingOrder,
61}
62
63/// A submission's recovery budget expired without establishing its venue outcome.
64///
65/// This diagnostic is not an order event and does not change order status.
66/// The live node publishes it after processing reconciliation events.
67/// The manager retains the unresolved submission; exhaustion does not establish a venue outcome.
68#[derive(Clone, Debug, PartialEq, Eq)]
69pub struct SubmissionRecoveryExhausted {
70    /// Trader which submitted the order.
71    pub trader_id: TraderId,
72    /// Execution client responsible for the order, when known.
73    pub client_id: Option<ClientId>,
74    /// Strategy which submitted the order.
75    pub strategy_id: StrategyId,
76    /// Instrument traded by the order.
77    pub instrument_id: InstrumentId,
78    /// Original client order identity.
79    pub client_order_id: ClientOrderId,
80    /// Recovery path which exhausted its budget.
81    pub source: SubmissionRecoverySource,
82    /// Native retry counter at exhaustion, not a count of wire requests.
83    pub retry_count: u32,
84    /// UNIX timestamp in nanoseconds when recovery was exhausted.
85    pub ts_event: UnixNanos,
86}