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 |
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));
}
/*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("XYZX");
//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) quote subscriptions
client.cancelSubscribeQuote(new HashSet<>());
//Cancel all symbol (stock) depth quote subscriptions
client.cancelSubscribeDepthQuote(new HashSet<>());
//Cancel all symbol (stock) 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.
US stock quote data example:
{
"symbol":"XYZX",
"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":"XYZX",
"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":"XYZX",
"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 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.
- 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("XYZX 20230317 150.0 CALL");
symbols.add("XYZX.US 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":"XYZX 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":"XYZX 230317C00150000",
"openInt":"82677"
}Option order book data example:
{
"symbol":"XYZX 20230317 150.0 CALL",
"type":"BBO",
"timestamp":"1676994393156",
"askPrice":4.85,
"askSize":"11",
"askTimestamp":"1676994393156",
"bidPrice":4.8,
"bidSize":"992",
"bidTimestamp":"1676994390931"
}Subscribe to Market Depth Quotes
subscribeDepthQuote(Set<String> symbols)
Cancellation Method
cancelSubscribeDepthQuote(Set<String> symbols)
Description
Subscribe to multi-level depth quotes, supporting stocks (US), and options (US). US stock depth quotes push frequency is 300ms, returning up to 40 levels of bid/ask order data.
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 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("XYZX");
symbols.add("ESmain");
symbols.add("XYZX 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 |
| 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": "XYZX",
"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 Tick-by-Tick Trade 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 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("XYZX");
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 |
| secType | SecType | STK |
| quoteLevel | string | Quote permission level from which data comes (for US stocks, usQuoteBasic has less trade tick data than usStockQuote) |
| 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 |
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": "XYZX",
"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"
}
]
}
Subscribe to Full Tick-by-Tick Trade 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 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("XYZX");
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":"XYZX","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 K-Line 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 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("XYZX");
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": "XYZX",
"amount": 617820.6508,
"serverTimestamp": "1712584569746"
}Subscribe to Stock Popular Trading Rankings
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 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 |
| 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 |
| 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 Popular Trading Rankings
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) |
| used | int | Number of subscribed market data symbols (stocks, options) used |
| subscribedSymbols | array | Subscribed market data symbols (stocks, options) |
| 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":[
"XYZX"
],
"tradeTickLimit":20,
"tradeTickUsed":4,
"used":0
}Updated 7 days ago