-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathtick_by_tick_last.rs
32 lines (23 loc) · 954 Bytes
/
tick_by_tick_last.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::time::Duration;
use ibapi::contracts::Contract;
use ibapi::Client;
// This example demonstrates how to stream tick by tick data for the last price of a contract.
fn main() {
env_logger::init();
let connection_string = "127.0.0.1:4002";
println!("connecting to server @ {connection_string}");
let client = Client::connect(connection_string, 100).expect("connection failed");
let contract = Contract::stock("NVDA");
let ticks = client.tick_by_tick_last(&contract, 0, false).expect("failed to get ticks");
println!(
"streaming last price for security_type: {:?}, symbol: {}",
contract.security_type, contract.symbol
);
for (i, trade) in ticks.timeout_iter(Duration::from_secs(10)).enumerate() {
println!("{}: {i:?} {trade:?}", contract.symbol);
}
// check for errors during streaming
if let Some(error) = ticks.error() {
println!("error: {}", error);
}
}