#![allow(clippy::uninlined_format_args)]
use clap::{arg, Command};
use ibapi::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let matches = Command::new("async_head_timestamp")
.arg(arg!(<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>("SYMBOL").expect("stock symbol is required");
println!("connection_string: {connection_string}, stock_symbol: {stock_symbol}");
let client = Client::connect(connection_string, 100).await?;
let contract = Contract::stock(stock_symbol.as_str()).build();
let what_to_show = HistoricalWhatToShow::Trades;
let trading_hours = TradingHours::Regular;
let head_timestamp = client.head_timestamp(&contract, what_to_show, trading_hours).await?;
println!("head_timestamp: {head_timestamp}");
Ok(())
}