-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added AdjustedLast to WhatToShow enum * Added an example to document a nuance of using WhatToShow::AdjustedLast
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use clap::{arg, Command}; | ||
|
||
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_ending_now") | ||
.about("Gets last 7 days of daily data for given stock") | ||
.arg(arg!(<STOCK_SYMBOL>).required(true)) | ||
.arg(arg!(--connection_string <VALUE>).default_value("127.0.0.1:4002")) | ||
.get_matches(); | ||
|
||
let connection_string = matches.get_one::<String>("connection_string").expect("connection_string is required"); | ||
let stock_symbol = matches.get_one::<String>("STOCK_SYMBOL").expect("stock symbol is required"); | ||
|
||
let client = Client::connect(&connection_string, 100).expect("connection failed"); | ||
|
||
let contract = Contract::stock(stock_symbol); | ||
|
||
// to use WhatToShow::AdjustedLast, historical_data_ending_now() must be used, as the API will return an error if historical_data() is used to specify an interval_end | ||
let historical_data = client | ||
.historical_data_ending_now(&contract, 7.days(), BarSize::Day, WhatToShow::AdjustedLast, true) | ||
.expect("historical data request failed"); | ||
|
||
println!("start_date: {}, end_date: {}", historical_data.start, historical_data.end); | ||
|
||
for bar in &historical_data.bars { | ||
println!("{bar:?}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters