获取合约
获取合约
签名
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> | 内部合约 ID |
| short_margin | Option<f64> | 做空保证金比例 |
| short_initial_margin | Option<f64> | 做空初始保证金比例 |
| short_maintenace_margin | Option<f64> | 做空维持保证金比例;Rust 字段名按 SDK 拼写保留 |
| long_initial_margin | Option<f64> | 做多初始保证金 |
| long_maintenace_margin | Option<f64> | 做多维持保证金;Rust 字段名按 SDK 拼写保留 |
| lot_size | Option<f64> | 每手数量 |
| tick_sizes | Option<Vec<TickSize>> | 价格精度列表 |
TickSize 字段:
| 字段 | Rust 类型 | 说明 |
|---|---|---|
| begin | Option<String> | 区间起始价格 |
| end | Option<String> | 区间结束价格 |
| tick_size | Option<f64> | 最小报价单位 |
| r#type | Option<String> | 区间类型 |
示例
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(())
}返回示例
[
{
"contractId": 11234,
"symbol": "AAPL",
"secType": "STK",
"currency": "USD",
"exchange": "SMART",
"primaryExchange": "NASDAQ",
"market": "US",
"tradeable": true,
"lotSize": 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>
返回字段同 获取合约,包括 Contract 与嵌套 TickSize 字段表。
示例
let contracts = trade.get_contracts(&["AAPL", "GOOG", "TSLA"], "STK").await?;
println!("获取到 {} 个合约", contracts.len());返回示例
[
{
"contractId": 11234,
"symbol": "AAPL",
"secType": "STK",
"currency": "USD",
"exchange": "SMART",
"tradeable": true
},
{
"contractId": 11235,
"symbol": "GOOG",
"secType": "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>
返回字段同 获取合约,包括 Contract 与嵌套 TickSize 字段表;衍生品合约通常还会包含 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);
}返回示例
[
{
"contractId": 55678,
"symbol": "AAPL",
"secType": "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 about 1 month ago
Did this page help you?
