use crate::contracts::{Contract, TagValue};
use crate::market_data::realtime::{Bar, WhatToShow};
use crate::market_data::TradingHours;
use crate::Error;
#[cfg(test)]
#[path = "bars_tests.rs"]
mod tests;
#[must_use = "RealtimeBarsBuilder does nothing until you call .subscribe()"]
pub struct RealtimeBarsBuilder<'a, C> {
client: &'a C,
contract: &'a Contract,
what_to_show: WhatToShow,
trading_hours: TradingHours,
options: Vec<TagValue>,
}
impl<'a, C> RealtimeBarsBuilder<'a, C> {
pub(crate) fn new(client: &'a C, contract: &'a Contract) -> Self {
Self {
client,
contract,
what_to_show: WhatToShow::Trades,
trading_hours: TradingHours::Regular,
options: Vec::new(),
}
}
pub fn what_to_show(mut self, what_to_show: WhatToShow) -> Self {
self.what_to_show = what_to_show;
self
}
pub fn trading_hours(mut self, trading_hours: TradingHours) -> Self {
self.trading_hours = trading_hours;
self
}
pub fn options(mut self, options: Vec<TagValue>) -> Self {
self.options = options;
self
}
}
#[cfg(feature = "sync")]
impl<'a> RealtimeBarsBuilder<'a, crate::client::sync::Client> {
pub fn subscribe(self) -> Result<crate::subscriptions::sync::Subscription<Bar>, Error> {
crate::market_data::realtime::sync::realtime_bars(self.client, self.contract, &self.what_to_show, self.trading_hours, &self.options)
}
}
#[cfg(feature = "async")]
impl<'a> RealtimeBarsBuilder<'a, crate::client::r#async::Client> {
pub async fn subscribe(self) -> Result<crate::subscriptions::Subscription<Bar>, Error> {
self.client
.subscribe_realtime_bars(self.contract, &self.what_to_show, self.trading_hours, &self.options)
.await
}
}