use ibapi::contracts::{Contract, ContractMonth, ExpirationDate, LegAction};
fn main() {
let aapl = Contract::stock("AAPL").build();
println!("Stock: {:?}", aapl.symbol);
let toyota = Contract::stock("7203").on_exchange("TSEJ").in_currency("JPY").primary("TSEJ").build();
println!("International stock: {:?} on {}", toyota.symbol, toyota.exchange);
let call = Contract::call("AAPL").strike(150.0).expires_on(2024, 12, 20).build();
println!(
"Call option: {} {} strike {} exp {}",
call.symbol, call.right, call.strike, call.last_trade_date_or_contract_month
);
let put = Contract::put("SPY")
.strike(450.0)
.expires(ExpirationDate::new(2024, 3, 15))
.on_exchange("CBOE")
.build();
println!("Put option: {} {} strike {}", put.symbol, put.right, put.strike);
let es_futures = Contract::futures("ES").expires_in(ContractMonth::new(2024, 3)).build();
println!("Futures: {} multiplier '{}'", es_futures.symbol, es_futures.multiplier);
let cl_futures = Contract::futures("CL").expires_in(ContractMonth::new(2024, 6)).multiplier(1000).build();
println!(
"Futures: {} multiplier {} expiry {}",
cl_futures.symbol, cl_futures.multiplier, cl_futures.last_trade_date_or_contract_month
);
let eur_usd = Contract::forex("EUR", "USD").amount(100_000).build();
println!("Forex: {}", eur_usd.symbol);
let btc = Contract::crypto("BTC").on_exchange("PAXOS").build();
println!("Crypto: {} on {}", btc.symbol, btc.exchange);
let spx = Contract::index("SPX");
println!("Index: {} on {}", spx.symbol, spx.exchange);
let spread = Contract::spread()
.calendar(12345, 67890) .build()
.expect("Valid spread");
println!("Calendar spread with {} legs", spread.combo_legs.len());
let custom_spread = Contract::spread()
.add_leg(11111, LegAction::Buy)
.ratio(2)
.done()
.add_leg(22222, LegAction::Sell)
.ratio(1)
.done()
.build()
.expect("Valid spread");
println!("Custom spread with {} legs", custom_spread.combo_legs.len());
println!("\nAll contracts created successfully using V2 API!");
}