Rust SDK

Tiger Open API Rust SDK, providing market data queries, order placement, account management, and real-time push notifications.

v0.3.0 introduces a fully typed request/response API. Every QuoteClient / TradeClient method returns a domain type (e.g. Vec<Brief>, Vec<Kline>, Vec<Order>, Option<PlaceOrderResult>) instead of Option<serde_json::Value>. Request structs serialize to snake_case on the wire and responses parse camelCase into strongly typed Rust structs. Array responses that the server wraps in { items: [...] } are unwrapped for you. See CHANGELOG.

Installation

Add the dependency to your Cargo.toml:

[dependencies]
tigeropen = "0.3.0"
tokio = { version = "1", features = ["full"] }

Requires Rust 1.70 or higher.

Configuration

The SDK supports multiple configuration methods. Priority: Environment Variables > Builder Settings (including config file) > Auto-discovered config file > Defaults.

The SDK automatically searches for a config file at these locations (no explicit path needed):

  1. Current directory: ./tiger_openapi_config.properties
  2. Home directory: ~/.tigeropen/tiger_openapi_config.properties

Method 1: Load from properties file (recommended)

use tigeropen::config::ClientConfig;

// Specify a config file path
let config = ClientConfig::builder()
    .properties_file("/path/to/tiger_openapi_config.properties")
    .build()?;

// Or pass no arguments — SDK auto-discovers the config file
let config = ClientConfig::builder().build()?;

Configuration file format:

tiger_id=your_developer_id
private_key=your_rsa_private_key
account=your_trading_account
license=TBUS

Method 2: Builder pattern

use tigeropen::config::ClientConfig;

let config = ClientConfig::builder()
    .tiger_id("your_tiger_id")
    .private_key("your_rsa_private_key")
    .account("your_trading_account")
    .build()?;

Method 3: Environment variables

export TIGEROPEN_TIGER_ID=your_developer_id
export TIGEROPEN_PRIVATE_KEY=your_rsa_private_key
export TIGEROPEN_ACCOUNT=your_trading_account
export TIGEROPEN_TOKEN=your_token  # Required for TBHK license

Configuration Options

OptionDescriptionRequiredDefault
tiger_idDeveloper IDYes-
private_keyRSA private key (PK1 and PK8 compatible)Yes-
accountTrading accountNo-
licenseLicense type (e.g. TBUS)No-
languageLanguage (ZhCn/EnUs)NoZhCn
timeoutRequest timeoutNo15s
tokenTBHK license tokenNo-

Auto-Detection

  • Device ID: Automatically detected from network interface MAC address (mac_address crate)
  • Dynamic domains: SDK fetches the latest server addresses from the domain garden (enabled by default)
  • Quote server: SDK resolves a dedicated quote server URL (LICENSE-QUOTE domain key)
  • Signature verification: Built-in Tiger public key for HTTP response signature verification

Quote Client

The QuoteClient takes an HttpClient wired to the quote server URL. Construct the HTTP client with HttpClient::with_quote_server(config) so that requests are routed to the dedicated quote endpoint (config.quote_server_url):

use tigeropen::client::http_client::HttpClient;
use tigeropen::config::ClientConfig;
use tigeropen::quote::QuoteClient;

let config = ClientConfig::builder().build()?;
let quote_http = HttpClient::with_quote_server(config);
let quote_client = QuoteClient::new(&quote_http);

Trade Client

The TradeClient takes a regular HttpClient and the trading account:

use tigeropen::client::http_client::HttpClient;
use tigeropen::config::ClientConfig;
use tigeropen::trade::TradeClient;

let config = ClientConfig::builder().build()?;
let account = config.account.clone();
let http = HttpClient::new(config);
let trade_client = TradeClient::new(&http, &account);

Push Client

The PushClient is constructed directly from the config and uses a Protobuf + TCP/TLS protocol. Connection is established with the free-standing async connect function:

use std::sync::Arc;
use tigeropen::config::ClientConfig;
use tigeropen::push::{connect, PushClient};

let config = ClientConfig::builder().build()?;
let push_client = Arc::new(PushClient::new(config, None));
connect(&push_client).await?;