Skip to content

Commit

Permalink
start options example
Browse files Browse the repository at this point in the history
  • Loading branch information
Wil Boayue committed Jan 22, 2025
1 parent e36b9e1 commit 4314bf6
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ibapi"
version = "1.0.11"
version = "1.1.0"
edition = "2021"
authors = ["Wil Boayue <[email protected]>"]
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."
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/historical_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
40 changes: 40 additions & 0 deletions examples/historical_data_options.rs
Original file line number Diff line number Diff line change
@@ -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!(<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);

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:?}");
}
}
2 changes: 1 addition & 1 deletion examples/readme_historical_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -779,13 +779,13 @@ impl Client {
pub fn historical_data(
&self,
contract: &Contract,
interval_end: OffsetDateTime,
interval_end: Option<OffsetDateTime>,
duration: historical::Duration,
bar_size: historical::BarSize,
what_to_show: historical::WhatToShow,
use_rth: bool,
) -> Result<historical::HistoricalData, Error> {
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].
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/market_data/historical/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4314bf6

Please sign in to comment.