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
//! Tick By Tick Last example
//!
//! # Usage
//!
//! ```bash
//! cargo run --features sync --example tick_by_tick_last
//! ```

use std::time::Duration;

use ibapi::client::blocking::Client;
use ibapi::contracts::Contract;

// 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").build();
    let ticks = client.tick_by_tick(&contract, 0).last().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_data(Duration::from_secs(10)).enumerate() {
        match trade {
            Ok(trade) => println!("{}: {i:?} {trade:?}", contract.symbol),
            Err(error) => {
                println!("error: {error:?}");
                break;
            }
        }
    }
}