TypeScript SDK
Tiger Open API TypeScript SDK, providing market data queries, order placement, account management, and real-time push notifications.
- Requires Node.js >= 16.0.0
- Supports both ESM and CommonJS
- Source repository: openapi-typescript-sdk
- npm packages:
@tigeropenapi/tigeropen(scoped) andtigeropen(unscoped alias)
v0.3.0 introduces a fully typed request/response API. Every
QuoteClient/TradeClientmethod returns a domain object (e.g.Brief,Kline,Order,PlaceOrderResult) instead of a rawApiResponseenvelope. Request parameters are written in idiomatic camelCase in TypeScript and the client automatically converts them tosnake_caseon the wire. Array responses that the server wraps in{ items: [...] }are unwrapped for you. See CHANGELOG.
Installation
npm install @tigeropenapi/tigeropen
# or the unscoped alias
npm install tigeropen
# or
yarn add @tigeropenapi/tigeropen
# or
pnpm add @tigeropenapi/tigeropenRequires Node.js >= 16.0.0.
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)
import { createClientConfig } from '@tigeropenapi/tigeropen';
// Specify a config file path
const config = createClientConfig({
propertiesFilePath: '/path/to/tiger_openapi_config.properties',
});
// Or pass no arguments — SDK auto-discovers the config file
const config = createClientConfig();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
import { createClientConfig } from '@tigeropenapi/tigeropen';
const config = createClientConfig({
tigerId: 'your_tiger_id',
privateKey: 'your_rsa_private_key',
account: '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 |
|---|---|---|---|
| tigerId | Developer ID | Yes | - |
| privateKey | RSA private key (PK1 and PK8 compatible) | Yes | - |
| account | Trading account | No | - |
| license | License type (e.g. TBUS) | No | - |
| language | Language (zh_CN/en_US) | No | zh_CN |
| timeout | Request timeout (seconds) | No | 15 |
| token | TBHK license token | No | - |
Auto-Detection
- Device ID: Automatically detected from network interface MAC address (
os.networkInterfaces()) - 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 configured to talk to the quote server. Pass { useQuoteServerUrl: true } as the third HttpClient argument so that requests are routed to the quote endpoint:
import {
createClientConfig,
HttpClient,
QuoteClient,
} from '@tigeropenapi/tigeropen';
const config = createClientConfig();
const quoteHttpClient = new HttpClient(config, undefined, { useQuoteServerUrl: true });
const quoteClient = new QuoteClient(quoteHttpClient);Trade Client
The TradeClient takes a regular HttpClient and the trading account:
import {
createClientConfig,
HttpClient,
TradeClient,
} from '@tigeropenapi/tigeropen';
const config = createClientConfig();
const tradeClient = new TradeClient(new HttpClient(config), config.account);Push Client
The PushClient is constructed directly from the config and uses a Protobuf + TLS protocol:
import { createClientConfig, PushClient } from '@tigeropenapi/tigeropen';
const config = createClientConfig();
const pushClient = new PushClient(config);
await pushClient.connect();Updated 17 days ago
