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