barter_data/subscription/
candle.rs

1use super::SubscriptionKind;
2use chrono::{DateTime, Utc};
3use serde::{Deserialize, Serialize};
4
5/// Barter [`Subscription`](super::Subscription) [`SubscriptionKind`] that yields [`Candle`]
6/// [`MarketEvent<T>`](crate::event::MarketEvent) events.
7#[derive(
8    Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default, Deserialize, Serialize,
9)]
10pub struct Candles;
11
12impl SubscriptionKind for Candles {
13    type Event = Candle;
14
15    fn as_str(&self) -> &'static str {
16        "candles"
17    }
18}
19
20impl std::fmt::Display for Candles {
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        write!(f, "{}", self.as_str())
23    }
24}
25
26/// Normalised Barter OHLCV [`Candle`] model.
27#[derive(Copy, Clone, PartialEq, PartialOrd, Debug, Deserialize, Serialize)]
28pub struct Candle {
29    pub close_time: DateTime<Utc>,
30    pub open: f64,
31    pub high: f64,
32    pub low: f64,
33    pub close: f64,
34    pub volume: f64,
35    pub trade_count: u64,
36}