Subscription APIs
Subscription APIs
Data streaming (data push) service is implemented by PushClient
object. To use those services , you need to initialize an instance of PushClient
first. Please see object list for a description of PushClient
. Our push services are all asynchronous functions. You need to implement your own callback function, to process the data pushed by the server.
The strategy for pushing subscription data is that subscription data with the same tigerId will only be pushed once. Therefore, only one valid tcp connection can be established for the same tigerId. If you try to create multiple tcp connections, the last one created will take effect, and the previous connection will be kicked out. If the quantitative strategy is deployed on multiple machines, it is recommended to subscribe to only one instance and share data internally.
Steps to use our push service:
Implement your callback function
Implement callback functions in
IApiComposeCallback
class, and pass inPushClient
object. You need to implement your own callback function, to process the data pushed by the server. For detailed examples, please see next section.Initialize TigerConfig
Construct a authentication object
TigerConfig
, use this object to initializePushClient
See the example below:TigerConfig.LogDir = "/data0/logs/tiger-openapi-cs"; config = new TigerConfig() { // The tiger_openapi_config.properties file is stored in your local directory. ConfigFilePath = "your local directory", // IsSslSocket = true; // default is true FailRetryCounts = 2, // (optional) range:[1, 5], default is 2 Language = Language.en_US, // (optional) default is en_US TimeZone = CustomTimeZone.HK_ZONE // (optional) default is HK_ZONE };
Initialize Push Client
Initialize
PushClient
:IApiComposeCallback callback = new DefaultApiComposeCallback(); PushClient client = PushClient.GetInstance().Config(config) .ApiComposeCallback(callback);
Connect to Sever
Call
client.Connect()
, use callbacks inIApiComposeCallback
to process the connection result messageUse Websocket Service
Use the methods of
PushClient
, such asPushClient.SubscribeQuote()
, to call relevant services. A list of methods is shown below.Disconnnect If you are done using the data feed pushed by the server, you can use
PushClien.Disconnect()
to disconnecet from the server. Using Disconnect() will cancel any remaining data feed subscription.
List of Available Data Push Services:
Account Change
Method | Description | Callback functiion |
---|---|---|
Subscribe | subscribe to account change | SubscribeEnd, OrderStatusChange, PositionChange, AssetChange, OrderTransactionChange |
CancelSubscribe | Cancel account change subscription | CancelSubscribeEnd |
Subscription
Method | Description | Callback functiion |
---|---|---|
SubscribeQuote | Subscribe to quote data | SubscribeEnd, QuoteChange, QuoteAskBidChange |
CancelSubscribeQuote | Cancel quote subscription | CancelSubscribeEnd |
SubscribeOption | Subscribe to option quote | SubscribeEnd, OptionChange, OptionAskBidChange |
CancelSubscribeOption | Cancel option quote subscription | CancelSubscribeEnd |
SubscribeFuture | Subscribe to future quote | SubscribeEnd, FutureChange, FutureAskBidChange |
CancelSubscribeFuture | Cancel future quote | CancelSubscribeEnd |
SubscribeDepthQuote | Subscribe depth quote | SubscribeEnd, DepthQuoteChange |
CancelSubscribeDepthQuote | Cancel depth quote subscription | CancelSubscribeEnd |
SubscribeTradeTick | Subscribe trade tick | SubscribeEnd, TradeTickChange |
CancelSubscribeTradeTick | Cancel trade tick subscription | CancelSubscribeEnd |
SubscribeStockTop | Subscribe stock top data | SubscribeEnd, StockTopPush |
CancelSubscribeStockTop | Cancel stock top subscription | CancelSubscribeEnd |
SubscribeOptionTop | Subscribe option top data | SubscribeEnd, OptionTopPush |
CancelSubscribeOptionTop | Cancel option top subscription | CancelSubscribeEnd |
SubscribeTradeTick | Subscribe full trade tick | SubscribeEnd, FullTickChange |
SubscribeKline | Subscribe minute kline | SubscribeEnd, KlineChange |
CancelSubscribeKline | Cancel minute kline subscription | CancelSubscribeEnd |
GetSubscribedSymbols | Get a List of Subscribed Symbols | GetSubscribedSymbolEnd |
Other Events
Events | Description |
---|---|
void ConnectAck() | Connection established |
void ConnectionClosed() | Connection closed |
void Error(String errorMsg) | Error |
void Error(int id, int errorCode, String errorMsg) | Error |
void ConnectionKickout(int errorCode, String errorMsg) | kicked by another connection.the sdk will close the local tcp connection. Please do not implement reconnection in this method, it will cause constant kicks and affect data push |
void HearBeat(String s) | connection heartbeat callback |