获取合约
获取合约
签名
pub async fn get_contract(&self, symbol: &str, sec_type: &str) -> Result<Vec<Contract>, TigerError>说明
根据标的代码和证券类型获取合约信息。
参数
| 参数 | Rust 类型 | 必填性/条件 | SDK 默认值 |
|---|---|---|---|
| symbol | &str | 必填 | 无 |
| sec_type | &str | 必填;支持 STK、OPT、WAR、IOPT、FUT、FUND、CC | 无 |
返回
Result<Vec<Contract>, TigerError>
| 字段 | 类型 | 说明 |
|---|---|---|
| contract_id | Option<i64> | 合约 ID |
| symbol | String | 标的代码 |
| sec_type | String | 证券类型 |
| currency | Option<String> | 币种 |
| exchange | Option<String> | 交易所 |
| primary_exchange | Option<String> | 主交易所 |
| expiry | Option<String> | 到期日 |
| strike | Option<f64> | 行权价 |
| right | Option<String> | 期权方向 PUT/CALL |
| multiplier | Option<f64> | 合约乘数 |
| identifier | Option<String> | 唯一标识 |
| name | Option<String> | 名称 |
| market | Option<String> | 市场 |
| tradeable | Option<bool> | 是否可交易 |
| conid | Option<i64> | IB 合约 ID |
| lot_size | Option<f64> | 每手数量 |
| tick_sizes | Option<Vec<TickSize>> | 价格精度列表 |
示例
use tigeropen::config::ClientConfig;
use tigeropen::trade::TradeClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfig::builder().build()?;
let trade = TradeClient::from_config(config);
let contracts = trade.get_contract("AAPL", "STK").await?;
for c in &contracts {
println!("{} {} exchange={:?} lot_size={:?}", c.symbol, c.sec_type, c.exchange, c.lot_size);
}
Ok(())
}返回示例
[
{
"contract_id": 11234,
"symbol": "AAPL",
"sec_type": "STK",
"currency": "USD",
"exchange": "SMART",
"primary_exchange": "NASDAQ",
"market": "US",
"tradeable": true,
"lot_size": 1.0,
"multiplier": 1.0
}
]请求频率
基础限流为 60 次/分钟。
批量获取合约
签名
pub async fn get_contracts(&self, symbols: &[&str], sec_type: &str) -> Result<Vec<Contract>, TigerError>说明
批量获取多个标的代码的合约信息。
参数
| 参数 | Rust 类型 | 必填性/条件 | SDK 默认值 |
|---|---|---|---|
| symbols | &[&str] | 必填 | 无 |
| sec_type | &str | 必填;仅支持 STK、FUT、CC | 无 |
返回
Result<Vec<Contract>, TigerError>
返回字段同 获取合约。
示例
let contracts = trade.get_contracts(&["AAPL", "GOOG", "TSLA"], "STK").await?;
println!("获取到 {} 个合约", contracts.len());返回示例
[
{
"contract_id": 11234,
"symbol": "AAPL",
"sec_type": "STK",
"currency": "USD",
"exchange": "SMART",
"tradeable": true
},
{
"contract_id": 11235,
"symbol": "GOOG",
"sec_type": "STK",
"currency": "USD",
"exchange": "SMART",
"tradeable": true
}
]请求频率
基础限流为 60 次/分钟。
获取行情合约
签名
pub async fn get_quote_contract(&self, symbol: &str, sec_type: &str, expiry: &str) -> Result<Vec<Contract>, TigerError>说明
获取期权、窝轮或牛熊证的行情合约信息。
参数
| 参数 | Rust 类型 | 必填性/条件 | SDK 默认值 |
|---|---|---|---|
| symbol | &str | 必填 | 无 |
| sec_type | &str | 必填;仅支持 OPT、WAR、IOPT | 无 |
| expiry | &str | OPT 必填;WAR/IOPT 可传空字符串;支持 yyyyMMdd 或 yyyy-MM-dd | 无 |
返回
Result<Vec<Contract>, TigerError>
返回字段同 获取合约,衍生品合约额外包含 strike、expiry、right、identifier。
示例
let contracts = trade.get_quote_contract("AAPL", "OPT", "20260919").await?;
for c in &contracts {
println!("{} strike={:?} right={:?}", c.symbol, c.strike, c.right);
}返回示例
[
{
"contract_id": 55678,
"symbol": "AAPL",
"sec_type": "OPT",
"currency": "USD",
"exchange": "SMART",
"expiry": "20260919",
"strike": 200.0,
"right": "CALL",
"multiplier": 100.0,
"identifier": "AAPL 260919C00200000"
}
]请求频率
基础限流为 60 次/分钟。get_quote_contract 与 get_derivative_contracts 均使用 quote_contract,共享此额度。
Updated 6 days ago
Did this page help you?
