-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
478 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use ibapi::{ | ||
contracts::{Contract, SecurityType}, | ||
orders::ExerciseAction, | ||
Client, | ||
}; | ||
|
||
fn main() { | ||
env_logger::init(); | ||
|
||
let client = Client::connect("127.0.0.1:4002", 100).expect("connection failed"); | ||
|
||
let contract = create_option_contract("AAPL", 180.0, "C", "20250221"); | ||
|
||
let accounts = client.managed_accounts().expect("could not get managed accounts"); | ||
let account = &accounts[0]; | ||
let manual_order_time = None; | ||
|
||
let subscription = client | ||
.exercise_options(&contract, ExerciseAction::Exercise, 100, account, true, manual_order_time) | ||
.expect("exercise options request failed!"); | ||
|
||
for status in &subscription { | ||
println!("{status:?}") | ||
} | ||
} | ||
|
||
fn create_option_contract(symbol: &str, strike: f64, right: &str, last_trade_date_or_contract_month: &str) -> Contract { | ||
Contract { | ||
symbol: symbol.to_owned(), | ||
security_type: SecurityType::Option, | ||
exchange: "SMART".to_owned(), | ||
currency: "USD".to_owned(), | ||
last_trade_date_or_contract_month: last_trade_date_or_contract_month.to_owned(), | ||
strike, | ||
right: right.to_owned(), | ||
multiplier: "100".to_owned(), | ||
..Default::default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use ibapi::{ | ||
contracts::{Contract, SecurityType}, | ||
orders::{self, order_builder, PlaceOrder}, | ||
Client, | ||
}; | ||
|
||
fn main() { | ||
env_logger::init(); | ||
|
||
let client = Client::connect("127.0.0.1:4002", 100).expect("connection failed"); | ||
|
||
let contract = create_option_contract("AAPL", 180.0, "C", "20250221"); | ||
|
||
let order_id = client.next_valid_order_id().expect("could not get next valid order id"); | ||
// let order_id = client.next_order_id(); | ||
println!("next order id: {order_id}"); | ||
|
||
let order = order_builder::market_order(orders::Action::Buy, 5.0); | ||
println!("contract: {contract:?}, order: {order:?}"); | ||
|
||
let subscription = client.place_order(order_id, &contract, &order).expect("could not place order"); | ||
for status in subscription { | ||
println!("{status:?}") | ||
} | ||
let order_id = client.next_order_id(); | ||
println!("next order id: {order_id}"); | ||
|
||
let order = order_builder::market_order(orders::Action::Buy, 5.0); | ||
println!("contract: {contract:?}, order: {order:?}"); | ||
|
||
let subscription = client.place_order(order_id, &contract, &order).expect("could not place order"); | ||
for status in subscription { | ||
println!("{status:?}"); | ||
if let PlaceOrder::OrderStatus(order_status) = status { | ||
if order_status.remaining == 0.0 { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn create_option_contract(symbol: &str, strike: f64, right: &str, last_trade_date_or_contract_month: &str) -> Contract { | ||
Contract { | ||
symbol: symbol.to_owned(), | ||
security_type: SecurityType::Option, | ||
exchange: "SMART".to_owned(), | ||
currency: "USD".to_owned(), | ||
last_trade_date_or_contract_month: last_trade_date_or_contract_month.to_owned(), | ||
strike, | ||
right: right.to_owned(), | ||
multiplier: "100".to_owned(), | ||
..Default::default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.