Quotation Subscription Push
Subscribe to Stock Quotes
subscribeQuote(Set<String> symbols)
Cancellation Method
cancelSubscribeQuote(Set<String> symbols)
Description
The subscription API provides stock quote data subscription services, allowing real-time access to quote change information.
The quote subscription push interface is an asynchronous interface. By implementing the ApiComposeCallback interface, you can obtain asynchronous request results.
The callback interface returns result types as basic quote QuoteBasicData objects and best bid/offer QuoteBBOData objects.
Input Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| symbols | Set<String> | Yes | Stock symbol list, stock symbol format: e.g., AAPL, 00700 |
Return Value
| Field | Type | Description |
|---|---|---|
| id | string | ID generated locally by the SDK when making a subscription request, incrementally sequential. Returns the request ID and subscription success result in the subscribeEnd(int id, String subject, String result) callback method |
Callback Interfaces
void quoteChange(QuoteBasicData data)void quoteAskBidChange(QuoteBBOData data)
Example
Define callback interfaces. After successful subscription, data will be received in the corresponding interfaces of this callback class.
package com.tigerbrokers.stock.openapi.demo;
import com.tigerbrokers.stock.openapi.client.socket.ApiComposeCallback;
import com.tigerbrokers.stock.openapi.client.socket.data.TradeTick;
import com.tigerbrokers.stock.openapi.client.socket.data.pb.AssetData;
import com.tigerbrokers.stock.openapi.client.socket.data.pb.KlineData;
import com.tigerbrokers.stock.openapi.client.socket.data.pb.OptionTopData;
import com.tigerbrokers.stock.openapi.client.socket.data.pb.OrderStatusData;
import com.tigerbrokers.stock.openapi.client.socket.data.pb.OrderTransactionData;
import com.tigerbrokers.stock.openapi.client.socket.data.pb.PositionData;
import com.tigerbrokers.stock.openapi.client.socket.data.pb.QuoteBBOData;
import com.tigerbrokers.stock.openapi.client.socket.data.pb.QuoteBasicData;
import com.tigerbrokers.stock.openapi.client.socket.data.pb.QuoteDepthData;
import com.tigerbrokers.stock.openapi.client.socket.data.pb.StockTopData;
import com.tigerbrokers.stock.openapi.client.socket.data.pb.TickData;
import com.tigerbrokers.stock.openapi.client.struct.SubscribedSymbol;
import com.tigerbrokers.stock.openapi.client.util.ApiLogger;
import com.tigerbrokers.stock.openapi.client.util.ProtoMessageUtil;
public class DefaultApiComposeCallback implements ApiComposeCallback {
/*Stock basic quote callback*/
@Override
public void quoteChange(QuoteBasicData data) {
ApiLogger.info("quoteChange:" + ProtoMessageUtil.toJson(data));
}
/*Stock best bid/ask quote callback*/
@Override
public void quoteAskBidChange(QuoteBBOData data) {
ApiLogger.info("quoteAskBidChange:" + ProtoMessageUtil.toJson(data));
}
/*Option quote callback*/
@Override
public void optionChange(QuoteBasicData data) {
ApiLogger.info("optionChange:" + ProtoMessageUtil.toJson(data));
}
/*Option best bid/ask quote callback*/
@Override
public void optionAskBidChange(QuoteBBOData data) {
ApiLogger.info("optionAskBidChange:" + ProtoMessageUtil.toJson(data));
}
/*Future quote callback*/
@Override
public void futureChange(QuoteBasicData data) {
ApiLogger.info("futureChange:" + ProtoMessageUtil.toJson(data));
}
/*Future best bid/ask quote callback*/
@Override
public void futureAskBidChange(QuoteBBOData data) {
ApiLogger.info("futureAskBidChange:" + ProtoMessageUtil.toJson(data));
}
/*Depth quote callback*/
@Override
public void depthQuoteChange(QuoteDepthData data) {
ApiLogger.info("depthQuoteChange:" + ProtoMessageUtil.toJson(data));
}
/*Tick-by-tick trade data callback*/
@Override
public void tradeTickChange(TradeTick data) {
ApiLogger.info("tradeTickChange:" + JacksonUtil.writeValueAsString(data));
}
/*Full tick-by-tick trade data callback*/
@Override
public void fullTickChange(TickData data) {
ApiLogger.info("fullTickChange:" + ProtoMessageUtil.toJson(data));
}
/*Minute K-line data callback*/
@Override
public void klineChange(KlineData data) {
ApiLogger.info("klineChange:" + ProtoMessageUtil.toJson(data));
}
/**Stock quote ranking data push*/
@Override
public void stockTopPush(StockTopData data) {
ApiLogger.info("stockTopPush, market:" + data.getMarket());
for (StockTopData.TopData topData : data.getTopDataList()) {
ApiLogger.info("stockTopPush, targetName:" + topData.getTargetName()
+ ", topList:" + ProtoMessageUtil.toJson(topData));
}
}
/**Option quote ranking data push*/
@Override
public void optionTopPush(OptionTopData data) {
ApiLogger.info("optionTopPush, market:" + data.getMarket());
for (OptionTopData.TopData topData : data.getTopDataList()) {
ApiLogger.info("optionTopPush, targetName:" + topData.getTargetName()
+ ", topList:" + ProtoMessageUtil.toJson(topData));
}
}
/*Subscription success callback*/
@Override
public void subscribeEnd(int id, String subject, String result) {
ApiLogger.info("subscribe " + subject + " end. id:" + id + ", " + result);
}
/*Cancel subscription callback*/
@Override
public void cancelSubscribeEnd(int id, String subject, String result) {
ApiLogger.info("cancel subscribe " + subject + " end. id:" + id + ", " + result);
}
/*Query subscribed symbol callback*/
@Override
public void getSubscribedSymbolEnd(SubscribedSymbol subscribedSymbol) {
ApiLogger.info("getSubscribedSymbolEnd:" + JSONObject.toJSONString(subscribedSymbol));
}
}Perform subscription
public class WebSocketDemo {
//When actually subscribing, you need to fill in tigerId and privateKey, and implement the ApiComposeCallback interface. The example uses DefaultApiComposeCallback
private static ClientConfig clientConfig = ClientConfig.DEFAULT_CONFIG;
private static WebSocketClient client;
static {
//Path where configuration files tiger_openapi_config.properties and tiger_openapi_token.properties exported from developer information page are stored
clientConfig.configFilePath = "/data/tiger_config";
// clientConfig.secretKey = "xxxxxx";// institutional trader private key
client = WebSocketClient.getInstance().clientConfig(clientConfig).apiComposeCallback(new DefaultApiComposeCallback());
}
public static void subscribe() {
client.connect();
Set<String> symbols = new HashSet<>();
//Stock subscription
symbols.add("AAPL");
symbols.add("SPY");
//Subscribe to related symbols
client.subscribeQuote(symbols);
//Subscribe to depth data (stocks only)
client.subscribeDepthQuote(symbols);
//Query subscription details
client.getSubscribedSymbols();
//Wait to receive data
TimeUnit.SECONDS.sleep(60000);
//Cancel subscription
client.cancelSubscribeQuote(symbols);
client.cancelSubscribeDepthQuote(symbols);
//Cancel all symbol (stock, option, future) quote subscriptions
client.cancelSubscribeQuote(new HashSet<>());
//Cancel all symbol (stock, future) depth quote subscriptions
client.cancelSubscribeDepthQuote(new HashSet<>());
//Cancel all symbol (stock, future) tick-by-tick quote subscriptions
client.cancelSubscribeTradeTick(new HashSet<>());
//Note: Actively disconnecting will clear all subscription data
//client.disconnect();
}
}Return Data
For all fields in stock quote callback data, refer to: Quote Push Data
CAUTION
Stock quote callback data has two types: basic quote
QuoteBasicDataand best bid/offerQuoteBBOData. The two data types return different fields.
Hong Kong stock quote data example:
{
"symbol":"00700",
"type":"BASIC",
"timestamp":"1684721758123",
"serverTimestamp":"1684721758228",
"avgPrice":330.493,
"latestPrice":332.2,
"latestPriceTimestamp":"1684721758103",
"latestTime":"05-22 10:15:58",
"preClose":333.2,
"volume":"4400026",
"amount":1454057948,
"open":331.8,
"high":334.2,
"low":328.2,
"marketStatus":"Trading",
"mi":{
"p":332.2,
"a":330.493,
"t":"1684721700000",
"v":"75400",
"o":331.6,
"h":332.2,
"l":331.4
}
}Hong Kong stock best bid/ask quote data example:
{
"symbol":"00700",
"type":"BBO",
"timestamp":"1684721757927",
"askPrice":332.2,
"askSize":"32100",
"askTimestamp":"1684721757344",
"bidPrice":332,
"bidSize":"3500",
"bidTimestamp":"1684721757773"
}US stock quote data example:
{
"symbol":"AAPL",
"type":"BASIC",
"timestamp":"1684766012120",
"serverTimestamp":"1684766012129",
"avgPrice":174.1721,
"latestPrice":174.175,
"latestPriceTimestamp":"1684766011918",
"latestTime":"05-22 10:33:31 EDT",
"preClose":175.16,
"volume":"12314802",
"amount":2144365591.410586,
"open":173.98,
"high":174.71,
"low":173.45,
"marketStatus":"Trading",
"mi":{
"p":174.175,
"a":174.1721,
"t":"1684765980000",
"v":"57641",
"o":174.21,
"h":174.22,
"l":174.14
}
}US stock order book data example:
{
"symbol":"AAPL",
"type":"BBO",
"timestamp":"1676992715509",
"askPrice":149.96,
"askSize":"200",
"askTimestamp":"1676992715367",
"bidPrice":149.94,
"bidSize":"700",
"bidTimestamp":"1676992715367"
}US stock pre-market trading data example:
CAUTION
The fields for US stock pre-market and after-hours trading are different from regular trading hours
{
"symbol":"AAPL",
"type":"BASIC",
"timestamp":"1684753559744",
"serverTimestamp":"1684753559752",
"latestPrice":173.66,
"latestPriceTimestamp":"1684753559744",
"latestTime":"07:05 EDT",
"preClose":175.16,
"volume":"366849",
"amount":63731858.18000001,
"hourTradingTag":"PreMarket",
"mi":{
"p":173.66,
"a":173.72891,
"t":"1684753500000",
"v":"5604",
"o":173.64,
"h":173.67,
"l":173.63
}
}Subscribe to Option Quotes
subscribeOption(Set<String> symbols)
Cancellation Method
cancelSubscribeOption(Set<String> symbols)
Description
Subscribe to option quotes (supports US and Hong Kong market options).
The quote subscription push interface is an asynchronous interface. By implementing the ApiComposeCallback interface, you can obtain asynchronous request results.
The callback interface returns result types as basic quote QuoteBasicData objects and best bid/offer QuoteBBOData objects.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| symbols | Set<String> | Yes | Option symbol list |
Option symbol format: Option symbols support 2 formats
- One format is symbol name + expiration date + strike price + direction, separated by spaces. E.g., (AAPL 20190329 182.5 PUT).
- The other format is identifier, which is returned when querying option quotes. E.g., (SPY 190508C00290000)
Return Value
| Field | Type | Description |
|---|---|---|
| id | string | ID generated locally by the SDK when making a subscription request, incrementally sequential. Returns the request ID and subscription success result in the subscribeEnd(int id, String subject, String result) callback method |
Subscription Example
Set<String> symbols = new HashSet<>();
//One way to subscribe to options
symbols.add("AAPL 20230317 150.0 CALL");
symbols.add("ALB.HK 20250730 117.50 CALL");
//Another way to subscribe to options
symbols.add("SPY 190508C00290000");
client.subscribeOption(symbols);
//Wait to receive the data
TimeUnit.SECONDS.sleep(120000);
// Cancel subscription
client.cancelSubscribeOption(symbols);Corresponding Callback Interfaces
void optionChange(QuoteBasicData data)void optionAskBidChange(QuoteBBOData data)
Return Data
Option trading data example:
{
"symbol":"AAPL 20230317 150.0 CALL",
"type":"BASIC",
"timestamp":"1676994444927",
"latestPrice":4.83,
"latestPriceTimestamp":"1676994444927",
"latestTime":"",
"preClose":6.21,
"volume":"3181",
"amount":939117.0060634613,
"open":4.85,
"high":5.6,
"low":4.64,
"identifier":"AAPL 230317C00150000",
"openInt":"82677"
}Option order book data example:
{
"symbol":"AAPL 20230317 150.0 CALL",
"type":"BBO",
"timestamp":"1676994393156",
"askPrice":4.85,
"askSize":"11",
"askTimestamp":"1676994393156",
"bidPrice":4.8,
"bidSize":"992",
"bidTimestamp":"1676994390931"
}Subscribe to Future Quotes
subscribeFuture(Set<String> symbols)
Cancellation Method
cancelSubscribeFuture(Set<String> symbols)
Description
Subscribe to future quotes.
The quote subscription push interface is an asynchronous interface. By implementing the ApiComposeCallback interface, you can obtain asynchronous request results.
The callback interface returns result types as basic quote QuoteBasicData objects and best bid/offer QuoteBBOData objects.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| symbols | Set<String> | Yes | Future symbol list |
Return Value
| Field | Type | Description |
|---|---|---|
| id | string | ID generated locally by the SDK when making a subscription request, incrementally sequential. Returns the request ID and subscription success result in the subscribeEnd(int id, String subject, String result) callback method |
Example
Set<String> symbols = new HashSet<>();
//Future subscription
symbols.add("ESmain");
symbols.add("ES2306");
client.subscribeFuture(symbols);
//Wait to receive the data
TimeUnit.SECONDS.sleep(120000);
// Cancel subscription
client.cancelSubscribeFuture(symbols);Corresponding Callback Interfaces
void futureChange(QuoteBasicData data)void futureAskBidChange(QuoteBBOData data)
Return Example
Future quote data example:
{
"symbol":"ESmain",
"type":"BASIC",
"timestamp":"1684766824130",
"avgPrice":4206.476,
"latestPrice":4202.5,
"latestPriceTimestamp":"1684766824000",
"latestTime":"05-22 09:47:04 -0500",
"preClose":4204.75,
"volume":"557570",
"open":4189,
"high":4221.75,
"low":4186.5,
"marketStatus":"Trading",
"tradeTime":"1684766824000",
"preSettlement":4204.75,
"minTick":0.25,
"mi":{
"p":4202.25,
"a":4206.476,
"t":"1684766820000",
"v":"96",
"o":4202.25,
"h":4202.5,
"l":4202.0
}
}Future order book data example:
{
"symbol":"ESmain",
"type":"BBO",
"timestamp":"1684766824130",
"askPrice":4202.75,
"askSize":"70",
"askTimestamp":"1684766824129",
"bidPrice":4202.5,
"bidSize":"2",
"bidTimestamp":"1684766824130"
}Subscribe to Depth Quotes
subscribeDepthQuote(Set<String> symbols)
Cancellation Method
cancelSubscribeDepthQuote(Set<String> symbols)
Description
Subscribe to multi-level depth quotes, supporting stocks (US/HK), options (US/HK), and futures. US stock depth quotes push frequency is 300ms, Hong Kong stock depth quotes push frequency is 2s, returning up to 40 levels of bid/ask order data (Hong Kong stocks only have 10 levels).
The quote subscription push interface is an asynchronous interface. By implementing the ApiComposeCallback interface, you can obtain asynchronous request results.
The callback interface returns result type as QuoteDepthData objects.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| symbols | Set<String> | Yes | Stock, option, future symbol list |
Return Value
| Field | Type | Description |
|---|---|---|
| id | string | ID generated locally by the SDK when making a subscription request, incrementally sequential. Returns the request ID and subscription success result in the subscribeEnd(int id, String subject, String result) callback method |
Example
Set<String> symbols = new HashSet<>();
//Depth quote subscription
symbols.add("AAPL");
symbols.add("ESmain");
symbols.add("AAPL 20240209 180.0 CALL");
client.subscribeDepthQuote(symbols);
//Wait to receive the data
TimeUnit.SECONDS.sleep(120000);
// Cancel subscription
client.cancelSubscribeDepthQuote(symbols);Callback Interface
void depthQuoteChange(QuoteDepthData data)
Return Data
Data structure as follows:
| Field | Type | Description |
|---|---|---|
| symbol | string | Stock symbol |
| timestamp | long | Depth data timestamp |
| ask | List<OrderBook> | Ask data |
| bid | List<OrderBook> | Bid data |
OrderBook data structure as follows:
| Field | Type | Description |
|---|---|---|
| price | double | Price for each level |
| volume | long | Order volume |
| orderCount | int | Number of orders (only available for Hong Kong stocks) |
| exchange | string | Option data source (only available for options). If price or volume is 0, it means the quote from this data source is invalid. For enum values, see: Option Exchanges |
| time | long | Option exchange order timestamp (only available for options) |
Callback Result Example
// US Market
{
"symbol": "AAPL",
"timestamp": "1676993368405",
"ask": {
"price": [
149.69,
149.69,
149.69,
149.69,
149.69,
149.69,
149.7,
149.7,
149.7,
149.7,
149.7,
149.7,
149.7,
149.7,
149.7,
149.7,
149.71,
149.71,
149.71,
149.71,
149.71,
149.71,
149.71,
149.71,
149.72,
149.72,
149.72,
149.72,
149.72,
149.72,
149.72,
149.72,
149.72,
149.72,
149.73,
149.73,
149.73,
149.73,
149.73,
149.73
],
"volume": [
"100",
"100",
"23",
"200",
"100",
"100",
"200",
"100",
"100",
"100",
"82",
"100",
"100",
"200",
"25",
"100",
"185",
"100",
"100",
"82",
"87",
"25",
"100",
"100",
"100",
"100",
"76",
"200",
"100",
"100",
"16",
"87",
"100",
"100",
"100",
"100",
"200",
"100",
"76",
"100"
]
},
"bid": {
"price": [
149.68,
149.68,
149.68,
149.68,
149.67,
149.67,
149.67,
149.67,
149.67,
149.67,
149.67,
149.67,
149.66,
149.66,
149.66,
149.66,
149.66,
149.66,
149.66,
149.66,
149.66,
149.66,
149.66,
149.66,
149.66,
149.65,
149.65,
149.65,
149.65,
149.65,
149.65,
149.65,
149.65,
149.65,
149.65,
149.64,
149.64,
149.64,
149.64,
149.64
],
"volume": [
"84",
"87",
"100",
"100",
"100",
"49",
"100",
"100",
"87",
"200",
"100",
"100",
"100",
"100",
"100",
"20",
"1",
"4",
"1",
"200",
"100",
"87",
"25",
"100",
"200",
"200",
"100",
"1",
"25",
"87",
"100",
"100",
"100",
"25",
"100",
"100",
"100",
"1",
"87",
"100"
]
}
}
// HK Market
{
"symbol": "00700",
"timestamp": "1670465696884",
"ask": {
"price": [
311.4,
311.6,
311.8,
312.0,
312.2,
312.4,
312.6,
312.8,
313.0,
313.2
],
"volume": [
"15600",
"5700",
"16600",
"33800",
"61100",
"14800",
"28300",
"28400",
"61100",
"39200"
],
"orderCount": [
16,
13,
19,
79,
39,
29,
66,
56,
160,
27
]
},
"bid": {
"price": [
311.2,
311.0,
310.8,
310.6,
310.4,
310.2,
310.0,
309.8,
309.6,
309.4
],
"volume": [
"2300",
"8300",
"18000",
"8800",
"7700",
"8500",
"26700",
"11700",
"13700",
"22600"
],
"orderCount": [
10,
15,
18,
9,
6,
11,
17,
30,
10,
5
]
}
}Subscribe to Trade Tick Data
subscribeTradeTick(Set<String> symbols)
Cancel Method
cancelSubscribeTradeTick(Set<String> symbols)
Description
Subscribe to stock trade tick data. Trade tick push interval is 200ms, using snapshot mode, pushing the latest 50 trade tick records each time.
The trade tick subscription push interface is asynchronous. You can get asynchronous request results by implementing the ApiComposeCallback interface.
The callback interface returns results of type TradeTick object.
Supports subscription for US and Hong Kong market stocks and futures
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| symbols | Set<String> | Yes | Stock and futures code list |
Return Value
| Field | Type | Description |
|---|---|---|
| id | string | ID generated locally by SDK subscription request, incrementally sequenced. Returns request ID and subscription success result in subscribeEnd(int id, String subject, String result) callback method |
Subscription Example
Set<String> symbols = new HashSet<>();
//Trade tick stock subscription
symbols.add("AAPL");
symbols.add("00700");
symbols.add("ESmain");
client.subscribeTradeTick(symbols);
//Wait to receive the data
TimeUnit.SECONDS.sleep(120000);
// Cancel subscription
client.cancelSubscribeTradeTick(symbols);Corresponding Callback Interface
void tradeTickChange(TradeTick data)
TradeTick data structure is as follows:
| Field | Type | Description |
|---|---|---|
| symbol | string | Stock symbol, futures symbol |
| secType | SecType | STK/FUT |
| quoteLevel | string | Quote permission level from which data comes (for US stocks, usQuoteBasic has less trade tick data than usStockQuote); futures have no level distinction |
| timestamp | long | Data timestamp |
| ticks | List<Tick> | Trade tick data collection |
ticks data structure is as follows:
Field | Type | Description |
|---|---|---|
sn | long | Trade tick sequence number |
volume | long | Trade volume |
tickType | string |
|
price | double | Trade price |
time | long | Trade timestamp |
cond | string | Trade condition list for each tick. Empty array indicates automatic matching trades for current batch (futures trade ticks don't have this) |
partCode | string | Exchange code for each trade (US stocks only) |
partName | string | Exchange name for each trade (US stocks only) |
Callback Result Example
// US Stock
{
"symbol": "AAPL",
"secType": "STK",
"quoteLevel": "usQuoteBasic",
"timestamp": 1676993925700,
"ticks": [
{
"sn": 116202,
"volume": 50,
"tickType": "*",
"price": 149.665,
"time": 1676993924289,
"cond": "US_REGULAR_SALE"
},
{
"sn": 116203,
"volume": 1,
"tickType": "*",
"price": 149.68,
"time": 1676993924459,
"cond": "US_REGULAR_SALE"
},
{
"sn": 116204,
"volume": 1,
"tickType": "*",
"price": 149.67,
"time": 1676993925200,
"cond": "US_REGULAR_SALE"
},
{
"sn": 116205,
"volume": 5,
"tickType": "*",
"price": 149.6652,
"time": 1676993925410,
"cond": "US_REGULAR_SALE"
}
]
}
// Hong Kong Stock
{
"symbol": "00700",
"secType": "STK",
"quoteLevel": "hkStockQuoteLv2",
"timestamp": 1669345639970,
"ticks": [
{
"sn": 35115,
"volume": 300,
"tickType": "+",
"price": 269.2,
"time": 1669345639496,
"cond": "HK_AUTOMATCH_NORMAL"
},
{
"sn": 35116,
"volume": 200,
"tickType": "+",
"price": 269.2,
"time": 1669345639610,
"cond": "HK_AUTOMATCH_NORMAL"
}
]
}
// Futures trade tick
{
"symbol": "HSImain",
"secType": "FUT",
"timestamp": 1669345640575,
"ticks": [
{
"sn": 261560,
"volume": 1,
"price": 17465.0,
"time": 1669345639000
},
{
"sn": 261561,
"volume": 1,
"price": 17465.0,
"time": 1669345639000
},
{
"sn": 261562,
"volume": 1,
"price": 17465.0,
"time": 1669345639000
},
{
"sn": 261563,
"volume": 1,
"price": 17465.0,
"time": 1669345639000
}
]
}Subscribe to Full Trade Tick Data
subscribeTradeTick(Set<String> symbols)
Cancel Method
cancelSubscribeTradeTick(Set<String> symbols)
Description
Subscribe to full trade tick data for stocks. You need to apply for permission from the administrator. This is different from the previous snapshot trade tick data. After obtaining permission, you need to configure locally ClientConfig.DEFAULT_CONFIG.useFullTick = true;
The trade tick subscription push interface is asynchronous. You can get asynchronous request results by implementing the ApiComposeCallback interface.
The callback interface returns results of type TickData object.
Supports subscription for US and Hong Kong market stocks
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| symbols | Set<String> | Yes | Stock code list |
Return Value
| Field | Type | Description |
|---|---|---|
| id | string | ID generated locally by SDK subscription request, incrementally sequenced. Returns request ID and subscription success result in subscribeEnd(int id, String subject, String result) callback method |
Subscription Example
Set<String> symbols = new HashSet<>();
//Trade tick stock subscription
symbols.add("AAPL");
symbols.add("00700");
client.subscribeTradeTick(symbols);
//Wait to receive the data
TimeUnit.SECONDS.sleep(120000);
// Cancel subscription
client.cancelSubscribeTradeTick(symbols);Corresponding Callback Interface
void fullTickChange(TickData data)
TickData data structure is as follows:
| Field | Type | Description |
|---|---|---|
| symbol | string | Stock symbol |
| timestamp | long | Data timestamp |
| ticks | List<Tick> | Trade tick data collection |
ticks data structure is as follows:
Field | Type | Description |
|---|---|---|
sn | long | Trade tick sequence number |
time | long | Trade timestamp |
price | float | Trade price |
volume | long | Trade volume |
type | string |
|
cond | string | Trade condition list for each tick. Empty array indicates automatic matching trades for current batch, may be null |
partCode | string | Exchange code for each trade (US stocks only), may be null |
Callback Result Example
{"symbol":"AAPL","ticks":[{"sn":"69745","time":"1712585464248","price":168.96,"volume":26,"type
":"+","partCode":"t"},{"sn":"69746","time":"1712585464248","price":168.96,"volume":22,"type":"+","partCode":"t"}],"timestamp":"1712585464415"
,"source":"NLS"}Subscribe to Minute Kline Data
subscribeKline(Set<String> symbols)
Cancel Method
cancelSubscribeKline(Set<String> symbols)
Description
Subscribe to minute kline data for stocks. You need to apply for permission from the administrator.
The minute kline subscription push interface is asynchronous. You can get asynchronous request results by implementing the ApiComposeCallback interface.
The callback interface returns results of type KlineData object.
Supports subscription for US and Hong Kong market stocks
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| symbols | Set<String> | Yes | Stock code list |
Return Value
| Field | Type | Description |
|---|---|---|
| id | string | ID generated locally by SDK subscription request, incrementally sequenced. Returns request ID and subscription success result in subscribeEnd(int id, String subject, String result) callback method |
Subscription Example
Set<String> symbols = new HashSet<>();
//Minute kline stock subscription
symbols.add("AAPL");
symbols.add("00700");
client.subscribeKline(symbols);
//Wait to receive the data
TimeUnit.SECONDS.sleep(120000);
// Cancel subscription
client.cancelSubscribeKline(symbols);Corresponding Callback Interface
void klineChange(KlineData data)
KlineData data structure is as follows:
| Field | Type | Description |
|---|---|---|
| time | long | Minute timestamp |
| open | float | Open price |
| high | float | High price |
| low | float | Low price |
| close | float | Close price |
| avg | float | Average price |
| volume | long | Volume |
| count | int | Trade count |
| symbol | string | Stock symbol |
| amount | double | Turnover amount |
| serverTimestamp | long | Server push timestamp |
Callback Result Example
{
"time": "1712584560000",
"open": 168.9779,
"high": 169.0015,
"low": 168.9752,
"close": 169.0,
"avg": 168.778,
"volume": "3664",
"count": 114,
"symbol": "AAPL",
"amount": 617820.6508,
"serverTimestamp": "1712584569746"
}Subscribe to Stock Ranking Data
subscribeStockTop(Market market, Set<Indicator> indicators)
Cancel Method
cancelSubscribeStockTop(Market market, Set<Indicator> indicators)
Description
Subscribe to stock ranking data. No push during non-trading hours, push interval is 30s, each push contains Top30 symbols data for subscribed indicators.
The push interface is asynchronous callback. You can get asynchronous request results by implementing the ApiComposeCallback interface.
The callback interface returns results of type StockTopData object. Each indicator data is sorted in descending order by indicator value.
Supports subscription for US and Hong Kong market stock indicators. During trading hours, ranking data has all indicators from StockRankingIndicator. For US stocks pre-market and after-hours, only change rate (changeRate) and 5-minute change rate (changeRate5Min) ranking data are available.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| market | Market | Yes | Market, supports US, HK |
| indicators | Set<Indicator> | No | Stock ranking indicators, defaults to all indicators, refer to StockRankingIndicator enum values (changeRate: daily change rate, changeRate5Min: 5-minute change rate, turnoverRate: turnover rate, amount: daily turnover amount, volume: daily volume, amplitude: daily amplitude) |
Return Value
| Field | Type | Description |
|---|---|---|
| id | string | ID generated locally by SDK subscription request, incrementally sequenced. Returns request ID and subscription success result in subscribeEnd(int id, String subject, String result) callback method |
Subscription Example
Market market = Market.US;
Set<Indicator> indicators = new HashSet<>();
indicators.add(StockRankingIndicator.Amplitude);
indicators.add(StockRankingIndicator.TurnoverRate);
//Subscribe to all indicators for the market
client.subscribeStockTop(market, null)
//Wait to receive the data
TimeUnit.SECONDS.sleep(120000);
// Cancel subscription of 'amplitude' and 'turnoverRate'
client.cancelSubscribeStockTop(market, indicators);
// Cancel all indicators' subscription
client.cancelSubscribeStockTop(market, null);Corresponding Callback Interface
void stockTopPush(StockTopData data)
StockTopData data structure is as follows:
| Field | Type | Description |
|---|---|---|
| market | string | Market: US/HK |
| timestamp | long | Timestamp |
| topData | List<TopData> | Ranking data list for each indicator |
TopData data structure is as follows:
| Field | Type | Description |
|---|---|---|
| targetName | string | Indicator name (changeRate, changeRate5Min, turnoverRate, amount, volume, amplitude) |
| item | List<StockItem> | Ranking data list for this indicator dimension |
StockItem data structure is as follows:
| Field | Type | Description |
|---|---|---|
| symbol | string | Symbol |
| latestPrice | double | Latest price |
| targetValue | double | Corresponding indicator value |
Callback Result Example
{
"market":"US",
"timestamp":"1687271010482",
"topData":[
{
"targetName":"changeRate",
"item":[
{
"symbol":"ICAD",
"latestPrice":1.63,
"targetValue":0.393162
},
{
"symbol":"DICE",
"latestPrice":46.54,
"targetValue":0.374889
},
{
"symbol":"VCIG",
"latestPrice":3.88,
"targetValue":0.371025
},
{
"symbol":"LYRA",
"latestPrice":3.75,
"targetValue":0.237624
},
{
"symbol":"CANO",
"latestPrice":1.4847,
"targetValue":0.18776
}
// ......
]
},
{
"targetName":"turnoverRate",
"item":[
{
"symbol":"SBBA",
"latestPrice":24.8,
"targetValue":191.046512
},
{
"symbol":"VCIG",
"latestPrice":3.88,
"targetValue":13.82794
},
{
"symbol":"BOIL",
"latestPrice":3.225,
"targetValue":10.681214
},
{
"symbol":"GDV",
"latestPrice":20.86,
"targetValue":8.257162
},
{
"symbol":"NUWE",
"latestPrice":3.1611,
"targetValue":6.755784
}
// ......
]
},
{
"targetName":"amount",
"item":[
{
"symbol":"TSLA",
"latestPrice":263.21,
"targetValue":10629393179.8
},
{
"symbol":"SPY",
"latestPrice":435.64,
"targetValue":5839415251.67
},
{
"symbol":"NVDA",
"latestPrice":428.3801,
"targetValue":5123997584.1
},
{
"symbol":"QQQ",
"latestPrice":364.72,
"targetValue":3979912590.29
},
{
"symbol":"BRK.A",
"latestPrice":509004,
"targetValue":2529965164.19
}
// ......
]
},
{
"targetName":"volume",
"item":[
{
"symbol":"TSLA",
"latestPrice":263.21,
"targetValue":40190416
},
{
"symbol":"NKLA",
"latestPrice":1.2586,
"targetValue":33326008
},
{
"symbol":"FISV",
"latestPrice":114.23,
"targetValue":31689406
},
{
"symbol":"SQQQ",
"latestPrice":19.93,
"targetValue":31339556
},
{
"symbol":"PLTR",
"latestPrice":15.98,
"targetValue":30249797
}
// ......
]
},
{
"targetName":"amplitude",
"item":[
{
"symbol":"ICAD",
"latestPrice":1.63,
"targetValue":0.333333
},
{
"symbol":"VCIG",
"latestPrice":3.88,
"targetValue":0.293286
},
{
"symbol":"GRCL",
"latestPrice":3.8285,
"targetValue":0.281059
},
{
"symbol":"ZJYL",
"latestPrice":10.2165,
"targetValue":0.278427
},
{
"symbol":"NUWE",
"latestPrice":3.1611,
"targetValue":0.262799
}
// ......
]
},
{
"targetName":"changeRate5Min",
"item":[
{
"symbol":"ICAD",
"latestPrice":1.63,
"targetValue":0.077419
},
{
"symbol":"EUDA",
"latestPrice":1.3,
"targetValue":0.072
},
{
"symbol":"WEL",
"latestPrice":10.75,
"targetValue":0.070233
},
{
"symbol":"TYGO",
"latestPrice":17.255,
"targetValue":0.068901
},
{
"symbol":"SSU",
"latestPrice":3.2512,
"targetValue":0.065967
}
// ......
]
}
]
}Subscribe to Option Ranking Data
subscribeOptionTop(Market market, Set<Indicator> indicators)
Cancel Method
cancelSubscribeOptionTop(Market market, Set<Indicator> indicators)
Description
Subscribe to option ranking data. No push during non-trading hours, push interval is 30s, each push contains Top50 symbols data for subscribed indicators.
The push interface is asynchronous callback. You can get asynchronous request results by implementing the ApiComposeCallback interface.
The callback interface returns results of type OptionTopData object. Big orders are single trade volumes greater than 1000, sorted by trade time in descending order. Other indicator data are cumulative indicator values for the trading day in descending order.
Supports subscription for US market option indicators. During trading hours, ranking data has all indicators from OptionRankingIndicator.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| market | Market | Yes | Market, supports US |
| indicators | Set<Indicator> | No | Option ranking indicators, defaults to all indicators, refer to OptionRankingIndicator enum values (bigOrder: big orders, volume: daily cumulative volume, amount: daily cumulative turnover amount, openInt: open interest) |
Return Value
| Field | Type | Description |
|---|---|---|
| id | string | ID generated locally by SDK subscription request, incrementally sequenced. Returns request ID and subscription success result in subscribeEnd(int id, String subject, String result) callback method |
Subscription Example
Market market = Market.US;
Set<Indicator> indicators = new HashSet<>();
indicators.add(OptionRankingIndicator.Amount);
indicators.add(OptionRankingIndicator.OpenInt);
//Subscribe to all indicators for the market
client.subscribeOptionTop(market, null)
//Wait to receive the data
TimeUnit.SECONDS.sleep(120000);
// Cancel subscription of 'amount' and 'openInt'
client.cancelSubscribeOptionTop(market, indicators);
// Cancel all indicators' subscription
client.cancelSubscribeOptionTop(market, null);Corresponding Callback Interface
void optionTopPush(OptionTopData data)
OptionTopData data structure is as follows:
| Field | Type | Description |
|---|---|---|
| market | string | Market: US |
| timestamp | long | Timestamp |
| topData | List<TopData> | Ranking data list for each indicator |
TopData data structure is as follows:
| Field | Type | Description |
|---|---|---|
| targetName | string | Indicator name (bigOrder, volume, amount, openInt) |
| bigOrder | List<BigOrder> | Big order indicator (bigOrder) data list |
| item | List<OptionItem> | Ranking data list for this indicator dimension |
BigOrder data structure is as follows:
| Field | Type | Description |
|---|---|---|
| symbol | string | Stock, ETF symbol |
| expiry | string | Expiry date, format: yyyyMMdd |
| strike | string | Strike price |
| right | string | CALL/PUT |
| dir | string | Trade direction: BUY/SELL/NONE |
| volume | double | Trade volume |
| price | double | Trade price |
| amount | double | Trade amount |
| tradeTime | long | Trade timestamp |
OptionItem data structure is as follows:
| Field | Type | Description |
|---|---|---|
| symbol | string | Stock, ETF symbol |
| expiry | string | Expiry date, format: yyyyMMdd |
| strike | string | Strike price |
| right | string | CALL/PUT |
| totalAmount | double | Trade amount |
| totalVolume | double | Trade volume |
| totalOpenInt | double | Open interest |
| volumeToOpenInt | double | Volume/Open interest |
| latestPrice | double | Latest price |
| updateTime | long | Indicator data update timestamp |
Callback Result Example
{
"market":"US",
"timestamp":"1687277160445",
"topData":[
{
"targetName":"volume",
"item":[
{
"symbol":"SPY",
"expiry":"20230620",
"strike":"435.0",
"right":"PUT",
"totalAmount":5394115,
"totalVolume":212478,
"totalOpenInt":16377,
"volumeToOpenInt":0.012467,
"latestPrice":0.25,
"updateTime":"1687277254390"
},
{
"symbol":"SPY",
"expiry":"20230620",
"strike":"436.0",
"right":"PUT",
"totalAmount":7754077,
"totalVolume":194423,
"totalOpenInt":13403,
"volumeToOpenInt":0.011408,
"latestPrice":0.58,
"updateTime":"1687277213603"
},
{
"symbol":"SPY",
"expiry":"20230620",
"strike":"437.0",
"right":"PUT",
"totalAmount":10420625,
"totalVolume":182078,
"totalOpenInt":13973,
"volumeToOpenInt":0.010683,
"latestPrice":1.17,
"updateTime":"1687277213602"
},
{
"symbol":"SPY",
"expiry":"20230620",
"strike":"438.0",
"right":"CALL",
"totalAmount":4482482,
"totalVolume":181899,
"totalOpenInt":961,
"volumeToOpenInt":0.010673,
"latestPrice":0.09,
"updateTime":"1687277213603"
},
{
"symbol":"SPY",
"expiry":"20230620",
"strike":"436.0",
"right":"CALL",
"totalAmount":7331667,
"totalVolume":150604,
"totalOpenInt":238,
"volumeToOpenInt":0.008837,
"latestPrice":0.66,
"updateTime":"1687277208599"
}
// ......
]
},
{
"targetName":"amount",
"item":[
{
"symbol":"TSLA",
"expiry":"20230721",
"strike":"5.0",
"right":"CALL",
"totalAmount":34061561,
"totalVolume":1812,
"totalOpenInt":18,
"volumeToOpenInt":0.00023,
"latestPrice":259.99,
"updateTime":"1687276953360"
},
{
"symbol":"TSLA",
"expiry":"20230721",
"strike":"500.0",
"right":"PUT",
"totalAmount":30877216,
"totalVolume":1960,
"volumeToOpenInt":0.000248,
"latestPrice":234.97,
"updateTime":"1687276953360"
},
{
"symbol":"TSLA",
"expiry":"20230623",
"strike":"265.0",
"right":"CALL",
"totalAmount":27928028,
"totalVolume":66361,
"totalOpenInt":12928,
"volumeToOpenInt":0.008405,
"latestPrice":6.5,
"updateTime":"1687277264395"
},
{
"symbol":"SPY",
"expiry":"20230721",
"strike":"420.0",
"right":"CALL",
"totalAmount":21629503,
"totalVolume":11105,
"totalOpenInt":46931,
"volumeToOpenInt":0.000652,
"latestPrice":19.27,
"updateTime":"1687273142271"
},
{
"symbol":"TSLA",
"expiry":"20230623",
"strike":"270.0",
"right":"CALL",
"totalAmount":17657903,
"totalVolume":61012,
"totalOpenInt":14302,
"volumeToOpenInt":0.007728,
"latestPrice":4.52,
"updateTime":"1687277254390"
}
// ......
]
},
{
"targetName":"openInt",
"item":[
{
"symbol":"AMC",
"expiry":"20230721",
"strike":"10.0",
"right":"CALL",
"totalAmount":4933,
"totalVolume":750,
"totalOpenInt":340843,
"volumeToOpenInt":0.00022,
"latestPrice":0.1,
"updateTime":"1687276788220"
},
{
"symbol":"AMC",
"expiry":"20230721",
"strike":"10.0",
"right":"PUT",
"totalVolume":1,
"totalOpenInt":321814,
"latestPrice":6.2,
"updateTime":"1687276853278"
},
{
"symbol":"AMC",
"expiry":"20230721",
"strike":"4.0",
"right":"PUT",
"totalAmount":117982,
"totalVolume":2748,
"totalOpenInt":242101,
"volumeToOpenInt":0.000806,
"latestPrice":0.81,
"updateTime":"1687277034280"
},
{
"symbol":"ATVI",
"expiry":"20240119",
"strike":"85.0",
"right":"PUT",
"totalAmount":3500,
"totalVolume":26,
"totalOpenInt":230702,
"volumeToOpenInt":0.000016,
"latestPrice":7,
"updateTime":"1687274092822"
},
{
"symbol":"EEM",
"expiry":"20231215",
"strike":"47.0",
"right":"CALL",
"totalAmount":310,
"totalVolume":15,
"totalOpenInt":183054,
"volumeToOpenInt":0.000003,
"latestPrice":0.18,
"updateTime":"1687269619956"
}
// ......
]
},
{
"targetName":"bigOrder",
"bigOrder":[
{
"symbol":"AMC",
"expiry":"20230818",
"strike":"10.0",
"right":"PUT",
"dir":"Buy",
"volume":1000,
"price":6.94,
"amount":694000,
"tradeTime":"1687276860753"
},
{
"symbol":"GLPI",
"expiry":"20230818",
"strike":"50.0",
"right":"CALL",
"dir":"Sell",
"volume":1094,
"price":1.2,
"amount":131280,
"tradeTime":"1687276744519"
},
{
"symbol":"AMD",
"expiry":"20230818",
"strike":"140.0",
"right":"CALL",
"dir":"Buy",
"volume":1700,
"price":3.25,
"amount":552500,
"tradeTime":"1687276467421"
},
{
"symbol":"AAPL",
"expiry":"20230915",
"strike":"185.0",
"right":"PUT",
"dir":"Sell",
"volume":1500,
"price":6.65,
"amount":997500,
"tradeTime":"1687276413267"
},
{
"symbol":"BABA",
"expiry":"20240119",
"strike":"75.0",
"right":"PUT",
"dir":"Sell",
"volume":1500,
"price":4.8,
"amount":720000,
"tradeTime":"1687276036749"
}
// ......
]
}
]
}Query Subscribed Symbols
getSubscribedSymbols()
Description
Query subscribed symbol information
Request Parameters
None
Subscription Example
client.getSubscribedSymbols();Corresponding Callback Interface
public void getSubscribedSymbolEnd(SubscribedSymbol subscribedSymbol) {
System.out.println(JSONObject.toJSONString(subscribedSymbol));
}Callback data structure is as follows:
| Field | Type | Description |
|---|---|---|
| limit | int | Maximum limit for subscribed market data symbols (stocks, options, futures) |
| used | int | Number of subscribed market data symbols (stocks, options, futures) used |
| subscribedSymbols | array | Subscribed market data symbols (stocks, options, futures) |
| askBidLimit | int | Maximum limit for subscribed depth market data stocks |
| askBidUsed | int | Number of subscribed depth market data stocks used |
| subscribedAskBidSymbols | array | Subscribed depth market data stock symbols |
| tradeTickLimit | int | Maximum limit for subscribed trade tick stocks |
| tradeTickUsed | int | Number of subscribed trade tick stocks used |
| subscribedTradeTickSymbols | array | Subscribed trade tick stock symbols |
Callback Result Example
{
"askBidLimit":10,
"askBidUsed":0,
"limit":20,
"subscribedAskBidSymbols":[
],
"subscribedSymbols":[
],
"subscribedTradeTickSymbols":[
"PDD",
"AMD",
"SPY",
"01810"
],
"tradeTickLimit":20,
"tradeTickUsed":4,
"used":0
}Updated 9 days ago
