-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
236 additions
and
53 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
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
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,34 @@ | ||
use std::sync::Arc; | ||
use std::thread; | ||
|
||
use ibapi::contracts::Contract; | ||
use ibapi::market_data::realtime::{BarSize, WhatToShow}; | ||
use ibapi::Client; | ||
|
||
fn main() { | ||
env_logger::init(); | ||
|
||
let connection_url = "127.0.0.1:4002"; | ||
let client = Arc::new(Client::connect(connection_url, 100).expect("connection to TWS failed!")); | ||
|
||
let symbols = vec!["AAPL", "NVDA"]; | ||
let mut handles = vec![]; | ||
|
||
for symbol in symbols { | ||
let client = Arc::clone(&client); | ||
let handle = thread::spawn(move || { | ||
let contract = Contract::stock(symbol); | ||
let subscription = client | ||
.realtime_bars(&contract, BarSize::Sec5, WhatToShow::Trades, false) | ||
.expect("realtime bars request failed!"); | ||
|
||
for bar in subscription { | ||
// Process each bar here (e.g., print or use in calculations) | ||
println!("bar: {bar:?}"); | ||
} | ||
}); | ||
handles.push(handle); | ||
} | ||
|
||
handles.into_iter().for_each(|handle| handle.join().unwrap()); | ||
} |
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 std::sync::Arc; | ||
use std::thread; | ||
|
||
use ibapi::contracts::Contract; | ||
use ibapi::market_data::realtime::{BarSize, WhatToShow}; | ||
use ibapi::Client; | ||
|
||
fn main() { | ||
env_logger::init(); | ||
|
||
let symbols = vec![("AAPL", 100), ("NVDA", 101)]; | ||
let mut handles = vec![]; | ||
|
||
for (symbol, client_id) in symbols { | ||
let handle = thread::spawn(move || { | ||
let connection_url = "127.0.0.1:4002"; | ||
let client = Arc::new(Client::connect(connection_url, client_id).expect("connection to TWS failed!")); | ||
|
||
let contract = Contract::stock(symbol); | ||
let subscription = client | ||
.realtime_bars(&contract, BarSize::Sec5, WhatToShow::Trades, false) | ||
.expect("realtime bars request failed!"); | ||
|
||
for bar in subscription { | ||
// Process each bar here (e.g., print or use in calculations) | ||
println!("bar: {bar:?}"); | ||
} | ||
}); | ||
handles.push(handle); | ||
} | ||
|
||
handles.into_iter().for_each(|handle| handle.join().unwrap()); | ||
} |
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
Oops, something went wrong.