股票
获取市场状态
对应的请求类:QuoteMarketRequest
说明
获取市场状态
参数
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
market | Market | Yes | 常用市场枚举值:US 美股,HK港股,CN A股,ALL 所有,枚举值详见: 市场枚举 |
lang | Language | No | 语言枚举值:zh_CN,zh_TW,en_US,默认:en_US,枚举值详见:语言枚举 |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteMarketResponse
source
其结构如下:
public class QuoteMarketResponse extends TigerResponse {
@JSONField(
name = "data"
)
private List<MarketItem> marketItems;
}
返回数据可用QuoteMarketResponse.getMarketItems()
方法访问,返回为marketItem
对象列表,其中 com.tigerbrokers.stock.openapi.client.https.domain.quote.item.MarketItem
属性如下:
字段 | 类型 | 说明 |
---|---|---|
market | string | 市场代码(US:美股,CN:沪深,HK:港股) |
marketStatus | string | 市场状态描述,非固定值,包括节假日信息等,如:"Not Yet Opened","Closed","Trading","Closed Independence Day",通过lang参数区分中英文文案,该字段可以用来做市场状态的提醒展示。 |
status | string | 市场状态,包括:NOT_YET_OPEN:未开盘,PRE_HOUR_TRADING:盘前交易,TRADING:交易中,MIDDLE_CLOSE:午间休市,POST_HOUR_TRADING:盘后交易,CLOSING:已收盘,EARLY_CLOSED:提前休市,MARKET_CLOSED:休市 |
openTime | string | 最近开盘、交易时间 MM-dd HH:mm:ss ,例如:当market=US时,openTime="07-04 09:30:00 EDT",其中EDT为美东时区。当market为CN,HK时,openTime="01-13 09:30:00",openTime不会返回时区。当market为其他市场时,会返回对应市场的时区。 |
MarketItem
的具体字段可通过对象的get方法,如getMarket()
,进行访问,或通过toString()
方法转换为字符串的形式
示例
TigerHttpClient client = TigerHttpClient.getInstance().clientConfig(
ClientConfig.DEFAULT_CONFIG);
QuoteMarketResponse response = client.execute(QuoteMarketRequest.newRequest(Market.US));
if (response.isSuccess()) {
System.out.println(Arrays.toString(response.getMarketItems().toArray()));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"code": 0,
"message": "success",
"timestamp": 1525938835697,
"data": [{"market":"US","marketStatus":"Closed Independence Day","status":"CLOSING","openTime":"07-04 09:30:00 EDT"}]
}
获取市场交易日历
对应的请求类:QuoteTradeCalendarRequest
说明
获取市场交易日历. 通过去除周末和该市场节假日得出,未去除临时休市的日期
参数
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
market | string | Yes | US 美股,HK港股,CN A股 |
begin_date | string | No | 日历起始日期(包含)。yyyy-MM-dd 格式,如 '2022-06-01' |
end_date | string | No | 日历截至日期(不包含)。yyyy-MM-dd 格式 |
begin_time 和 end_time 传参处理如下:
begin_time是否传递 | end_time是否传递 | 说明 |
---|---|---|
yes | yes | begin_time和end_time分别为所传值 |
yes | no | end_time为begin_time往后365天 |
no | yes | begin_time为end_time往前365天 |
no | no | begin_time为当前日期,end_time为begin_time往后30天 |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteTradeCalendarResponse
source
其结构如下:
public class QuoteTradeCalendarResponse extends TigerResponse {
@JSONField(name = "data")
private List<TradeCalendar> items;
}
返回数据可用QuoteTradeCalendarResponse.getItems()
方法访问,返回为TradeCalendar
对象列表,其中 com.tigerbrokers.stock.openapi.client.https.domain.quote.item.TradeCalendar
属性如下:
字段 | 类型 | 说明 |
---|---|---|
date | string | 交易日日期 |
type | string | 交易日类型. TRADING为正常交易日,全天交易; EARLY_CLOSE为提前休市 |
示例
TigerHttpClient client = TigerHttpClient.getInstance().clientConfig(
ClientConfig.DEFAULT_CONFIG);
QuoteTradeCalendarRequest request = QuoteTradeCalendarRequest.newRequest(
Market.US, "2022-06-01", "2022-06-30");
QuoteTradeCalendarResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(Arrays.toString(response.getItems().toArray()));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"code":0,
"message":"success",
"timestamp":1655968809209,
"data":[{"date":"2022-06-01","type":"TRADING"},{"date":"2022-06-02","type":"TRADING"},{"date":"2022-06-03","type":"TRADING"},{"date":"2022-06-06","type":"TRADING"},{"date":"2022-06-07","type":"TRADING"},{"date":"2022-06-08","type":"TRADING"},{"date":"2022-06-09","type":"TRADING"},{"date":"2022-06-10","type":"TRADING"},{"date":"2022-06-13","type":"TRADING"},{"date":"2022-06-14","type":"TRADING"},{"date":"2022-06-15","type":"TRADING"},{"date":"2022-06-16","type":"TRADING"},{"date":"2022-06-17","type":"TRADING"},{"date":"2022-06-21","type":"TRADING"},{"date":"2022-06-22","type":"TRADING"},{"date":"2022-06-23","type":"TRADING"},{"date":"2022-06-24","type":"TRADING"},{"date":"2022-06-27","type":"TRADING"},{"date":"2022-06-28","type":"TRADING"},{"date":"2022-06-29","type":"TRADING"}],
"sign":"QEHsOPx7JSp5VZ3eYatbTLXy7wK7RIgWMqQfqEuEog+tQ12ThnucHPoXpcFj8wgwUU77KhLDL6KVgNBPC/D1GgXKPaWPo1E77d9Nabd9OYAwqNINP//GSuEd8ai7b32EQ4uWTrF3ycQh7g7Lb7f5nvqZypmFuaphFyTEoQfwKp8="
}
获取股票代码列表
对应的请求类:QuoteSymbolRequest
说明
获取股票代码列表
参数
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
market | string | Yes | US 美股,HK港股,CN A股 |
include_otc | boolean | No | 是否包含OTC标的,默认:false |
lang | string | No | 语言支持: zh_CN,zh_TW,en_US, 默认: en_US |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteSymbolResponse
source
具体结构如下
public class QuoteSymbolResponse extends TigerResponse {
@JSONField(name = "data")
private List<String> symbols;
}
返回数据可以通过QuoteSymbolResponse.getSymbols()
方法调用,结果为包含返回股票代码数据的List
示例
TigerHttpClient client = TigerHttpClient.getInstance().clientConfig(
ClientConfig.DEFAULT_CONFIG);
QuoteSymbolResponse response = client.execute(QuoteSymbolRequest.newRequest(Market.US).includeOTC(false));
if (response.isSuccess()) {
System.out.println(Arrays.toString(response.getSymbols().toArray()));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"code": 0,
"message": "success",
"timestamp": 1525938835697,
"data": ["A", "A.W", "AA", "AA-B", "AAAP", "AABA", "AAC", "AADR", "AAIT", "AAL", "AALCP", "AAMC", "AAME"]
}
获取股票代码列表和名称
对应的请求类:QuoteSymbolNameRequest
说明
获取股票代码列表和名称
参数
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
market | string | Yes | US 美股,HK港股, CN A股 |
include_otc | boolean | No | 是否包含OTC标的,默认:false |
lang | string | No | 语言支持: zh_CN,zh_TW,en_US, 默认: en_US |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteSymbolNameResponse
source
具体结构如下
public class QuoteSymbolNameResponse extends TigerResponse {
@JSONField(name = "data")
private List<SymbolNameItem> symbolNameItems;
}
返回数据可通过QuoteSymbolNameResponse.getSymbolNameItems()
方法访问,返回为包含SymbolNameItem
对象的List,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.symbolNameItems
属性如下:
字段 | 类型 | 说明 |
---|---|---|
name | string | 股票名称 |
symbol | string | 股票代码 |
SymbolNameItem
的具体字段可通过对象的get方法,如getName()
进行访问,或通过toString()
方法转换为字符串的形式
示例
TigerHttpClient client = TigerHttpClient.getInstance().clientConfig(
ClientConfig.DEFAULT_CONFIG);
QuoteSymbolNameResponse response = client.execute(QuoteSymbolNameRequest.newRequest(Market.US).includeOTC(false));
if (response.isSuccess()) {
System.out.println(Arrays.toString(response.getSymbolNameItems().toArray()));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"code": 0,
"message": "success",
"timestamp": 1525938835697,
"data": [{"name":"CKH Holdings","symbol":"00001"},{"name":"CLP","symbol":"00002"}]
}
获取股票延迟行情
对应的请求类:QuoteDelayRequest
说明
获取延迟行情,此行情接口不需要购买行情权限即可调用,目前免费提供给用户
参数
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | array | Yes | 股票代码(单次请求上限50),目前仅支持获取美股延迟行情。 如 ['AAPL', 'MSFT'] |
示例
List<String> symbols = new ArrayList<>();
symbols.add("AAPL");
symbols.add("TSLA");
QuoteDelayRequest delayRequest = QuoteDelayRequest.newRequest(symbols);
QuoteDelayResponse response = client.execute(delayRequest);
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteDelayResponse
source
具体结构如下:
public class QuoteDelayResponse extends TigerResponse {
@JSONField(name = "data")
private List<QuoteDelayItem> quoteDelayItems;
}
返回数据可通过TigerResponse.getQuoteDelayItems()
方法访问,返回为包含QuoteDelayItem
对象的List,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.quoteDelayItem
属性如下:
字段 | 类型 | 说明 |
---|---|---|
close | double | 收盘价 |
high | double | 最高价 |
low | double | 最低价 |
open | double | 开盘价 |
preClose | double | 昨日收盘价 |
time | long | 时间 |
volume | long | 成交量 |
QuoteDelayItem
的具体字段可通过对象的get方法,如getClose()
进行访问
返回示例
[
{
"close": 156.81,
"halted": 0,
"high": 160.45,
"low": 156.36,
"open": 159.565,
"preClose": 161.94,
"symbol": "AAPL",
"time": 1637949600000,
"volume": 76959752
},
{
"close": 1081.92,
"halted": 0,
"high": 1108.7827,
"low": 1081,
"open": 1099.47,
"preClose": 1116,
"symbol": "TSLA",
"time": 1637949600000,
"volume": 11680890
}
]
获取分时数据
对应的请求类:QuoteTimelineRequest
说明
获取分时数据
参数
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | array | Yes | 股票代码列表 |
period | string | Yes | 分时周期,包含:day 和 day5 |
trade_session | String | No | TradeSession枚举对象,盘前:PreMarket, 盘中:Regular, 盘后:AfterHours。默认为盘中 |
begin_time | long | No | 开始时间(毫秒时间戳),默认返回当天数据 |
lang | string | No | 语言支持: zh_CN,zh_TW,en_US, 默认: en_US |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteTimelineResponse
source
具体结构如下:
返回数据可通过QuoteTimelineResponse.getTimelineItems()
方法访问,返回为包含TimelineItem
对象的List,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.TimelineItem
属性如下:
字段 | 类型 | 说明 |
---|---|---|
symbol | string | 股票代码 |
period | string | 周期 day or 5day |
preClose | double | 昨日收盘价 |
intraday | object | 盘中分时数组,字段参考下面说明 |
preMarket | object | (仅美股) 盘前分时数组和起始结束时间,字段参考下面说明 |
afterHours | object | (仅美股) 盘后分时数组和起始结束时间,字段参考下面说明 |
TimelineItem
的具体字段可通过对象的get方法,如getSymbol()
,进行访问
分时数据intraday字段:
分时字段 | 说明 |
---|---|
volume | 成交量 |
avgPrice | 平均成交价格 |
price | 最新价格 |
time | 当前分时时间 |
示例
TigerHttpClient client = TigerHttpClient.getInstance().clientConfig(
ClientConfig.DEFAULT_CONFIG);
QuoteTimelineResponse response = client.execute(QuoteTimelineRequest.newRequest(List.of("AAPL"), 1544129760000L));
if (response.isSuccess()) {
System.out.println(Arrays.toString(response.getTimelineItems().toArray()));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"code": 0,
"data": [
{
"symbol": "AAPL",
"preMarket": {
"endTime": 1544106600000,
"beginTime": 1544086800000,
"items": [
]
},
"period": "day",
"preClose": 176.69000244140625,
"afterHours": {
"endTime": 1544144400000,
"beginTime": 1544130000000,
"items": [
{
"volume": 872772,
"avgPrice": 174.71916,
"price": 174.69,
"time": 1544130000000
},
{
"volume": 3792,
"avgPrice": 174.71893,
"price": 174.66,
"time": 1544130060000
}
]
},
"intraday": [
{
"items": [
{
"volume": 201594,
"avgPrice": 172.0327,
"price": 174.34,
"time": 1544129760000
},
{
"volume": 139040,
"avgPrice": 172.03645,
"price": 174.4156,
"time": 1544129820000
},
{
"volume": 178427,
"avgPrice": 172.0413,
"price": 174.44,
"time": 1544129880000
},
{
"volume": 2969567,
"avgPrice": 172.21619,
"price": 174.72,
"time": 1544129940000
}
]
}
]
}
],
"timestamp": 1544185099595,
"message": "success"
}
获取历史分时数据
对应的请求类:QuoteHistoryTimelineRequest
说明
获取历史1分钟的分时数据
参数
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | array | Yes | 股票代码列表 |
date | string | Yes | 年月日yyyyMMdd,例如20220420 |
right | RightOption | No | 前复权:br, 不复权:nr;默认:nr |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteHistoryTimelineResponse
source
具体结构如下:
返回数据可通过QuoteHistoryTimelineResponse.getTimelineItems()
方法访问,返回为包含HistoryTimelineItem
对象的List,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.HistoryTimelineItem
属性如下:
字段 | 类型 | 说明 |
---|---|---|
symbol | string | 股票代码 |
items | TimelinePoint | 盘中分时数组,字段参考下面说明 |
TimelineItem
的具体字段可通过对象的get方法,如getSymbol()
,进行访问
分时数据items字段TimelinePoint:
分时字段 | 说明 |
---|---|
volume | 成交量 |
avgPrice | 平均成交价格 |
price | 最新价格 |
time | 当前分时时间 |
示例
TigerHttpClient client = TigerHttpClient.getInstance().clientConfig(
ClientConfig.DEFAULT_CONFIG);
List<String> symbols = new ArrayList<>();
symbols.add("AAPL");
QuoteHistoryTimelineRequest request = QuoteHistoryTimelineRequest.newRequest(symbols, "20220420");
request.withRight(RightOption.br);
QuoteHistoryTimelineResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(Arrays.toString(response.getTimelineItems().toArray()));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"code":0,
"message":"success",
"timestamp":1651737871819,
"data":[
{
"symbol":"AAPL",
"items":[
{
"time":1650461400000,
"volume":1414143,
"price":168.75,
"avgPrice":168.66885
},
{
"time":1650461460000,
"volume":392862,
"price":168.25,
"avgPrice":168.65086
},
// ....
{
"time":1650484680000,
"volume":443549,
"price":167.24,
"avgPrice":167.47902
},
{
"time":1650484740000,
"volume":6457118,
"price":167.23,
"avgPrice":167.45808
}
]
}
]
}
获取实时行情
对应的请求类:QuoteRealTimeQuoteRequest
说明
获取实时行情,需要购买行情权限才可以开通
参数
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | array | Yes | 股票代码列表(单次上限50) |
includeHourTrading | Boolean | No | 是否包含美股盘前盘后数据,默认: false |
lang | string | No | 语言支持: zh_CN,zh_TW,en_US, 默认: en_US |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteRealTimeQuoteResponse
source
返回数据可通过QuoteRealTimeQuoteResponse.getRealTimeQuoteItems()
方法访问,返回RealTimeQuoteItem
对象,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.RealTimeQuoteItem
属性如下:
字段 | 类型 | 说明 |
---|---|---|
symbol | string | 股票代码 |
open | double | 开盘价 |
high | double | 最高价 |
low | double | 最低价 |
close | double | 收盘价 |
preClose | double | 前一交易日收盘价 |
latestPrice | double | 最新价 |
latestTime | long | 最新成交时间 |
askPrice | double | 卖盘价 |
askSize | long | 卖盘数量 |
bidPrice | double | 买盘价 |
bidSize | long | 买盘数量 |
volume | long | 成交量 |
status | string | 交易状态 |
hourTrading | object | 美股盘前盘后数据(includeHourTrading参数为true,且盘前盘后时间段才有数据) |
其中hourTrading
对象包含的字段:
字段 | 类型 | 说明 |
---|---|---|
tag | string | 盘前("Pre-Mkt")、盘后("Post-Mkt")标识 |
latestPrice | double | 最新价 |
preClose | double | 昨收价 |
latestTime | string | 最新成交时间(美东时间) |
volume | long | 成交量 |
timestamp | long | 最新成交时间 |
具体字段可通过对象的get方法,如getSymbol()
,进行访问
示例
QuoteRealTimeQuoteResponse response = client.execute(QuoteRealTimeQuoteRequest.newRequest(List.of("AAPL"), true));
if (response.isSuccess()) {
System.out.println(Arrays.toString(response.getRealTimeQuoteItems().toArray()));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"code":0,
"data":[
{
"askPrice":174.8,
"latestPrice":175.08,
"symbol":"AAPL",
"bidSize":200,
"bidPrice":174.71,
"volume":116803357,
"high":175.96,
"preClose":171.18,
"low":170.7,
"hourTrading":{
"volume":3418089,
"latestPrice":174.72,
"preClose":175.08,
"latestTime":"18:50 EST",
"tag":"Post-Mkt",
"timestamp":1639007439976
},
"latestTime":1638997200000,
"close":175.08,
"askSize":200,
"open":172.125,
"status":"NORMAL"
}
],
"success":true,
"sign":"BxcUz9YfmWcnSsmQKLcnFnVpHAT5bDdX69YntqaVIVdVqMlhSaaaW8ur3yaWP6GB6NAec2ds6s1ZB/4X40kg8lHb6u6y2V0hvHE2Q3uDNgkoukmDcAetdwRo/MAiqtQRACFGAd/AOlyhDsJyuzTf7T14zDMl5cfOfbwe2+RDjgg=",
"message":"success",
"timestamp":1639007449806
}
获取K线数据
对应的请求类:QuoteKlineRequest
说明
获取指定股票的K线数据,可指定不同的时间粒度。目前此接口支持获取以日、周、月、年、分钟、3分钟、5分钟、15分钟、30分钟、60分钟、2小时、4小时为单位的K线数据。考虑到接口性能和稳定性,此接口请求最高限制为1200条。对于需要更多历史数据进行分析或回测的用户,可以自行实现循环或者使用pageToken,通过多次请求的方式获取更长时间范围的历史的数据。需要注意的是,可以请求的K线时间长度可能会存在限制,具体请见历史行情限制
参数
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | array | Yes | 股票代码列表,上限:50,其中A股上限:10 |
period | string | Yes | K线类型,取值范围(day:日K,week:周K,month:月K,year:年K,1min:1分钟,3min:3分钟,5min:5分钟,15min:15分钟,30min:30分钟,60min:60分钟,120min:2小时,240min:4小时) |
right | string | No | 复权选项 ,br: 前复权(默认),nr: 不复权 |
begin_time | long | No | 开始时间,默认:-1,单位:毫秒(ms),前闭后开区间,即查询结果会包含起始时间数据,如查询周/月/年K线,会返回包含当前周期的数据(如:起始时间为周三,会返回从这周一的K线) |
end_time | long | No | 结束时间,默认:-1,单位:毫秒(ms) |
limit | integer | No | 单次请求返回K线数量,不传默认是300,limit不能超过1200,如果limit设置大于1200,只会返回1200条数据 |
lang | string | No | 语言支持: zh_CN,zh_TW,en_US, 默认: en_US |
pageToken | string | No | 分页查询token(只支持单个symbol,指定begin_time的查询),使用pageToken分页拉取数据时其他查询条件不能改变 |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteKlineResponse
source
返回数据可通过QuoteKlineResponse.getKlineItems()
方法访问,返回KlineItem
对象列表,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.KlineItem
属性如下:
字段 | 类型 | 说明 |
---|---|---|
symbol | string | 股票代码 |
period | string | K线周期 |
nextPageToken | string | 查询下一页的token(只支持单个symbol,begin_time不为-1时才有效),如果没有更多数据返回null |
items | array | K线对象KlinePoint的数组,字段参考下面说明 |
其中K线数据KlinePoint的属性如下:
K线字段 | 类型 | 说明 |
---|---|---|
close | double | 收盘价 |
high | double | 最高价 |
low | double | 最低价 |
open | double | 开盘价 |
time | long | 时间 |
volume | long | 成交量 |
amount | double | 成交额 |
具体字段可通过对象的get方法,如getSymbol()
,进行访问
示例
TigerHttpClient client = TigerHttpClient.getInstance().clientConfig(
ClientConfig.DEFAULT_CONFIG);
List<String> symbols = new ArrayList<>();
symbols.add("AAPL");
QuoteKlineResponse response = client.execute(QuoteKlineRequest.newRequest(symbols, KType.day, "2023-05-16", "2023-05-19")
.withLimit(1000)
.withRight(RightOption.br));
if (response.isSuccess()) {
System.out.println(JSONObject.toJSONString(response));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"code":0,
"data":[
{
"items":[
{
"amount":7140962535.379684,
"close":172.07,
"high":173.1383,
"low":171.7991,
"open":171.99,
"time":1684209600000,
"volume":42110293
},
{
"amount":9878512463.233082,
"close":172.69,
"high":172.925,
"low":170.4201,
"open":171.71,
"time":1684296000000,
"volume":57951604
},
{
"amount":9839606365.96335,
"close":175.05,
"high":175.24,
"low":172.58,
"open":173,
"time":1684382400000,
"volume":65496657
}
],
"period":"day",
"symbol":"AAPL"
}
],
"message":"success",
"sign":"vayBuY47WEr6fJeKKlylYqtpNHlWLbguhO9EbUQNR8Y0MdN51ju2BnPuGnNMyBZkiwBL+rG0KuUW0vbQYXGGmiIV3gfxAJA2NwXaLvOK2iQiSOzc6fAuBzyGe1etDtcvnn5apBFB5opLKVqb+lpLEhsPLzcv8rPV6I1ZCLMeQhU=",
"success":true,
"timestamp":1684831488647
}
PageToken示例
List<String> symbols = new ArrayList<>();
symbols.add("AAPL");
QuoteKlineRequest request = QuoteKlineRequest.newRequest(symbols, KType.min1,
"2022-04-25 00:00:00",
"2022-04-28 00:00:00", TimeZoneId.NewYork);
request.withLimit(200);
request.withRight(RightOption.br);
int count = 1;
while (true) {
QuoteKlineResponse response = client.execute(request);
System.out.println(
"search time:" + count + ", success:" + response.isSuccess() + ", msg:" + response.getMessage());
if (!response.isSuccess()) {
break;
}
System.out.println(response.getKlineItems());
if (response.getKlineItems().size() == 0) {
break;
}
KlineItem klineItem = response.getKlineItems().get(0);
if (klineItem.getNextPageToken() == null) {
break;
}
count++;
// 10 times per minute
try {
TimeUnit.SECONDS.sleep(6);
} catch (InterruptedException e) {
e.printStackTrace();
}
// set pagination token then query the next page
request.withPageToken(klineItem.getNextPageToken());
}
PageToken工具类
默认每页1000,分页查询10000条数据在客户端合并后返回。可以参考工具类提供的几个重载方法,工具方法最多一次汇集10000条数据;另外注意每页数据大小设置,每次分页请求服务器会计算一次请求,会影响接口调用频率。可参照示例自行实现,注意翻页边界避免死循环
List<KlinePoint> list =
PageTokenUtil.getKlineByPage("AAPL", KType.min1,
"2022-04-25 00:00:00",
"2022-04-28 00:00:00", TimeZoneId.NewYork,
RightOption.br, 10, 30, PageTokenUtil.DEFAULT_TIME_INTERVAL);
for (KlinePoint item : list) {
System.out.println("content:" + item);
}
获取深度行情数据
对应的请求类:QuoteDepthRequest
说明
获取输入证券代码的买卖N档挂单数据,包括委托价格,数量及订单数,单次请求上限为50只
CAUTION
港股交易日收市竞价时间为16:00-16:10(于16:08与16:10之间随机收市),当天最后一条深度排盘数据一般在16:10之后的一两分钟后更新
请求频率 频率限制请参考:请求频率限制
参数
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | array | Yes | 股票代码列表(单次上限50) |
market | string | Yes | US 美股,HK港股,CN A股,ALL 所有(参考Market枚举类) |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteDepthResponse
source
具体结构如下
public class QuoteDepthResponse extends TigerResponse {
@JSONField(name = "data")
private List<QuoteDepthItem> quoteDepthItems;
}
返回数据可通过QuoteDepthResponse.getQuoteDepthItems()
方法访问,返回为包含QuoteDepthItem
对象的List,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.QuoteDepthItem
属性如下:
字段 | 类型 | 说明 |
---|---|---|
symbol | string | 股票代码 |
asks | list | 卖盘分档 |
bids | list | 买盘分档 |
其中买卖盘详细字段如下:
字段 | 类型 | 说明 |
---|---|---|
price | double | 委托价 |
volume | long | 委托量 |
count | int | 委托订单数(只有港股市场有,美股市场没有值) |
示例
TigerHttpClient client = TigerHttpClient.getInstance().clientConfig(
ClientConfig.DEFAULT_CONFIG);
List<String> symbols = new ArrayList<>();
symbols.add("DD");
QuoteDepthResponse response = client.execute(QuoteDepthRequest.newRequest(symbols, Market.US.name()));
if (response.isSuccess()) {
for (QuoteDepthItem item : response.getQuoteDepthItems()) {
System.out.println(item.getSymbol());
System.out.println(Arrays.toString(item.getAsks().toArray()));
System.out.println(Arrays.toString(item.getBids().toArray()));
}
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"code":0,
"message":"success",
"timestamp":1653064415298,
"data":[
{"symbol":"DD",
"asks":[{"price":62.88,"count":0,"volume":50},{"price":62.88,"count":0,"volume":27},{"price":62.89,"count":0,"volume":50},{"price":62.89,"count":0,"volume":200},{"price":62.89,"count":0,"volume":100},{"price":62.9,"count":0,"volume":50},{"price":62.9,"count":0,"volume":10},{"price":62.91,"count":0,"volume":50},{"price":62.91,"count":0,"volume":100},{"price":62.92,"count":0,"volume":50},{"price":62.92,"count":0,"volume":50},{"price":62.92,"count":0,"volume":100},{"price":62.93,"count":0,"volume":50},{"price":62.93,"count":0,"volume":49},{"price":62.93,"count":0,"volume":100},{"price":62.94,"count":0,"volume":50},{"price":62.94,"count":0,"volume":300},{"price":62.95,"count":0,"volume":50},{"price":62.96,"count":0,"volume":50},{"price":62.97,"count":0,"volume":50},{"price":62.98,"count":0,"volume":50},{"price":62.99,"count":0,"volume":50},{"price":62.99,"count":0,"volume":100},{"price":63.0,"count":0,"volume":50},{"price":63.01,"count":0,"volume":50},{"price":63.02,"count":0,"volume":100},{"price":63.02,"count":0,"volume":50},{"price":63.03,"count":0,"volume":100},{"price":63.03,"count":0,"volume":50},{"price":63.05,"count":0,"volume":18},{"price":63.05,"count":0,"volume":100},{"price":63.07,"count":0,"volume":200},{"price":63.16,"count":0,"volume":100},{"price":63.32,"count":0,"volume":100},{"price":63.32,"count":0,"volume":100},{"price":63.48,"count":0,"volume":100},{"price":63.5,"count":0,"volume":100},{"price":63.88,"count":0,"volume":800},{"price":63.88,"count":0,"volume":100},{"price":64.14,"count":0,"volume":100}],
"bids":[{"price":62.86,"count":0,"volume":50},{"price":62.86,"count":0,"volume":200},{"price":62.86,"count":0,"volume":2},{"price":62.86,"count":0,"volume":6},{"price":62.85,"count":0,"volume":50},{"price":62.84,"count":0,"volume":50},{"price":62.84,"count":0,"volume":100},{"price":62.83,"count":0,"volume":50},{"price":62.82,"count":0,"volume":50},{"price":62.82,"count":0,"volume":300},{"price":62.81,"count":0,"volume":50},{"price":62.8,"count":0,"volume":50},{"price":62.79,"count":0,"volume":50},{"price":62.78,"count":0,"volume":50},{"price":62.77,"count":0,"volume":50},{"price":62.76,"count":0,"volume":50},{"price":62.76,"count":0,"volume":100},{"price":62.75,"count":0,"volume":50},{"price":62.75,"count":0,"volume":100},{"price":62.74,"count":0,"volume":50},{"price":62.73,"count":0,"volume":50},{"price":62.73,"count":0,"volume":100},{"price":62.7,"count":0,"volume":100},{"price":62.67,"count":0,"volume":50},{"price":62.67,"count":0,"volume":200},{"price":62.62,"count":0,"volume":11},{"price":62.62,"count":0,"volume":100},{"price":62.61,"count":0,"volume":100},{"price":62.59,"count":0,"volume":100},{"price":62.58,"count":0,"volume":45},{"price":62.5,"count":0,"volume":20},{"price":62.27,"count":0,"volume":100},{"price":62.25,"count":0,"volume":100},{"price":62.25,"count":0,"volume":100},{"price":62.1,"count":0,"volume":500},{"price":62.1,"count":0,"volume":10},{"price":62.0,"count":0,"volume":8},{"price":61.94,"count":0,"volume":100},{"price":61.9,"count":0,"volume":100},{"price":61.74,"count":0,"volume":800}]
}
]
}
获取逐笔成交
对应的请求类:QuoteTradeTickRequest
说明
获取逐笔成交数据,该接口可以支持在收盘后查询当前交易日的全量逐笔记录,也可以支持查询盘中最新的实时逐笔记录。
参数
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | array | Yes | 股票代码列表,支持陆股通股、港股、美股 |
trade_session | String | No | TradeSession枚举对象,盘前:PreMarket, 盘中:Regular, 盘后:AfterHours。默认为盘中 |
beginIndex | long | yes | 起始索引,当日索引值从0开始,如果beginIndex和endIndex设置为-1,会返回最新的逐笔数据,后续查询时,可以把上次查询返回的endIndex值当做beginIndex,从而进行连续查询,返回数据为前闭后开集合,比如:beginIndex=1,endIndex=100,会返回从1到99的记录,下次查询时,设置beginIndex=100,endIndex=200。 |
endIndex | long | yes | 结束索引,结束索引和起始索引的差值不能大于2000,大于2000时默认返回从起始索引开始的200条记录。当limit参数小于起始和结束索引的差值时,只会返回从起始索引开始的limit条逐笔数据。 |
limit | integer | No | 单次请求返回的逐笔数量,如果起始和结束索引的间隔没有超过2000,会按照实际条数返回,否则会默认为200。 |
lang | string | No | 语言支持: zh_CN,zh_TW,en_US, 默认: en_US |
beginIndex 和 endIndex参数使用说明
查询方式 | beginIndex | endIndex | 描述 |
---|---|---|---|
查询最新逐笔记录 | -1 | -1 | 默认返回limit条最新的逐笔记录。limit 默认为200 |
根据区间查询当日逐笔 | 具体数值 | 具体数值 | 举例:beginIndex=10, endIndex=100 ,会返回包含10到99的 90条记录。如果limit设置为20,则会返回10到29的20条记录。 |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteTradeTickResponse
source
结构如下:
public class QuoteTradeTickResponse extends TigerResponse {
@JSONField(name = "data")
private List<TradeTickItem> tradeTickItems;
}
返回数据可通过QuoteTradeTickResponse.getTradeTickItems()
方法访问,返回TradeTickItem
对象,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.TradeTickItem
属性如下:
字段 | 类型 | 说明 |
---|---|---|
beginIndex | long | 返回数据的实际开始索引 |
endIndex | long | 返回数据的实际结束索引 |
symbol | string | 请求的股票代码 |
items | List<TickPoint> | 包含逐笔成交数据的List,单条逐笔成交数据保存在TickPoint对象中 |
其中TickPoint
对象字段如下:
字段 | 类型 | 说明 |
---|---|---|
time | long | 交易时间戳 |
price | double | 成交价 |
volume | long | 成交量 |
type | string | "+"表示主动买入,"-"表示主动卖出,"*"表示中性 |
具体字段可通过对象的get方法,如getTime()
进行访问, 或通过对象的toString()
方法转换为字符串
示例
TigerHttpClient client = TigerHttpClient.getInstance().clientConfig(
ClientConfig.DEFAULT_CONFIG);
List<String> symbols = new ArrayList<>();
symbols.add("AAPL");
QuoteTradeTickRequest request = QuoteTradeTickRequest.newRequest(symbols, 0, 30, 10);
request.setTradeSession(TradeSession.Regular);
QuoteTradeTickResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(JSONObject.toJSONString(response));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"code": 0,
"data": [
{
"beginIndex": 0,
"endIndex": 10,
"items": [
{
"price": 169.59,
"time": 1712323800003,
"type": "*",
"volume": 32
},
{
"price": 169.59,
"time": 1712323800003,
"type": "*",
"volume": 8
},
{
"price": 169.59,
"time": 1712323800003,
"type": "*",
"volume": 148
},
{
"price": 169.59,
"time": 1712323800003,
"type": "*",
"volume": 1010
},
{
"price": 169.59,
"time": 1712323800005,
"type": "*",
"volume": 600
},
{
"price": 169.59,
"time": 1712323800007,
"type": "*",
"volume": 32
},
{
"price": 169.59,
"time": 1712323800008,
"type": "*",
"volume": 33
},
{
"price": 169.59,
"time": 1712323800011,
"type": "*",
"volume": 12
},
{
"price": 169.59,
"time": 1712323800011,
"type": "*",
"volume": 186
},
{
"price": 169.59,
"time": 1712323800012,
"type": "*",
"volume": 40
}
],
"symbol": "AAPL"
}
],
"message": "success",
"sign": "XEEDI1HLzWT8rkZp4boFge4OehCeXOVuXJ6U4Lgve1vUz898Ne8Q4CF/f/OIUVcHfC7XbrjqYmHJBwDdQEdfucRdsKH7g0SimlMAnyimNnya4lKIaQ6CRbfE5faEe2sdopjnwZggFkycnCeB0JhiTK72xR5uTC0gGlcaaPY36o4=",
"success": true,
"timestamp": 1712557783317
}
获取股票交易信息
对应的请求类:QuoteStockTradeRequest
说明
获取股票交易所需的信息,包括每手股数,报价精度及股价最小变动单位
参数
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | array | Yes | 股票代码列表,上限为:50 |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteStockTradeResponse
source
结构如下:
public class QuoteStockTradeResponse extends TigerResponse {
@JSONField(name = "data")
private List<QuoteStockTradeItem> stockTradeItems;
public List<QuoteStockTradeItem> getStockTradeItems() {
return stockTradeItems;
}
}
返回数据可通过QuoteStockTradeResponse.getStockTradeItems()
方法访问,返回QuoteStockTradeItem
对象,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.QuoteStockTradeItem
属性如下:
名称 | 类型 | 说明 |
---|---|---|
symbol | String | 股票代码 |
lotSize | Integer | 每手股数 |
spreadScale | Integer | 报价精度 |
minTick | Double | 股价最小变动单位 |
具体字段可通过对象的get方法,如getSymbol()
进行访问, 或通过对象的toString()
方法转换为字符串
示例
List<String> symbols = new ArrayList<>();
symbols.add("00700");
symbols.add("00810");
QuoteStockTradeResponse response = client.execute(QuoteStockTradeRequest.newRequest(symbols));
if (response.isSuccess()) {
System.out.println(Arrays.toString(response.getStockTradeItems().toArray()));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"code": 0,
"data": [{
"lotSize": 100,
"minTick": 0.2,
"spreadScale": 0,
"symbol": "00700"
}, {
"lotSize": 6000,
"minTick": 0.001,
"spreadScale": 0,
"symbol": "00810"
}],
"message": "success",
"timestamp": 1546853907390
}
获取股票资金流数据
对应的请求类:QuoteCapitalFlowRequest
说明
获取股票资金净流入数据,包括最近一个交易日的实时分钟数据,和不同周期的净流入数据。对不同的时间粒度,支持获取以日、周、月、季、半年、年为单位的数据,最高限制为1200条,默认为200条。
参数
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbol | string | Yes | 股票代码 |
period | string | Yes | 数据类型,取值范围(intraday:实时,day:日,week:周,month:月,year:年,quarter:季度,6month:半年) |
market | string | Yes | US 美股,HK港股,CN A股(实时资金流向不支持A股) |
begin_time | long | No | 开始时间,默认:-1,单位:毫秒(ms),前闭后开区间,即查询结果会包含起始时间数据,如查询周/月/年K线,会返回包含当前周期的数据(如:起始时间为周三,会返回从这周一的数据) |
end_time | long | No | 结束时间,默认:-1,单位:毫秒(ms) |
limit | integer | No | 单次请求返回数量,不传默认是200,limit不能超过1200,如果limit设置大于1200,只会返回1200条数据 |
lang | string | No | 语言支持: zh_CN,zh_TW,en_US, 默认: en_US |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteCapitalFlowResponse
source
返回数据可通过QuoteCapitalFlowResponse.getCapitalFlowItem()
方法访问,返回CapitalFlowItem
对象,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.CapitalFlowItem
属性如下:
字段 | 类型 | 说明 |
---|---|---|
symbol | string | 股票代码 |
period | string | 周期 |
items | array | 资金净流入数组,字段参考下面说明 |
其中具体时间点的数据items属性如下:
字段 | 类型 | 说明 |
---|---|---|
netInflow | double | 净流入金额,负数表示流出 |
time | string | 标的所在市场时区的时间字符串,实时数据时为"11-25 12:48:00 EST"格式,非实时数据为"2022-11-22"格式 |
timestamp | long | 时间 |
示例
TigerHttpClient client = TigerHttpClient.getInstance().clientConfig(
ClientConfig.DEFAULT_CONFIG);
// 实时数据
QuoteCapitalFlowRequest request = QuoteCapitalFlowRequest.newRequest(
"AAPL", Market.US, CapitalPeriod.intraday);
QuoteCapitalFlowResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(JSONObject.toJSON(response.getCapitalFlowItem()));
} else {
System.out.println("response error:" + response.getMessage());
}
// 最近10天资金净流入数据
QuoteCapitalFlowRequest request = QuoteCapitalFlowRequest.newRequest(
"00700", Market.HK, CapitalPeriod.day);
request.setLimit(10);
QuoteCapitalFlowResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(JSONObject.toJSON(response.getCapitalFlowItem()));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
// 实时数据
{
"symbol":"AAPL",
"items":[
{
"netInflow":-109057032.2042,
"time":"11-25 09:30:00 EST",
"timestamp":1669386600000
},
{
"netInflow":-116890065.471,
"time":"11-25 09:31:00 EST",
"timestamp":1669386660000
}
]
}
// 最近10天资金净流入数据
{
"symbol":"00700",
"period":"day",
"items":[
{
"netInflow":687742300,
"time":"2022-11-14",
"timestamp":1668355200000
},
{
"netInflow":1926444000,
"time":"2022-11-15",
"timestamp":1668441600000
},
{
"netInflow":1033900840,
"time":"2022-11-16",
"timestamp":1668528000000
},
{
"netInflow":1667729580,
"time":"2022-11-17",
"timestamp":1668614400000
},
{
"netInflow":284728680,
"time":"2022-11-18",
"timestamp":1668700800000
},
{
"netInflow":661046060,
"time":"2022-11-21",
"timestamp":1668960000000
},
{
"netInflow":-86129700,
"time":"2022-11-22",
"timestamp":1669046400000
},
{
"netInflow":350223200,
"time":"2022-11-23",
"timestamp":1669132800000
},
{
"netInflow":-161005460,
"time":"2022-11-24",
"timestamp":1669219200000
},
{
"netInflow":17355680,
"time":"2022-11-25",
"timestamp":1669305600000
}
]
}
获取股票资金分布
对应的请求类:QuoteCapitalDistributionRequest
说明
获取股票资金分布。
参数
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbol | string | Yes | 股票代码 |
market | string | Yes | US 美股,HK港股,CN A股 |
lang | string | No | 语言支持: zh_CN,zh_TW,en_US, 默认: en_US |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteCapitalDistributionResponse
source
返回数据可通过QuoteCapitalDistributionResponse.getCapitalDistributionItem()
方法访问,返回CapitalDistributionItem
对象,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.CapitalDistributionItem
属性如下:
字段 | 类型 | 说明 |
---|---|---|
symbol | string | 股票代码 |
netInflow | double | 净流入金额(资金总流入 - 资金总流出),负数表示流出 |
inAll | double | 资金流入总额(大单+中单+小单) |
inBig | double | 大单流入 |
inMid | double | 中单流入 |
inSmall | double | 小单流入 |
outAll | double | 资金流出总额(大单+中单+小单) |
outBig | double | 大单流出 |
outMid | double | 中单流出 |
outSmall | double | 小单流出 |
示例
TigerHttpClient client = TigerHttpClient.getInstance().clientConfig(
ClientConfig.DEFAULT_CONFIG);
QuoteCapitalDistributionRequest request = QuoteCapitalDistributionRequest.newRequest(
"00700", Market.HK);
QuoteCapitalDistributionResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(JSONObject.toJSON(response.getCapitalDistributionItem()));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"inBig":721190520,
"netInflow":481406280,
"symbol":"00700",
"outBig":464624440,
"outAll":3639820460,
"inAll":4121226740,
"inMid":604918520,
"inSmall":2795117700,
"outMid":572017220,
"outSmall":2603178800
}
获取港股经纪商买卖席位
对应的请求类:QuoteStockBrokerRequest
说明
获取港股经纪商买卖席位。
参数
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbol | string | Yes | 股票代码 |
limit | integer | No | 单次请求返回买方/卖方席位数量,不传默认是40,limit不能超过60,如果limit设置大于60,只会返回60条数据 |
lang | string | No | 语言支持: zh_CN,zh_TW,en_US, 默认: en_US |
返回
com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteStockBrokerResponse
source
返回数据可通过QuoteStockBrokerResponse.getStockBrokerItem()
方法访问,返回StockBrokerItem
对象,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.StockBrokerItem
属性如下:
字段 | 类型 | 说明 |
---|---|---|
symbol | string | 股票代码 |
bidBroker | array | 买方不同价格档位数组,字段参考LevelBroker说明 |
askBroker | array | 卖方不同价格档位数组,字段参考LevelBroker说明 |
其中LevelBroker属性如下:
字段 | 类型 | 说明 |
---|---|---|
level | integer | 价格档位 |
price | double | 价格 |
brokerCount | integer | 席位数量 |
broker | array | 经纪商买卖席位列表 |
示例
TigerHttpClient client = TigerHttpClient.getInstance().clientConfig(
ClientConfig.DEFAULT_CONFIG);
QuoteStockBrokerRequest request = QuoteStockBrokerRequest.newRequest("00700", 10, Language.zh_CN);
QuoteStockBrokerResponse response = client.execute(request);
if (response.isSuccess()) {
System.out.println(JSONObject.toJSON(response.getStockBrokerItem()));
} else {
System.out.println("response error:" + response.getMessage());
}
返回示例
{
"bidBroker":[
{
"level":1,
"price":287.8,
"brokerCount":7,
"broker":[
{
"name":"中国投资",
"id":"6997"
},
{
"name":"中国投资",
"id":"6998"
},
{
"name":"中银",
"id":"8134"
},
{
"name":"中国投资",
"id":"6998"
},
{
"name":"中国创盈",
"id":"5999"
},
{
"name":"中国投资",
"id":"6996"
},
{
"name":"J.P. Morgan",
"id":"5342"
}
]
},
{
"level":2,
"price":287.6,
"brokerCount":3,
"broker":[
{
"name":"中国投资",
"id":"6998"
},
{
"name":"中国投资",
"id":"6999"
},
{
"name":"中国创盈",
"id":"5998"
}
]
}
],
"symbol":"00700",
"askBroker":[
{
"level":1,
"price":288,
"brokerCount":10,
"broker":[
{
"name":"FUTU Securities",
"id":"8461"
},
{
"name":"中国创盈",
"id":"5998"
},
{
"name":"工银亚洲",
"id":"8117"
},
{
"name":"中国创盈",
"id":"5998"
},
{
"name":"中国投资",
"id":"6999"
},
{
"name":"汇丰",
"id":"8577"
},
{
"name":"中国投资",
"id":"6996"
},
{
"name":"中国投资",
"id":"6999"
},
{
"name":"FUTU Securities",
"id":"8462"
},
{
"name":"汇丰",
"id":"8575"
}
]
}
]
}