nautilus_model/
venues.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3//  https://poseitrader.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//! Common `Venue` constants.
17
18use std::{
19    collections::HashMap,
20    sync::{LazyLock, Mutex, OnceLock},
21};
22
23use crate::identifiers::Venue;
24
25static CBCM_LOCK: OnceLock<Venue> = OnceLock::new();
26static GLBX_LOCK: OnceLock<Venue> = OnceLock::new();
27static NYUM_LOCK: OnceLock<Venue> = OnceLock::new();
28static XCBT_LOCK: OnceLock<Venue> = OnceLock::new();
29static XCEC_LOCK: OnceLock<Venue> = OnceLock::new();
30static XCME_LOCK: OnceLock<Venue> = OnceLock::new();
31static XFXS_LOCK: OnceLock<Venue> = OnceLock::new();
32static XNYM_LOCK: OnceLock<Venue> = OnceLock::new();
33
34impl Venue {
35    /// Returns the CBCM (Chicago Board of Trade) venue.
36    #[allow(non_snake_case)]
37    pub fn CBCM() -> Self {
38        *CBCM_LOCK.get_or_init(|| Self::from("CBCM"))
39    }
40    /// Returns the GLBX (Globex) venue.
41    #[allow(non_snake_case)]
42    pub fn GLBX() -> Self {
43        *GLBX_LOCK.get_or_init(|| Self::from("GLBX"))
44    }
45    /// Returns the NYUM (New York Mercantile Exchange) venue.
46    #[allow(non_snake_case)]
47    pub fn NYUM() -> Self {
48        *NYUM_LOCK.get_or_init(|| Self::from("NYUM"))
49    }
50    /// Returns the XCBT (Chicago Board of Trade) venue.
51    #[allow(non_snake_case)]
52    pub fn XCBT() -> Self {
53        *XCBT_LOCK.get_or_init(|| Self::from("XCBT"))
54    }
55    /// Returns the XCEC (Chicago Mercantile Exchange Center) venue.
56    #[allow(non_snake_case)]
57    pub fn XCEC() -> Self {
58        *XCEC_LOCK.get_or_init(|| Self::from("XCEC"))
59    }
60    /// Returns the XCME (Chicago Mercantile Exchange) venue.
61    #[allow(non_snake_case)]
62    pub fn XCME() -> Self {
63        *XCME_LOCK.get_or_init(|| Self::from("XCME"))
64    }
65    /// Returns the XFXS (CME FX) venue.
66    #[allow(non_snake_case)]
67    pub fn XFXS() -> Self {
68        *XFXS_LOCK.get_or_init(|| Self::from("XFXS"))
69    }
70    /// Returns the XNYM (New York Mercantile Exchange) venue.
71    #[allow(non_snake_case)]
72    pub fn XNYM() -> Self {
73        *XNYM_LOCK.get_or_init(|| Self::from("XNYM"))
74    }
75}
76
77pub static VENUE_MAP: LazyLock<Mutex<HashMap<&str, Venue>>> = LazyLock::new(|| {
78    let mut map = HashMap::new();
79    map.insert(Venue::CBCM().inner().as_str(), Venue::CBCM());
80    map.insert(Venue::GLBX().inner().as_str(), Venue::GLBX());
81    map.insert(Venue::NYUM().inner().as_str(), Venue::NYUM());
82    map.insert(Venue::XCBT().inner().as_str(), Venue::XCBT());
83    map.insert(Venue::XCEC().inner().as_str(), Venue::XCEC());
84    map.insert(Venue::XCME().inner().as_str(), Venue::XCME());
85    map.insert(Venue::XFXS().inner().as_str(), Venue::XFXS());
86    map.insert(Venue::XNYM().inner().as_str(), Venue::XNYM());
87    Mutex::new(map)
88});