Skip to main content

rustrade_data/subscription/
candle.rs

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