Preparation
Environment requirement
- Operation system requirement:
- Windows
- MacOS
- Linux
- Solaris
- C# 8.0+ .NET 6.0+
Install .NET
To minimize compatibility issues, we recommend you to install Visual Studio 2022 + .NET 6.0
Install latest version .NET:
- Access Official Website: https://dotnet.microsoft.com/download/dotnet-core
- Install the .NET, verify version:
dotnet --version
Install Tiger Open API C# SDK
Method 1:Use Nuget Depository(Recommended)
Use nuget install or upgrade sdk version in cmd :
$ dotnet add package TigerOpenAPI --version 1.1.0
Method 2:Github Code Repository
The source code of the SDK project is published on Github code repositories
git address:
https://github.com/tigerfintech/openapi-cs-sdk/
You can choose to clone/download the source code from the code repository and package manually.
Install IDE
We recommend using Visual Studio as the IDE
Official Download Page:
https://visualstudio.microsoft.com/
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/C# private key format is different from that used by the python/C++ SDK. The Java/C# 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 TigerConfig.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 IP 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 class Demo
{
static QuoteClient quoteClient;
static TradeClient tradeClient;
static Demo() {
// set log directory. log file name: tiger_openapi.2023-02-22.log
TigerConfig.LogDir = "/data0/logs/tiger-openapi-cs";
// ApiLogger.DebugEnabled = true; // debug level for test
// tiger config
TigerConfig config = new TigerConfig()
{
// The tiger_openapi_config.properties file is stored in your local directory.
ConfigFilePath = "/data0/tiger_config", // your local directory
Language = Language.en_US, // (optional) default is en_US
TimeZone = CustomTimeZone.HK_ZONE // (optional) default is HK_ZONE
// IsSslSocket = true, // default is true
// AutoGrabPermission = true, // (optional) default is true
// FailRetryCounts = 2, // (optional) fail retry count, range:[1, 5], default is 2
// AutoRefreshToken = true, // default is true, only support 'TBHK' license
// RefreshTokenIntervalDays = 5, // default is 5; refresh the token every 5 days
// RefreshTokenTime = "12:30:00", // default is empty, formate is HH:mm:ss
// SecretKey = "xxxxxx", // Institutional user private key
};
quoteClient = new QuoteClient(config);
tradeClient = new TradeClient(config);
}
}
Configuration instructions:
- TigerConfig.ConfigFilePath: The directory wherestored.tiger_openapi_config.properties and tiger_openapi_token.properties are stored
- TigerConfig.TigerId:tigerId(tiger_openapi_config.properties file configuration priority)
- TigerConfig.DefaultAccount:account,prime account or paper account(tiger_openapi_config.properties file configuration priority)
- TigerConfig.PrivateKey:RSA key(tiger_openapi_config.properties file configuration priority)
- TigerConfig.SecretKey:It is the key of an institutional trader. If you are an institutional user, you need to configure this information
- TigerConfig.IsSslSocket:Whether the socket uses SSL
- TigerConfig.AutoGrabPermission:Whether to grab quote permission for this device during initialization
- TigerConfig.AutoRefreshToken:auto refresh token
- TigerConfig.FailRetryCounts:The number of retries for API request failures, up to 5 times
- TigerConfig.TimeZone:The default time zone, used when requesting the API
- TigerConfig.Language:The default language, used when requesting the API