Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1012.01 in progress #34

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Cargo.lock
/.vscode/

*.log
log/
15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "IBKR-API-Rust"
version = "0.1.0"
authors = ["brett.miller@sparkstart.com"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -15,18 +15,19 @@ name = "twsapi_client"
path = "src/bin/manual_tests.rs"

[dependencies]
bzip2 = "0.3.3"
openssl = { version = "0.10", features = ["vendored"] }
bzip2 = "0.4.3"
log = "0.4.8"
log4rs = "0.12.0"
bytebuffer = "0.2.1"
log4rs = "1.0.0"
bytebuffer = "2.1.1"
encoding = "0.2"
num = "0.3.0"
num = "0.4.0"
num-derive = "0.3"
num-traits = "0.2.12"
byteorder = "1.3.4"
ascii = "1.0.0"
from-ascii = "0.0.1"
serde = { version = "1.0", features = ["derive"] }
bigdecimal = "0.1.2"
float-cmp = "0.8.0"
bigdecimal = "0.3.0"
float-cmp = "0.9.0"
chrono = "0.4.11"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# IBKR-API-Rust

Port of Interactive Broker's trading API written in Rust (API_Version=9.76.01)
## This branch is currently in progress to upgrade to version 10.12.01. Do not use until it is merged to master!!!

Port of Interactive Broker's trading API written in Rust (API_Version=10.12.01)

Please see the latest IB Tws Api documentation here: <http://interactivebrokers.github.io/tws-api/introduction.html>.

Expand Down
5 changes: 1 addition & 4 deletions src/examples/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,7 @@ impl Wrapper for DefaultWrapper {
.iter()
.map(|x| x.as_str())
.collect::<Vec<&str>>(),
strikes
.iter()
.map(|x| x.clone())
.collect::<Vec<BigDecimal>>()
strikes.iter().cloned().collect::<Vec<BigDecimal>>()
);
}

Expand Down
119 changes: 61 additions & 58 deletions src/examples/order_samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,36 +463,42 @@ pub fn bracket_order(
stop_loss_price: f64,
) -> (Order, Order, Order) {
// This will be our main or "parent" order
let mut parent = Order::default();
parent.order_id = parent_order_id;
parent.action = action.to_string();
parent.order_type = "LMT".to_string();
parent.total_quantity = quantity;
parent.lmt_price = limit_price;
// The parent and children orders will need this attribute set to False to prevent accidental executions.
// The LAST CHILD will have it set to True,
parent.transmit = false;

let mut take_profit = Order::default();
take_profit.order_id = parent.order_id + 1;
take_profit.action = (if action == "BUY" { "SELL" } else { "BUY" }).to_string();
take_profit.order_type = "LMT".to_string();
take_profit.total_quantity = quantity;
take_profit.lmt_price = take_profit_limit_price;
take_profit.parent_id = parent_order_id;
take_profit.transmit = false;

let mut stop_loss = Order::default();
stop_loss.order_id = parent.order_id + 2;
stop_loss.action = (if action == "BUY" { "SELL" } else { "BUY" }).to_string();
stop_loss.order_type = "STP".to_string();
// stop trigger price
stop_loss.aux_price = stop_loss_price;
stop_loss.total_quantity = quantity;
stop_loss.parent_id = parent_order_id;
// In this case, the low side order will be the last child being sent. Therefore, it needs to set this attribute to True
// to activate all its predecessors
stop_loss.transmit = true;
let parent = Order {
order_id: parent_order_id,
action: action.to_string(),
order_type: "LMT".to_string(),
total_quantity: quantity,
lmt_price: limit_price,
// The parent and children orders will need this attribute set to False to prevent accidental executions.
// The LAST CHILD will have it set to True,
transmit: false,
..Order::default()
};

let take_profit = Order {
order_id: parent.order_id + 1,
action: (if action == "BUY" { "SELL" } else { "BUY" }).to_string(),
order_type: "LMT".to_string(),
total_quantity: quantity,
lmt_price: take_profit_limit_price,
parent_id: parent_order_id,
transmit: false,
..Order::default()
};

let stop_loss = Order {
order_id: parent.order_id + 2,
action: (if action == "BUY" { "SELL" } else { "BUY" }).to_string(),
order_type: "STP".to_string(),
// stop trigger price
aux_price: stop_loss_price,
total_quantity: quantity,
parent_id: parent_order_id,
// In this case, the low side order will be the last child being sent. Therefore, it needs to set this attribute to True
// to activate all its predecessors
transmit: true,
..Order::default()
};

(parent, take_profit, stop_loss)
}
Expand All @@ -503,12 +509,12 @@ pub fn bracket_order(
/// at which the filled portion of the order executed.
//==================================================================================================
pub fn market_to_limit(action: &str, quantity: f64) -> Order {
let mut order = Order::default();
order.action = action.to_string();
order.order_type = "MTL".to_string();
order.total_quantity = quantity;

order
Order {
action: action.to_string(),
order_type: "MTL".to_string(),
total_quantity: quantity,
..Order::default()
}
}

/// This order type is useful for futures traders using Globex. A Market with Protection order is a market order that will be cancelled and
Expand All @@ -517,12 +523,12 @@ pub fn market_to_limit(action: &str, quantity: f64) -> Order {
/// Products: FUT, FOP
//==================================================================================================
pub fn market_with_protection(action: &str, quantity: f64) -> Order {
let mut order = Order::default();
order.action = action.to_string();
order.order_type = "MKT PRT".to_string();
order.total_quantity = quantity;

order
Order {
action: action.to_string(),
order_type: "MKT PRT".to_string(),
total_quantity: quantity,
..Order::default()
}
}

/// A stop order is an instruction to submit a buy or sell market order if and when the user-specified stop trigger price is attained or
Expand All @@ -533,13 +539,13 @@ pub fn market_with_protection(action: &str, quantity: f64) -> Order {
/// Products: CFD, BAG, CASH, FUT, FOP, OPT, STK, WAR
//==================================================================================================
pub fn stop(action: &str, quantity: f64, stop_price: f64) -> Order {
let mut order = Order::default();
order.action = action.to_string();
order.order_type = "STP".to_string();
order.aux_price = stop_price;
order.total_quantity = quantity;

order
Order {
action: action.to_string(),
order_type: "STP".to_string(),
aux_price: stop_price,
total_quantity: quantity,
..Order::default()
}
}

/// A stop-Limit order is an instruction to submit a buy or sell limit order when the user-specified stop trigger price is attained or
Expand Down Expand Up @@ -853,12 +859,11 @@ pub fn attach_adjustable_to_stop(
) -> Order {
// Attached order is a conventional STP order in opposite direction
let mut order = stop(
(if parent.action == "BUY" {
if parent.action == "BUY" {
"SELL"
} else {
"BUY"
})
.as_ref(),
},
parent.total_quantity,
attached_order_stop_price,
);
Expand All @@ -883,12 +888,11 @@ pub fn attach_adjustable_to_stop_limit(
) -> Order {
// Attached order is a conventional STP order
let mut order = stop(
(if parent.action == "BUY" {
if parent.action == "BUY" {
"SELL"
} else {
"BUY"
})
.as_ref(),
},
parent.total_quantity,
attached_order_stop_price,
);
Expand Down Expand Up @@ -916,12 +920,11 @@ pub fn attach_adjustable_to_trail(
) -> Order {
// Attached order is a conventional STP order
let mut order = stop(
(if parent.action == "BUY" {
if parent.action == "BUY" {
"SELL"
} else {
"BUY"
})
.as_ref(),
},
parent.total_quantity,
attached_order_stop_price,
);
Expand Down
Loading