Skip to content

Commit 86c3aff

Browse files
author
Wil Boayue
committed
doc cleanup
1 parent ca60945 commit 86c3aff

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

examples/calculate_implied_volatility.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
use ibapi::contracts::{Contract, SecurityType};
1+
use ibapi::contracts::Contract;
22
use ibapi::Client;
33

44
fn main() {
55
env_logger::init();
66

77
let client = Client::connect("127.0.0.1:4002", 100).expect("connection failed");
88

9-
let contract = Contract {
10-
symbol: "AAPL".into(),
11-
security_type: SecurityType::Option,
12-
exchange: "SMART".into(),
13-
currency: "USD".into(),
14-
last_trade_date_or_contract_month: "20250620".into(), // Expiry date (YYYYMMDD)
15-
strike: 240.0,
16-
right: "C".into(), // Option type: "C" for Call, "P" for Put
17-
..Default::default()
18-
};
9+
let contract = Contract::option("AAPL", "20250620", 240.0, "C");
1910

2011
let calculation = client.calculate_implied_volatility(&contract, 25.0, 235.0).expect("request failed");
2112
println!("calculation: {:?}", calculation);

src/contracts.rs

+21
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,27 @@ impl Contract {
203203
}
204204
}
205205

206+
/// Creates option contract from specified symbol, expiry date, strike price and option type.
207+
/// Defaults currency to USD and exchange to SMART.
208+
///
209+
/// # Arguments
210+
/// * `symbol` - Symbols of the underlying asset.
211+
/// * `expiration_date` - Expiration date of option contract (YYYYMMDD)
212+
/// * `strike` - Strike price of the option contract.
213+
/// * `right` - Option type: "C" for Call, "P" for Put
214+
pub fn option(symbol: &str, expiration_date: &str, strike: f64, right: &str) -> Contract {
215+
Contract {
216+
symbol: symbol.into(),
217+
security_type: SecurityType::Option,
218+
exchange: "SMART".into(),
219+
currency: "USD".into(),
220+
last_trade_date_or_contract_month: expiration_date.into(), // Expiry date (YYYYMMDD)
221+
strike,
222+
right: right.into(), // Option type: "C" for Call, "P" for Put
223+
..Default::default()
224+
}
225+
}
226+
206227
/// Is Bag request
207228
pub fn is_bag(&self) -> bool {
208229
self.security_type == SecurityType::Spread

0 commit comments

Comments
 (0)