ibapi 3.0.0

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.
Documentation
//! Readme Realtime Data 1 example
//!
//! # Usage
//!
//! ```bash
//! cargo run --features sync --example readme_realtime_data_1
//! ```

use ibapi::client::blocking::Client;
use ibapi::prelude::*;

fn main() {
    env_logger::init();

    let connection_url = "127.0.0.1:4002";
    let client = Client::connect(connection_url, 100).expect("connection to TWS failed!");

    // Request real-time bars data for AAPL with 5-second intervals
    let contract = Contract::stock("AAPL").build();
    let subscription = client
        .realtime_bars(&contract)
        .trading_hours(TradingHours::Extended)
        .subscribe()
        .expect("realtime bars request failed!");

    for bar in subscription.iter_data() {
        match bar {
            Ok(bar) => println!("bar: {bar:?}"),
            Err(e) => {
                eprintln!("error: {e:?}");
                break;
            }
        }
    }
}