Contract
ib_interface.api.contract
Financial instrument types used by Interactive Brokers.
FundAssetType
Fund asset type classification.
FundDistributionPolicyIndicator
Fund distribution policy classification.
Contract
Contract(**kwargs) can create any contract using keyword
arguments. To simplify working with contracts, there are also more
specialized contracts that take optional positional arguments.
Some examples::
Contract(conId=270639) Stock('AMD', 'SMART', 'USD') Stock('INTC', 'SMART', 'USD', primaryExchange='NASDAQ') Forex('EURUSD') CFD('IBUS30') Future('ES', '20180921', 'GLOBEX') Option('SPY', '20170721', 240, 'C', 'SMART') Bond(secIdType='ISIN', secId='US03076KAA60') Crypto('BTC', 'PAXOS', 'USD')
Args: conId (int): The unique IB contract identifier. symbol (str): The contract (or its underlying) symbol. secType (str): The security type:
-
'STK' = Stock (or ETF)
-
'OPT' = Option
-
'FUT' = Future
-
'IND' = Index
-
'FOP' = Futures option
-
'CASH' = Forex pair
-
'CFD' = CFD
-
'BAG' = Combo
-
'WAR' = Warrant
-
'BOND' = Bond
-
'CMDTY' = Commodity
-
'NEWS' = News
-
'FUND' = Mutual fund
-
'CRYPTO' = Crypto currency
-
'EVENT' = Bet on an event lastTradeDateOrContractMonth (str): The 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 (float): The option's strike price. right (str): Put or Call. Valid values are 'P', 'PUT', 'C', 'CALL', or '' for non-options. multiplier (str): The instrument's multiplier (i.e. options, futures). exchange (str): The destination exchange. currency (str): The underlying's currency. localSymbol (str): The contract's symbol within its primary exchange. For options, this will be the OCC symbol. primaryExchange (str): The 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. tradingClass (str): The 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". includeExpired (bool): If 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. secIdType (str): Security identifier type. Examples for Apple:
- secIdType='ISIN', secId='US0378331005'
- secIdType='CUSIP', secId='037833100' secId (str): Security identifier. comboLegsDescrip (str): Description of the combo legs. comboLegs (List[ComboLeg]): The legs of a combined contract definition. deltaNeutralContract (DeltaNeutralContract): Delta and underlying price for Delta-Neutral combo orders.
create
def create(kwargs = {}) -> Contract
Create and a return a specialized contract based on the given secType, or a general Contract if secType is not given.
isHashable
def isHashable() -> bool
See if this contract can be hashed by conId.
Note: Bag contracts always get conId=28812380, so they're not hashable.
Stock
Option
Future
ContFuture
Forex
pair
def pair() -> str
Short name of pair.
Index
CFD
Commodity
Bond
FuturesOption
MutualFund
Warrant
Bag
Crypto
TagValue
ComboLeg
DeltaNeutralContract
TradingSession
ContractDetails
Extended contract information returned by reqContractDetails().
Size precision fields (API v222+): minSize: Minimum order size for the contract. sizeIncrement: Minimum size increment for order quantities. suggestedSizeIncrement: Suggested size increment for UI display. minAlgoSize: Minimum order size when using algorithmic orders. lastPricePrecision: Decimal precision of the last traded price. lastSizePrecision: Decimal precision of the last traded size.
Fund fields (API v222+): fundName: Name of the fund. fundFamily: Fund family name. fundType: Fund type classification string. fundFrontLoad: Front-end load fee percentage. fundBackLoad: Back-end (deferred) load fee percentage. fundBackLoadTimeInterval: Time interval for deferred load schedule. fundManagementFee: Annual management fee percentage. fundClosed: True if the fund is closed to all activity. fundClosedForNewInvestors: True if closed to new investors only. fundClosedForNewMoney: True if closed to new money from existing investors. fundNotifyAmount: Minimum transaction amount requiring notification. fundMinimumInitialPurchase: Minimum initial purchase amount. fundSubsequentMinimumPurchase: Minimum subsequent purchase amount. fundBlueSkyStates: US states where the fund is registered. fundBlueSkyTerritories: US territories where the fund is registered. fundDistributionPolicyIndicator: Whether the fund accumulates or distributes income. See FundDistributionPolicyIndicator. fundAssetType: Asset class classification. See FundAssetType.
tradingSessions
def tradingSessions() -> List[TradingSession]
liquidSessions
def liquidSessions() -> List[TradingSession]