Skip to main content

nautilus_data/engine/
bar.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
16use std::fmt::Debug;
17
18use nautilus_common::msgbus::{MStr, Topic, TypedHandler};
19use nautilus_model::data::{Bar, QuoteTick, TradeTick};
20
21/// Typed subscription for bar aggregator handlers.
22///
23/// Stores the topic and handler for each data type so we can properly
24/// unsubscribe from the typed routers.
25#[derive(Clone)]
26pub enum BarAggregatorSubscription {
27    Bar {
28        topic: MStr<Topic>,
29        handler: TypedHandler<Bar>,
30    },
31    Trade {
32        topic: MStr<Topic>,
33        handler: TypedHandler<TradeTick>,
34    },
35    Quote {
36        topic: MStr<Topic>,
37        handler: TypedHandler<QuoteTick>,
38    },
39}
40
41impl Debug for BarAggregatorSubscription {
42    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43        match self {
44            Self::Bar { topic, handler } => f
45                .debug_struct(stringify!(Bar))
46                .field("topic", topic)
47                .field("handler_id", &handler.id())
48                .finish(),
49            Self::Trade { topic, handler } => f
50                .debug_struct(stringify!(Trade))
51                .field("topic", topic)
52                .field("handler_id", &handler.id())
53                .finish(),
54            Self::Quote { topic, handler } => f
55                .debug_struct(stringify!(Quote))
56                .field("topic", topic)
57                .field("handler_id", &handler.id())
58                .finish(),
59        }
60    }
61}