Skip to main content

nautilus_model/identifiers/
mod.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//! Identifiers for the trading domain model.
17//!
18//! # Design notes
19//!
20//! - `TradeId` remains a fixed-size `StackStr` with a 36-character limit.
21//! - High-cardinality external IDs must not use `Ustr`, because interning
22//!   unique values grows process memory without bound.
23//! - Some identifiers still use fixed-size `repr(C)` storage because the
24//!   current Cython/C ABI shares raw layout by value.
25//! - A deeper storage redesign is deferred to V2, when the ABI can move to
26//!   conversion-based bindings instead of layout sharing.
27
28use serde::{Deserialize, Deserializer, Serialize, Serializer};
29
30#[macro_use]
31mod macros;
32
33pub mod account_id;
34pub mod actor_id;
35pub mod client_id;
36pub mod client_order_id;
37pub mod component_id;
38pub mod exec_algorithm_id;
39pub mod instrument_id;
40pub mod option_series_id;
41pub mod order_list_id;
42pub mod position_id;
43pub mod strategy_id;
44pub mod symbol;
45pub mod trade_id;
46pub mod trader_id;
47pub mod venue;
48pub mod venue_order_id;
49
50#[cfg(any(test, feature = "stubs"))]
51pub mod stubs;
52
53// Re-exports
54pub use crate::identifiers::{
55    account_id::AccountId, actor_id::ActorId, client_id::ClientId, client_order_id::ClientOrderId,
56    component_id::ComponentId, exec_algorithm_id::ExecAlgorithmId, instrument_id::InstrumentId,
57    option_series_id::OptionSeriesId, order_list_id::OrderListId, position_id::PositionId,
58    strategy_id::StrategyId, symbol::Symbol, trade_id::TradeId, trader_id::TraderId, venue::Venue,
59    venue_order_id::VenueOrderId,
60};
61
62impl_from_str_for_identifier!(account_id::AccountId);
63impl_from_str_for_identifier!(actor_id::ActorId);
64impl_from_str_for_identifier!(client_id::ClientId);
65impl_from_str_for_identifier!(client_order_id::ClientOrderId);
66impl_from_str_for_identifier!(component_id::ComponentId);
67impl_from_str_for_identifier!(exec_algorithm_id::ExecAlgorithmId);
68impl_from_str_for_identifier!(order_list_id::OrderListId);
69impl_from_str_for_identifier!(position_id::PositionId);
70impl_from_str_for_identifier!(strategy_id::StrategyId);
71impl_from_str_for_identifier!(symbol::Symbol);
72impl_from_str_for_identifier!(trade_id::TradeId);
73impl_from_str_for_identifier!(trader_id::TraderId);
74impl_from_str_for_identifier!(venue::Venue);
75impl_from_str_for_identifier!(venue_order_id::VenueOrderId);
76
77impl_serialization_for_identifier!(account_id::AccountId);
78impl_serialization_for_identifier!(actor_id::ActorId);
79impl_serialization_for_identifier!(client_id::ClientId);
80impl_serialization_for_identifier!(client_order_id::ClientOrderId);
81impl_serialization_for_identifier!(component_id::ComponentId);
82impl_serialization_for_identifier!(exec_algorithm_id::ExecAlgorithmId);
83impl_serialization_for_identifier!(order_list_id::OrderListId);
84impl_serialization_for_identifier!(strategy_id::StrategyId);
85impl_serialization_for_identifier!(trader_id::TraderId);
86impl_serialization_for_identifier!(venue::Venue);
87impl_serialization_for_identifier!(venue_order_id::VenueOrderId);
88
89impl_serialization_for_identifier_utf8!(position_id::PositionId);
90impl_serialization_for_identifier_utf8!(symbol::Symbol);
91
92impl_as_ref_for_identifier!(account_id::AccountId);
93impl_as_ref_for_identifier!(actor_id::ActorId);
94impl_as_ref_for_identifier!(client_id::ClientId);
95impl_as_ref_for_identifier!(client_order_id::ClientOrderId);
96impl_as_ref_for_identifier!(component_id::ComponentId);
97impl_as_ref_for_identifier!(exec_algorithm_id::ExecAlgorithmId);
98impl_as_ref_for_identifier!(order_list_id::OrderListId);
99impl_as_ref_for_identifier!(position_id::PositionId);
100impl_as_ref_for_identifier!(strategy_id::StrategyId);
101impl_as_ref_for_identifier!(symbol::Symbol);
102impl_as_ref_for_identifier!(trader_id::TraderId);
103impl_as_ref_for_identifier!(venue::Venue);
104impl_as_ref_for_identifier!(venue_order_id::VenueOrderId);
105
106/// Print interned string cache statistics for debugging purposes.
107pub fn interned_string_stats() {
108    ustr::total_allocated();
109    ustr::total_capacity();
110
111    ustr::string_cache_iter().for_each(|s| println!("{s}"));
112}