use time::OffsetDateTime;
use crate::contracts::Contract;
use crate::market_data::historical::{Duration, Schedule};
use crate::Error;
#[cfg(test)]
#[path = "schedule_tests.rs"]
mod tests;
#[must_use = "HistoricalScheduleBuilder does nothing until you call .fetch()"]
pub struct HistoricalScheduleBuilder<'a, C> {
client: &'a C,
contract: &'a Contract,
duration: Duration,
ending: Option<OffsetDateTime>,
}
impl<'a, C> HistoricalScheduleBuilder<'a, C> {
pub(crate) fn new(client: &'a C, contract: &'a Contract, duration: Duration) -> Self {
Self {
client,
contract,
duration,
ending: None,
}
}
pub fn ending(mut self, end_date: OffsetDateTime) -> Self {
self.ending = Some(end_date);
self
}
}
#[cfg(feature = "sync")]
impl<'a> HistoricalScheduleBuilder<'a, crate::client::sync::Client> {
pub fn fetch(self) -> Result<Schedule, Error> {
crate::market_data::historical::sync::historical_schedule(self.client, self.contract, self.ending, self.duration)
}
}
#[cfg(feature = "async")]
impl<'a> HistoricalScheduleBuilder<'a, crate::client::r#async::Client> {
pub async fn fetch(self) -> Result<Schedule, Error> {
crate::market_data::historical::r#async::historical_schedule(self.client, self.contract, self.ending, self.duration).await
}
}