证券类
get_market_state 获取市场状态
value QuoteClient::get_market_state(string market);
说明
获取被查询市场的状态(开盘,盘前交易,盘后等),并获取被查询市场的最近开盘时间
请求频率
频率限制请参考:接口请求限制
参数
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
market | Market | Yes | 查询的市场,可以使用 tigerapi/enums.h Market 下提供的枚举常量,如 Market.US,参见枚举参数部分 |
返回
元素为 MarketStatus 对象,MarketStatus结构如下:
参数名 | 类型 | 描述 |
---|---|---|
market | utility::string_t | 市场名称 |
trading_status | utility::string_t | 交易状态码。未开盘 NOT_YET_OPEN; 盘前交易 PRE_HOUR_TRADING; 交易中 TRADING; 午间休市 MIDDLE_CLOSE; 盘后交易 POST_HOUR_TRADING; 已收盘 CLOSING; 提前休市 EARLY_CLOSED; 休市 MARKET_CLOSED; |
status | utility::string_t | 交易状态描述 |
open_time | datetime | 最近的开盘、交易时间,带tzinfo |
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
/**
* 使用封装后的行情接口 QuoteClient
*/
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value result = quote_client->get_market_state("US");
cout << result << endl;
return 0;
}
** 返回示例 **
[{"market":"HK","marketStatus":"Trading","openTime":"01-12 09:30:00","status":"TRADING"}]
get_trading_calendar
获取市场交易日历
QuoteClient::get_trading_calendar(market, begin_date, end_date)
说明
获取市场交易日历. 通过去除周末和该市场节假日得出,未去除临时休市的日期.
提供2015年之后到本年底的日历。 如果超出范围,则起止时间会被处理到提供数据的范围内。
请求频率
频率限制请参考:接口请求限制
参数
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
market | Market | Yes | 查询的市场,可以使用 tigerapi/enums.h Market 下提供的枚举常量,如 Market.US,参见枚举参数部分 |
begin_date | str | No | 日历起始时间, 结果里包含本日。yyyy-MM-dd 格式,如 '2022-06-01' |
end_date | str | 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天 |
返回
参数名 | 类型 | 描述 |
---|---|---|
date | str | 交易日日期 |
type | str | 交易日类型. TRADING为正常交易日,全天交易; EARLY_CLOSE为提前休市 |
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value result = quote_client->get_trading_calendar("US", "2023-01-01", "2023-03-01");
cout << result << endl;
return 0;
}
返回示例
[{"date":"2023-01-03","type":"TRADING"},{"date":"2023-01-04","type":"TRADING"},{"date":"2023-01-05","type":"TRADING"},{"date":"2023-01-06","type":"TRADING"},{"date":"2023-01-09","type":"TRADING"},{"date":"2023-01-10","type":"TRADING"},{"date":"2023-01-11","type":"TRADING"},{"date":"2023-01-12","type":"TRADING"},{"date":"2023-01-13","type":"TRADING"},{"date":"2023-01-17","type":"TRADING"},{"date":"2023-01-18","type":"TRADING"},{"date":"2023-01-19","type":"TRADING"},{"date":"2023-01-20","type":"TRADING"},{"date":"2023-01-23","type":"TRADING"},{"date":"2023-01-24","type":"TRADING"},{"date":"2023-01-25","type":"TRADING"},{"date":"2023-01-26","type":"TRADING"},{"date":"2023-01-27","type":"TRADING"},{"date":"2023-01-30","type":"TRADING"},{"date":"2023-01-31","type":"TRADING"},{"date":"2023-02-01","type":"TRADING"},{"date":"2023-02-02","type":"TRADING"},{"date":"2023-02-03","type":"TRADING"},{"date":"2023-02-06","type":"TRADING"},{"date":"2023-02-07","type":"TRADING"},{"date":"2023-02-08","type":"TRADING"},{"date":"2023-02-09","type":"TRADING"},{"date":"2023-02-10","type":"TRADING"},{"date":"2023-02-13","type":"TRADING"},{"date":"2023-02-14","type":"TRADING"},{"date":"2023-02-15","type":"TRADING"},{"date":"2023-02-16","type":"TRADING"},{"date":"2023-02-17","type":"TRADING"},{"date":"2023-02-21","type":"TRADING"},{"date":"2023-02-22","type":"TRADING"},{"date":"2023-02-23","type":"TRADING"},{"date":"2023-02-24","type":"TRADING"},{"date":"2023-02-27","type":"TRADING"},{"date":"2023-02-28","type":"TRADING"}]
get_symbols 获取所有证券代码列表
value get_symbols(Market market = Market::ALL);
说明
获取所选市场所有证券的代码列表,包含退市和不可交易的部分代码以及指数。
请求频率
频率限制请参考:接口请求限制
参数
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
market | Market | Yes | 查询的市场, 可以使用tigerapi/enums.h Market下提供的枚举常量,如 US |
返回
元素为市场所有证券的symbol,包含退市和不可交易的部分代码。其中以.
开头的代码为指数, 如 .DJI
表示道琼斯指数。
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value result = quote_client->get_symbols();
cout << result << endl;
return 0;
}
返回示例
"ZCMD","ZD","ZDGE","ZEAL","ZECP","ZEN","ZENV","ZEPP","ZEST","ZETA","ZEUS","ZEV","ZG","ZH","ZHDG","ZI","ZIG","ZIM","ZINGU","ZION","ZIONL","ZIONO","ZIONP","ZIP","ZIVO","ZKIN","ZLAB","ZM","ZNH","ZNTEU","ZNTL","ZOM","ZROZ","ZS","ZSB","ZSL","ZT","ZTAQU","ZTO","ZTR","ZTS","ZUMZ","ZUO","ZVIA","ZWS","ZY","ZYME","ZYNE","ZYXI"]
get_symbol_names 获取代码及名称列表
value get_all_symbol_names(Market market = Market::ALL);
value get_all_symbol_names(string market="ALL");
说明
获取所选市场所有证券的代码及名称
请求频率
频率限制请参考:接口请求限制
参数
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
market | Market | Yes | 查询的市场,可以使用tigerapi/enums.h Market下提供的枚举常量,如 Market.US |
返回
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbol | string | Yes | 股票代码 |
name | string | Yes | 股票名称 |
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value result = quote_client->get_symbol_names();
cout << result << endl;
return 0;
}
返回示例
[{"name":"CKH HOLDINGS","symbol":"00001"},{"name":"CLP HOLDINGS","symbol":"00002"},
{"name":"HK & CHINA GAS","symbol":"00003"},{"name":"WHARF HOLDINGS","symbol":"00004"},
{"name":"HSBC HOLDINGS","symbol":"00005"}]
get_timeline 获取最近一个交易日的分时数据
value get_timeline(const value &symbols, bool include_hour_trading=false, long begin_time=-1);
说明
获取最近一个交易日的分时数据,分时数据与分钟bar类似,每分钟产生一个。只支持查询最新一个交易日的数据,如果需要历史数据,请使用 get_bars
接口查询
请求频率
频率限制请参考:接口请求限制
参数
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | value | Yes | 证券代码列表,单次上限50只,如 ['AAPL', 'TSLA'] |
include_hour_trading | bool | No | 是否包含盘前盘后分时数据,可选填,如 True 或 False |
begin_time | utility::string_t | No | 获取分时数据的起始时间, 支持毫秒级别的时间戳,或日期时间字符串。如 1639386000000 或 '2019-06-07 23:00:00' 或 '2019-06-07',默认返回当天数据 |
lang | Language | No | 支持的语言,可以使用tigerapi/enums.h Language下提供的枚举常量,默认为英文 |
返回
结构如下:
COLUMN | 类型 | 描述 |
---|---|---|
symbol | str | 证券代码,如 AAPL |
time | int | 精确到毫秒的时间戳,如 1639386000000 |
price | float | 当前分钟的收盘价 |
avg_price | float | 截至到当前时间的成交量加权均价 |
pre_close | float | 昨日收盘价 |
volume | int | 这一分钟的成交量 |
trading_session | str | 字符串, "pre_market" 表示盘前交易, "regular" 表示盘中交易, "after_hours"表示盘后交易。 |
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value symbols = value::array();
symbols[0] = value::string("AAPL");
symbols[1] = value::string("JD");
value result = quote_client->get_timeline(symbols);
cout << result << endl;
return 0;
}
返回示例
get_history_timeline 获取历史分时数据
value get_history_timeline(const value &symbols, string date, QuoteRight right=QuoteRight::br);
说明
获取某一日期的历史分时数据
请求频率
频率限制请参考:接口请求限制
参数
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | list<str...> | Yes | 证券代码列表,单次上限50只,如 ['AAPL', 'TSLA'] |
date | str | Yes | 日期字符串。如 '2022-04-14' |
right | QuoteRight | No | 行情复权,默认前复权。可以使用tigerapi/enums.h QuoteRight的枚举值 |
返回
结构如下:
COLUMN | 类型 | 描述 |
---|---|---|
symbol | str | 证券代码,如 AAPL |
time | int | 精确到毫秒的时间戳,如 1639386000000 |
price | float | 当前分钟的收盘价 |
avg_price | float | 截至到当前时间的成交量加权均价 |
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value symbols = value::array();
symbols[0] = value::string("AAPL");
symbols[1] = value::string("JD");
value result = quote_client->get_history_timeline(symbols, "2023-01-10");
cout << result << endl;
return 0;
}
返回示例
[{"items":[{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673361000000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673361060000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673361120000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673361180000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673361240000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673364660000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673364720000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673364780000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673364840000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673364900000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673364960000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673365020000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673365080000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673365140000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673365200000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673365260000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673365320000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673365380000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673365440000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673365500000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673365560000,"volume":0},{"avgPrice":130.15000000000001,"price":130.15000000000001,"time":1673365620000,"volume":0},{"avgPrice":63.130000000000003,"price":63.130000000000003,"time":1673384220000,"volume":0},{"avgPrice":63.130000000000003,"price":63.130000000000003,"time":1673384280000,"volume":0},{"avgPrice":63.662365000000001,"price":63.649999999999999,"time":1673384340000,"volume":230124}],"symbol":"JD"}]
get_trade_tick 获取逐笔成交数据
value get_trade_tick(const value &symbols, TradingSession trade_session=TradingSession::Regular, long begin_index=-1, long end_index=-1, int limit=100);
说明
获取逐笔成交数据,该接口可以支持在收盘后查询当前交易日的全量逐笔记录,也可以支持查询盘中最新的实时逐笔记录。
请求频率
频率限制请参考:接口请求限制
参数
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | list<str...> | Yes | 证券代码列表,最多50个 |
trade_session | tigerapi/enums.h TradingSession | No | 交易时段,盘前/盘中/盘后。非必填,默认返回盘中数据 |
begin_index | int | No | 起始索引,当日索引值从0开始,如果begin_index和end_index设置为-1,会返回最新的逐笔数据,后续查询时,可以把上次查询返回的end_index值当做begin_index,从而进行连续查询,返回数据为前闭后开集合,比如:begin_index=1,end_index=100,会返回从1到99的记录,下次查询时,设置begin_index=100,end_index=200。 |
end_index | int | No | 结束索引,结束索引和起始索引的差值不能大于2000,大于2000时默认返回从起始索引开始的200条记录。当limit参数小于起始和结束索引的差值时,只会返回从起始索引开始的limit条逐笔数据。 |
limit | int | No | 返回条数限制,默认返回:200,最大限制:2000 |
lang | Language | No | 支持的语言, 可以使用 tigerapi/enums.h Language 下提供的枚举常量,默认英文 |
begin_index 和 end_index参数使用说明
查询方式 | begin_index | end_index | 描述 |
---|---|---|---|
查询最新逐笔记录 | -1 | -1 | 默认返回limit条最新的逐笔记录。limit 默认为200 |
根据区间查询当日逐笔 | 具体数值 | 具体数值 | 举例:begin_index=10, end_index=100 ,会返回包含10到99的 90条记录。如果limit设置为20,则会返回10到29的20条记录。 |
返回
结构如下:
参数名 | 类型 | 描述 |
---|---|---|
index | int | 索引值 |
time | int | 毫秒时间戳 |
price | float | 成交价 |
volume | int | 成交量 |
direction | str | 价格变动方向,"+"表示主动买入,"-"表示主动卖出,"*"表示中性 |
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value symbols = value::array();
symbols[0] = value::string("AAPL");
symbols[1] = value::string("JD");
value result = quote_client->get_trade_tick(symbols);
cout << result << endl;
return 0;
}
返回示例
get_quote_real_time 获取股票实时行情
value get_quote_real_time(const value &symbols);
说明
获取股票的实时行情,使用前需购买相应的行情权限,单次请求限制50只股票
请求频率
频率限制请参考:接口请求限制
参数
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | list<str...> | Yes | 证券代码的列表,最多50只,如 ['AAPL', 'MSFT'] |
lang | Language | No | 支持的语言,可以使用tigerapi/enums.h Language下提供的枚举常量 |
返回
结构如下:
COLUMN | 类型 | 描述 |
---|---|---|
symbol | str | 证券代码 |
ask_price | float | 卖一价 |
ask_size | int | 卖一量 |
bid_price | float | 买一价 |
bid_size | int | 买一量 |
pre_close | float | 前收价 |
latest_price | float | 最新价 |
latest_time | int | 最新成交时间,毫秒单位数字时间戳 |
volume | int | 成交量 |
open | float | 开盘价 |
high | float | 最高价 |
low | float | 最低价 |
status | str | 交易状态 |
status(交易状态) 取值:
- "UNKNOWN": 未知
- "NORMAL": 正常
- "HALTED": 停牌
- "DELIST": 退市
- "NEW": 新股
- "ALTER": 变更
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value symbols = value::array();
symbols[0] = value::string("AAPL");
symbols[1] = value::string("JD");
value result = quote_client->get_quote_real_time(symbols);
cout << result << endl;
return 0;
}
get_quote_delay 获取股票延迟行情
value get_quote_delay(const value &symbols);
说明
本接口为免费延迟行情接口。不需要购买行情权限,开通开发者账号后可直接请求使用。目前仅支持获取美股延迟行情,相对实时行情延迟15分钟
请求频率
频率限制请参考:接口请求限制
参数
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | list<str...> | Yes | 证券代码的列表,目前仅支持获取美股延迟行情。 如 ['AAPL', 'MSFT'],单次请求上限50 |
lang | Language | No | 支持的语言, 可以使用tigerapi/enums.h Language下提供的枚举常量, 如 Language.en_US |
返回
结构如下:
参数名 | 类型 | 描述 |
---|---|---|
symbol | str | 证券代码 |
pre_close | float | 前收价 |
time | int | 最近成交时间,毫秒为单位的数字时间戳,如 1639429200000 |
volume | int | 成交量 |
open | float | 开盘价 |
high | float | 最高价 |
low | float | 最低价 |
close | float | 收盘价 |
halted | float | 标的状态 (0: 正常 3: 停牌 4: 退市 7: 新股 8: 变更) |
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value symbols = value::array();
symbols[0] = value::string("AAPL");
symbols[1] = value::string("JD");
value result = quote_client->get_quote_delay(symbols);
cout << result << endl;
return 0;
}
返回示例
[{"close":130.72999999999999,"halted":0,"high":131.2636,"low":128.12,"open":130.25999999999999,"preClose":130.15000000000001,"symbol":"AAPL","time":1673384400000,"volume":63896155},{"close":63.649999999999999,"halted":0,"high":64.620000000000005,"low":62.950000000000003,"open":64.099999999999994,"preClose":63.130000000000003,"symbol":"JD","time":1673384400000,"volume":5537959}]
get_kline 获取K线数据
value get_kline(const value &symbols, BarPeriod period=BarPeriod::DAY, long begin_time=-1, long end_time=-1,
QuoteRight right=QuoteRight::br, int limit=251, string page_token="");
value get_kline(const value &symbols, string period, long begin_time=-1, long end_time=-1,
string right="br", int limit=251, string page_token="");
说明
获取指定股票的K线数据,可指定不同的时间粒度。目前此接口支持获取以日、周、月、年、分钟、5分钟、15分钟、30分钟、60分钟为单位的K线数据。 考虑到接口性能和稳定性,此接口请求最高限制为1200条。对于需要更多历史数据进行分析或回测的用户,可以通过 get_bars_by_page
方法请求。也可以自行实现循环,通过多次请求的方式获取更长时间范围的历史的数据。我们编写了一个示例以供参考,需要注意的是,可以请求的K线时间长度可能会存在限制,具体请见历史行情限制
请求频率
频率限制请参考:接口请求限制
参数
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | list<str...> | Yes | 证券代码列表,单次上限50只, 如 ['AAPL', 'GOOG'] |
period | BarPeriod | No | 获取的K线周期。默认 BarPeriod.DAY,可以使用 tigerapi/enums.h BarPeriod 下提供的枚举常量,如 BarPeriod.DAY。 'day'/'week'/'month'/'year'/'1min'/'5min'/'15min'/'30min'/'60min' |
begin_time | int或str | No | 起始时间。支持毫秒级别的时间戳或日期字符串,如 1639371600000 或 '2019-06-07 23:00:00' 或 '2019-06-07' |
end_time | int或str | No | 截至时间。支持毫秒级别的时间戳或日期字符串,如 1639371600000 或 '2019-06-07 23:00:00' 或 '2019-06-07' |
right | QuoteRight | No | 复权方式。默认前复权,可以使用 tigerapi/enums.h QuoteRight 下提供的枚举常量,如 QuoteRight.BR 前复权,QuoteRight.NR 不复权 |
limit | int | No | 限制数据的条数。默认 251 |
lang | Language | No | 支持的语言, 可以使用 tigerapi/enums.h Language 下提供的枚举常量, 如 Language.zh_CN |
page_token | str | No | 分页token,记录分页的位置,上次请求返回的 next_page_token 可传入作为下次请求的起始标志 |
返回
结构如下:
参数名 | 类型 | 描述 |
---|---|---|
time | int | 毫秒时间戳,如 1639371600000 |
open | float | Bar 的开盘价 |
close | float | Bar 的收盘价 |
high | float | Bar 的最高价 |
low | float | Bar 的最低价 |
volume | float | Bar 的成交量 |
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value symbols = value::array();
symbols[0] = value::string("AAPL");
symbols[1] = value::string("JD");
value result = quote_client->get_kline(symbols);
cout << result << endl;
return 0;
}
返回示例
[
{
"items": [
{
"close": 139.5,
"high": 141.43000000000001,
"low": 137.49000000000001,
"open": 140.41,
"time": 1667883600000,
"volume": 89908477
},
{
"close": 134.87,
"high": 138.55000000000001,
"low": 134.5933,
"open": 138.5,
"time": 1667970000000,
"volume": 74917794
},
{
"close": 146.87,
"high": 146.87,
"low": 139.5,
"open": 141.24000000000001,
"time": 1668056400000,
"volume": 118854028
},
{
"close": 149.69999999999999,
"high": 150.00999999999999,
"low": 144.37,
"open": 145.81999999999999,
"time": 1668142800000,
"volume": 93979665
},
{
"close": 148.28,
"high": 150.28,
"low": 147.43000000000001,
"open": 148.97,
"time": 1668402000000,
"volume": 73374114
}
],
"period": "day",
"symbol": "AAPL"
},
{
"items": [
{
"close": 45.490000000000002,
"high": 45.840000000000003,
"low": 43.950099999999999,
"open": 45,
"time": 1667883600000,
"volume": 9351285
},
{
"close": 42.460000000000001,
"high": 43.600000000000001,
"low": 42.195,
"open": 43.435000000000002,
"time": 1667970000000,
"volume": 9533906
},
{
"close": 46.030000000000001,
"high": 46.93,
"low": 45.229999999999997,
"open": 45.390000000000001,
"time": 1668056400000,
"volume": 11965986
},
{
"close": 48.93,
"high": 50.549999999999997,
"low": 48.530000000000001,
"open": 49.469999999999999,
"time": 1668142800000,
"volume": 12951770
},
{
"close": 50.850000000000001,
"high": 52.020000000000003,
"low": 50.119999999999997,
"open": 50.939999999999998,
"time": 1668402000000,
"volume": 12662512
}
],
"period": "day",
"symbol": "JD"
}
]
get_depth_quote 获取深度行情
value QuoteClient::get_depth_quote(symbols, market)
说明
获取输入证券代码的买卖N档挂单数据,包括委托价格,数量及订单数,单次请求上限为50只
CAUTION
港股交易日收市竞价时间为16:00-16:10(于16:08与16:10之间随机收市),当天最后一条深度排盘数据一般在16:10之后的一两分钟后更新
请求频率
频率限制请参考:接口请求限制
参数
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | list<str...> | Yes | 证券代码列表,单次上限50只 |
market | Market | Yes | 查询的市场, 可以使用 tigerapi/enums.h Market 下提供的枚举常量 |
返回
asks 和 bids 对应的列表项数据含义为 (委托价格,委托数量,委托订单数) :
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value symbols = value::array();
symbols[0] = value::string("AAPL");
symbols[1] = value::string("JD");
value result = quote_client->get_quote_depth(symbols);
cout << result << endl;
return 0;
}
返回示例
[{"symbol":"00700","asks":[{"price":342.8,"count":8,"volume":52100},{"price":343.0,"count":53,"volume":116100},{"price":343.2,"count":20,"volume":118200},{"price":343.4,"count":18,"volume":73400},{"price":343.6,"count":16,"volume":70000},{"price":343.8,"count":19,"volume":35000},{"price":344.0,"count":48,"volume":110600},{"price":344.2,"count":22,"volume":142900},{"price":344.4,"count":19,"volume":54600},{"price":344.6,"count":19,"volume":70000}],"bids":[{"price":342.6,"count":4,"volume":64000},{"price":342.4,"count":2,"volume":12000},{"price":342.2,"count":7,"volume":67800},{"price":342.0,"count":10,"volume":71300},{"price":341.8,"count":22,"volume":16700},{"price":341.6,"count":19,"volume":18200},{"price":341.4,"count":12,"volume":79100},{"price":341.2,"count":14,"volume":97200},{"price":341.0,"count":42,"volume":56500},{"price":340.8,"count":26,"volume":46100}]}]
get_quote_stock_trade 获取股票交易需要的信息
QuoteClient::get_quote_stock_trade(symbols)
说明
获取股票交易需要的信息,如每手股数,比如港股下单股数必须为每手股数的整数倍
请求频率
频率限制请参考:接口请求限制
参数
参数名 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbols | list<str...> | Yes | 证券代码列表, 上限为50 |
返回
结构如下:
COLUMN | 类型 | 描述 |
---|---|---|
symbol | str | 证券代码 |
lot_size | int | 每手股数 |
min_tick | float | 价格最小变动单位 |
spread_scale | float | 报价精度 |
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value symbols = value::array();
symbols[0] = value::string("AAPL");
symbols[1] = value::string("JD");
value result = quote_client->get_quote_stock_trade(symbols);
cout << result << endl;
return 0;
}
返回示例
[{"lotSize":1,"minTick":0.01,"spreadScale":1,"symbol":"AAPL"},{"lotSize":1,"minTick":0.01,"spreadScale":1,"symbol":"JD"}]
get_capital_flow 获取股票资金流数据
value QuoteClient::get_capital_flow
说明
获取股票资金净流入数据,包括最近一个交易日的实时分钟数据,和不同周期的净流入数据。对不同的时间粒度,支持获取以日、周、月、季、半年、年为单位的数据,最高限制为1200条,默认为200条。
参数、
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbol | string | Yes | 股票代码 |
period | CapitalPeriod | Yes | 数据类型,取值范围(intraday:实时,day:日,week:周,month:月,year:年,quarter:季度,6month:半年) |
market | Market | Yes | US 美股,HK港股,CN A股(实时资金流向不支持A股) |
begin_time | int | No | 开始时间,默认:-1,单位:毫秒(ms),前闭后开区间,即查询结果会包含起始时间数据,如查询周/月/年K线,会返回包含当前周期的数据(如:起始时间为周三,会返回从这周一的数据) |
end_time | int | No | 结束时间,默认:-1,单位:毫秒(ms) |
limit | int | No | 单次请求返回数量,不传默认是200,limit不能超过1200,如果limit设置大于1200,只会返回1200条数据 |
lang | Lang | No | 语言支持: zh_CN,zh_TW,en_US, 默认: en_US |
返回
字段 | 类型 | 说明 |
---|---|---|
symbol | string | 股票代码 |
period | string | 周期 |
time | string | 标的所在市场时区的时间字符串,实时数据时为"11-25 12:48:00 EST"格式,非实时数据为"2022-11-22"格式 |
timestamp | int | 13位时间戳 |
net_inflow | float | 净流入金额,负数表示流出 |
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig(true);
config.private_key = "-----BEGIN RSA PRIVATE KEY-----\n"
"xxxxxx私钥字符串xxxxxxxx"
"-----END RSA PRIVATE KEY-----";
config.tiger_id = "开发者ID";
config.account = "资金账户";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value symbols = value::array();
symbols[0] = value::string("AAPL");
symbols[1] = value::string("JD");
value result = quote_client->get_capital_flow("AAPL", "US", "intraday");
cout << result << endl;
return 0;
}
返回示例
{"items":[{"netInflow":66792509.8979,"time":"01-10 09:30:00 EST","timestamp":1673361000000},{"netInflow":68356370.344899997,"time":"01-10 09:31:00 EST","timestamp":1673361060000},{"netInflow":70886790.490799993,"time":"01-10 09:32:00 EST","timestamp":1673361120000},{"netInflow":73072909.183300003,"time":"01-10 09:33:00 EST","timestamp":1673361180000},{"netInflow":18778097.630399998,"time":"01-10 15:45:00 EST","timestamp":1673383500000},{"netInflow":17920771.363000002,"time":"01-10 15:46:00 EST","timestamp":1673383560000},{"netInflow":16638279.7092,"time":"01-10 15:47:00 EST","timestamp":1673383620000},{"netInflow":16618314.0484,"time":"01-10 15:48:00 EST","timestamp":1673383680000},{"netInflow":16369111.518200001,"time":"01-10 15:49:00 EST","timestamp":1673383740000},{"netInflow":24502314.359200001,"time":"01-10 15:50:00 EST","timestamp":1673383800000},{"netInflow":25853726.0222,"time":"01-10 15:51:00 EST","timestamp":1673383860000},{"netInflow":22492884.448399998,"time":"01-10 15:52:00 EST","timestamp":1673383920000},{"netInflow":23272406.638500001,"time":"01-10 15:53:00 EST","timestamp":1673383980000},{"netInflow":22988058.011999998,"time":"01-10 15:54:00 EST","timestamp":1673384040000},{"netInflow":28326520.442699999,"time":"01-10 15:55:00 EST","timestamp":1673384100000},{"netInflow":24328584.693300001,"time":"01-10 15:56:00 EST","timestamp":1673384160000},{"netInflow":29597845.616900001,"time":"01-10 15:57:00 EST","timestamp":1673384220000},{"netInflow":27514469.558699999,"time":"01-10 15:58:00 EST","timestamp":1673384280000},{"netInflow":35487493.496799998,"time":"01-10 15:59:00 EST","timestamp":1673384340000}],"period":"intraday","symbol":"AAPL"}
get_capital_distribution 获取股票资金分布
value get_capital_distribution(string symbol, Market market = Market::US);
说明
获取股票资金分布。
参数
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbol | str | Yes | 股票代码 |
market | Market | Yes | US 美股,HK港股,CN A股 |
lang | Lang | No | 语言支持: zh_CN,zh_TW,en_US, 默认: en_US |
返回
字段 | 类型 | 说明 |
---|---|---|
symbol | str | 股票代码 |
net_inflow | float | 净流入金额(资金总流入 - 资金总流出),负数表示流出 |
in_all | float | 资金流入总额(大单+中单+小单) |
in_big | float | 大单流入 |
in_mid | float | 中单流入 |
in_small | float | 小单流入 |
out_all | float | 资金流出总额(大单+中单+小单) |
out_big | float | 大单流出 |
out_mid | float | 中单流出 |
out_small | float | 小单流出 |
示例
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value symbols = value::array();
symbols[0] = value::string("AAPL");
symbols[1] = value::string("JD");
value result = quote_client->get_capital_distribution("AAPL");
cout << result << endl;
return 0;
}
返回示例
{"inAll":3333362528.4099998,"inBig":577964736.26520014,"inMid":273636829.47490007,"inSmall":2481760962.6747251,"netInflow":35487493.5,"outAll":3297875034.9200001,"outBig":483301755.98959994,"outMid":292564622.11769968,"outSmall":2522008656.8106923,"symbol":"AAPL"}
get_stock_broker 获取港股经纪商买卖席位
value get_stock_broker(string symbol, int limit=40);
说明
获取港股经纪商买卖席位。
参数、
参数 | 类型 | 是否必填 | 描述 |
---|---|---|---|
symbol | str | Yes | 股票代码 |
limit | int | No | 单次请求返回买方/卖方席位数量,不传默认是40,limit不能超过60,如果limit设置大于60,只会返回60条数据 |
lang | Lang | No | 语言支持: zh_CN,zh_TW,en_US, 默认: en_US |
返回
字段 | 类型 | 说明 |
---|---|---|
symbol | str | 股票代码 |
bid_broker | tigeropen.quote.domain.stock_broker.LevelBroker | 买方不同价格档位数组,字段参考LevelBroker说明 |
ask_broker | tigeropen.quote.domain.stock_broker.LevelBroker | 卖方不同价格档位数组,字段参考LevelBroker说明 |
其中LevelBroker属性如下:
field | type | desc |
---|---|---|
level | int | 价格档位 |
price | float | 价格 |
broker_count | int | 席位数量 |
broker | list[igeropen.quote.domain.stock_broker.Broker] | 经纪商买卖席位列表, 字段参考Broker说明 |
Broker attributes:
field | type | desc |
---|---|---|
id | str | broker id |
name | str | broker name |
Example
#include "tigerapi/quote_client.h"
using namespace std;
using namespace web;
using namespace web::json;
using namespace TIGER_API;
int main(int argc, char *args[]) {
/************************** set config **********************/
ClientConfig config = ClientConfig();
config.private_key = "xxxxxx your private key string xxxxxxxx";
config.tiger_id = "your tiger id";
config.account = "your account";
std::shared_ptr<QuoteClient> quote_client = std::make_shared<QuoteClient>(config);
value symbols = value::array();
symbols[0] = value::string("AAPL");
symbols[1] = value::string("JD");
value result = quote_client->get_stock_broker(symbols);
cout << result << endl;
return 0;
}
Return example
StockBroker({'symbol': '01810',
'bid_broker': [
LevelBroker({'level': 1, 'price': 11.46, 'broker_count': 5,
'broker': [Broker({'id': '5999', 'name': '中国创盈'}), Broker({'id': '4374', 'name': '巴克莱亚洲'}),
Broker({'id': '1438', 'name': 'Susquehanna'}), Broker({'id': '4821', 'name': '华盛'}),
Broker({'id': '6998', 'name': '中国投资'})]})],
'ask_broker': [
LevelBroker({'level': 1, 'price': 11.48, 'broker_count': 5,
'broker': [Broker({'id': '4374', 'name': '巴克莱亚洲'}), Broker({'id': '9056', 'name': '瑞银'}),
Broker({'id': '2027', 'name': '东亚'}), Broker({'id': '4821', 'name': '华盛'}),
Broker({'id': '4374', 'name': '巴克莱亚洲'})]})]})