use crate::contracts::Contract;
use crate::market_data::realtime::TickTypes;
use crate::Error;
#[cfg(test)]
mod tests;
pub struct MarketDataBuilder<'a, C> {
client: &'a C,
contract: &'a Contract,
generic_ticks: Vec<String>,
snapshot: bool,
regulatory_snapshot: bool,
}
impl<'a, C> MarketDataBuilder<'a, C> {
pub fn new(client: &'a C, contract: &'a Contract) -> Self {
Self {
client,
contract,
generic_ticks: Vec::new(),
snapshot: false,
regulatory_snapshot: false,
}
}
pub fn generic_ticks(mut self, ticks: &[&str]) -> Self {
self.generic_ticks = ticks.iter().map(|s| s.to_string()).collect();
self
}
pub fn snapshot(mut self) -> Self {
self.snapshot = true;
self
}
pub fn regulatory_snapshot(mut self) -> Self {
self.regulatory_snapshot = true;
self
}
pub fn streaming(mut self) -> Self {
self.snapshot = false;
self
}
}
#[cfg(feature = "sync")]
impl<'a> MarketDataBuilder<'a, crate::client::sync::Client> {
pub fn subscribe(self) -> Result<crate::subscriptions::sync::Subscription<TickTypes>, Error> {
let generic_ticks: Vec<&str> = self.generic_ticks.iter().map(|s| s.as_str()).collect();
crate::market_data::realtime::blocking::market_data(self.client, self.contract, &generic_ticks, self.snapshot, self.regulatory_snapshot)
}
}
#[cfg(feature = "async")]
impl<'a> MarketDataBuilder<'a, crate::client::r#async::Client> {
pub async fn subscribe(self) -> Result<crate::subscriptions::Subscription<TickTypes>, Error> {
let generic_ticks: Vec<&str> = self.generic_ticks.iter().map(|s| s.as_str()).collect();
crate::market_data::realtime::market_data(self.client, self.contract, &generic_ticks, self.snapshot, self.regulatory_snapshot).await
}
}