# 獲取區間漲跌幅
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_period_change_rank(market, period_type=None, sort_dir=None, count=10, offset=None, filter_list=None)
介紹
獲取區間漲跌幅排行,返回指定市場中按不同時間週期(5分鐘至250日/年初至今)的漲跌幅排行,支持豐富的篩選條件(市值、價格、PE、PB、換手率、量比、振幅等)。
參數
參數 類型 說明 market Market 市場類型(HK/US)(必填) period_type RankPeriodType 排序週期,默認 5 分鐘 sort_dir RankSortDir 排序方向,默認降序 count int 返回數量 [1, 200],默認 10 offset int 起始位置,默認 0 filter_list list[ PeriodChangeRankFilter]篩選條件列表(多條件爲 AND 關係) 輸入限制
filter_list篩選條件(PeriodChangeRankFilter):構造參數 說明 indicator_type篩選因子類型( PeriodChangeIndicatorType,必填)interval_min範圍最小值(閉區間) interval_max範圍最大值(閉區間)
返回
參數 類型 說明 ret RET_CODE 接口調用結果 data pd.DataFrame 當 ret == RET_OK,返回 (all_count, DataFrame) 元組 str 當 ret != RET_OK,返回錯誤描述 - 數據格式如下:
字段 類型 說明 security str 股票代碼(如 'US.AAPL')name str 股票名稱 cur_price float 最新價 change_ratio float 今日漲跌幅(%) turnover float 成交額 volume int 成交量 market_cap float 市值 change_rate_5min float 5分鐘漲跌幅(%) change_rate_5d float 5日漲跌幅(%) change_rate_10d float 10日漲跌幅(%) change_rate_20d float 20日漲跌幅(%) change_rate_60d float 60日漲跌幅(%) change_rate_120d float 120日漲跌幅(%) change_rate_250d float 250日漲跌幅(%) change_rate_ytd float 年初至今漲跌幅(%) pe_ttm float 市盈率 TTM pb float 市淨率 turnover_ratio float 換手率(%) volume_ratio float 量比 amplitude float 振幅(%)
- 數據格式如下:
Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.get_period_change_rank(market=Market.US, count=2)
if ret == RET_OK:
all_count, df = data
print(f'總數據量: {all_count}')
print(df)
else:
print('error:', data)
quote_ctx.close()
2
3
4
5
6
7
8
9
10
11
12
13
- Output
總數據量: 6429
security name cur_price change_ratio turnover volume market_cap change_rate_5min change_rate_5d change_rate_10d change_rate_20d change_rate_60d change_rate_120d change_rate_250d change_rate_ytd pe_ttm pb turnover_ratio volume_ratio amplitude
0 US.JYD 佳裕達物流 0.93 11.537 271197.0 311313 7717977.00 9.540 32.80 30.875 20.779 -68.150 -80.128 -90.610 -81.374 -0.40558 0.49892 5.220 0.732 20.94
1 US.RAIN Rain Enhancement Technologies 2.23 19.892 112286.0 56451 18261097.59 9.313 -2.62 1.826 -6.302 -21.754 -71.914 -22.299 -61.815 -1.79838 -1.27283 2.812 0.816 27.15
2
3
4
# Qot_GetPeriodChangeRank.proto
介紹
獲取區間漲跌幅排行,返回指定市場中按不同時間週期(5分鐘至250日/年初至今)的漲跌幅排行,支持豐富的篩選條件(市值、價格、PE、PB、換手率、量比、振幅等)。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序週期
enum PeriodType {
PeriodType_Unknown = 0;
PeriodType_5Min = 1; // 5分鐘(默認)
PeriodType_1Day = 2; // 1日
PeriodType_5Day = 3; // 5日
PeriodType_20Day = 4; // 20日
PeriodType_60Day = 5; // 60日
PeriodType_120Day = 6; // 120日
PeriodType_250Day = 7; // 250日
PeriodType_YTD = 8; // 年初至今
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 最新價區間
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_ChangeRatio = 3; // 漲跌幅區間(按所選週期)
IndicatorType_Volume = 4; // 成交量區間
IndicatorType_Turnover = 5; // 成交額區間
IndicatorType_PE = 6; // 市盈率TTM區間
IndicatorType_PB = 7; // 市淨率區間
IndicatorType_TurnoverRatio = 8; // 換手率區間
IndicatorType_VolumeRatio = 9; // 量比區間
IndicatorType_Amplitude = 10; // 振幅區間
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間
}
message C2S {
required int32 market = 1; // Qot_Common.QotMarket (HK=1, US=11)
optional int32 periodType = 2; // PeriodType, 排序週期, 默認5分鐘
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 6; // 篩選條件(AND關係)
}
// 區間漲跌幅數據項
message PeriodChangeRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double curPrice = 10; // 最新價
optional double changeRatio = 11; // 今日漲跌幅(%)
optional double turnover = 12; // 成交額
optional int64 volume = 13; // 成交量
optional double marketCap = 14; // 市值
optional double changeRate5Min = 20; // 5分鐘漲跌幅(%)
optional double changeRate5D = 21; // 5日漲跌幅(%)
optional double changeRate10D = 22; // 10日漲跌幅(%)
optional double changeRate20D = 23; // 20日漲跌幅(%)
optional double changeRate60D = 24; // 60日漲跌幅(%)
optional double changeRate120D = 25; // 120日漲跌幅(%)
optional double changeRate250D = 26; // 250日漲跌幅(%)
optional double changeRateYTD = 27; // 年初至今漲跌幅(%)
optional double peTTM = 30; // 市盈率TTM
optional double pb = 31; // 市淨率
optional double turnoverRatio = 32; // 換手率(%)
optional double volumeRatio = 33; // 量比
optional double amplitude = 34; // 振幅(%)
}
message S2C {
repeated PeriodChangeRankItem dataList = 1; // 數據列表
optional int32 allCount = 2; // 符合條件的總數據量
}
message Request {
required C2S c2s = 1;
}
message Response {
required int32 retType = 1 [default = -400]; // RetType, 返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
協議 ID
3416
uint GetPeriodChangeRank(Qot_GetPeriodChangeRank.Request req);
virtual void OnReply_GetPeriodChangeRank(FTAPI_Conn client, uint nSerialNo, Qot_GetPeriodChangeRank.Response rsp);
介紹
獲取區間漲跌幅排行,返回指定市場中按不同時間週期(5分鐘至250日/年初至今)的漲跌幅排行,支持豐富的篩選條件(市值、價格、PE、PB、換手率、量比、振幅等)。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序週期
enum PeriodType {
PeriodType_Unknown = 0;
PeriodType_5Min = 1; // 5分鐘(默認)
PeriodType_1Day = 2; // 1日
PeriodType_5Day = 3; // 5日
PeriodType_20Day = 4; // 20日
PeriodType_60Day = 5; // 60日
PeriodType_120Day = 6; // 120日
PeriodType_250Day = 7; // 250日
PeriodType_YTD = 8; // 年初至今
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 最新價區間
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_ChangeRatio = 3; // 漲跌幅區間(按所選週期)
IndicatorType_Volume = 4; // 成交量區間
IndicatorType_Turnover = 5; // 成交額區間
IndicatorType_PE = 6; // 市盈率TTM區間
IndicatorType_PB = 7; // 市淨率區間
IndicatorType_TurnoverRatio = 8; // 換手率區間
IndicatorType_VolumeRatio = 9; // 量比區間
IndicatorType_Amplitude = 10; // 振幅區間
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間
}
message C2S {
required int32 market = 1; // Qot_Common.QotMarket (HK=1, US=11)
optional int32 periodType = 2; // PeriodType, 排序週期, 默認5分鐘
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 6; // 篩選條件(AND關係)
}
// 區間漲跌幅數據項
message PeriodChangeRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double curPrice = 10; // 最新價
optional double changeRatio = 11; // 今日漲跌幅(%)
optional double turnover = 12; // 成交額
optional int64 volume = 13; // 成交量
optional double marketCap = 14; // 市值
optional double changeRate5Min = 20; // 5分鐘漲跌幅(%)
optional double changeRate5D = 21; // 5日漲跌幅(%)
optional double changeRate10D = 22; // 10日漲跌幅(%)
optional double changeRate20D = 23; // 20日漲跌幅(%)
optional double changeRate60D = 24; // 60日漲跌幅(%)
optional double changeRate120D = 25; // 120日漲跌幅(%)
optional double changeRate250D = 26; // 250日漲跌幅(%)
optional double changeRateYTD = 27; // 年初至今漲跌幅(%)
optional double peTTM = 30; // 市盈率TTM
optional double pb = 31; // 市淨率
optional double turnoverRatio = 32; // 換手率(%)
optional double volumeRatio = 33; // 量比
optional double amplitude = 34; // 振幅(%)
}
message S2C {
repeated PeriodChangeRankItem dataList = 1; // 數據列表
optional int32 allCount = 2; // 符合條件的總數據量
}
message Request {
required C2S c2s = 1;
}
message Response {
required int32 retType = 1 [default = -400]; // RetType, 返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
- 接口調用結果,結構參見 RetType
協議 ID
3416
Example
public class Program : FTSPI_Qot, FTSPI_Conn {
FTAPI_Qot qot = new FTAPI_Qot();
public Program() {
qot.SetClientInfo("csharp", 1); //設置客戶端信息
qot.SetConnCallback(this); //設置連接回調
qot.SetQotCallback(this); //設置行情回調
}
public void Start() {
qot.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(FTAPI_Conn client, long errCode, String desc)
{
Console.Write("Qot onInitConnect: ret={0} desc={1} connID={2}
", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
QotGetPeriodChangeRank.C2S c2s = QotGetPeriodChangeRank.C2S.CreateBuilder()
.SetMarket(11)
.SetCount(3)
.Build();
QotGetPeriodChangeRank.Request req = QotGetPeriodChangeRank.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetPeriodChangeRank(req);
Console.Write("Send QotGetPeriodChangeRank: {0}
", seqNo);
}
public void OnDisconnect(FTAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}
", errCode);
}
public void OnReply_GetPeriodChangeRank(FTAPI_Conn client, uint nSerialNo, QotGetPeriodChangeRank.Response rsp)
{
Console.Write("Reply: QotGetPeriodChangeRank: {0}
", nSerialNo);
if (rsp.RetType == 0 && rsp.HasS2C)
Console.Write("{0}
", rsp.ToString());
}
public static void Main(String[] args) {
FTAPI.Init();
Program program = new Program();
program.Start();
while (true)
Thread.Sleep(1000 * 600);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
- Output
Send QotGetPeriodChangeRank: 3
Reply: QotGetPeriodChangeRank: 3
GetPeriodChangeRank: errCode 0, retMsg , retType 0
{
"allCount": 6429,
"dataList": [
{ "security": { "market": 11, "code": "PAVM" }, "name": "PAVmed", "curPrice": 5.16, "changeRatio": 3.200 },
{ "security": { "market": 11, "code": "JLHL" }, "name": "巨龍在線", "curPrice": 39.69, "changeRatio": 18.832 },
{ "security": { "market": 11, "code": "DGICB" }, "name": "多尼戈爾股份-B", "curPrice": 22.86, "changeRatio": 21.531 }
]
}
2
3
4
5
6
7
8
9
10
11
int getPeriodChangeRank(Qot_GetPeriodChangeRank.Request req);
onReply_GetPeriodChangeRank(FTAPI_Conn client, int nSerialNo, Qot_GetPeriodChangeRank.Response rsp)
介紹
獲取區間漲跌幅排行,返回指定市場中按不同時間週期(5分鐘至250日/年初至今)的漲跌幅排行,支持豐富的篩選條件(市值、價格、PE、PB、換手率、量比、振幅等)。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序週期
enum PeriodType {
PeriodType_Unknown = 0;
PeriodType_5Min = 1; // 5分鐘(默認)
PeriodType_1Day = 2; // 1日
PeriodType_5Day = 3; // 5日
PeriodType_20Day = 4; // 20日
PeriodType_60Day = 5; // 60日
PeriodType_120Day = 6; // 120日
PeriodType_250Day = 7; // 250日
PeriodType_YTD = 8; // 年初至今
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 最新價區間
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_ChangeRatio = 3; // 漲跌幅區間(按所選週期)
IndicatorType_Volume = 4; // 成交量區間
IndicatorType_Turnover = 5; // 成交額區間
IndicatorType_PE = 6; // 市盈率TTM區間
IndicatorType_PB = 7; // 市淨率區間
IndicatorType_TurnoverRatio = 8; // 換手率區間
IndicatorType_VolumeRatio = 9; // 量比區間
IndicatorType_Amplitude = 10; // 振幅區間
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間
}
message C2S {
required int32 market = 1; // Qot_Common.QotMarket (HK=1, US=11)
optional int32 periodType = 2; // PeriodType, 排序週期, 默認5分鐘
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 6; // 篩選條件(AND關係)
}
// 區間漲跌幅數據項
message PeriodChangeRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double curPrice = 10; // 最新價
optional double changeRatio = 11; // 今日漲跌幅(%)
optional double turnover = 12; // 成交額
optional int64 volume = 13; // 成交量
optional double marketCap = 14; // 市值
optional double changeRate5Min = 20; // 5分鐘漲跌幅(%)
optional double changeRate5D = 21; // 5日漲跌幅(%)
optional double changeRate10D = 22; // 10日漲跌幅(%)
optional double changeRate20D = 23; // 20日漲跌幅(%)
optional double changeRate60D = 24; // 60日漲跌幅(%)
optional double changeRate120D = 25; // 120日漲跌幅(%)
optional double changeRate250D = 26; // 250日漲跌幅(%)
optional double changeRateYTD = 27; // 年初至今漲跌幅(%)
optional double peTTM = 30; // 市盈率TTM
optional double pb = 31; // 市淨率
optional double turnoverRatio = 32; // 換手率(%)
optional double volumeRatio = 33; // 量比
optional double amplitude = 34; // 振幅(%)
}
message S2C {
repeated PeriodChangeRankItem dataList = 1; // 數據列表
optional int32 allCount = 2; // 符合條件的總數據量
}
message Request {
required C2S c2s = 1;
}
message Response {
required int32 retType = 1 [default = -400]; // RetType, 返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
- 接口調用結果,結構參見 RetType
協議 ID
3416
Example
public class QotDemo implements FTSPI_Qot, FTSPI_Conn {
FTAPI_Conn_Qot qot = new FTAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1); //設置客戶端信息
qot.setConnSpi(this); //設置連接回調
qot.setQotSpi(this); //設置行情回調
}
public void start() {
qot.initConnect("127.0.0.1", (short)11111, false);
}
@Override
public void onInitConnect(FTAPI_Conn client, long errCode, String desc)
{
System.out.printf("Qot onInitConnect: ret=%d desc=%s connID=%d
", errCode, desc, client.getConnectID());
if (errCode != 0)
return;
QotGetPeriodChangeRank.C2S c2s = QotGetPeriodChangeRank.C2S.newBuilder()
.setMarket(11)
.setCount(3)
.build();
QotGetPeriodChangeRank.Request req = QotGetPeriodChangeRank.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getPeriodChangeRank(req);
System.out.printf("Send QotGetPeriodChangeRank: %d
", seqNo);
}
@Override
public void onDisconnect(FTAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d
", errCode);
}
@Override
public void onReply_GetPeriodChangeRank(FTAPI_Conn client, int nSerialNo, QotGetPeriodChangeRank.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetPeriodChangeRank failed: %s
", rsp.getRetMsg());
} else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetPeriodChangeRank: %s
", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
FTAPI.init();
QotDemo qot = new QotDemo();
qot.start();
while (true) {
try {
Thread.sleep(1000 * 600);
} catch (InterruptedException exc) {
}
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
- Output
Send QotGetPeriodChangeRank: 3
Receive QotGetPeriodChangeRank: {
"allCount": 6429,
"dataList": [
{ "security": { "market": 11, "code": "PAVM" }, "name": "PAVmed", "curPrice": 5.16, "changeRatio": 3.200 },
{ "security": { "market": 11, "code": "JLHL" }, "name": "巨龍在線", "curPrice": 39.69, "changeRatio": 18.832 },
{ "security": { "market": 11, "code": "DGICB" }, "name": "多尼戈爾股份-B", "curPrice": 22.86, "changeRatio": 21.531 }
]
}
2
3
4
5
6
7
8
9
Futu::u32_t GetPeriodChangeRank(const Qot_GetPeriodChangeRank::Request &stReq);
virtual void OnReply_GetPeriodChangeRank(Futu::u32_t nSerialNo, const Qot_GetPeriodChangeRank::Response &stRsp) = 0;
介紹
協議請求及回應定義
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序週期
enum PeriodType {
PeriodType_Unknown = 0;
PeriodType_5Min = 1; // 5分鐘(默認)
PeriodType_1Day = 2; // 1日
PeriodType_5Day = 3; // 5日
PeriodType_20Day = 4; // 20日
PeriodType_60Day = 5; // 60日
PeriodType_120Day = 6; // 120日
PeriodType_250Day = 7; // 250日
PeriodType_YTD = 8; // 年初至今
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 最新價區間
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_ChangeRatio = 3; // 漲跌幅區間(按所選週期)
IndicatorType_Volume = 4; // 成交量區間
IndicatorType_Turnover = 5; // 成交額區間
IndicatorType_PE = 6; // 市盈率TTM區間
IndicatorType_PB = 7; // 市淨率區間
IndicatorType_TurnoverRatio = 8; // 換手率區間
IndicatorType_VolumeRatio = 9; // 量比區間
IndicatorType_Amplitude = 10; // 振幅區間
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間
}
message C2S {
required int32 market = 1; // Qot_Common.QotMarket (HK=1, US=11)
optional int32 periodType = 2; // PeriodType, 排序週期, 默認5分鐘
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 6; // 篩選條件(AND關係)
}
// 區間漲跌幅數據項
message PeriodChangeRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double curPrice = 10; // 最新價
optional double changeRatio = 11; // 今日漲跌幅(%)
optional double turnover = 12; // 成交額
optional int64 volume = 13; // 成交量
optional double marketCap = 14; // 市值
optional double changeRate5Min = 20; // 5分鐘漲跌幅(%)
optional double changeRate5D = 21; // 5日漲跌幅(%)
optional double changeRate10D = 22; // 10日漲跌幅(%)
optional double changeRate20D = 23; // 20日漲跌幅(%)
optional double changeRate60D = 24; // 60日漲跌幅(%)
optional double changeRate120D = 25; // 120日漲跌幅(%)
optional double changeRate250D = 26; // 250日漲跌幅(%)
optional double changeRateYTD = 27; // 年初至今漲跌幅(%)
optional double peTTM = 30; // 市盈率TTM
optional double pb = 31; // 市淨率
optional double turnoverRatio = 32; // 換手率(%)
optional double volumeRatio = 33; // 量比
optional double amplitude = 34; // 振幅(%)
}
message S2C {
repeated PeriodChangeRankItem dataList = 1; // 數據列表
optional int32 allCount = 2; // 符合條件的總數據量
}
message Request {
required C2S c2s = 1;
}
message Response {
required int32 retType = 1 [default = -400]; // RetType, 返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
- 介面呼叫結果,結構參見 RetType
協議 ID
3416
Example
class Program : public FTSPI_Qot, public FTSPI_Conn
{
public:
Program() {
m_pQotApi = FTAPI::CreateQotApi();
m_pQotApi->RegisterQotSpi(this);
m_pQotApi->RegisterConnSpi(this);
}
~Program() {
if (m_pQotApi != nullptr) {
m_pQotApi->UnregisterQotSpi();
m_pQotApi->UnregisterConnSpi();
FTAPI::ReleaseQotApi(m_pQotApi);
m_pQotApi = nullptr;
}
}
void Start() {
m_pQotApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(FTAPI_Conn* pConn, Futu::i64_t nErrCode, const char* strDesc) {
Qot_GetPeriodChangeRank::Request req;
Qot_GetPeriodChangeRank::C2S *c2s = req.mutable_c2s();
c2s->set_market(Qot_Common::QotMarket::QotMarket_US_Security);
c2s->set_count(50);
m_GetPeriodChangeRankSerialNo = m_pQotApi->GetPeriodChangeRank(req);
}
virtual void OnReply_GetPeriodChangeRank(Futu::u32_t nSerialNo, const Qot_GetPeriodChangeRank::Response &stRsp) {
if (nSerialNo != m_GetPeriodChangeRankSerialNo) return;
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_GetPeriodChangeRankSerialNo = 0;
};
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
- Output
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"dataList": [
{
"security": {
"market": 11,
"code": "NVDA"
},
"name": "NVIDIA",
"curPrice": 875.4,
"changeRatio": 9.32,
"turnover": 28500000000.0,
"marketCap": 2150000000000.0
}
],
"allCount": 50
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
getPeriodChangeRank(qotGetPeriodChangeRank)
介紹
獲取區間漲跌幅排行,返回指定市場中按不同時間週期(5分鐘至250日/年初至今)的漲跌幅排行,支持豐富的篩選條件(市值、價格、PE、PB、換手率、量比、振幅等)。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序週期
enum PeriodType {
PeriodType_Unknown = 0;
PeriodType_5Min = 1; // 5分鐘(默認)
PeriodType_1Day = 2; // 1日
PeriodType_5Day = 3; // 5日
PeriodType_20Day = 4; // 20日
PeriodType_60Day = 5; // 60日
PeriodType_120Day = 6; // 120日
PeriodType_250Day = 7; // 250日
PeriodType_YTD = 8; // 年初至今
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 最新價區間
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_ChangeRatio = 3; // 漲跌幅區間(按所選週期)
IndicatorType_Volume = 4; // 成交量區間
IndicatorType_Turnover = 5; // 成交額區間
IndicatorType_PE = 6; // 市盈率TTM區間
IndicatorType_PB = 7; // 市淨率區間
IndicatorType_TurnoverRatio = 8; // 換手率區間
IndicatorType_VolumeRatio = 9; // 量比區間
IndicatorType_Amplitude = 10; // 振幅區間
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間
}
message C2S {
required int32 market = 1; // Qot_Common.QotMarket (HK=1, US=11)
optional int32 periodType = 2; // PeriodType, 排序週期, 默認5分鐘
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 6; // 篩選條件(AND關係)
}
// 區間漲跌幅數據項
message PeriodChangeRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double curPrice = 10; // 最新價
optional double changeRatio = 11; // 今日漲跌幅(%)
optional double turnover = 12; // 成交額
optional int64 volume = 13; // 成交量
optional double marketCap = 14; // 市值
optional double changeRate5Min = 20; // 5分鐘漲跌幅(%)
optional double changeRate5D = 21; // 5日漲跌幅(%)
optional double changeRate10D = 22; // 10日漲跌幅(%)
optional double changeRate20D = 23; // 20日漲跌幅(%)
optional double changeRate60D = 24; // 60日漲跌幅(%)
optional double changeRate120D = 25; // 120日漲跌幅(%)
optional double changeRate250D = 26; // 250日漲跌幅(%)
optional double changeRateYTD = 27; // 年初至今漲跌幅(%)
optional double peTTM = 30; // 市盈率TTM
optional double pb = 31; // 市淨率
optional double turnoverRatio = 32; // 換手率(%)
optional double volumeRatio = 33; // 量比
optional double amplitude = 34; // 振幅(%)
}
message S2C {
repeated PeriodChangeRankItem dataList = 1; // 數據列表
optional int32 allCount = 2; // 符合條件的總數據量
}
message Request {
required C2S c2s = 1;
}
message Response {
required int32 retType = 1 [default = -400]; // RetType, 返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
- 接口調用結果,結構參見 RetType
協議 ID
3416
Example
import ftWebsocket from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
import beautify from "js-beautify";
function QotGetPeriodChangeRank(){
const { RetType } = Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 11111, false, "xxxxxx"];
let websocket = new ftWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) {
const req = {
c2s: { market: 11, count: 3 },
};
websocket.GetPeriodChangeRank(req)
.then((res)=>{
let { errCode, retMsg, retType, s2c } = res
console.log("GetPeriodChangeRank: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
let data = beautify(JSON.stringify(s2c), { indent_size: 2, space_in_empty_paren: true });
console.log(data);
}
})
.catch((error)=>{ console.log("error:", error); });
} else {
console.log("start error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{ websocket.stop(); process.exit(); }, 5000);
}
QotGetPeriodChangeRank()
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
- Output
GetPeriodChangeRank: errCode 0, retMsg , retType 0
{
"allCount": 6429,
"dataList": [
{ "security": { "market": 11, "code": "PAVM" }, "name": "PAVmed", "curPrice": 5.16, "changeRatio": 3.200 },
{ "security": { "market": 11, "code": "JLHL" }, "name": "巨龍在線", "curPrice": 39.69, "changeRatio": 18.832 },
{ "security": { "market": 11, "code": "DGICB" }, "name": "多尼戈爾股份-B", "curPrice": 22.86, "changeRatio": 21.531 }
]
}
2
3
4
5
6
7
8
9
接口限制
- 30 秒內最多 60 次請求
- 分頁請求僅首頁計入限頻統計
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_period_change_rank(market, period_type=None, sort_dir=None, count=10, offset=None, filter_list=None)
介紹
獲取區間漲跌幅排行,返回指定市場中按不同時間週期(5分鐘至250日/年初至今)的漲跌幅排行,支持豐富的篩選條件(市值、價格、PE、PB、換手率、量比、振幅等)。
參數
參數 類型 說明 market Market 市場類型(HK/US)(必填) period_type RankPeriodType 排序週期,默認 5 分鐘 sort_dir RankSortDir 排序方向,默認降序 count int 返回數量 [1, 200],默認 10 offset int 起始位置,默認 0 filter_list list[ PeriodChangeRankFilter]篩選條件列表(多條件爲 AND 關係) 輸入限制
filter_list篩選條件(PeriodChangeRankFilter):構造參數 說明 indicator_type篩選因子類型( PeriodChangeIndicatorType,必填)interval_min範圍最小值(閉區間) interval_max範圍最大值(閉區間)
返回
參數 類型 說明 ret RET_CODE 接口調用結果 data pd.DataFrame 當 ret == RET_OK,返回 (all_count, DataFrame) 元組 str 當 ret != RET_OK,返回錯誤描述 - 數據格式如下:
字段 類型 說明 security str 股票代碼(如 'US.AAPL')name str 股票名稱 cur_price float 最新價 change_ratio float 今日漲跌幅(%) turnover float 成交額 volume int 成交量 market_cap float 市值 change_rate_5min float 5分鐘漲跌幅(%) change_rate_5d float 5日漲跌幅(%) change_rate_10d float 10日漲跌幅(%) change_rate_20d float 20日漲跌幅(%) change_rate_60d float 60日漲跌幅(%) change_rate_120d float 120日漲跌幅(%) change_rate_250d float 250日漲跌幅(%) change_rate_ytd float 年初至今漲跌幅(%) pe_ttm float 市盈率 TTM pb float 市淨率 turnover_ratio float 換手率(%) volume_ratio float 量比 amplitude float 振幅(%)
- 數據格式如下:
Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.get_period_change_rank(market=Market.US, count=2)
if ret == RET_OK:
all_count, df = data
print(f'總數據量: {all_count}')
print(df)
else:
print('error:', data)
quote_ctx.close()
2
3
4
5
6
7
8
9
10
11
12
13
- Output
總數據量: 6429
security name cur_price change_ratio turnover volume market_cap change_rate_5min change_rate_5d change_rate_10d change_rate_20d change_rate_60d change_rate_120d change_rate_250d change_rate_ytd pe_ttm pb turnover_ratio volume_ratio amplitude
0 US.JYD 佳裕達物流 0.93 11.537 271197.0 311313 7717977.00 9.540 32.80 30.875 20.779 -68.150 -80.128 -90.610 -81.374 -0.40558 0.49892 5.220 0.732 20.94
1 US.RAIN Rain Enhancement Technologies 2.23 19.892 112286.0 56451 18261097.59 9.313 -2.62 1.826 -6.302 -21.754 -71.914 -22.299 -61.815 -1.79838 -1.27283 2.812 0.816 27.15
2
3
4
# Qot_GetPeriodChangeRank.proto
介紹
獲取區間漲跌幅排行,返回指定市場中按不同時間週期(5分鐘至250日/年初至今)的漲跌幅排行,支持豐富的篩選條件(市值、價格、PE、PB、換手率、量比、振幅等)。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序週期
enum PeriodType {
PeriodType_Unknown = 0;
PeriodType_5Min = 1; // 5分鐘(默認)
PeriodType_1Day = 2; // 1日
PeriodType_5Day = 3; // 5日
PeriodType_20Day = 4; // 20日
PeriodType_60Day = 5; // 60日
PeriodType_120Day = 6; // 120日
PeriodType_250Day = 7; // 250日
PeriodType_YTD = 8; // 年初至今
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 最新價區間
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_ChangeRatio = 3; // 漲跌幅區間(按所選週期)
IndicatorType_Volume = 4; // 成交量區間
IndicatorType_Turnover = 5; // 成交額區間
IndicatorType_PE = 6; // 市盈率TTM區間
IndicatorType_PB = 7; // 市淨率區間
IndicatorType_TurnoverRatio = 8; // 換手率區間
IndicatorType_VolumeRatio = 9; // 量比區間
IndicatorType_Amplitude = 10; // 振幅區間
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間
}
message C2S {
required int32 market = 1; // Qot_Common.QotMarket (HK=1, US=11)
optional int32 periodType = 2; // PeriodType, 排序週期, 默認5分鐘
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 6; // 篩選條件(AND關係)
}
// 區間漲跌幅數據項
message PeriodChangeRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double curPrice = 10; // 最新價
optional double changeRatio = 11; // 今日漲跌幅(%)
optional double turnover = 12; // 成交額
optional int64 volume = 13; // 成交量
optional double marketCap = 14; // 市值
optional double changeRate5Min = 20; // 5分鐘漲跌幅(%)
optional double changeRate5D = 21; // 5日漲跌幅(%)
optional double changeRate10D = 22; // 10日漲跌幅(%)
optional double changeRate20D = 23; // 20日漲跌幅(%)
optional double changeRate60D = 24; // 60日漲跌幅(%)
optional double changeRate120D = 25; // 120日漲跌幅(%)
optional double changeRate250D = 26; // 250日漲跌幅(%)
optional double changeRateYTD = 27; // 年初至今漲跌幅(%)
optional double peTTM = 30; // 市盈率TTM
optional double pb = 31; // 市淨率
optional double turnoverRatio = 32; // 換手率(%)
optional double volumeRatio = 33; // 量比
optional double amplitude = 34; // 振幅(%)
}
message S2C {
repeated PeriodChangeRankItem dataList = 1; // 數據列表
optional int32 allCount = 2; // 符合條件的總數據量
}
message Request {
required C2S c2s = 1;
}
message Response {
required int32 retType = 1 [default = -400]; // RetType, 返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
協議 ID
3416
uint GetPeriodChangeRank(Qot_GetPeriodChangeRank.Request req);
virtual void OnReply_GetPeriodChangeRank(FTAPI_Conn client, uint nSerialNo, Qot_GetPeriodChangeRank.Response rsp);
介紹
獲取區間漲跌幅排行,返回指定市場中按不同時間週期(5分鐘至250日/年初至今)的漲跌幅排行,支持豐富的篩選條件(市值、價格、PE、PB、換手率、量比、振幅等)。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序週期
enum PeriodType {
PeriodType_Unknown = 0;
PeriodType_5Min = 1; // 5分鐘(默認)
PeriodType_1Day = 2; // 1日
PeriodType_5Day = 3; // 5日
PeriodType_20Day = 4; // 20日
PeriodType_60Day = 5; // 60日
PeriodType_120Day = 6; // 120日
PeriodType_250Day = 7; // 250日
PeriodType_YTD = 8; // 年初至今
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 最新價區間
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_ChangeRatio = 3; // 漲跌幅區間(按所選週期)
IndicatorType_Volume = 4; // 成交量區間
IndicatorType_Turnover = 5; // 成交額區間
IndicatorType_PE = 6; // 市盈率TTM區間
IndicatorType_PB = 7; // 市淨率區間
IndicatorType_TurnoverRatio = 8; // 換手率區間
IndicatorType_VolumeRatio = 9; // 量比區間
IndicatorType_Amplitude = 10; // 振幅區間
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間
}
message C2S {
required int32 market = 1; // Qot_Common.QotMarket (HK=1, US=11)
optional int32 periodType = 2; // PeriodType, 排序週期, 默認5分鐘
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 6; // 篩選條件(AND關係)
}
// 區間漲跌幅數據項
message PeriodChangeRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double curPrice = 10; // 最新價
optional double changeRatio = 11; // 今日漲跌幅(%)
optional double turnover = 12; // 成交額
optional int64 volume = 13; // 成交量
optional double marketCap = 14; // 市值
optional double changeRate5Min = 20; // 5分鐘漲跌幅(%)
optional double changeRate5D = 21; // 5日漲跌幅(%)
optional double changeRate10D = 22; // 10日漲跌幅(%)
optional double changeRate20D = 23; // 20日漲跌幅(%)
optional double changeRate60D = 24; // 60日漲跌幅(%)
optional double changeRate120D = 25; // 120日漲跌幅(%)
optional double changeRate250D = 26; // 250日漲跌幅(%)
optional double changeRateYTD = 27; // 年初至今漲跌幅(%)
optional double peTTM = 30; // 市盈率TTM
optional double pb = 31; // 市淨率
optional double turnoverRatio = 32; // 換手率(%)
optional double volumeRatio = 33; // 量比
optional double amplitude = 34; // 振幅(%)
}
message S2C {
repeated PeriodChangeRankItem dataList = 1; // 數據列表
optional int32 allCount = 2; // 符合條件的總數據量
}
message Request {
required C2S c2s = 1;
}
message Response {
required int32 retType = 1 [default = -400]; // RetType, 返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
- 接口調用結果,結構參見 RetType
協議 ID
3416
Example
public class Program : MMSPI_Qot, MMSPI_Conn {
MMAPI_Qot qot = new MMAPI_Qot();
public Program() {
qot.SetClientInfo("csharp", 1); //設置客戶端信息
qot.SetConnCallback(this); //設置連接回調
qot.SetQotCallback(this); //設置行情回調
}
public void Start() {
qot.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(MMAPI_Conn client, long errCode, String desc)
{
Console.Write("Qot onInitConnect: ret={0} desc={1} connID={2}
", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
QotGetPeriodChangeRank.C2S c2s = QotGetPeriodChangeRank.C2S.CreateBuilder()
.SetMarket(11)
.SetCount(3)
.Build();
QotGetPeriodChangeRank.Request req = QotGetPeriodChangeRank.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetPeriodChangeRank(req);
Console.Write("Send QotGetPeriodChangeRank: {0}
", seqNo);
}
public void OnDisconnect(MMAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}
", errCode);
}
public void OnReply_GetPeriodChangeRank(MMAPI_Conn client, uint nSerialNo, QotGetPeriodChangeRank.Response rsp)
{
Console.Write("Reply: QotGetPeriodChangeRank: {0}
", nSerialNo);
if (rsp.RetType == 0 && rsp.HasS2C)
Console.Write("{0}
", rsp.ToString());
}
public static void Main(String[] args) {
MMAPI.Init();
Program program = new Program();
program.Start();
while (true)
Thread.Sleep(1000 * 600);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
- Output
Send QotGetPeriodChangeRank: 3
Reply: QotGetPeriodChangeRank: 3
GetPeriodChangeRank: errCode 0, retMsg , retType 0
{
"allCount": 6429,
"dataList": [
{ "security": { "market": 11, "code": "PAVM" }, "name": "PAVmed", "curPrice": 5.16, "changeRatio": 3.200 },
{ "security": { "market": 11, "code": "JLHL" }, "name": "巨龍在線", "curPrice": 39.69, "changeRatio": 18.832 },
{ "security": { "market": 11, "code": "DGICB" }, "name": "多尼戈爾股份-B", "curPrice": 22.86, "changeRatio": 21.531 }
]
}
2
3
4
5
6
7
8
9
10
11
int getPeriodChangeRank(Qot_GetPeriodChangeRank.Request req);
onReply_GetPeriodChangeRank(FTAPI_Conn client, int nSerialNo, Qot_GetPeriodChangeRank.Response rsp)
介紹
獲取區間漲跌幅排行,返回指定市場中按不同時間週期(5分鐘至250日/年初至今)的漲跌幅排行,支持豐富的篩選條件(市值、價格、PE、PB、換手率、量比、振幅等)。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序週期
enum PeriodType {
PeriodType_Unknown = 0;
PeriodType_5Min = 1; // 5分鐘(默認)
PeriodType_1Day = 2; // 1日
PeriodType_5Day = 3; // 5日
PeriodType_20Day = 4; // 20日
PeriodType_60Day = 5; // 60日
PeriodType_120Day = 6; // 120日
PeriodType_250Day = 7; // 250日
PeriodType_YTD = 8; // 年初至今
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 最新價區間
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_ChangeRatio = 3; // 漲跌幅區間(按所選週期)
IndicatorType_Volume = 4; // 成交量區間
IndicatorType_Turnover = 5; // 成交額區間
IndicatorType_PE = 6; // 市盈率TTM區間
IndicatorType_PB = 7; // 市淨率區間
IndicatorType_TurnoverRatio = 8; // 換手率區間
IndicatorType_VolumeRatio = 9; // 量比區間
IndicatorType_Amplitude = 10; // 振幅區間
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間
}
message C2S {
required int32 market = 1; // Qot_Common.QotMarket (HK=1, US=11)
optional int32 periodType = 2; // PeriodType, 排序週期, 默認5分鐘
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 6; // 篩選條件(AND關係)
}
// 區間漲跌幅數據項
message PeriodChangeRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double curPrice = 10; // 最新價
optional double changeRatio = 11; // 今日漲跌幅(%)
optional double turnover = 12; // 成交額
optional int64 volume = 13; // 成交量
optional double marketCap = 14; // 市值
optional double changeRate5Min = 20; // 5分鐘漲跌幅(%)
optional double changeRate5D = 21; // 5日漲跌幅(%)
optional double changeRate10D = 22; // 10日漲跌幅(%)
optional double changeRate20D = 23; // 20日漲跌幅(%)
optional double changeRate60D = 24; // 60日漲跌幅(%)
optional double changeRate120D = 25; // 120日漲跌幅(%)
optional double changeRate250D = 26; // 250日漲跌幅(%)
optional double changeRateYTD = 27; // 年初至今漲跌幅(%)
optional double peTTM = 30; // 市盈率TTM
optional double pb = 31; // 市淨率
optional double turnoverRatio = 32; // 換手率(%)
optional double volumeRatio = 33; // 量比
optional double amplitude = 34; // 振幅(%)
}
message S2C {
repeated PeriodChangeRankItem dataList = 1; // 數據列表
optional int32 allCount = 2; // 符合條件的總數據量
}
message Request {
required C2S c2s = 1;
}
message Response {
required int32 retType = 1 [default = -400]; // RetType, 返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
- 接口調用結果,結構參見 RetType
協議 ID
3416
Example
public class QotDemo implements MMSPI_Qot, MMSPI_Conn {
MMAPI_Conn_Qot qot = new MMAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1); //設置客戶端信息
qot.setConnSpi(this); //設置連接回調
qot.setQotSpi(this); //設置行情回調
}
public void start() {
qot.initConnect("127.0.0.1", (short)11111, false);
}
@Override
public void onInitConnect(MMAPI_Conn client, long errCode, String desc)
{
System.out.printf("Qot onInitConnect: ret=%d desc=%s connID=%d
", errCode, desc, client.getConnectID());
if (errCode != 0)
return;
QotGetPeriodChangeRank.C2S c2s = QotGetPeriodChangeRank.C2S.newBuilder()
.setMarket(11)
.setCount(3)
.build();
QotGetPeriodChangeRank.Request req = QotGetPeriodChangeRank.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getPeriodChangeRank(req);
System.out.printf("Send QotGetPeriodChangeRank: %d
", seqNo);
}
@Override
public void onDisconnect(MMAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d
", errCode);
}
@Override
public void onReply_GetPeriodChangeRank(MMAPI_Conn client, int nSerialNo, QotGetPeriodChangeRank.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetPeriodChangeRank failed: %s
", rsp.getRetMsg());
} else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetPeriodChangeRank: %s
", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
MMAPI.init();
QotDemo qot = new QotDemo();
qot.start();
while (true) {
try {
Thread.sleep(1000 * 600);
} catch (InterruptedException exc) {
}
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
- Output
Send QotGetPeriodChangeRank: 3
Receive QotGetPeriodChangeRank: {
"allCount": 6429,
"dataList": [
{ "security": { "market": 11, "code": "PAVM" }, "name": "PAVmed", "curPrice": 5.16, "changeRatio": 3.200 },
{ "security": { "market": 11, "code": "JLHL" }, "name": "巨龍在線", "curPrice": 39.69, "changeRatio": 18.832 },
{ "security": { "market": 11, "code": "DGICB" }, "name": "多尼戈爾股份-B", "curPrice": 22.86, "changeRatio": 21.531 }
]
}
2
3
4
5
6
7
8
9
moomoo::u32_t GetPeriodChangeRank(const Qot_GetPeriodChangeRank::Request &stReq);
virtual void OnReply_GetPeriodChangeRank(moomoo::u32_t nSerialNo, const Qot_GetPeriodChangeRank::Response &stRsp) = 0;
介紹
協議請求及回應定義
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序週期
enum PeriodType {
PeriodType_Unknown = 0;
PeriodType_5Min = 1; // 5分鐘(默認)
PeriodType_1Day = 2; // 1日
PeriodType_5Day = 3; // 5日
PeriodType_20Day = 4; // 20日
PeriodType_60Day = 5; // 60日
PeriodType_120Day = 6; // 120日
PeriodType_250Day = 7; // 250日
PeriodType_YTD = 8; // 年初至今
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 最新價區間
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_ChangeRatio = 3; // 漲跌幅區間(按所選週期)
IndicatorType_Volume = 4; // 成交量區間
IndicatorType_Turnover = 5; // 成交額區間
IndicatorType_PE = 6; // 市盈率TTM區間
IndicatorType_PB = 7; // 市淨率區間
IndicatorType_TurnoverRatio = 8; // 換手率區間
IndicatorType_VolumeRatio = 9; // 量比區間
IndicatorType_Amplitude = 10; // 振幅區間
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間
}
message C2S {
required int32 market = 1; // Qot_Common.QotMarket (HK=1, US=11)
optional int32 periodType = 2; // PeriodType, 排序週期, 默認5分鐘
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 6; // 篩選條件(AND關係)
}
// 區間漲跌幅數據項
message PeriodChangeRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double curPrice = 10; // 最新價
optional double changeRatio = 11; // 今日漲跌幅(%)
optional double turnover = 12; // 成交額
optional int64 volume = 13; // 成交量
optional double marketCap = 14; // 市值
optional double changeRate5Min = 20; // 5分鐘漲跌幅(%)
optional double changeRate5D = 21; // 5日漲跌幅(%)
optional double changeRate10D = 22; // 10日漲跌幅(%)
optional double changeRate20D = 23; // 20日漲跌幅(%)
optional double changeRate60D = 24; // 60日漲跌幅(%)
optional double changeRate120D = 25; // 120日漲跌幅(%)
optional double changeRate250D = 26; // 250日漲跌幅(%)
optional double changeRateYTD = 27; // 年初至今漲跌幅(%)
optional double peTTM = 30; // 市盈率TTM
optional double pb = 31; // 市淨率
optional double turnoverRatio = 32; // 換手率(%)
optional double volumeRatio = 33; // 量比
optional double amplitude = 34; // 振幅(%)
}
message S2C {
repeated PeriodChangeRankItem dataList = 1; // 數據列表
optional int32 allCount = 2; // 符合條件的總數據量
}
message Request {
required C2S c2s = 1;
}
message Response {
required int32 retType = 1 [default = -400]; // RetType, 返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
- 介面呼叫結果,結構參見 RetType
協議 ID
3416
Example
class Program : public MMSPI_Qot, public MMSPI_Conn
{
public:
Program() {
m_pQotApi = MMAPI::CreateQotApi();
m_pQotApi->RegisterQotSpi(this);
m_pQotApi->RegisterConnSpi(this);
}
~Program() {
if (m_pQotApi != nullptr) {
m_pQotApi->UnregisterQotSpi();
m_pQotApi->UnregisterConnSpi();
MMAPI::ReleaseQotApi(m_pQotApi);
m_pQotApi = nullptr;
}
}
void Start() {
m_pQotApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(MMAPI_Conn* pConn, moomoo::i64_t nErrCode, const char* strDesc) {
Qot_GetPeriodChangeRank::Request req;
Qot_GetPeriodChangeRank::C2S *c2s = req.mutable_c2s();
c2s->set_market(Qot_Common::QotMarket::QotMarket_US_Security);
c2s->set_count(50);
m_GetPeriodChangeRankSerialNo = m_pQotApi->GetPeriodChangeRank(req);
}
virtual void OnReply_GetPeriodChangeRank(moomoo::u32_t nSerialNo, const Qot_GetPeriodChangeRank::Response &stRsp) {
if (nSerialNo != m_GetPeriodChangeRankSerialNo) return;
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
MMAPI_Qot *m_pQotApi;
moomoo::u32_t m_GetPeriodChangeRankSerialNo = 0;
};
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
- Output
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"dataList": [
{
"security": {
"market": 11,
"code": "NVDA"
},
"name": "NVIDIA",
"curPrice": 875.4,
"changeRatio": 9.32,
"turnover": 28500000000.0,
"marketCap": 2150000000000.0
}
],
"allCount": 50
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
getPeriodChangeRank(qotGetPeriodChangeRank)
介紹
獲取區間漲跌幅排行,返回指定市場中按不同時間週期(5分鐘至250日/年初至今)的漲跌幅排行,支持豐富的篩選條件(市值、價格、PE、PB、換手率、量比、振幅等)。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序週期
enum PeriodType {
PeriodType_Unknown = 0;
PeriodType_5Min = 1; // 5分鐘(默認)
PeriodType_1Day = 2; // 1日
PeriodType_5Day = 3; // 5日
PeriodType_20Day = 4; // 20日
PeriodType_60Day = 5; // 60日
PeriodType_120Day = 6; // 120日
PeriodType_250Day = 7; // 250日
PeriodType_YTD = 8; // 年初至今
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 最新價區間
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_ChangeRatio = 3; // 漲跌幅區間(按所選週期)
IndicatorType_Volume = 4; // 成交量區間
IndicatorType_Turnover = 5; // 成交額區間
IndicatorType_PE = 6; // 市盈率TTM區間
IndicatorType_PB = 7; // 市淨率區間
IndicatorType_TurnoverRatio = 8; // 換手率區間
IndicatorType_VolumeRatio = 9; // 量比區間
IndicatorType_Amplitude = 10; // 振幅區間
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間
}
message C2S {
required int32 market = 1; // Qot_Common.QotMarket (HK=1, US=11)
optional int32 periodType = 2; // PeriodType, 排序週期, 默認5分鐘
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 6; // 篩選條件(AND關係)
}
// 區間漲跌幅數據項
message PeriodChangeRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double curPrice = 10; // 最新價
optional double changeRatio = 11; // 今日漲跌幅(%)
optional double turnover = 12; // 成交額
optional int64 volume = 13; // 成交量
optional double marketCap = 14; // 市值
optional double changeRate5Min = 20; // 5分鐘漲跌幅(%)
optional double changeRate5D = 21; // 5日漲跌幅(%)
optional double changeRate10D = 22; // 10日漲跌幅(%)
optional double changeRate20D = 23; // 20日漲跌幅(%)
optional double changeRate60D = 24; // 60日漲跌幅(%)
optional double changeRate120D = 25; // 120日漲跌幅(%)
optional double changeRate250D = 26; // 250日漲跌幅(%)
optional double changeRateYTD = 27; // 年初至今漲跌幅(%)
optional double peTTM = 30; // 市盈率TTM
optional double pb = 31; // 市淨率
optional double turnoverRatio = 32; // 換手率(%)
optional double volumeRatio = 33; // 量比
optional double amplitude = 34; // 振幅(%)
}
message S2C {
repeated PeriodChangeRankItem dataList = 1; // 數據列表
optional int32 allCount = 2; // 符合條件的總數據量
}
message Request {
required C2S c2s = 1;
}
message Response {
required int32 retType = 1 [default = -400]; // RetType, 返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
- 接口調用結果,結構參見 RetType
協議 ID
3416
Example
import mmWebsocket from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function QotGetPeriodChangeRank(){
const { RetType } = Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 11111, false, "xxxxxx"];
let websocket = new mmWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) {
const req = {
c2s: { market: 11, count: 3 },
};
websocket.GetPeriodChangeRank(req)
.then((res)=>{
let { errCode, retMsg, retType, s2c } = res
console.log("GetPeriodChangeRank: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
let data = beautify(JSON.stringify(s2c), { indent_size: 2, space_in_empty_paren: true });
console.log(data);
}
})
.catch((error)=>{ console.log("error:", error); });
} else {
console.log("start error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{ websocket.stop(); process.exit(); }, 5000);
}
QotGetPeriodChangeRank()
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
- Output
GetPeriodChangeRank: errCode 0, retMsg , retType 0
{
"allCount": 6429,
"dataList": [
{ "security": { "market": 11, "code": "PAVM" }, "name": "PAVmed", "curPrice": 5.16, "changeRatio": 3.200 },
{ "security": { "market": 11, "code": "JLHL" }, "name": "巨龍在線", "curPrice": 39.69, "changeRatio": 18.832 },
{ "security": { "market": 11, "code": "DGICB" }, "name": "多尼戈爾股份-B", "curPrice": 22.86, "changeRatio": 21.531 }
]
}
2
3
4
5
6
7
8
9
接口限制
- 30 秒內最多 60 次請求
- 分頁請求僅首頁計入限頻統計
← 獲取賣空異動榜 獲取破淨高股息國央企 →