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    #[default]
48    ResolveLocally,
49    /// Retains unacknowledged orders without further automatic per-order recovery queries.
50    RetainUnresolved,
51}
52
53/// Recovery path which exhausted its query budget.
54#[derive(Clone, Copy, Debug, PartialEq, Eq)]
55pub enum SubmissionRecoverySource {
56    /// The scheduled inflight checker exhausted its retry limit.
57    Inflight,
58    /// Full-history reconciliation and its targeted query found no definitive outcome.
59    MissingOrder,
60}
61
62/// A submission's recovery budget expired without establishing its venue outcome.
63///
64/// This diagnostic is not an order event and does not change order status.
65/// The live node publishes it after processing reconciliation events.
66/// The manager retains the unresolved submission; exhaustion does not establish a venue outcome.
67#[derive(Clone, Debug, PartialEq, Eq)]
68pub struct SubmissionRecoveryExhausted {
69    /// Trader which submitted the order.
70    pub trader_id: TraderId,
71    /// Execution client responsible for the order, when known.
72    pub client_id: Option<ClientId>,
73    /// Strategy which submitted the order.
74    pub strategy_id: StrategyId,
75    /// Instrument traded by the order.
76    pub instrument_id: InstrumentId,
77    /// Original client order identity.
78    pub client_order_id: ClientOrderId,
79    /// Recovery path which exhausted its budget.
80    pub source: SubmissionRecoverySource,
81    /// Native retry counter at exhaustion, not a count of wire requests.
82    pub retry_count: u32,
83    /// UNIX timestamp in nanoseconds when recovery was exhausted.
84    pub ts_event: UnixNanos,
85}