Subscription APIs
Subscription APIs
Data streaming (data push) service is implemented by WebSocketClient
object. To use those services , you need to initialize an instance of WebSocketClient
first. Please see object list for a description of WebSocketClient
. 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
ApiComposeCallback
class, and pass inWebSocketClient
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 an instance of ApiAuthentication
Construct a authentication object
ApiAuthentication
, use this object to initializeWebSocketClient
See the example below:ClientConfig clientConfig = ClientConfig.DEFAULT_CONFIG; // The tiger_openapi_config.properties file is stored in your local directory. clientConfig.configFilePath = "your local directory"; // clientConfig.isSslSocket = true; // default is true ApiAuthentication authentication = ApiAuthentication.build(clientConfig.tigerId, clientConfig.privateKey);
Initialize Websocket Client
Initialize
WebSocketClient
:WebSocketClient client = WebSocketClient.getInstance().clientConfig(clientConfig).apiComposeCallback(new DefaultApiComposeCallback());
Connect to Sever
Call WebSocketClient.connect(), use callbacks in
ApiComposeCallback
to process the connection result messageUse Websocket Service
Use the methods of
WebSocketClient
, such asWebSocketClient.subscribe()
, 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
WebSocketClient.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 |