use std::fmt;
use chrono::{DateTime, Utc, serde::ts_milliseconds};
use serde::Deserialize;
use crate::shared::models::price::Price;
#[derive(Debug, Clone, Deserialize)]
pub struct PriceEntry {
#[serde(with = "ts_milliseconds")]
time: DateTime<Utc>,
value: Price,
}
impl PriceEntry {
pub fn time(&self) -> DateTime<Utc> {
self.time
}
pub fn value(&self) -> Price {
self.value
}
pub fn as_data_str(&self) -> String {
format!("time: {}\nvalue: {}", self.time.to_rfc3339(), self.value)
}
}
impl fmt::Display for PriceEntry {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Price Entry:")?;
for line in self.as_data_str().lines() {
write!(f, "\n {line}")?;
}
Ok(())
}
}