Preparation
Environment requirement
- Operation system requirement:
- Windows
- MacOS
- Linux
- Solaris
- JDK 1.7+
Install Java Development Kit
To minimize compatibility issues, we recommend you to install the version of JDK 1.8+
Install latest version JDK:
- Access Oracle Website: https://www.oracle.com/java/technologies/downloads/
- Install the JDK
Install Tiger Open API Java SDK
Method 1:Use Maven Depository Dependency(Recommended)
It is recommended that you get the SDK by adding Maven dependencies. Java developers can get the Java SDK through the Maven repository, which will be updated from time to time, the latest version is as follows.
Please add the following code to the pom.xml file.
<dependency>
<groupId>io.github.tigerbrokers</groupId>
<artifactId>openapi-java-sdk</artifactId>
<version>2.2.1</version>
</dependency>
Method 2:Github/Gitee Code Repository
The source code of the SDK project is published on both Github and Gitee code repositories
git address:
https://github.com/tigerbrokers/openapi-java-sdk
gitee address:
https://gitee.com/tigerbrokers/openapi-java-sdk
You can choose to clone/download the source code from the code repository and add the dependencies manually.
Install IDE
We recommend using IntelliJ IDEA as the IDE
Official Download Page:
https://www.jetbrains.com/idea/download/
Registered Developer Information
Before using the OpenAPI, please apply for permission. Personal users can register as developers on the API website registered, and institutional users can access the Institutional Account Center. Please use Chrome for this page
To access the Open API, you need to Open a tiger account and Funded.
During the registration process, you will be asked to sign an API authorization agreement, Then you need to complete the developer information registration on this page, please fill in and submit your information.
You can obtain the following information upon sucessful registration:
- tigerId: A unique Developer ID assgined by the OpenAPI platform. It is used to identify a developer,you have to pass in ID to use API.
- account: Account number,you will need to pass in your account number when you are calling trade related APIs。There are 3 types of accounts: global account, standard account and paper account.
- Global Account:a string beginning with capital letter U, example:U12300123,
- Prime Account:number(5 to 10 digit), example:51230321,
- Paper Account:17 digit number,example:20191106192858300,
Only active accounts with balance will be shown on the page, if an user has both active global account and standard account, they will both be shown on the developer info page.
Developer Register Page: Use your phone and verifyCode to register.
Developer Info Page: Tiger ID,Live Account,Paper Account,License Info will be used in SDK.
Attention:You need to keep the privateKey in the picture below locally and keep it properly to prevent leakage, please update it in time if you find leakage. The private key will not be saved on the Tiger server, users need to save it before refreshing the page. The private key will disappear automatically after the page is refreshed. If the private key is not saved, you can replace it by re-generate
button.
After regeneration, download the tiger_openapi_config.properties file to the local. Copy the tiger_openapi_config.properties file to the directory configured by ClientConfig.DEFAULT_CONFIG.configFilePath.
The content format of the tiger_openapi_config.properties file is as follows. ‘account’ is the default account, which can be replaced between the prime account and the paper account.
private_key_pk1=MIICXgIBAAKBgQCodM4fM5cz+tj8SUuxxSbSMFxNHM23hftjAuXr9THweyFtTmA/mxwo9HYEhYjxCgYAJt78xbzw7aiKu+pI45O8il8ns6UL3mT59QlCKu0+FZmF2g54teyqoiol71xcM096D3ss0oJzKGt+btvlBzdcrXM6+pZqbK14ASWGE4uBEQIDAQABAoGAX5iBjFVTngzhbDIQAZ73C9qj1qLc3yPqZ+KyJbgskeLeMlCC8DWOwnMQMjqxXtAoXZexfVKdiT/lIG3JY3m6URzfYwJt5VUD9LeIcyPxuj7Eg2vxlZwJ6slT7DQ6LJCbUe1PUDlKKXYe/wEUNJ3dEJ/eFEhR8vNyFlW8DJj+az0CQQDhQwYUZIcq+9WDcSen5Sm5oS765aMAyWcOdkpokau+fZ/H9NwT0U+jaEHyswZMJBTDJ42iS8HV0MuGdtLJ7JzHAkEAv3Fq1AHHJ1Tyxtf/VWHBRfx304NFlDX87Ji7uyv1t+05ZYVT0U8Q5CUPdBA3QexMBKd1i6BXUH/xOY5aX+UrZwJBAKR7ej79wK0kQh2+TESOUs9W4KUXdNSoO3YV7fM5Gvz3Yepx4xkdZ1dcU3tSObDzT63IfeUaCCmGUnaW4QfMnBUCQQCMOsK6mrbLe7D9sBgK7bkJz73iA+UChG1IzTOuDaxGVpDVaU0VI2pHA1KHfJ1NP44LVrKGXSO4Bo+mzjwqxA3/AkEApA8roUKXtKTqC2rb8hs5AscMpHFUl7ZbVeKX14gAg9QPWxkh8BcB1dljAsrp7irEtq4VezD2Cf40b52Fcx+pvA==
private_key_pk8=MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAKh0zh8zlzP62PxJS7HFJtIwXE0czbeF+2MC5ev1MfB7IW1OYD+bHCj0dgSFiPEKBgAm3vzFvPDtqIq76kjjk7yKXyezpQveZPn1CUIq7T4VmYXaDni17KqiKiXvXFwzT3oPeyzSgnMoa35u2+UHN1ytczr6lmpsrXgBJYYTi4ERAgMBAAECgYBfmIGMVVOeDOFsMhABnvcL2qPWotzfI+pn4rIluCyR4t4yUILwNY7CcxAyOrFe0Chdl7F9Up2JP+UgbcljebpRHN9jAm3lVQP0t4hzI/G6PsSDa/GVnAnqyVPsNDoskJtR7U9QOUopdh7/ARQ0nd0Qn94USFHy83IWVbwMmP5rPQJBAOFDBhRkhyr71YNxJ6flKbmhLvrlowDJZw52SmiRq759n8f03BPRT6NoQfKzBkwkFMMnjaJLwdXQy4Z20snsnMcCQQC/cWrUAccnVPLG1/9VYcFF/HfTg0WUNfzsmLu7K/W37TllhVPRTxDkJQ90EDdB7EwEp3WLoFdQf/E5jlpf5StnAkEApHt6Pv3ArSRCHb5MRI5Sz1bgpRd01Kg7dhXt8zka/Pdh6nHjGR1nV1xTe1I5sPNPrch95RoIKYZSdpbhB8ycFQJBAIw6wrqatst7sP2wGArtuQnPveID5QKEbUjNM64NrEZWkNVpTRUjakcDUod8nU0/jgtWsoZdI7gGj6bOPCrEDf8CQQCkDyuhQpe0pOoLatvyGzkCxwykcVSXtltV4pfXiACD1A9bGSHwFwHV2WMCyunuKsS2rhV7MPYJ/jRvnYVzH6m8
tiger_id=20150001
account=12345678
license=TBHK
env=PROD
RSA Keys
The Tiger Open API uses RSA for authentication. RSA encryption is used to secure user interface requests. The RSA bidirectional signature authentication mechanism is used to prevent interface requests from being maliciously tampered. The private key is saved locally by the user.
Attention:
- The Java private key format is different from that used by the Java SDK. The Java private key format is PKCS#8. If any problem occurs when you use the SDK, please check whether the private key is in the correct format first
Token(Optional)
The TBHK license (users of other licenses can ignore it) needs to generate a token. After the token expires, it needs to be regenerated, and download the tiger_openapi_token.properties file to the local. Copy the tiger_openapi_token.properties file to the directory configured by ClientConfig.DEFAULT_CONFIG.configFilePath. The validity period of the token is 15 days. If it expires, you need to regenerate and export a new token file on the developer information page. Before it expires, it can be refreshed by API. SDK default implementation: refresh the token every 5 days, and update the local tiger_openapi_token.properties file at the same time, Configurable automatic refresh cycle days (refreshTokenIntervalDays) and specific time (refreshTokenTime). If you need to refresh the token yourself, please configure clientConfig.isAutoRefreshToken = false.
additional configuration, optional
Title | Required | Description |
---|---|---|
IP White List | No | Only IP addresses in the white list can access Tiger API,use “;” to divide multiple IPs |
Callback URL | No | customized callback URL of users's program, used for receive the message for update on order and account status, user can also use the callback function provided in the SDK to receive callback messages |
Subscribing to Market Data (Optional)
We offer our users free access to delayed market data for the U.S market. Our customers from Mainland China will also get free Level 2 Quote Subscription for HK market. Live quotes data are also available for a fee. Please note that Open API is an independent service from our APP, and API data need to be purchase seperately. Please follow the instructions below to subscribe market data for API:
Individuals
1.Login Personal Center to purchase quote.
2.Go to Tiger Trade APP - Profile- Market Data Store- OpenAPI and select from the subscription list shown on this page
Institutional user
Go to Tiger Brokers Institutional Account Center - Market Data and subscribe
API Config
Before using the API, you need to complete the relevant configuration of the API interface call. Specific configuration information (including tigerId, account, license, privateKey and other configurations, the value of the tiger_openapi_config.properties file is preferred) can be found on the developer information page.
For users holding TBHK license, 'tiger_openapi_token.properties' configuration file is required. This file must be placed in the path specified by 'configFilePath'
public static ClientConfig clientConfig = ClientConfig.DEFAULT_CONFIG;
public static TigerHttpClient client;
static {
// set log directory. log file name: tiger_openapi.2023-02-22.log
ApiLogger.setEnabled(true, "/data/tiger_openapi/logs/");
// ApiLogger.setDebugEnabled(false); // ouput debug level log
// The tiger_openapi_config.properties file is stored in your local directory.
clientConfig.configFilePath = "/data/tiger_config";
// clientConfig.isSslSocket = true; // default is true
// clientConfig.isAutoGrabPermission = true;// default is true
// clientConfig.failRetryCounts = 2; // fail retry count, default is 2
// clientConfig.timeZone = TimeZoneId.Shanghai; // default time zone
// clientConfig.language = Language.en_US; // default language
// clientConfig.isAutoRefreshToken = true; // default is true, only support 'TBHK' license
// clientConfig.refreshTokenIntervalDays = 5; // default is 5; refresh the token every 5 days
// clientConfig.refreshTokenTime = "12:30:00"; // default is empty, HH:mm:ss
// clientConfig.secretKey = "xxxxxx";// Institutional user private key
client = TigerHttpClient.getInstance().clientConfig(clientConfig);
}
Configuration instructions:
- clientConfig.configFilePath: The directory wherestored.tiger_openapi_config.properties and tiger_openapi_token.properties are stored
- clientConfig.tigerId:tigerId(tiger_openapi_config.properties file configuration priority)
- clientConfig.defaultAccount:account,prime account or paper account(tiger_openapi_config.properties file configuration priority)
- clientConfig.privateKey:RSA key(tiger_openapi_config.properties file configuration priority)
- clientConfig.secretKey:It is the key of an institutional trader. If you are an institutional user, you need to configure this information
- clientConfig.isSslSocket:Whether the socket uses SSL
- clientConfig.isAutoGrabPermission:Whether to grab quote permission for this device during initialization
- clientConfig.failRetryCounts:The number of retries for API request failures, up to 5 times
- clientConfig.timeZone:The default time zone, used when requesting the API
- clientConfig.language:The default language, used when requesting the API