pub struct Contract {Show 20 fields
pub contract_id: i32,
pub symbol: Symbol,
pub security_type: SecurityType,
pub last_trade_date_or_contract_month: String,
pub strike: f64,
pub right: String,
pub multiplier: String,
pub exchange: Exchange,
pub currency: Currency,
pub local_symbol: String,
pub primary_exchange: Exchange,
pub trading_class: String,
pub include_expired: bool,
pub security_id_type: String,
pub security_id: String,
pub combo_legs_description: String,
pub combo_legs: Vec<ComboLeg>,
pub delta_neutral_contract: Option<DeltaNeutralContract>,
pub issuer_id: String,
pub description: String,
}Expand description
Contract describes an instrument’s definition
Fields§
§contract_id: i32The unique IB contract identifier.
symbol: SymbolThe underlying’s asset symbol.
security_type: SecurityTypeType of security (stock, option, future, etc.).
last_trade_date_or_contract_month: StringThe contract’s last trading day or contract month (for Options and Futures). Strings with format YYYYMM will be interpreted as the Contract Month whereas YYYYMMDD will be interpreted as Last Trading Day.
strike: f64The option’s strike price.
right: StringEither Put or Call (i.e. Options). Valid values are P, PUT, C, CALL.
multiplier: StringThe instrument’s multiplier (i.e. options, futures).
exchange: ExchangeThe destination exchange.
currency: CurrencyThe underlying’s currency.
local_symbol: StringThe contract’s symbol within its primary exchange For options, this will be the OCC symbol.
primary_exchange: ExchangeThe contract’s primary exchange. For smart routed contracts, used to define contract in case of ambiguity. Should be defined as native exchange of contract, e.g. ISLAND for MSFT For exchanges which contain a period in name, will only be part of exchange name prior to period, i.e. ENEXT for ENEXT.BE.
trading_class: StringThe trading class name for this contract. Available in TWS contract description window as well. For example, GBL Dec ’13 future’s trading class is “FGBL”.
include_expired: boolIf set to true, contract details requests and historical data queries can be performed pertaining to expired futures contracts. Expired options or other instrument types are not available.
security_id_type: StringSecurity’s identifier when querying contract’s details or placing orders ISIN - Example: Apple: US0378331005 CUSIP - Example: Apple: 037833100.
security_id: StringIdentifier of the security type.
combo_legs_description: StringDescription of the combo legs.
combo_legs: Vec<ComboLeg>Individual legs composing a combo contract.
delta_neutral_contract: Option<DeltaNeutralContract>Delta and underlying price for Delta-Neutral combo orders. Underlying (STK or FUT), delta and underlying price goes into this attribute.
issuer_id: StringIdentifier of the issuer for bonds and structured products.
description: StringHuman-readable description provided by TWS.
Implementations§
Source§impl Contract
impl Contract
Sourcepub fn stock(symbol: impl Into<Symbol>) -> StockBuilder<Symbol>
pub fn stock(symbol: impl Into<Symbol>) -> StockBuilder<Symbol>
Creates a stock contract builder.
§Examples
use ibapi::contracts::{Contract, Exchange, Currency};
// Simple stock
let aapl = Contract::stock("AAPL").build();
// Stock with customization
let toyota = Contract::stock("7203")
.on_exchange("TSEJ")
.in_currency("JPY")
.build();Sourcepub fn call(
symbol: impl Into<Symbol>,
) -> OptionBuilder<Symbol, Missing, Missing>
pub fn call( symbol: impl Into<Symbol>, ) -> OptionBuilder<Symbol, Missing, Missing>
Creates a call option contract builder.
§Examples
use ibapi::contracts::Contract;
let call = Contract::call("AAPL")
.strike(150.0)
.expires_on(2024, 12, 20)
.build();Sourcepub fn put(symbol: impl Into<Symbol>) -> OptionBuilder<Symbol, Missing, Missing>
pub fn put(symbol: impl Into<Symbol>) -> OptionBuilder<Symbol, Missing, Missing>
Creates a put option contract builder.
§Examples
use ibapi::contracts::Contract;
let put = Contract::put("SPY")
.strike(450.0)
.expires_on(2024, 12, 20)
.build();Sourcepub fn futures(symbol: impl Into<Symbol>) -> FuturesBuilder<Symbol, Missing>
pub fn futures(symbol: impl Into<Symbol>) -> FuturesBuilder<Symbol, Missing>
Creates a futures contract builder.
§Examples
use ibapi::contracts::{Contract, ContractMonth};
let es = Contract::futures("ES")
.expires_in(ContractMonth::new(2024, 3))
.build();Sourcepub fn forex(
base: impl Into<Currency>,
quote: impl Into<Currency>,
) -> ForexBuilder
pub fn forex( base: impl Into<Currency>, quote: impl Into<Currency>, ) -> ForexBuilder
Creates a forex contract builder.
§Examples
use ibapi::contracts::{Contract, Currency};
let eur_usd = Contract::forex("EUR", "USD")
.amount(100_000)
.build();Sourcepub fn crypto(symbol: impl Into<Symbol>) -> CryptoBuilder
pub fn crypto(symbol: impl Into<Symbol>) -> CryptoBuilder
Creates a crypto contract builder.
§Examples
use ibapi::contracts::Contract;
let btc = Contract::crypto("BTC").build();Sourcepub fn index(symbol: &str) -> Contract
pub fn index(symbol: &str) -> Contract
Creates an index contract.
§Examples
use ibapi::contracts::Contract;
let spx = Contract::index("SPX");Sourcepub fn bond_cusip(cusip: impl Into<String>) -> Contract
pub fn bond_cusip(cusip: impl Into<String>) -> Contract
Create a bond contract with CUSIP identifier
§Example
use ibapi::contracts::Contract;
// US Treasury bond by CUSIP
let bond = Contract::bond_cusip("912810RN0");Sourcepub fn bond_isin(isin: impl Into<String>) -> Contract
pub fn bond_isin(isin: impl Into<String>) -> Contract
Create a bond contract with ISIN identifier
§Example
use ibapi::contracts::Contract;
// European bond by ISIN
let bond = Contract::bond_isin("DE0001102309");Sourcepub fn bond(identifier: BondIdentifier) -> Contract
pub fn bond(identifier: BondIdentifier) -> Contract
Create a bond contract with CUSIP or ISIN identifier
§Example
use ibapi::contracts::{Contract, BondIdentifier, Cusip, Isin};
// US Treasury bond by CUSIP
let bond = Contract::bond(BondIdentifier::Cusip(Cusip::new("912810RN0")));
// European bond by ISIN
let bond = Contract::bond(BondIdentifier::Isin(Isin::new("DE0001102309")));Sourcepub fn spread() -> SpreadBuilder
pub fn spread() -> SpreadBuilder
Creates a spread/combo contract builder.
§Examples
use ibapi::contracts::{Contract, LegAction};
let spread = Contract::spread()
.calendar(12345, 67890)
.build();Sourcepub fn news(provider_code: &str) -> Contract
pub fn news(provider_code: &str) -> Contract
Creates a news contract from the specified provider code.
§Examples
use ibapi::contracts::{Contract, Symbol, Exchange};
let news = Contract::news("BRFG");
assert_eq!(news.symbol, Symbol::from("BRFG:BRFG_ALL"));
assert_eq!(news.exchange, Exchange::from("BRFG"));Sourcepub fn option(
symbol: &str,
expiration_date: &str,
strike: f64,
right: &str,
) -> Contract
pub fn option( symbol: &str, expiration_date: &str, strike: f64, right: &str, ) -> Contract
Creates an option contract from the specified parameters.
Currency defaults to USD and exchange defaults to SMART.
§Arguments
symbol- Symbol of the underlying assetexpiration_date- Expiration date of option contract (YYYYMMDD)strike- Strike price of the option contractright- Option type: “C” for Call, “P” for Put
§Examples
use ibapi::contracts::{Contract, Symbol};
let call = Contract::option("AAPL", "20240119", 150.0, "C");
assert_eq!(call.symbol, Symbol::from("AAPL"));
assert_eq!(call.strike, 150.0);
assert_eq!(call.right, "C");Creates a simple option contract (for backward compatibility). For new code, use Contract::call() or Contract::put() builders instead.