Rust SDK
Tiger Open API Rust SDK, providing market data queries, order placement, account management, and real-time push notifications.
- Requires Rust 1.70 or higher
- Source repository: openapi-rust-sdk
- Crates.io: tigeropen
v0.3.0 introduces a fully typed request/response API. Every
QuoteClient/TradeClientmethod returns a domain type (e.g.Vec<Brief>,Vec<Kline>,Vec<Order>,Option<PlaceOrderResult>) instead ofOption<serde_json::Value>. Request structs serialize tosnake_caseon the wire and responses parsecamelCaseinto 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):
- Current directory:
./tiger_openapi_config.properties - 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=TBUSMethod 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 licenseConfiguration Options
| Option | Description | Required | Default |
|---|---|---|---|
| tiger_id | Developer ID | Yes | - |
| private_key | RSA private key (PK1 and PK8 compatible) | Yes | - |
| account | Trading account | No | - |
| license | License type (e.g. TBUS) | No | - |
| language | Language (ZhCn/EnUs) | No | ZhCn |
| timeout | Request timeout | No | 15s |
| token | TBHK license token | No | - |
Auto-Detection
- Device ID: Automatically detected from network interface MAC address (
mac_addresscrate) - 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-QUOTEdomain 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("e_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?;Updated 17 days ago
