use crate::contracts::{OptionChain, SecurityType};
use crate::Error;
#[must_use = "OptionChainBuilder does nothing until you call .subscribe()"]
pub struct OptionChainBuilder<'a, C> {
client: &'a C,
symbol: &'a str,
security_type: SecurityType,
contract_id: i32,
exchange: Option<&'a str>,
}
impl<'a, C> OptionChainBuilder<'a, C> {
pub(crate) fn new(client: &'a C, symbol: &'a str, security_type: SecurityType, contract_id: i32) -> Self {
Self {
client,
symbol,
security_type,
contract_id,
exchange: None,
}
}
pub fn exchange(mut self, exchange: &'a str) -> Self {
self.exchange = Some(exchange);
self
}
}
#[cfg(feature = "sync")]
impl<'a> OptionChainBuilder<'a, crate::client::sync::Client> {
pub fn subscribe(self) -> Result<crate::subscriptions::sync::Subscription<OptionChain>, Error> {
crate::contracts::sync::option_chain(self.client, self.symbol, self.exchange, self.security_type, self.contract_id)
}
}
#[cfg(feature = "async")]
impl<'a> OptionChainBuilder<'a, crate::client::r#async::Client> {
pub async fn subscribe(self) -> Result<crate::subscriptions::r#async::Subscription<OptionChain>, Error> {
crate::contracts::r#async::option_chain(self.client, self.symbol, self.exchange, self.security_type, self.contract_id).await
}
}