use std::fmt::Debug;
use nautilus_common::{
messages::data::{SubscribeBars, SubscribeCommand},
msgbus::{MStr, Topic, TypedHandler},
};
use nautilus_core::UUID4;
use nautilus_model::data::{Bar, BarType, QuoteTick, TradeTick};
#[derive(Clone, Debug)]
pub(super) struct BarAggregationSubscription {
pub(super) command: SubscribeBars,
pub(super) source: Option<SubscribeCommand>,
}
pub(crate) type BarAggregatorKey = (BarType, Option<UUID4>);
#[inline]
pub(crate) fn bar_aggregator_key(bar_type: BarType, request_id: Option<UUID4>) -> BarAggregatorKey {
(bar_type.standard(), request_id)
}
#[derive(Clone)]
pub enum BarAggregatorSubscription {
Bar {
topic: MStr<Topic>,
handler: TypedHandler<Bar>,
},
Trade {
topic: MStr<Topic>,
handler: TypedHandler<TradeTick>,
},
Quote {
topic: MStr<Topic>,
handler: TypedHandler<QuoteTick>,
},
}
impl Debug for BarAggregatorSubscription {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Bar { topic, handler } => f
.debug_struct(stringify!(Bar))
.field("topic", topic)
.field("handler_id", &handler.id())
.finish(),
Self::Trade { topic, handler } => f
.debug_struct(stringify!(Trade))
.field("topic", topic)
.field("handler_id", &handler.id())
.finish(),
Self::Quote { topic, handler } => f
.debug_struct(stringify!(Quote))
.field("topic", topic)
.field("handler_id", &handler.id())
.finish(),
}
}
}