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,
56    actor_id::ActorId,
57    client_id::ClientId,
58    client_order_id::ClientOrderId,
59    component_id::ComponentId,
60    exec_algorithm_id::ExecAlgorithmId,
61    instrument_id::InstrumentId,
62    option_series_id::OptionSeriesId,
63    order_list_id::OrderListId,
64    position_id::PositionId,
65    strategy_id::{StrategyId, normalize_order_id_tag},
66    symbol::Symbol,
67    trade_id::TradeId,
68    trader_id::TraderId,
69    venue::Venue,
70    venue_order_id::VenueOrderId,
71};
72
73impl_from_str_for_identifier!(account_id::AccountId);
74impl_from_str_for_identifier!(actor_id::ActorId);
75impl_from_str_for_identifier!(client_id::ClientId);
76impl_from_str_for_identifier!(client_order_id::ClientOrderId);
77impl_from_str_for_identifier!(component_id::ComponentId);
78impl_from_str_for_identifier!(exec_algorithm_id::ExecAlgorithmId);
79impl_from_str_for_identifier!(order_list_id::OrderListId);
80impl_from_str_for_identifier!(position_id::PositionId);
81impl_from_str_for_identifier!(strategy_id::StrategyId);
82impl_from_str_for_identifier!(symbol::Symbol);
83impl_from_str_for_identifier!(trade_id::TradeId);
84impl_from_str_for_identifier!(trader_id::TraderId);
85impl_from_str_for_identifier!(venue::Venue);
86impl_from_str_for_identifier!(venue_order_id::VenueOrderId);
87
88impl_serialization_for_identifier!(account_id::AccountId);
89impl_serialization_for_identifier!(actor_id::ActorId);
90impl_serialization_for_identifier!(client_id::ClientId);
91impl_serialization_for_identifier!(client_order_id::ClientOrderId);
92impl_serialization_for_identifier!(component_id::ComponentId);
93impl_serialization_for_identifier!(exec_algorithm_id::ExecAlgorithmId);
94impl_serialization_for_identifier!(order_list_id::OrderListId);
95impl_serialization_for_identifier!(position_id::PositionId);
96impl_serialization_for_identifier!(strategy_id::StrategyId);
97impl_serialization_for_identifier!(symbol::Symbol);
98impl_serialization_for_identifier!(trader_id::TraderId);
99impl_serialization_for_identifier!(venue::Venue);
100impl_serialization_for_identifier!(venue_order_id::VenueOrderId);
101
102impl_as_ref_for_identifier!(account_id::AccountId);
103impl_as_ref_for_identifier!(actor_id::ActorId);
104impl_as_ref_for_identifier!(client_id::ClientId);
105impl_as_ref_for_identifier!(client_order_id::ClientOrderId);
106impl_as_ref_for_identifier!(component_id::ComponentId);
107impl_as_ref_for_identifier!(exec_algorithm_id::ExecAlgorithmId);
108impl_as_ref_for_identifier!(order_list_id::OrderListId);
109impl_as_ref_for_identifier!(position_id::PositionId);
110impl_as_ref_for_identifier!(strategy_id::StrategyId);
111impl_as_ref_for_identifier!(symbol::Symbol);
112impl_as_ref_for_identifier!(trader_id::TraderId);
113impl_as_ref_for_identifier!(venue::Venue);
114impl_as_ref_for_identifier!(venue_order_id::VenueOrderId);
115
116/// Print interned string cache statistics for debugging purposes.
117pub fn interned_string_stats() {
118    ustr::total_allocated();
119    ustr::total_capacity();
120
121    ustr::string_cache_iter().for_each(|s| println!("{s}"));
122}