获取合约

获取合约

签名

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

说明

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

参数

参数类型必填说明
symbol&str股票代码,如 AAPL
sec_type&str证券类型:STK/OPT/FUT/WAR/IOPT

返回

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
  }
]

批量获取合约

签名

pub async fn get_contracts(&self, symbols: &[&str], sec_type: &str) -> Result<Vec<Contract>, TigerError>

说明

批量获取多个股票代码的合约信息。

参数

参数类型必填说明
symbols&[&str]股票代码数组,如 &["AAPL", "GOOG"]
sec_type&str证券类型:STK/OPT/FUT/WAR/IOPT

返回

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
  }
]

获取行情合约

签名

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

说明

获取衍生品的行情合约信息,适用于期权、期货等。

参数

参数类型必填说明
symbol&str股票代码
sec_type&str证券类型:OPT/FUT/WAR/IOPT
expiry&str到期日,格式 YYYYMMDD

返回

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"
  }
]

Did this page help you?