获取合约

获取合约

签名

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_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>内部合约 ID
short_marginOption<f64>做空保证金比例
short_initial_marginOption<f64>做空初始保证金比例
short_maintenace_marginOption<f64>做空维持保证金比例;Rust 字段名按 SDK 拼写保留
long_initial_marginOption<f64>做多初始保证金
long_maintenace_marginOption<f64>做多维持保证金;Rust 字段名按 SDK 拼写保留
lot_sizeOption<f64>每手数量
tick_sizesOption<Vec<TickSize>>价格精度列表

TickSize 字段:

字段Rust 类型说明
beginOption<String>区间起始价格
endOption<String>区间结束价格
tick_sizeOption<f64>最小报价单位
r#typeOption<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&strOPT 必填;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,共享此额度。


Did this page help you?