股票

大约 23 分钟

获取市场状态

对应的请求类:QuoteMarketRequest

说明

获取市场状态

参数

参数类型是否必填说明
marketMarketYes常用市场枚举值:US 美股,HK港股,CN A股,ALL 所有,枚举值详见: 市场枚举
langLanguageNo语言枚举值:zh_CN,zh_TW,en_US,默认:en_US,枚举值详见:语言枚举

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteMarketResponsesourceopen in new window

其结构如下:

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 属性如下:

字段类型说明
marketstring市场代码(US:美股,CN:沪深,HK:港股)
marketStatusstring市场状态描述,非固定值,包括节假日信息等,如:"Not Yet Opened","Closed","Trading","Closed Independence Day",通过lang参数区分中英文文案,该字段可以用来做市场状态的提醒展示。
statusstring市场状态,包括:NOT_YET_OPEN:未开盘,PRE_HOUR_TRADING:盘前交易,TRADING:交易中,MIDDLE_CLOSE:午间休市,POST_HOUR_TRADING:盘后交易,CLOSING:已收盘,EARLY_CLOSED:提前休市,MARKET_CLOSED:休市
openTimestring最近开盘、交易时间 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

说明

获取市场交易日历. 通过去除周末和该市场节假日得出,未去除临时休市的日期

参数

参数类型是否必填说明
marketstringYesUS 美股,HK港股,CN A股
begin_datestringNo日历起始日期(包含)。yyyy-MM-dd 格式,如 '2022-06-01'
end_datestringNo日历截至日期(不包含)。yyyy-MM-dd 格式

begin_time 和 end_time 传参处理如下:

begin_time是否传递end_time是否传递说明
yesyesbegin_time和end_time分别为所传值
yesnoend_time为begin_time往后365天
noyesbegin_time为end_time往前365天
nonobegin_time为当前日期,end_time为begin_time往后30天

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteTradeCalendarResponsesourceopen in new window

其结构如下:

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 属性如下:

字段类型说明
datestring交易日日期
typestring交易日类型. 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

说明

获取股票代码列表

参数

参数类型是否必填说明
marketstringYesUS 美股,HK港股,CN A股
include_otcbooleanNo是否包含OTC标的,默认:false
langstringNo语言支持: zh_CN,zh_TW,en_US, 默认: en_US

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteSymbolResponsesourceopen in new window

具体结构如下

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

说明

获取股票代码列表和名称

参数

参数类型是否必填说明
marketstringYesUS 美股,HK港股, CN A股
include_otcbooleanNo是否包含OTC标的,默认:false
langstringNo语言支持: zh_CN,zh_TW,en_US, 默认: en_US

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteSymbolNameResponsesourceopen in new window

具体结构如下

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 属性如下:

字段类型说明
namestring股票名称
symbolstring股票代码

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

说明

获取延迟行情,此行情接口不需要购买行情权限即可调用,目前免费提供给用户

参数

参数类型是否必填描述
symbolsarrayYes股票代码(单次请求上限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 sourceopen in new window

具体结构如下:

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 属性如下:

字段类型说明
closedouble收盘价
highdouble最高价
lowdouble最低价
opendouble开盘价
preClosedouble昨日收盘价
timelong时间
volumelong成交量

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

说明

获取分时数据

参数

参数类型是否必填描述
symbolsarrayYes股票代码列表
periodstringYes分时周期,包含:day 和 day5
trade_sessionStringNoTradeSession枚举对象,盘前:PreMarket, 盘中:Regular, 盘后:AfterHours。默认为盘中
begin_timelongNo开始时间(毫秒时间戳),默认返回当天数据
langstringNo语言支持: zh_CN,zh_TW,en_US, 默认: en_US

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteTimelineResponsesourceopen in new window

具体结构如下:

返回数据可通过QuoteTimelineResponse.getTimelineItems()方法访问,返回为包含TimelineItem对象的List,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.TimelineItem 属性如下:

字段类型说明
symbolstring股票代码
periodstring周期 day or 5day
preClosedouble昨日收盘价
intradayobject盘中分时数组,字段参考下面说明
preMarketobject(仅美股) 盘前分时数组和起始结束时间,字段参考下面说明
afterHoursobject(仅美股) 盘后分时数组和起始结束时间,字段参考下面说明

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分钟的分时数据

参数

参数类型是否必填描述
symbolsarrayYes股票代码列表
datestringYes年月日yyyyMMdd,例如20220420
rightRightOptionNo前复权:br, 不复权:nr;默认:nr

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteHistoryTimelineResponsesourceopen in new window

具体结构如下:

返回数据可通过QuoteHistoryTimelineResponse.getTimelineItems()方法访问,返回为包含HistoryTimelineItem对象的List,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.HistoryTimelineItem 属性如下:

字段类型说明
symbolstring股票代码
itemsTimelinePoint盘中分时数组,字段参考下面说明

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

说明

获取实时行情,需要购买行情权限才可以开通

参数

参数类型是否必填描述
symbolsarrayYes股票代码列表(单次上限50)
includeHourTradingBooleanNo是否包含美股盘前盘后数据,默认: false
langstringNo语言支持: zh_CN,zh_TW,en_US, 默认: en_US

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteRealTimeQuoteResponsesourceopen in new window

返回数据可通过QuoteRealTimeQuoteResponse.getRealTimeQuoteItems()方法访问,返回RealTimeQuoteItem对象,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.RealTimeQuoteItem 属性如下:

字段类型说明
symbolstring股票代码
opendouble开盘价
highdouble最高价
lowdouble最低价
closedouble收盘价
preClosedouble前一交易日收盘价
latestPricedouble最新价
latestTimelong最新成交时间
askPricedouble卖盘价
askSizelong卖盘数量
bidPricedouble买盘价
bidSizelong买盘数量
volumelong成交量
statusstring交易状态
hourTradingobject美股盘前盘后数据(includeHourTrading参数为true,且盘前盘后时间段才有数据)

其中hourTrading对象包含的字段:

字段类型说明
tagstring盘前("Pre-Mkt")、盘后("Post-Mkt")标识
latestPricedouble最新价
preClosedouble昨收价
latestTimestring最新成交时间(美东时间)
volumelong成交量
timestamplong最新成交时间

具体字段可通过对象的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分钟为单位的K线数据。考虑到接口性能和稳定性,此接口请求最高限制为1200条。对于需要更多历史数据进行分析或回测的用户,可以自行实现循环或者使用pageToken,通过多次请求的方式获取更长时间范围的历史的数据。需要注意的是,可以请求的K线时间长度可能会存在限制,具体请见历史行情限制

参数

参数类型是否必填描述
symbolsarrayYes股票代码列表,上限:50,其中A股上限:10
periodstringYesK线类型,取值范围(day:日K,week:周K,month:月K,year:年K,1min:1分钟,3min:3分钟,5min:5分钟,15min:15分钟,30min:30分钟,60min:60分钟)
rightstringNo复权选项 ,br: 前复权(默认),nr: 不复权
begin_timelongNo开始时间,默认:-1,单位:毫秒(ms),前闭后开区间,即查询结果会包含起始时间数据,如查询周/月/年K线,会返回包含当前周期的数据(如:起始时间为周三,会返回从这周一的K线)
end_timelongNo结束时间,默认:-1,单位:毫秒(ms)
limitintegerNo单次请求返回K线数量,不传默认是300,limit不能超过1200,如果limit设置大于1200,只会返回1200条数据
langstringNo语言支持: zh_CN,zh_TW,en_US, 默认: en_US
pageTokenstringNo分页查询token(只支持单个symbol,指定begin_time的查询),使用pageToken分页拉取数据时其他查询条件不能改变

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteKlineResponsesourceopen in new window

返回数据可通过QuoteKlineResponse.getKlineItems()方法访问,返回KlineItem对象列表,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.KlineItem 属性如下:

字段类型说明
symbolstring股票代码
periodstringK线周期
nextPageTokenstring查询下一页的token(只支持单个symbol,begin_time不为-1时才有效),如果没有更多数据返回null
itemsarrayK线对象KlinePoint的数组,字段参考下面说明

其中K线数据KlinePoint的属性如下:

K线字段类型说明
closedouble收盘价
highdouble最高价
lowdouble最低价
opendouble开盘价
timelong时间
volumelong成交量
amountdouble成交额

具体字段可通过对象的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之后的一两分钟后更新

请求频率 频率限制请参考:请求频率限制

参数

参数类型是否必填描述
symbolsarrayYes股票代码列表(单次上限50)
marketstringYesUS 美股,HK港股,CN A股,ALL 所有(参考Market枚举类)

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteDepthResponsesourceopen in new window

具体结构如下

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 属性如下:

字段类型说明
symbolstring股票代码
askslist卖盘分档
bidslist买盘分档

其中买卖盘详细字段如下:

字段类型说明
pricedouble委托价
volumelong委托量
countint委托订单数(只有港股市场有,美股市场没有值)

示例

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

说明

获取逐笔成交数据,该接口可以支持在收盘后查询当前交易日的全量逐笔记录,也可以支持查询盘中最新的实时逐笔记录。

参数

参数类型是否必填描述
symbolsarrayYes股票代码列表,支持陆股通股、港股、美股
trade_sessionStringNoTradeSession枚举对象,盘前:PreMarket, 盘中:Regular, 盘后:AfterHours。默认为盘中
beginIndexlongyes起始索引,当日索引值从0开始,如果beginIndex和endIndex设置为-1,会返回最新的逐笔数据,后续查询时,可以把上次查询返回的endIndex值当做beginIndex,从而进行连续查询,返回数据为前闭后开集合,比如:beginIndex=1,endIndex=100,会返回从1到99的记录,下次查询时,设置beginIndex=100,endIndex=200。
endIndexlongyes结束索引,结束索引和起始索引的差值不能大于2000,大于2000时默认返回从起始索引开始的200条记录。当limit参数小于起始和结束索引的差值时,只会返回从起始索引开始的limit条逐笔数据。
limitintegerNo单次请求返回的逐笔数量,如果起始和结束索引的间隔没有超过2000,会按照实际条数返回,否则会默认为200。
langstringNo语言支持: zh_CN,zh_TW,en_US, 默认: en_US

beginIndex 和 endIndex参数使用说明

查询方式beginIndexendIndex描述
查询最新逐笔记录-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.QuoteTradeTickResponsesourceopen in new window

结构如下:

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 属性如下:

字段类型说明
beginIndexlong返回数据的实际开始索引
endIndexlong返回数据的实际结束索引
symbolstring请求的股票代码
itemsList<TickPoint>包含逐笔成交数据的List,单条逐笔成交数据保存在TickPoint对象中

其中TickPoint对象字段如下:

字段类型说明
timelong交易时间戳
pricedouble成交价
volumelong成交量
typestring"+"表示主动买入,"-"表示主动卖出,"*"表示中性

具体字段可通过对象的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

说明

获取股票交易所需的信息,包括每手股数,报价精度及股价最小变动单位

参数

参数类型是否必填描述
symbolsarrayYes股票代码列表,上限为:50

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteStockTradeResponsesourceopen in new window

结构如下:

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 属性如下:

名称类型说明
symbolString股票代码
lotSizeInteger每手股数
spreadScaleInteger报价精度
minTickDouble股价最小变动单位

具体字段可通过对象的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条。

参数

参数类型是否必填描述
symbolstringYes股票代码
periodstringYes数据类型,取值范围(intraday:实时,day:日,week:周,month:月,year:年,quarter:季度,6month:半年)
marketstringYesUS 美股,HK港股,CN A股(实时资金流向不支持A股)
begin_timelongNo开始时间,默认:-1,单位:毫秒(ms),前闭后开区间,即查询结果会包含起始时间数据,如查询周/月/年K线,会返回包含当前周期的数据(如:起始时间为周三,会返回从这周一的数据)
end_timelongNo结束时间,默认:-1,单位:毫秒(ms)
limitintegerNo单次请求返回数量,不传默认是200,limit不能超过1200,如果limit设置大于1200,只会返回1200条数据
langstringNo语言支持: zh_CN,zh_TW,en_US, 默认: en_US

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteCapitalFlowResponsesourceopen in new window

返回数据可通过QuoteCapitalFlowResponse.getCapitalFlowItem()方法访问,返回CapitalFlowItem对象,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.CapitalFlowItem 属性如下:

字段类型说明
symbolstring股票代码
periodstring周期
itemsarray资金净流入数组,字段参考下面说明

其中具体时间点的数据items属性如下:

字段类型说明
netInflowdouble净流入金额,负数表示流出
timestring标的所在市场时区的时间字符串,实时数据时为"11-25 12:48:00 EST"格式,非实时数据为"2022-11-22"格式
timestamplong时间

示例

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

说明

获取股票资金分布。

参数

参数类型是否必填描述
symbolstringYes股票代码
marketstringYesUS 美股,HK港股,CN A股
langstringNo语言支持: zh_CN,zh_TW,en_US, 默认: en_US

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteCapitalDistributionResponsesourceopen in new window

返回数据可通过QuoteCapitalDistributionResponse.getCapitalDistributionItem()方法访问,返回CapitalDistributionItem对象,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.CapitalDistributionItem 属性如下:

字段类型说明
symbolstring股票代码
netInflowdouble净流入金额(资金总流入 - 资金总流出),负数表示流出
inAlldouble资金流入总额(大单+中单+小单)
inBigdouble大单流入
inMiddouble中单流入
inSmalldouble小单流入
outAlldouble资金流出总额(大单+中单+小单)
outBigdouble大单流出
outMiddouble中单流出
outSmalldouble小单流出

示例

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

说明

获取港股经纪商买卖席位。

参数

参数类型是否必填描述
symbolstringYes股票代码
limitintegerNo单次请求返回买方/卖方席位数量,不传默认是40,limit不能超过60,如果limit设置大于60,只会返回60条数据
langstringNo语言支持: zh_CN,zh_TW,en_US, 默认: en_US

返回

com.tigerbrokers.stock.openapi.client.https.response.quote.QuoteStockBrokerResponsesourceopen in new window

返回数据可通过QuoteStockBrokerResponse.getStockBrokerItem()方法访问,返回StockBrokerItem对象,其中com.tigerbrokers.stock.openapi.client.https.domain.quote.item.StockBrokerItem 属性如下:

字段类型说明
symbolstring股票代码
bidBrokerarray买方不同价格档位数组,字段参考LevelBroker说明
askBrokerarray卖方不同价格档位数组,字段参考LevelBroker说明

其中LevelBroker属性如下:

字段类型说明
levelinteger价格档位
pricedouble价格
brokerCountinteger席位数量
brokerarray经纪商买卖席位列表

示例

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"
                }
            ]
        }
    ]
}
上次编辑于: