Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/market_data/historical/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ pub(crate) async fn historical_data(
what_to_show: WhatToShow,
trading_hours: TradingHours,
) -> Result<HistoricalData, Error> {
common::validate_historical_data(client.server_version(), contract, end_date, Some(what_to_show))?;
common::validate_historical_data(client.server_version(), contract, end_date, what_to_show)?;

retry_on_connection_reset(client, || async {
let builder = client.request();
Expand All @@ -298,7 +298,7 @@ pub(crate) async fn historical_data(
end_date,
duration,
bar_size,
Some(what_to_show),
what_to_show,
trading_hours.use_rth(),
false,
&Vec::<crate::contracts::TagValue>::default(),
Expand Down Expand Up @@ -348,7 +348,7 @@ pub(crate) async fn historical_data_stream(
None, // IBKR requires end_date=None when keep_up_to_date=true
duration,
bar_size,
Some(what_to_show),
what_to_show,
trading_hours.use_rth(),
true, // keep_up_to_date — the whole point of .stream()
&Vec::<crate::contracts::TagValue>::default(),
Expand Down Expand Up @@ -397,7 +397,7 @@ pub(crate) async fn historical_schedule(
end_date: Option<OffsetDateTime>,
duration: Duration,
) -> Result<Schedule, Error> {
common::validate_historical_data(client.server_version(), contract, end_date, Some(WhatToShow::Schedule))?;
common::validate_historical_data(client.server_version(), contract, end_date, WhatToShow::Schedule)?;

request_helpers::one_shot_by_request_id(
client,
Expand All @@ -408,7 +408,7 @@ pub(crate) async fn historical_schedule(
end_date,
duration,
BarSize::Day,
Some(WhatToShow::Schedule),
WhatToShow::Schedule,
true,
false,
&Vec::<crate::contracts::TagValue>::default(),
Expand Down
6 changes: 3 additions & 3 deletions src/market_data/historical/async_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ async fn test_historical_data() {
.end_date(Some(end_date))
.duration(duration)
.bar_size(bar_size)
.what_to_show(Some(what_to_show))
.what_to_show(what_to_show)
.use_rth(true),
);
}
Expand Down Expand Up @@ -422,7 +422,7 @@ async fn test_historical_schedules() {
.end_date(Some(end_date))
.duration(duration)
.bar_size(BarSize::Day)
.what_to_show(Some(WhatToShow::Schedule))
.what_to_show(WhatToShow::Schedule)
.use_rth(true),
);
}
Expand Down Expand Up @@ -749,7 +749,7 @@ async fn test_historical_data_streaming_with_updates() {
.contract(&contract)
.duration(Duration::days(1))
.bar_size(BarSize::Hour)
.what_to_show(Some(WhatToShow::Trades))
.what_to_show(WhatToShow::Trades)
.use_rth(true)
.keep_up_to_date(true),
);
Expand Down
10 changes: 5 additions & 5 deletions src/market_data/historical/builder/data_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ mod sync_tests {
.end_date(None)
.duration(Duration::days(7))
.bar_size(BarSize::Hour)
.what_to_show(Some(WhatToShow::Trades))
.what_to_show(WhatToShow::Trades)
.use_rth(true),
);
}
Expand Down Expand Up @@ -144,7 +144,7 @@ mod sync_tests {
.end_date(Some(end))
.duration(Duration::days(2))
.bar_size(BarSize::Hour)
.what_to_show(Some(WhatToShow::MidPoint))
.what_to_show(WhatToShow::MidPoint)
.use_rth(false),
);
}
Expand Down Expand Up @@ -172,7 +172,7 @@ mod sync_tests {
.end_date(Some(end))
.duration(Duration::days(8))
.bar_size(BarSize::Hour)
.what_to_show(Some(WhatToShow::Trades))
.what_to_show(WhatToShow::Trades)
.use_rth(true),
);
}
Expand Down Expand Up @@ -309,7 +309,7 @@ mod async_tests {
.end_date(None)
.duration(Duration::days(7))
.bar_size(BarSize::Hour)
.what_to_show(Some(WhatToShow::Trades))
.what_to_show(WhatToShow::Trades)
.use_rth(true),
);
}
Expand Down Expand Up @@ -338,7 +338,7 @@ mod async_tests {
.end_date(Some(end))
.duration(Duration::days(8))
.bar_size(BarSize::Hour)
.what_to_show(Some(WhatToShow::Trades))
.what_to_show(WhatToShow::Trades)
.use_rth(true),
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/market_data/historical/builder/schedule_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod sync_tests {
.end_date(None)
.duration(Duration::days(7))
.bar_size(BarSize::Day)
.what_to_show(Some(WhatToShow::Schedule))
.what_to_show(WhatToShow::Schedule)
.use_rth(true),
);
}
Expand All @@ -72,7 +72,7 @@ mod sync_tests {
.end_date(Some(end))
.duration(Duration::days(30))
.bar_size(BarSize::Day)
.what_to_show(Some(WhatToShow::Schedule))
.what_to_show(WhatToShow::Schedule)
.use_rth(true),
);
}
Expand Down Expand Up @@ -113,7 +113,7 @@ mod async_tests {
.end_date(None)
.duration(Duration::days(7))
.bar_size(BarSize::Day)
.what_to_show(Some(WhatToShow::Schedule))
.what_to_show(WhatToShow::Schedule)
.use_rth(true),
);
}
Expand All @@ -139,7 +139,7 @@ mod async_tests {
.end_date(Some(end))
.duration(Duration::days(30))
.bar_size(BarSize::Day)
.what_to_show(Some(WhatToShow::Schedule))
.what_to_show(WhatToShow::Schedule)
.use_rth(true),
);
}
Expand Down
5 changes: 2 additions & 3 deletions src/market_data/historical/common/encoders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) fn encode_request_historical_data(
end_date: Option<OffsetDateTime>,
duration: Duration,
bar_size: BarSize,
what_to_show: Option<WhatToShow>,
what_to_show: WhatToShow,
use_rth: bool,
keep_up_to_date: bool,
chart_options: &[crate::contracts::TagValue],
Expand All @@ -64,14 +64,13 @@ pub(crate) fn encode_request_historical_data(
use crate::proto::encoders::{some_bool, some_str};
use prost::Message;
let end_str = end_date.to_field();
let wts_str = what_to_show.to_field();
let request = crate::proto::HistoricalDataRequest {
req_id: Some(request_id),
contract: Some(crate::proto::encoders::encode_contract(contract)),
end_date_time: some_str(&end_str),
duration: Some(duration.to_field()),
bar_size_setting: Some(bar_size.to_field()),
what_to_show: some_str(&wts_str),
what_to_show: Some(what_to_show.to_field()),
use_rth: some_bool(use_rth),
format_date: Some(DATE_FORMAT),
keep_up_to_date: some_bool(keep_up_to_date),
Expand Down
6 changes: 3 additions & 3 deletions src/market_data/historical/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ pub(crate) fn validate_historical_data(
server_version: i32,
contract: &Contract,
end_date: Option<OffsetDateTime>,
what_to_show: Option<WhatToShow>,
what_to_show: WhatToShow,
) -> Result<(), Error> {
if !contract.trading_class.is_empty() || contract.contract_id > 0 {
check_version(server_version, Features::TRADING_CLASS)?;
}

if what_to_show == Some(WhatToShow::Schedule) {
if what_to_show == WhatToShow::Schedule {
check_version(server_version, Features::HISTORICAL_SCHEDULE)?;
}

if end_date.is_some() && what_to_show == Some(WhatToShow::AdjustedLast) {
if end_date.is_some() && what_to_show == WhatToShow::AdjustedLast {
return Err(Error::InvalidArgument(
"end_date must be None when requesting WhatToShow::AdjustedLast.".into(),
));
Expand Down
9 changes: 0 additions & 9 deletions src/market_data/historical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,15 +672,6 @@ impl ToField for WhatToShow {
}
}

impl ToField for Option<WhatToShow> {
fn to_field(&self) -> String {
match self {
Some(what_to_show) => what_to_show.to_string(),
None => "".into(),
}
}
}

// Re-export non-function items
#[cfg(feature = "async")]
pub use r#async::TickSubscription;
Expand Down
10 changes: 5 additions & 5 deletions src/market_data/historical/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ pub(crate) fn historical_data(
what_to_show: WhatToShow,
trading_hours: TradingHours,
) -> Result<HistoricalData, Error> {
common::validate_historical_data(client.server_version(), contract, end_date, Some(what_to_show))?;
common::validate_historical_data(client.server_version(), contract, end_date, what_to_show)?;

retry_on_connection_reset(client, || {
let builder = client.request();
Expand All @@ -272,7 +272,7 @@ pub(crate) fn historical_data(
end_date,
duration,
bar_size,
Some(what_to_show),
what_to_show,
trading_hours.use_rth(),
false,
&Vec::<crate::contracts::TagValue>::default(),
Expand Down Expand Up @@ -321,7 +321,7 @@ pub(crate) fn historical_data_stream(
None, // IBKR requires end_date=None when keep_up_to_date=true
duration,
bar_size,
Some(what_to_show),
what_to_show,
trading_hours.use_rth(),
true, // keep_up_to_date — the whole point of .stream()
&Vec::<crate::contracts::TagValue>::default(),
Expand Down Expand Up @@ -370,7 +370,7 @@ pub(crate) fn historical_schedule(
end_date: Option<OffsetDateTime>,
duration: Duration,
) -> Result<Schedule, Error> {
common::validate_historical_data(client.server_version(), contract, end_date, Some(WhatToShow::Schedule))?;
common::validate_historical_data(client.server_version(), contract, end_date, WhatToShow::Schedule)?;

request_helpers::blocking::one_shot_by_request_id(
client,
Expand All @@ -381,7 +381,7 @@ pub(crate) fn historical_schedule(
end_date,
duration,
BarSize::Day,
Some(WhatToShow::Schedule),
WhatToShow::Schedule,
true,
false,
&Vec::<crate::contracts::TagValue>::default(),
Expand Down
8 changes: 4 additions & 4 deletions src/market_data/historical/sync_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ fn test_historical_data() {
.end_date(Some(end_date))
.duration(duration)
.bar_size(bar_size)
.what_to_show(Some(what_to_show))
.what_to_show(what_to_show)
.use_rth(trading_hours.use_rth()),
);
}
Expand Down Expand Up @@ -316,7 +316,7 @@ fn test_historical_schedules() {
.end_date(Some(end_date))
.duration(duration)
.bar_size(BarSize::Day)
.what_to_show(Some(WhatToShow::Schedule))
.what_to_show(WhatToShow::Schedule)
.use_rth(true),
);
}
Expand Down Expand Up @@ -893,7 +893,7 @@ fn test_historical_data_streaming_with_updates() {
.contract(&contract)
.duration(Duration::days(1))
.bar_size(BarSize::Hour)
.what_to_show(Some(WhatToShow::Trades))
.what_to_show(WhatToShow::Trades)
.use_rth(true)
.keep_up_to_date(true),
);
Expand Down Expand Up @@ -1199,7 +1199,7 @@ fn test_historical_schedules_ending_now() {
.contract(&contract)
.duration(duration)
.bar_size(BarSize::Day)
.what_to_show(Some(WhatToShow::Schedule))
.what_to_show(WhatToShow::Schedule)
.use_rth(true),
);
}
Expand Down
9 changes: 4 additions & 5 deletions src/testdata/builders/market_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub struct HistoricalDataRequestBuilder {
pub end_date: Option<OffsetDateTime>,
pub duration: Duration,
pub bar_size: BarSize,
pub what_to_show: Option<HistoricalWhatToShow>,
pub what_to_show: HistoricalWhatToShow,
pub use_rth: bool,
pub keep_up_to_date: bool,
}
Expand All @@ -95,7 +95,7 @@ impl Default for HistoricalDataRequestBuilder {
end_date: None,
duration: Duration::days(1),
bar_size: BarSize::Day,
what_to_show: None,
what_to_show: HistoricalWhatToShow::Trades,
use_rth: false,
keep_up_to_date: false,
}
Expand Down Expand Up @@ -123,7 +123,7 @@ impl HistoricalDataRequestBuilder {
self.bar_size = v;
self
}
pub fn what_to_show(mut self, v: Option<HistoricalWhatToShow>) -> Self {
pub fn what_to_show(mut self, v: HistoricalWhatToShow) -> Self {
self.what_to_show = v;
self
}
Expand All @@ -143,14 +143,13 @@ impl RequestEncoder for HistoricalDataRequestBuilder {

fn to_proto(&self) -> Self::Proto {
let end_str = self.end_date.to_field();
let wts_str = self.what_to_show.to_field();
proto::HistoricalDataRequest {
req_id: Some(self.request_id),
contract: Some(encode_contract(&self.contract)),
end_date_time: some_str(&end_str),
duration: Some(self.duration.to_field()),
bar_size_setting: Some(self.bar_size.to_field()),
what_to_show: some_str(&wts_str),
what_to_show: Some(self.what_to_show.to_field()),
use_rth: some_bool(self.use_rth),
format_date: Some(DATE_FORMAT),
keep_up_to_date: some_bool(self.keep_up_to_date),
Expand Down
Loading