pub struct PeggedToBenchmark { /* private fields */ }Expand description
Builder for a pegged-to-benchmark order referencing another contract.
Pegged-to-benchmark orders track the price of a different contract (the reference contract) and adjust automatically as that contract moves. The order is active while the reference price stays inside an optional range and is cancelled if it leaves the range.
action, quantity, and starting_price are required and supplied to
PeggedToBenchmark::new. The reference contract (id + exchange) is
also required and supplied via reference_contract; build returns
Err(ValidationError::MissingRequiredField("reference_contract")) if it
was not set. All other fields are optional.
§Examples
use ibapi::orders::{order_builder::PeggedToBenchmark, Action};
let order = PeggedToBenchmark::new(Action::Buy, 100.0, 50.0)
.reference_contract(12345, "ISLAND")
.pegged_change_amount(0.02)
.reference_change_amount(0.01)
.stock_reference_price(49.0)
.reference_range(48.0, 52.0)
.build()
.expect("reference_contract is set");
assert_eq!(order.order_type, "PEG BENCH");Implementations§
Source§impl PeggedToBenchmark
impl PeggedToBenchmark
Sourcepub fn new(
action: Action,
quantity: f64,
starting_price: f64,
) -> PeggedToBenchmark
pub fn new( action: Action, quantity: f64, starting_price: f64, ) -> PeggedToBenchmark
Start a new pegged-to-benchmark order with the required core fields.
Sourcepub fn reference_contract(
self,
id: i32,
exchange: impl Into<String>,
) -> PeggedToBenchmark
pub fn reference_contract( self, id: i32, exchange: impl Into<String>, ) -> PeggedToBenchmark
Set the reference contract by id and exchange. Required.
Sourcepub fn pegged_change_amount(self, amount: f64) -> PeggedToBenchmark
pub fn pegged_change_amount(self, amount: f64) -> PeggedToBenchmark
Set how much this order’s price moves per reference_change_amount
of movement in the reference contract.
Sourcepub fn pegged_change_amount_decrease(self, decrease: bool) -> PeggedToBenchmark
pub fn pegged_change_amount_decrease(self, decrease: bool) -> PeggedToBenchmark
If true, the order price moves opposite the reference price.
Defaults to false.
Sourcepub fn reference_change_amount(self, amount: f64) -> PeggedToBenchmark
pub fn reference_change_amount(self, amount: f64) -> PeggedToBenchmark
Set the reference contract price change that triggers a
pegged_change_amount adjustment in this order.
Sourcepub fn stock_reference_price(self, price: f64) -> PeggedToBenchmark
pub fn stock_reference_price(self, price: f64) -> PeggedToBenchmark
Set the starting reference price used to compute the pegged offset.
Sourcepub fn reference_range(self, lower: f64, upper: f64) -> PeggedToBenchmark
pub fn reference_range(self, lower: f64, upper: f64) -> PeggedToBenchmark
Keep the order active only while the reference contract trades between
lower and upper.
Sourcepub fn build(self) -> Result<Order, ValidationError>
pub fn build(self) -> Result<Order, ValidationError>
Build the Order, validating that reference_contract was set.
Trait Implementations§
Source§impl Clone for PeggedToBenchmark
impl Clone for PeggedToBenchmark
Source§fn clone(&self) -> PeggedToBenchmark
fn clone(&self) -> PeggedToBenchmark
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more