Get Contract
What is a Contract
We refer to what is being traded in an order as a "contract". The specs of a specific contract are set by a exchange, and are used to identify a specific asset in global markets, across the exchanges. This information, and the information required to trade a certain contract, are embedded in the Contract object.
A typical contract object includes the following elements:
- Symbol: The ticker symbol of the stock/equity. The symbol of most U.S stocks only contains letters, HK stocks and Chinese A-Shares uses numbers as symbols of stocks. For example, the symbol of Tiger Brokers (NASDAQ) is TIGR
- Security type: Common Security types includes STK(Stocks), OPT(Options), FUT(Futures) and CASH(Forex). For example, the Security type of Tiger Brokers (NASDAQ) is TIGR
- Exchange: The code of the exchange in which the requested asset is traded. Contracts with Security typ of STK does not require this data field, as the orders will be routed automatically to a designated exchange, However, for futures, this field is necessary
Most stocks, CFDs, indexes or Forexs can be identify by those four elements. However, some contracts like Futures and Options has more attributes in their corresponding contract objects
Stocks
ContractItem contract = new ContractItem();
contract.Symbol ="TIGR";
contract.SecType ="STK";
contract.Currency ="USD"; //Optional, USD by default
contract.Market = "US"; //Optional, including US(United States) , HK (HongKong), CN(A-Shares), etc. US by default
Options
Tiger Securities's API support 2 option contract format:
One is the four-factor approach, including symbol, expiry, strike, right.
The other is the standard OCC option contract format, fixed length of 21 bits. contains four parts:
- The code of the relevant stock or ETP, e.g. (AAPL), is fixed at six characters, with the missing digits filled by spaces
- Option expiration date, 6 digits, format: yymmdd
- Option type,including P or C, for put or call
- Option exercise price, the value of the price x 1000, fixed 8 digits, the first few digits are filled by 0
ContractItem contract = new ContractItem();
contract.Symbol ="AAPL";
contract.SecType ="OPT";
contract.Currency ="USD";
contract.Expiry="20180821";
contract.Strike = 30;
contract.Right ="CALL";
contract.Multiplier =100.0;
contract.Market = "US"; // Optional
Futures
ContractItem contract = new ContractItem();
contract.Symbol ="CL1901";
contract.SecType ="FUT";
contract.Exchange ="SGX";
contract.Currency ="USD";
contract.Expiry="20190328";
contract.Multiplier=1.0;
Get Contract
Description
Get contract information. Use this method with gobal account and prime account, ContractItem
will have different data fields. Use the same account to get contract information and to place orders.
Argument
Argument | Type | optional | Desription |
---|---|---|---|
account | string | Yes | Account id: 13810712 |
symbol | string | Yes | Ticker symbol of the stock/equity, example: 'AAPL' |
sec_type | string | Yes | Securtiy type, example: STK |
currency | string | No | USD/HKD/CNH |
expiry | string | No | Options expiration date, format: 'yyyyMMdd', example: '20220121' |
strike | double | No | Options strike price. Required for options |
right | string | No | CALL/PUT. Required for options |
exchange | string | No | Exchange code (U.S stocks SMART, Shanghai-Hong Kong Stock Connect-SEHK, A-Shares-SEHKNTL,Shenzhen-Hong Kong Stock Connect SEHKSZSE) |
secret_key | string | No | ecret key for the trader of institutions, please config in client_config, ignore if you are a indiviual user |
ResponseTigerOpenAPI.Trade.Response.ContractResponse
source
Structured as follows:
namespace TigerOpenAPI.Trade.Response
{
public class ContractResponse : TigerResponse
{
[JsonProperty(PropertyName = "data")]
public ContractItem Data { get; set; }
}
}
Use ContractResponse.Data
to access returned data. This method will return a ContractItem
object, whereTigerOpenAPI.Trade.Response.ContractItem
has the following attributes:
Name | Example | Description |
---|---|---|
identifier | CL2109/AAPL | Asset identifier |
name | K12 INC | name of the asset |
contractId | 1 | IB contract id |
symbol | LRN | stock ticker symbol |
secType | STK | STK/OPT/WAR/IOPT, STK by default |
expiry | 20171117 | Contract expiration date |
contractMonth | 201804 | Delivery month |
strike | 24.0 | strike price for options |
right | PUT | Put/Call for options |
type | ES | futures type |
multiplier | 0.0 | multiplier for options, futures, CBBCs |
exchange | NYSE | Exchange code |
primaryExchange | NYSE | Primary exchange |
market | US | market /US/HK/CN |
currency | USD | USD/HKD/CNH |
localSymbol | 1033 | used in HK market to identify warrant and CBBC |
tradingClass | LRN | Trading class |
minTick | 0.001 | minimum ticksize |
tickSizes | [ { "begin":"0", "end":"1", "tickSize":0.0001, "type":"CLOSED" }, { "begin":"1", "end":"Infinity", "tickSize":0.01, "type":"OPEN" } ] | only support stocks,type: OPEN/OPEN_CLOSED/CLOSED/CLOSED_OPEN, tickSize:minTick for different price ranges |
marginable | true | if able to purchase with financing |
longInitialMargin | 1 | Long initial margin |
longMaintenanceMargin | 1 | Long maintenance margin |
shortInitialMargin | 0.35 | Short intial margin |
shortMaintenanceMargin | 0.3 | Short maintenance margin(prime account only ) |
shortable | true | available for shorting |
shortableCount | 10000000 | amount of shares you can short |
shortFeeRate | 0 | short fee rate |
tradeable | true | if available for trading(STK type only) |
closeOnly | false | Is it only possible to close the position |
continuous | false | Futures only, if the contract is continuous |
lastTradingDate | 2019-01-01 | Futures only, last trading date |
firstNoticeDate | 2019-01-01 | Futures only, first notice date |
lastBiddingCloseTime | 0 | Futures only, last bidding date |
isEtf | false | is ETF |
etfLeverage | 3 | ETF leverage |
discountedDayInitialMargin | 3069.0 | Futures only, Intraday initial margin discount |
discountedDayMaintenanceMargin | 2790.0 | Futures only, Intraday maintenance margin discount |
discountedTimeZoneCode | CDT | Futures only, Intraday margin discount period time zone |
discountedStartAt | 17:30:00 | Futures only, Intraday margin discount start time |
discountedEndAt | 14:30:00 | Futures only, Intraday margin discount end time |
Example
// init trade client
TradeClient tradeClient = new TradeClient(config);
static async Task<ContractResponse?> GetContractAsync(TradeClient tradeClient)
{
// get stock contract
TigerRequest<ContractResponse> request = new TigerRequest<ContractResponse>()
{
ApiMethodName = TradeApiService.CONTRACT,
ModelValue = new ContractModel()
{
Symbol = "AAPL"
}
};
ContractResponse? response = await tradeClient.ExecuteAsync(request);
ApiLogger.Info("response:" + JsonConvert.SerializeObject(response, TigerClient.JsonSet));
// get options contract
request = new TigerRequest<ContractResponse>()
{
ApiMethodName = TradeApiService.CONTRACT,
ModelValue = new ContractModel()
{
SecType = SecType.OPT.ToString(),
Symbol = "AAPL",
Strike = 150.0,
Expiry = "20230616",
Right = Right.CALL.ToString(),
Currency = Currency.USD.ToString()
}
};
response = await tradeClient.ExecuteAsync(request);
ApiLogger.Info("options response:" + JsonConvert.SerializeObject(response, TigerClient.JsonSet));
// get warrant contract
request = new TigerRequest<ContractResponse>()
{
ApiMethodName = TradeApiService.CONTRACT,
ModelValue = new ContractModel()
{
SecType = SecType.WAR.ToString(),
Symbol = "29263",
Strike = 351.567,
Expiry = "20230330",
Right = Right.CALL.ToString()
}
};
response = await tradeClient.ExecuteAsync(request);
ApiLogger.Info("warrants response:" + JsonConvert.SerializeObject(response, TigerClient.JsonSet));
// get futures contract
request = new TigerRequest<ContractResponse>()
{
ApiMethodName = TradeApiService.CONTRACT,
ModelValue = new ContractModel()
{
SecType = SecType.FUT.ToString(),
Symbol = "JPY2306"
}
};
response = await tradeClient.ExecuteAsync(request);
ApiLogger.Info("futures response:" + JsonConvert.SerializeObject(response, TigerClient.JsonSet));
return response;
}
Response Example
response:{"data":{"identifier":"AAPL","symbol":"AAPL","secType":"STK","multiplier":1.0,"market":"US","currency":"USD","localSymbol":"AAPL","tradingClass":"AAPL","name":"Apple","tradeable":true,"marginable":true,"shortInitialMargin":0.35,"shortMaintenanceMargin":0.3,"longInitialMargin":0.3,"longMaintenanceMargin":0.25,"tickSizes":[{"begin":"0","end":"1","type":"CLOSED","tickSize":0.0001},{"begin":"1","end":"Infinity","type":"OPEN","tickSize":0.01}]},"message":"success","timestamp":1678248447856,"sign":"R6uVWPOfoYR7C+/U4mw8pYgsfLaLHyL8UJ5Bgr4GII6JYBYYvz3OBYYwZDTGmTIjjdEeSm8llgojY6VMiEwIVXPqbr+C3HvLM8JpztbCe4gvnFXlfHSVMDoNMariVIF2IdcET2eNqJANVJXDFAJa0jZWMaNjmBZwcllgnEIvH8k="}
options response:{"data":{"identifier":"AAPL 230616C00150000","symbol":"AAPL","secType":"OPT","expiry":"20230616","strike":150.0,"right":"CALL","multiplier":1.0,"market":"US","currency":"USD","localSymbol":"AAPL","tradingClass":"AAPL","name":"Apple","tradeable":true,"shortInitialMargin":1.0,"shortMaintenanceMargin":1.0,"longInitialMargin":1.0,"longMaintenanceMargin":1.0,"tickSizes":[{"begin":"0","end":"Infinity","type":"CLOSED_OPEN","tickSize":0.01}]},"message":"success","timestamp":1678248435184,"sign":"KUvm5w4MW0o4x/UhaKUudo+/ToOoGSIUvaS5/O1OpKLpszMMarEqUAPBMpo/q1X5cbkan1yH5jDpaL55jCwM4vM2fvh1vvBme1M+BgWfHNk27TSSB6vTtTp37T6P1FXM0GPKDZmmyq7cRHeLDefyvd5W8ha0lXAHma4tB8u5Vj0="}
warrants response:{"data":{"identifier":"29263 230330C00351567","symbol":"29263","secType":"WAR","expiry":"20230330","strike":351.567,"right":"CALL","multiplier":10000.0,"market":"HK","currency":"HKD","localSymbol":"29263","tradingClass":"29263","name":"CTTENCT@EC2303D.C","tradeable":true,"shortInitialMargin":1.0,"shortMaintenanceMargin":1.0,"longInitialMargin":1.0,"longMaintenanceMargin":1.0,"tickSizes":[{"begin":"0","end":"0.25","type":"CLOSED","tickSize":0.001},{"begin":"0.25","end":"0.5","type":"OPEN_CLOSED","tickSize":0.005},{"begin":"0.5","end":"10","type":"OPEN_CLOSED","tickSize":0.01},{"begin":"10","end":"20","type":"OPEN_CLOSED","tickSize":0.02},{"begin":"20","end":"100","type":"OPEN_CLOSED","tickSize":0.05},{"begin":"100","end":"200","type":"OPEN_CLOSED","tickSize":0.1},{"begin":"200","end":"500","type":"OPEN_CLOSED","tickSize":0.2},{"begin":"500","end":"1000","type":"OPEN_CLOSED","tickSize":0.5},{"begin":"1000","end":"2000","type":"OPEN_CLOSED","tickSize":1.0},{"begin":"2000","end":"5000","type":"OPEN_CLOSED","tickSize":2.0},{"begin":"5000","end":"Infinity","type":"OPEN","tickSize":5.0}]},"message":"success","timestamp":1678248448209,"sign":"KUvm5w4MW0o4x/UhaKUudo+/ToOoGSIUvaS5/O1OpKLpszMMarEqUAPBMpo/q1X5cbkan1yH5jDpaL55jCwM4vM2fvh1vvBme1M+BgWfHNk27TSSB6vTtTp37T6P1FXM0GPKDZmmyq7cRHeLDefyvd5W8ha0lXAHma4tB8u5Vj0="}
futures response:{"data":{"identifier":"JPY2306","symbol":"JPY2306","secType":"FUT","multiplier":1.0,"market":"US","currency":"USD","localSymbol":"JPY2306","tradingClass":"JPY2306","name":"Japanese Yen - Jun 2023","tradeable":true,"marginable":true,"shortInitialMargin":4092.0,"shortMaintenanceMargin":3720.0,"longInitialMargin":4092.0,"longMaintenanceMargin":3720.0,"tickSizes":[{"begin":"0","end":"Infinity","type":"CLOSED_OPEN","tickSize":5E-07}],"discountedDayInitialMargin":3069.0,"discountedDayMaintenanceMargin":2790.0,"discountedTimeZoneCode":"CDT","discountedStartAt":"17:30:00","discountedEndAt":"14:30:00"},"message":"success","timestamp":1683181339383,"sign":"bORW/gW79+1+woZIiEyAB+SdMBbfdTdBJQ3u2jqm+1IeE73ke2y2/bELBQA17U4H01wKndZLA+3hLB2RtJg6MOmsIDCnwMdMuTX3atuAqk5enG/HlTsz/sqqNRSBua//rocgrpv94+huJixSbfq0PoUA/+m9Txu2sJ05ICzN6Zo="}
Get Multiple Contracts
Description
Get multiple contracts. Use this method with gobal account and prime account, ContractItem
will have different data fields. Use the same account to get contract information and to place orders.
CAUTION
There is no field related to margin in the contract returned by the prime account
Argument
Argument | Type | optional | Desription |
---|---|---|---|
account | string | Yes | Account id: 13810712 |
symbols | List<string> | Yes | Ticker symbol of the stock/equity, example: 'AAPL'. Maximum 50 per request |
sec_type | string | Yes | Securtiy type, example: STK/FUT |
currency | string | No | USD/HKD/CNH |
secret_key | string | No | ecret key for the trader of institutions, please config in client_config, ignore if you are a indiviual user |
ResponseTigerOpenAPI.Trade.Response.ContractsResponse
source
Structured as follows:
namespace TigerOpenAPI.Trade.Response
{
public class ContractsResponse : TigerResponse
{
[JsonProperty(PropertyName = "data")]
public Dictionary<string, List<ContractItem>> Data { get; set; }
}
}
Use ContractsResponse.Data
to access returned data. This method will return ContractItem
objects, whereTigerOpenAPI.Trade.Response.ContractItem
has the following attributes:
Name | Example | Description |
---|---|---|
identifier | CL2109/AAPL | Asset identifier |
name | K12 INC | name of the asset |
contractId | 1 | IB contract id |
symbol | LRN | stock ticker symbol |
secType | STK | STK/OPT/WAR/IOPT, STK by default |
expiry | 20171117 | Contract expiration date |
contractMonth | 201804 | Delivery month |
strike | 24.0 | strike price for options |
right | PUT | Put/Call for options |
type | ES | futures type |
multiplier | 0.0 | multiplier for options, futures, CBBCs |
exchange | NYSE | Exchange code |
primaryExchange | NYSE | Primary exchange |
market | US | market /US/HK/CN |
currency | USD | USD/HKD/CNH |
localSymbol | 1033 | used in HK market to identify warrant and CBBC |
tradingClass | LRN | Trading class |
minTick | 0.001 | minimum ticksize |
tickSizes | [ { "begin":"0", "end":"1", "tickSize":0.0001, "type":"CLOSED" }, { "begin":"1", "end":"Infinity", "tickSize":0.01, "type":"OPEN" } ] | only support stocks,type: OPEN/OPEN_CLOSED/CLOSED/CLOSED_OPEN, tickSize:minTick for different price ranges |
marginable | true | if able to purchase with financing |
longInitialMargin | 1 | Long initial margin |
longMaintenanceMargin | 1 | Long maintenance margin |
shortInitialMargin | 0.35 | Short intial margin |
shortMaintenanceMargin | 0.3 | Short maintenance margin(prime account only ) |
shortable | true | available for shorting |
shortableCount | 10000000 | amount of shares you can short |
shortFeeRate | 0 | short fee rate |
tradeable | true | if available for trading(STK type only) |
closeOnly | false | Is it only possible to close the position |
continuous | false | Futures only, if the contract is continuous |
lastTradingDate | 2019-01-01 | Futures only, last trading date |
firstNoticeDate | 2019-01-01 | Futures only, first notice date |
lastBiddingCloseTime | 0 | Futures only, last bidding date |
isEtf | false | is ETF |
etfLeverage | 0 | ETF leverage |
Example
static async Task<ContractsResponse?> GetContractsAsync(TradeClient tradeClient)
{
TigerRequest<ContractsResponse> request = new TigerRequest<ContractsResponse>()
{
ApiMethodName = TradeApiService.CONTRACTS,
ModelValue = new ContractsModel()
{
SecType = SecType.STK.ToString(),
Symbols = new List<string> { "AAPL", "TSLA" },
Account = "13810712"
}
};
return await tradeClient.ExecuteAsync(request);
}
Response Example
{
"data":{
"items":[
{
"contractId":0,
"identifier":"AAPL",
"symbol":"AAPL",
"secType":"STK",
"expiry":null,
"contractMonth":null,
"strike":"NaN",
"right":null,
"multiplier":1,
"exchange":null,
"market":"US",
"primaryExchange":null,
"currency":"USD",
"localSymbol":"AAPL",
"tradingClass":"AAPL",
"name":"Apple Inc",
"tradeable":true,
"closeOnly":false,
"minTick":"NaN",
"marginable":false,
"shortInitialMargin":"NaN",
"shortMaintenanceMargin":"NaN",
"shortFeeRate":"NaN",
"shortable":false,
"shortableCount":0,
"longInitialMargin":"NaN",
"longMaintenanceMargin":"NaN",
"lastTradingDate":null,
"firstNoticeDate":null,
"lastBiddingCloseTime":0,
"continuous":false,
"type":null,
"ibCode":null,
"tickSizes":[
{
"begin":"0",
"end":"1",
"type":"CLOSED",
"tickSize":0.0001
},
{
"begin":"1",
"end":"Infinity",
"type":"OPEN",
"tickSize":0.01
}
],
"discountedDayInitialMargin":"NaN",
"discountedDayMaintenanceMargin":"NaN",
"discountedTimeZoneCode":null,
"discountedStartAt":null,
"discountedEndAt":null,
"isEtf":false,
"etfLeverage":0
},
{
"contractId":0,
"identifier":"TSLA",
"symbol":"TSLA",
"secType":"STK",
"expiry":null,
"contractMonth":null,
"strike":"NaN",
"right":null,
"multiplier":1,
"exchange":null,
"market":"US",
"primaryExchange":null,
"currency":"USD",
"localSymbol":"TSLA",
"tradingClass":"TSLA",
"name":"Tesla Motors",
"tradeable":true,
"closeOnly":false,
"minTick":"NaN",
"marginable":false,
"shortInitialMargin":"NaN",
"shortMaintenanceMargin":"NaN",
"shortFeeRate":"NaN",
"shortable":false,
"shortableCount":0,
"longInitialMargin":"NaN",
"longMaintenanceMargin":"NaN",
"lastTradingDate":null,
"firstNoticeDate":null,
"lastBiddingCloseTime":0,
"continuous":false,
"type":null,
"ibCode":null,
"tickSizes":[
{
"begin":"0",
"end":"1",
"type":"CLOSED",
"tickSize":0.0001
},
{
"begin":"1",
"end":"Infinity",
"type":"OPEN",
"tickSize":0.01
}
],
"discountedDayInitialMargin":"NaN",
"discountedDayMaintenanceMargin":"NaN",
"discountedTimeZoneCode":null,
"discountedStartAt":null,
"discountedEndAt":null,
"isEtf":false,
"etfLeverage":0
}
]
},
"code":0,
"message":"success",
"timestamp":1684915702228,
"sign":"DveGmN84KAMpKv7Ud7XqE/ZpNqO82JYxboPeuLfZwHIXdA2Q4OOe8x/kYVhAKIL+tjg/4if71LxPpB7o3dd1I1VZf3LgusRsShTfHrAZOetiv9kW5Y1rpTeiAEaeez4hwPiBUnxxXsK9d/2+9MtwnqhDvrazj3VBstmc7DZ+RBE="
}
Get Contract for Options and Warrants
Description
Get stock‘s Warrant and CBBC contracts
Argument
Argument | Type | Required | Description |
---|---|---|---|
symbols | string | Yes | symbol of the underlying asset |
sec_type | string | Yes | Security types, possible values are: OPT-options/ WAR-warrants/ IOPT-CBBCs) |
expiry | String | No | Expiration date(yyyyMMdd), must have a value for OPT type |
lang | string | No | Language: zh_CN,zh_TW,en_US, en_US by default |
Response:TigerOpenAPI.Quote.Response.QuoteContractResponse
source
Structured as follows:
namespace TigerOpenAPI.Quote.Response
{
public class QuoteContractResponse : TigerResponse
{
[JsonProperty(PropertyName = "data")]
public QuoteContractItem Data { get; set; }
}
}
Use QuoteContractResponse.Data
to access returned data. This method will return a QuoteContractItem
object, whereTigerOpenAPI.Quote.Response.QuoteContract
has the following attributes:
Name | Type | Description |
---|---|---|
symbol | string | Stock ticker symbol |
name | string | Contract name |
exchange | string | Exchange where the contract is traded |
market | string | Market where the contract is traded |
secType | string | Security type |
currency | string | Currency |
expiry | string | Expiration date for options, warrants, CBBC, futures, e.g. 20171117 |
right | string | PUT/CALL for options, warrants, futures and CBBCs |
strike | string | Strike price |
multiplier | double | Multiplier for options, warrants, futures and CBBCs |
Response Example:
static async Task<QuoteContractResponse?> GetQuoteContractAsync(QuoteClient quoteClient)
{
TigerRequest<QuoteContractResponse> request = new TigerRequest<QuoteContractResponse>()
{
ApiMethodName = QuoteApiService.QUOTE_CONTRACT,
ModelValue = new QuoteContractsModel()
{
Symbol = "00700",
SecType = SecType.WAR,
Expiry = "20211223"
}
};
return await quoteClient.ExecuteAsync(request);
}
Response Example:
{
"code": 0,
"data": [{
"symbol": "00700",
"secType": "WAR",
"items": [{
"currency": "HKD",
"exchange": "SEHK",
"expiry": "20211223",
"market": "HK",
"multiplier": 50000.0,
"name": "MSTENCT@EC2112B.C",
"right": "CALL",
"secType": "WAR",
"strike": "719.38",
"symbol": "13745"
}, {
"currency": "HKD",
"exchange": "SEHK",
"expiry": "20211223",
"market": "HK",
"multiplier": 5000.0,
"name": "JPTENCT@EC2112A.C",
"right": "CALL",
"secType": "WAR",
"strike": "900.5",
"symbol": "13680"
}]
}],
"message": "success",
"sign": "bxQhZiWMsT9aSVTNtt2SXVeeh5w8Ypug/6UY3nL9N7LFKB1YxBVpQoKDJ4JloFojyb/CPCGT0fCXTxboDBTZvnA4stjbh1YqbNlz2lNqmHhpxYUKMdE+w2hFKVvoYMlMPCmsY5NqSQ3S/fsSzZrJyxBRPzZ+d+0qb7VSYw9yhho=",
"success": true,
"timestamp": 1637686550209
}