Get Contracts
Contract Introduction
A contract refers to the trading object or underlying asset (such as a stock or option). Contracts are uniformly formulated by exchanges. For example, to purchase the SPDR S&P 500 ETF, you can uniquely identify it through the symbol "SPY" and market information (i.e., market='US', US market). Through contract information, we can uniquely determine an underlying asset when placing orders or obtaining market data. Common contracts include stock contracts, option contracts, etc.
Most contracts (such as stocks, CFDs, indices) can be uniquely determined by the following four basic attributes:
- Symbol: Generally, US and UK stock contract codes are English letters
- Security Type: Common contract types include STK (stock), OPT (option)
- Currency: Common currencies include USD (US Dollar)
- Exchange: STK type contracts generally don't use the exchange field, orders are automatically routed
Some contracts (such as options) require additional information to uniquely identify them due to their more complex nature.
Here are several common contract types and their constituent elements:
Stock
contract = Contract()
contract.symbol ="SPY"
contract.sec_type ="STK"
contract.currency ="USD" #not required
contract.market = "US" #not requiredOptions
TradeUP API's option contracts support two methods:
-
One is the four-element method: symbol (stock code), expiry (option expiration date), strike (option strike price), right (option direction).
-
The other is the standard OCC option contract format with a fixed length of 21 characters, including four parts:
- Related stock or ETF code, fixed at six characters, padded with spaces if insufficient
- Option expiration date, 6 digits, format: yymmdd
- Option type, value is P or C, representing put or call
- Option strike price, value is price x 1000, fixed at 8 digits, padded with zeros if insufficient

get_contract Get Single Contract Information
TradeClient.get_contract(symbol, sec_type=SecurityType.STK, currency=None, exchange=None, expiry=None, strike=None, put_call=None)
Description
Query single contract information required for trading
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| symbol | str | Yes | Stock symbol |
| sec_type | SecurityType | No | Security type, tigeropen.common.consts.SecurityType enum, Default: SecurityType.STK |
| currency | Currency | No | Currency, tigeropen.common.consts.Currency enum, e.g., Currency.USD |
| exchange | str | No | Exchange, optional, e.g., 'CBOE' |
| expiry | str | No | Contract expiration date (for options), format yyyyMMdd, e.g., '20220130' |
| strike | float | No | Strike price (for options) |
| put_call | str | No | Put/Call (for options), 'PUT' for put, 'CALL' for call |
Return
tigeropen.trade.domain.contract.Contract contract object, see Object Introduction. Common attributes:
Object Attributes
| Attribute | Type | Description |
|---|---|---|
| identifier | str | Unique identifier, stock identifier same as symbol |
| symbol | str | Stock symbol, option contract symbol is the underlying symbol |
| sec_type | str | STK stock/OPT option/IOPT CBBC, etc., default STK |
| name | str | Contract name |
| currency | str | Currency, e.g., USD |
| exchange | str | Exchange |
| expiry | str | Options only, option expiration date |
| strike | float | Options only, option strike price |
| multiplier | float | Multiplier, quantity per lot |
| put_call | str | Options only, option direction, CALL or PUT |
| short_margin | float | Short margin ratio (deprecated, use short_initial_margin instead) |
| short_initial_margin | float | Short initial margin ratio |
| short_maintenance_margin | float | Short maintenance margin ratio (prime accounts have values) |
| short_fee_rate | float | Short fee rate |
| shortable | bool | Whether shortable |
| shortable_count | int | Short pool remaining |
| long_initial_margin | float | Long initial margin |
| long_maintenance_margin | float | Long maintenance margin |
| contract_month | str | Contract month, e.g., 202201 for January 2022 |
| primary_exchange | str | Stock listing exchange |
| marginable | bool | Whether marginable |
| market | str | Market, e.g., US |
| min_tick | float | Minimum tick size |
| tickSizes | [{"begin":"0","end":"1","tickSize":1.0E-4,"type":"CLOSED"},{"begin":"1","end":"Infinity","tickSize":0.01,"type":"OPEN"}] | Minimum tick size price ranges, when order price is in begin-end range, must meet tickSize requirement. begin: left price range, end: right price range, type: range type OPEN/OPEN_CLOSED/CLOSED/CLOSED_OPEN, tickSize: minimum price unit |
| trading_class | str | Contract trading class name |
| close_only | bool | Whether close-only |
| status | str | Contract status |
| trade | bool | Whether tradable |
| is_etf | bool | Whether ETF |
| etf_leverage | int | ETF leverage ratio, only exists when contract is ETF |
| lot_size | float | Minimum tradable asset quantity in single transaction |
| support_overnight_trading | bool | Whether supports overnight trading |
| support_fractional_share | bool | Whether supports fractional share trading (prime/paper trading accounts only) |
Note
print only displays partial attributes, use
print(contract.to_str())to print all attributes
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')
trade_client = TradeClient(client_config)
# Stock
contract = trade_client.get_contract('XYZX', sec_type=SecurityType.STK)
# contract = trade_client.get_contract('ES2306', sec_type=SecurityType.STK)
print(contract)
# By default only prints contract symbol/type/currency. Use to_str to print all attributes. For more attributes, specify attribute name directly, e.g., contract.short_margin
print(contract.to_str())
# View short initial margin
print(contract.short_initial_margin)Return Example
{'contract_id': 1916, 'symbol': 'XYZX', 'currency': 'USD', 'sec_type': 'STK', 'exchange': None, 'origin_symbol': None,
'local_symbol': 'XYZX', 'expiry': None, 'strike': None, 'put_call': None, 'multiplier': 1.0, 'name': 'Apple Inc',
'short_margin': 0.35, 'short_initial_margin': 0.35, 'short_maintenance_margin': 0.3, 'short_fee_rate': None,
'shortable': True, 'shortable_count': None, 'long_initial_margin': 0.3, 'long_maintenance_margin': 0.25,
'contract_month': None, 'identifier': 'XYZX', 'primary_exchange': 'NASDAQ', 'market': 'US', 'min_tick': None,
'tick_sizes': [{'begin': '0', 'end': '1', 'type': 'CLOSED', 'tick_size': 0.0001}, {'begin': '1', 'end': 'Infinity',
'type': 'OPEN', 'tick_size': 0.01}], 'trading_class': 'XYZX', 'status': 1, 'marginable': True, 'trade': True,
'close_only': False, 'continuous': None, 'last_trading_date': None, 'first_notice_date': None,
'last_bidding_close_time': None, 'is_etf': False, 'etf_leverage': None, 'discounted_day_initial_margin': None,
'discounted_day_maintenance_margin': None, 'discounted_time_zone_code': None, 'discounted_start_at': None,
'discounted_end_at': None, 'categories': None, 'lot_size': 1.0, 'support_overnight_trading': True}
get_contracts Get Multiple Contract Information
TradeClient.get_contracts(symbol, sec_type=SecurityType.STK, currency=None, exchange=None):
Description
Query multiple contract information required for trading, returned as a list
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| symbol | str | Yes | Stock symbol, e.g., ''. Maximum 50 symbols per request |
| sec_type | SecurityType | No | Security type, tigeropen.common.consts.SecurityType enum, Default: SecurityType.STK |
| currency | Currency | No | Currency, tigeropen.common.consts.Currency enum, e.g., Currency.USD |
| exchange | str | No | Exchange, optional, e.g., 'CBOE' |
Return
list
Each item in the list is a contract object (tigeropen.trade.domain.contract.Contract), see Object Introduction. Common attributes:
Object Attributes
| Attribute | Description |
|---|---|
| identifier | Unique identifier, stock identifier same as symbol, option is 21-character identifier |
| symbol | Stock symbol, option contract symbol is the underlying symbol |
| sec_type | STK stock/OPT option/IOPT CBBC, etc., default STK |
| name | Contract name |
| currency | Currency, e.g., USD |
| exchange | Exchange |
| expiry | Options and, option expiration date |
| strike | Options only, option strike price |
| multiplier | Multiplier, quantity per lot |
| put_call | Options only, option direction, CALL or PUT |
| short_margin | Short margin ratio (deprecated, use short_initial_margin instead) |
| short_initial_margin | Short initial margin ratio |
| short_maintenance_margin | Short maintenance margin ratio (prime accounts have values) |
| short_fee_rate | Short fee rate |
| shortable | Short pool remaining |
| long_initial_margin | Long initial margin |
| long_maintenance_margin | Long maintenance margin |
| contract_month | Contract month, e.g., 202201 for January 2022 |
| primary_exchange | Stock listing exchange |
| market | Market, e.g., US |
| min_tick | Minimum tick size |
| tickSizes | Stock only, minimum tick size price ranges, when order price is in begin-end range, must meet tickSize requirement. begin: left price range, end: right price range, type: range type OPEN/OPEN_CLOSED/CLOSED/CLOSED_OPEN, tickSize: minimum price unit |
| trading_class | Contract trading class name |
| status | Contract status |
| is_etf | Whether ETF |
| etf_leverage | ETF leverage ratio, only exists when contract is ETF |
Note
print only displays partial attributes, use
print(contract.to_str())to print all attributes
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')
trade_client = TradeClient(client_config)
contracts = trade_client.get_contracts('XYZX', sec_type=SecurityType.STK)
print(contracts)
print(contracts[0].to_str())Return Example
[
{'contract_id': 1916, 'symbol': 'XYZX', 'currency': 'USD', 'sec_type': 'STK', 'exchange': None, 'origin_symbol': None,
'local_symbol': 'XYZX', 'expiry': None, 'strike': None, 'put_call': None, 'multiplier': 1.0, 'name': 'Apple Inc',
'short_margin': None, 'short_initial_margin': None, 'short_maintenance_margin': None, 'short_fee_rate': None,
'shortable': None, 'shortable_count': None, 'long_initial_margin': None, 'long_maintenance_margin': None,
'contract_month': None, 'identifier': 'XYZX', 'primary_exchange': None, 'market': 'US', 'min_tick': None,
'tick_sizes': [{'begin': '0', 'end': '1', 'type': 'CLOSED', 'tick_size': 0.0001}, {'begin': '1', 'end': 'Infinity',
'type': 'OPEN', 'tick_size': 0.01}], 'trading_class': 'XYZX', 'status': 1, 'marginable': None, 'trade': True,
'close_only': False, 'continuous': None, 'last_trading_date': None, 'first_notice_date': None,
'last_bidding_close_time': None, 'is_etf': False, 'etf_leverage': None, 'discounted_day_initial_margin': None,
'discounted_day_maintenance_margin': None, 'discounted_time_zone_code': None, 'discounted_start_at': None,
'discounted_end_at': None, 'categories': None, 'lot_size': 1.0, 'support_overnight_trading': True}]Create Contract Objects Locally
Stock
from tigeropen.common.util.contract_utils import stock_contract
# US Stock
contract = stock_contract(symbol='XYZX', currency='USD')Options
from tigeropen.common.util.contract_utils import option_contract, option_contract_by_symbol
contract = option_contract(identifier='XYZX 190118P00160000')
# or
contract = option_contract_by_symbol('XYZX', '20200110', strike=280.0, put_call='PUT', currency='USD')
# Convert between option symbol and four elements
from tigeropen.common.util.contract_utils import extract_option_info, get_option_identifier
# Create option symbol from four elements
underlying_symbol='XYZX'
expiry='20200110'
put_call='PUT'
strike=280
identifier = get_option_identifier(underlying_symbol, expiry, put_call, strike)
# Extract four elements from option symbol identifier='XYZX 190118P00160000'
symbol, expiry, put_call, strike = extract_option_info(identifier)
print(identifier)Updated 7 days ago