use chrono::{DateTime, Utc};
#[cfg(feature = "dataframe")]
use df_derive_macros::ToDataFrame;
use paft_domain::{Instrument, MarketState};
use paft_money::{Currency, PriceAmount, QuantityAmount};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "dataframe", derive(ToDataFrame))]
pub struct GenericSnapshot<M = ()> {
#[cfg_attr(feature = "dataframe", df_derive(as_string))]
pub instrument: Instrument,
pub name: Option<String>,
#[cfg_attr(feature = "dataframe", df_derive(as_str))]
pub market_state: Option<MarketState>,
#[serde(default, with = "chrono::serde::ts_milliseconds_option")]
pub as_of: Option<DateTime<Utc>>,
#[cfg_attr(feature = "dataframe", df_derive(as_str))]
pub currency: Currency,
pub last: Option<PriceAmount>,
pub previous_close: Option<PriceAmount>,
pub open: Option<PriceAmount>,
pub day_high: Option<PriceAmount>,
pub day_low: Option<PriceAmount>,
pub volume: Option<QuantityAmount>,
#[serde(flatten, default = "Default::default")]
pub provider: M,
}
impl<M: Default> GenericSnapshot<M> {
#[must_use]
pub fn new(instrument: Instrument, currency: Currency) -> Self {
Self {
instrument,
name: None,
market_state: None,
as_of: None,
currency,
last: None,
previous_close: None,
open: None,
day_high: None,
day_low: None,
volume: None,
provider: M::default(),
}
}
}
pub type Snapshot = GenericSnapshot<()>;