pub struct SpreadBuilder { /* private fields */ }Expand description
Spread/Combo builder
Implementations§
Source§impl SpreadBuilder
impl SpreadBuilder
Source§impl SpreadBuilder
impl SpreadBuilder
Sourcepub fn add_leg(
self,
contract_id: impl Into<ContractId>,
action: LegAction,
) -> LegBuilder
pub fn add_leg( self, contract_id: impl Into<ContractId>, action: LegAction, ) -> LegBuilder
Begin configuring a new leg for the spread.
Sourcepub fn long_calendar(
self,
near_id: impl Into<ContractId>,
far_id: impl Into<ContractId>,
) -> Self
pub fn long_calendar( self, near_id: impl Into<ContractId>, far_id: impl Into<ContractId>, ) -> Self
Long calendar spread: sell the near-dated leg, buy the far-dated leg.
Buy the combo to open. Both legs normally share strike and right.
Sourcepub fn short_calendar(
self,
near_id: impl Into<ContractId>,
far_id: impl Into<ContractId>,
) -> Self
pub fn short_calendar( self, near_id: impl Into<ContractId>, far_id: impl Into<ContractId>, ) -> Self
Short calendar spread: buy the near-dated leg, sell the far-dated leg.
Buy the combo to open. Both legs normally share strike and right.
Sourcepub fn vertical(
self,
long_id: impl Into<ContractId>,
short_id: impl Into<ContractId>,
) -> Self
pub fn vertical( self, long_id: impl Into<ContractId>, short_id: impl Into<ContractId>, ) -> Self
Vertical spread: buy the long leg, sell the short leg.
For an iron condor, use iron_condor.
use ibapi::contracts::Contract;
let (long_call, short_call) = (100, 105);
let bull_call = Contract::spread().symbol("AAPL").vertical(long_call, short_call).build()?;Sourcepub fn straddle(
self,
call_id: impl Into<ContractId>,
put_id: impl Into<ContractId>,
) -> Self
pub fn straddle( self, call_id: impl Into<ContractId>, put_id: impl Into<ContractId>, ) -> Self
Long straddle: buy a call and a put with the same strike and expiry.
Buy the combo to open.
use ibapi::contracts::Contract;
let (call, put) = (100, 101);
let straddle = Contract::spread().symbol("AAPL").straddle(call, put).build()?;Sourcepub fn strangle(
self,
call_id: impl Into<ContractId>,
put_id: impl Into<ContractId>,
) -> Self
pub fn strangle( self, call_id: impl Into<ContractId>, put_id: impl Into<ContractId>, ) -> Self
Long strangle: buy an out-of-the-money call and put with the same expiry and different strikes.
Buy the combo to open. The legs are those of straddle; only the
strikes differ.
use ibapi::contracts::Contract;
let (call, put) = (110, 90);
let strangle = Contract::spread().symbol("AAPL").strangle(call, put).build()?;Sourcepub fn butterfly(self, legs: ButterflyLegs) -> Self
pub fn butterfly(self, legs: ButterflyLegs) -> Self
Long butterfly: buy 1 lower, sell 2 middle, buy 1 upper.
All legs share right and expiry. Buy the combo to open. The legs are named fields, so a wing cannot be swapped with the body by argument order.
use ibapi::contracts::{ButterflyLegs, Contract};
let butterfly = Contract::spread()
.symbol("AAPL")
.butterfly(ButterflyLegs {
lower: 100.into(),
middle: 105.into(),
upper: 110.into(),
})
.build()?;Sourcepub fn iron_condor(self, legs: IronCondorLegs) -> Self
pub fn iron_condor(self, legs: IronCondorLegs) -> Self
Iron condor: a put vertical plus a call vertical, each long the wing and short the body.
Legs are added as buy long put, sell short put, buy long call, sell short call. Buy the combo to open: it opens for a credit, so the limit price is negative. TWS rejects a positive price with 201 (“Guaranteed-to-Lose”). The legs are named fields because four ids in a fixed order compile when swapped and build a different strategy.
use ibapi::contracts::{Contract, IronCondorLegs};
let iron_condor = Contract::spread()
.symbol("AAPL")
.iron_condor(IronCondorLegs {
long_put: 100.into(),
short_put: 105.into(),
short_call: 110.into(),
long_call: 115.into(),
})
.build()?;Sourcepub fn collar(self, legs: CollarLegs) -> Self
pub fn collar(self, legs: CollarLegs) -> Self
Collar: buy the stock, buy a put below it as a floor, sell a call above it as a cap.
Legs are added as buy stock (ratio shares_per_contract), buy put, sell call. Buy the
combo to open. The limit price is per combo, a debit of about
shares_per_contract × spot + put − call.
§Examples
use ibapi::contracts::{CollarLegs, Contract};
let collar = Contract::spread()
.symbol("AAPL")
.collar(CollarLegs {
stock: 265598.into(),
put: 100.into(),
call: 101.into(),
shares_per_contract: 100,
})
.build()?;Sourcepub fn symbol(self, symbol: impl Into<Symbol>) -> Self
pub fn symbol(self, symbol: impl Into<Symbol>) -> Self
Set the combo’s symbol. TWS requires it to place the combo and rejects one without it with 321.
Usually the underlying. For a combo across underlyings, TWS’s samples join them with a
comma ("IBKR,MCD").
§Examples
use ibapi::contracts::Contract;
let (long_call, short_call) = (100, 105);
let bull_call = Contract::spread().symbol("AAPL").vertical(long_call, short_call).build()?;
assert_eq!(bull_call.symbol.to_string(), "AAPL");Sourcepub fn in_currency(self, currency: impl Into<Currency>) -> Self
pub fn in_currency(self, currency: impl Into<Currency>) -> Self
Override the spread currency, useful for non-USD underlyings.
Sourcepub fn on_exchange(self, exchange: impl Into<Exchange>) -> Self
pub fn on_exchange(self, exchange: impl Into<Exchange>) -> Self
Route the spread order to a specific exchange.