diff --git a/Cargo.toml b/Cargo.toml index 0f0dd2c6..a5189abd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ibapi" -version = "1.0.11" +version = "1.1.0" edition = "2021" authors = ["Wil Boayue "] description = "A Rust implementation of the Interactive Brokers TWS API, providing a reliable and user friendly interface for TWS and IB Gateway. Designed with a focus on simplicity and performance." diff --git a/README.md b/README.md index b4bd23c7..3430d468 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ fn main() { let historical_data = client .historical_data( &contract, - datetime!(2023-04-11 20:00 UTC), + Some(datetime!(2023-04-11 20:00 UTC)), 1.days(), BarSize::Hour, WhatToShow::Trades, diff --git a/examples/historical_data.rs b/examples/historical_data.rs index 98e74c60..98e7ec94 100644 --- a/examples/historical_data.rs +++ b/examples/historical_data.rs @@ -24,7 +24,7 @@ fn main() { let historical_data = client .historical_data( &contract, - datetime!(2023-04-11 20:00 UTC), + Some(datetime!(2023-04-11 20:00 UTC)), 1.days(), BarSize::Hour, WhatToShow::Trades, diff --git a/examples/historical_data_options.rs b/examples/historical_data_options.rs new file mode 100644 index 00000000..98e7ec94 --- /dev/null +++ b/examples/historical_data_options.rs @@ -0,0 +1,40 @@ +use clap::{arg, Command}; +use time::macros::datetime; + +use ibapi::contracts::Contract; +use ibapi::market_data::historical::{BarSize, ToDuration, WhatToShow}; +use ibapi::Client; + +fn main() { + env_logger::init(); + + let matches = Command::new("historical_data") + .about("Get last 30 days of daily data for given stock") + .arg(arg!().required(true)) + .arg(arg!(--connection_string ).default_value("127.0.0.1:4002")) + .get_matches(); + + let connection_string = matches.get_one::("connection_string").expect("connection_string is required"); + let stock_symbol = matches.get_one::("STOCK_SYMBOL").expect("stock symbol is required"); + + let client = Client::connect(&connection_string, 100).expect("connection failed"); + + let contract = Contract::stock(stock_symbol); + + let historical_data = client + .historical_data( + &contract, + Some(datetime!(2023-04-11 20:00 UTC)), + 1.days(), + BarSize::Hour, + WhatToShow::Trades, + true, + ) + .expect("historical data request failed"); + + println!("start: {:?}, end: {:?}", historical_data.start, historical_data.end); + + for bar in &historical_data.bars { + println!("{bar:?}"); + } +} diff --git a/examples/readme_historical_data.rs b/examples/readme_historical_data.rs index cd4d80f3..a5a9d7b6 100644 --- a/examples/readme_historical_data.rs +++ b/examples/readme_historical_data.rs @@ -15,7 +15,7 @@ fn main() { let historical_data = client .historical_data( &contract, - datetime!(2023-04-11 20:00 UTC), + Some(datetime!(2023-04-11 20:00 UTC)), 1.days(), BarSize::Hour, WhatToShow::Trades, diff --git a/src/client.rs b/src/client.rs index c1645c60..a9b60f98 100644 --- a/src/client.rs +++ b/src/client.rs @@ -767,7 +767,7 @@ impl Client { /// let contract = Contract::stock("TSLA"); /// /// let historical_data = client - /// .historical_data(&contract, datetime!(2023-04-15 0:00 UTC), 7.days(), BarSize::Day, WhatToShow::Trades, true) + /// .historical_data(&contract, Some(datetime!(2023-04-15 0:00 UTC)), 7.days(), BarSize::Day, WhatToShow::Trades, true) /// .expect("historical data request failed"); /// /// println!("start_date: {}, end_date: {}", historical_data.start, historical_data.end); @@ -779,13 +779,13 @@ impl Client { pub fn historical_data( &self, contract: &Contract, - interval_end: OffsetDateTime, + interval_end: Option, duration: historical::Duration, bar_size: historical::BarSize, what_to_show: historical::WhatToShow, use_rth: bool, ) -> Result { - historical::historical_data(self, contract, Some(interval_end), duration, bar_size, Some(what_to_show), use_rth) + historical::historical_data(self, contract, interval_end, duration, bar_size, Some(what_to_show), use_rth) } /// Requests interval of historical data ending now for [Contract]. @@ -818,6 +818,7 @@ impl Client { /// println!("{bar:?}"); /// } /// ``` + #[deprecated(since = "1.1.0", note = "use `historical_data` instead")] pub fn historical_data_ending_now( &self, contract: &Contract, diff --git a/src/market_data/historical/tests.rs b/src/market_data/historical/tests.rs index f519aa7c..ba307590 100644 --- a/src/market_data/historical/tests.rs +++ b/src/market_data/historical/tests.rs @@ -87,7 +87,7 @@ fn test_historical_data() { let use_rth = true; let historical_data = client - .historical_data(&contract, interval_end, duration, bar_size, what_to_show, use_rth) + .historical_data(&contract, Some(interval_end), duration, bar_size, what_to_show, use_rth) .expect("historical data request failed"); // Assert Response