Go SDK
Tiger Open API Go SDK, providing market data queries, order placement, account management, and real-time push notifications.
- Requires Go 1.20 or higher
- Source repository: openapi-go-sdk
Installation
go get github.com/tigerfintech/openapi-go-sdkRequires Go 1.20 or higher.
Configuration
The SDK supports multiple configuration methods. Priority: Environment Variables > Code 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)
// Specify a config file path
cfg, err := config.NewClientConfig(
config.WithPropertiesFile("/path/to/tiger_openapi_config.properties"),
)
// Or pass no arguments — SDK auto-discovers the config file
cfg, err := config.NewClientConfig()Configuration file format:
tiger_id=your_developer_id
private_key=your_rsa_private_key
account=your_trading_account
license=TBUSMethod 2: Set directly in code
cfg, err := config.NewClientConfig(
config.WithTigerID("your_tiger_id"),
config.WithPrivateKey("your_rsa_private_key"),
config.WithAccount("your_trading_account"),
)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 (zh_CN/zh_TW/en_US) | No | zh_CN |
| timeout | Request timeout | No | 15s |
| token | TBHK license token | No | - |
Auto-Detection
- Device ID: Automatically detected from network interface MAC address
- 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 SDK provides a dedicated quote HTTP client NewQuoteHttpClient that automatically uses the quote server URL:
cfg, _ := config.NewClientConfig()
quoteHttpClient := client.NewQuoteHttpClient(cfg)
qc := quote.NewQuoteClient(quoteHttpClient)Requests and Responses
All responses are strongly typed
Every method returns a concrete struct (or slice/pointer) defined in the model package — you don't have to call json.Unmarshal yourself:
briefs, _ := qc.GetBrief(model.BriefRequest{Symbols: []string{"AAPL", "TSLA"}})
for _, b := range briefs {
fmt.Printf("%s latestPrice=%.2f\n", b.Symbol, b.LatestPrice)
}
placed, _ := tc.PlaceOrder(order)
fmt.Println("order id:", placed.ID)Common return types:
| Data shape | Return type |
|---|---|
| Multi-symbol quotes / positions / orders | []model.Brief / []model.Position / []model.Order |
| Single aggregate object | *model.PrimeAsset / *model.CapitalDistribution / *model.PreviewResult |
| Place / modify / cancel order | *model.PlaceOrderResult / *model.OrderIDResult |
Request parameter style (Go idioms)
- Few required parameters (≤3) — positional arguments:
GetBrief(symbols)/GetKline(symbol, period)/GetCapitalFlow(symbol, market, period). - Many parameters or optional fields — Request struct:
GetFinancialDaily(FinancialDailyRequest{...})/GetFutureKline(FutureKlineRequest{...})/MarketScanner(MarketScannerRequest{...})/PlaceOrder(OrderRequest{...}). - Request struct
jsontags aresnake_caseto match the server wire format; response structjsontags arecamelCase.
Updated 15 days ago
