获取合约

获取合约

签名

pub async fn get_contract(&self, symbol: &str, sec_type: &str) -> Result<Vec<Contract>, TigerError>

说明

根据标的代码和证券类型获取合约信息。

参数

参数Rust 类型必填性/条件SDK 默认值
symbol&str必填
sec_type&str必填;支持 STKOPTWARIOPTFUTFUNDCC

返回

Result<Vec<Contract>, TigerError>

字段类型说明
contract_idOption<i64>合约 ID
symbolString标的代码
sec_typeString证券类型
currencyOption<String>币种
exchangeOption<String>交易所
primary_exchangeOption<String>主交易所
expiryOption<String>到期日
strikeOption<f64>行权价
rightOption<String>期权方向 PUT/CALL
multiplierOption<f64>合约乘数
identifierOption<String>唯一标识
nameOption<String>名称
marketOption<String>市场
tradeableOption<bool>是否可交易
conidOption<i64>IB 合约 ID
lot_sizeOption<f64>每手数量
tick_sizesOption<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必填;仅支持 STKFUTCC

返回

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必填;仅支持 OPTWARIOPT
expiry&strOPT 必填;WAR/IOPT 可传空字符串;支持 yyyyMMddyyyy-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_contractget_derivative_contracts 均使用 quote_contract,共享此额度。


Did this page help you?