# 獲取賣空異動榜
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_short_selling_rank(market=None, sort_field=None, sort_dir=None, count=10, offset=None, plate_list=None)
介紹
獲取賣空異動榜,返回美股/港股賣空數據排行,支持14種排序維度和行業板塊篩選,包含賣空數量、比例、空頭持倉、回補天數等數據。
參數
參數 類型 說明 market Market 市場類型(HK/US),默認 US sort_field ShortSellingSortField 排序字段,默認賣空變化量 sort_dir RankSortDir 排序方向,默認降序 count int 返回數量 [1, 35],默認 10 offset int 起始位置,默認 0 plate_list list[str] 行業板塊代碼列表(如 ['US.BK2024']),空=全部返回
參數 類型 說明 ret RET_CODE 接口調用結果 data pd.DataFrame 當 ret == RET_OK,返回 (all_count, DataFrame) 元組 str 當 ret != RET_OK,返回錯誤描述 - 數據格式如下:
字段 類型 說明 security str 股票代碼(如 'US.GME')name str 股票名稱 close_price float 收盤價 change_ratio float 漲跌幅(%) change_ratio_5d float 5日漲跌幅(%) change_ratio_10d float 10日漲跌幅(%) volume int 成交量 short_number int 賣空數量 short_number_change int 賣空變化量 short_ratio float 賣空比例(%) short_ratio_change float 賣空變化比例(%) short_position_volume int 空頭持倉數量 short_position_ratio float 空頭持倉比例(%) days_to_cover float 回補天數 week_avg_short_number int 近一週日均賣空 week_avg_short_ratio float 近一週日均賣空比例(%) month_avg_short_number int 近一月日均賣空 month_avg_short_ratio float 近一月日均賣空比例(%)
- 數據格式如下:
Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.get_short_selling_rank(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
總數據量: 0
security name close_price change_ratio change_ratio_5d change_ratio_10d volume short_number short_number_change short_ratio short_ratio_change short_position_volume short_position_ratio days_to_cover week_avg_short_number week_avg_short_ratio month_avg_short_number month_avg_short_ratio
0 US.SKYQ Sky Quarry 1.9000 62.39 45.03 4.39 221413731 20302431 20226903 9.16 26780.66 327119 6.82 1.0 4111613 9.19 1136188 8.26
1 US.TNON Tenon Medical 0.6215 77.57 0.72 2.89 271138156 15289764 15273389 5.63 93272.60 149174 1.28 2.9 3063337 5.01 772705 5.04
2
3
4
# Qot_GetShortSellingRank.proto
介紹
獲取賣空異動榜,返回美股/港股賣空數據排行,支持14種排序維度和行業板塊篩選,包含賣空數量、比例、空頭持倉、回補天數等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序字段
enum ShortSellingSortField {
ShortSellingSortField_Unknown = 0; // 默認(賣空變化量)
ShortSellingSortField_ShortNumberChange = 1; // 賣空變化量
ShortSellingSortField_ShortRatioChange = 2; // 賣空變化比例
ShortSellingSortField_ShortNumber = 3; // 賣空數量
ShortSellingSortField_ShortRatio = 4; // 賣空比例
ShortSellingSortField_Volume = 5; // 成交量
ShortSellingSortField_PositionVolume = 6; // 空頭持倉數量
ShortSellingSortField_PositionRatio = 7; // 空頭持倉比例
ShortSellingSortField_DaysToCover = 8; // 回補天數
ShortSellingSortField_WeekAvgVolume = 9; // 近一週日均成交量
ShortSellingSortField_WeekAvgShortNumber = 10; // 近一週日均賣空數量
ShortSellingSortField_WeekAvgShortRatio = 11; // 近一週日均賣空比例
ShortSellingSortField_MonthAvgVolume = 12; // 近一月日均成交量
ShortSellingSortField_MonthAvgShortNumber = 13; // 近一月日均賣空數量
ShortSellingSortField_MonthAvgShortRatio = 14; // 近一月日均賣空比例
}
message C2S {
optional int32 market = 1; // Qot_Common.QotMarket, 市場(HK=1, US=11), 默認US
optional int32 sortField = 2; // ShortSellingSortField, 排序字段, 默認賣空變化量
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,35], 默認10
repeated Qot_Common.Security plateList = 6; // 行業板塊列表, 空=全部
}
// 賣空異動數據項
message ShortSellingRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double closePrice = 10; // 收盤價
optional double changeRatio = 11; // 漲跌幅(%)
optional double changeRatio5D = 12; // 5日漲跌幅(%)
optional double changeRatio10D = 13; // 10日漲跌幅(%)
optional int64 volume = 14; // 成交量
optional int64 shortNumber = 20; // 賣空數量
optional int64 shortNumberChange = 21; // 賣空變化量
optional double shortRatio = 22; // 賣空比例(%)
optional double shortRatioChange = 23; // 賣空變化比例(%)
optional int64 shortPositionVolume = 24; // 空頭持倉數量
optional double shortPositionRatio = 25; // 空頭持倉比例(%)
optional double daysToCover = 26; // 回補天數
optional int64 weekAvgShortNumber = 27; // 近一週日均賣空
optional double weekAvgShortRatio = 28; // 近一週日均賣空比例(%)
optional int64 monthAvgShortNumber = 29; // 近一月日均賣空
optional double monthAvgShortRatio = 30; // 近一月日均賣空比例(%)
}
message S2C {
repeated ShortSellingRankItem 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
協議 ID
3415
uint GetShortSellingRank(Qot_GetShortSellingRank.Request req);
virtual void OnReply_GetShortSellingRank(FTAPI_Conn client, uint nSerialNo, Qot_GetShortSellingRank.Response rsp);
介紹
獲取賣空異動榜,返回美股/港股賣空數據排行,支持14種排序維度和行業板塊篩選,包含賣空數量、比例、空頭持倉、回補天數等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序字段
enum ShortSellingSortField {
ShortSellingSortField_Unknown = 0; // 默認(賣空變化量)
ShortSellingSortField_ShortNumberChange = 1; // 賣空變化量
ShortSellingSortField_ShortRatioChange = 2; // 賣空變化比例
ShortSellingSortField_ShortNumber = 3; // 賣空數量
ShortSellingSortField_ShortRatio = 4; // 賣空比例
ShortSellingSortField_Volume = 5; // 成交量
ShortSellingSortField_PositionVolume = 6; // 空頭持倉數量
ShortSellingSortField_PositionRatio = 7; // 空頭持倉比例
ShortSellingSortField_DaysToCover = 8; // 回補天數
ShortSellingSortField_WeekAvgVolume = 9; // 近一週日均成交量
ShortSellingSortField_WeekAvgShortNumber = 10; // 近一週日均賣空數量
ShortSellingSortField_WeekAvgShortRatio = 11; // 近一週日均賣空比例
ShortSellingSortField_MonthAvgVolume = 12; // 近一月日均成交量
ShortSellingSortField_MonthAvgShortNumber = 13; // 近一月日均賣空數量
ShortSellingSortField_MonthAvgShortRatio = 14; // 近一月日均賣空比例
}
message C2S {
optional int32 market = 1; // Qot_Common.QotMarket, 市場(HK=1, US=11), 默認US
optional int32 sortField = 2; // ShortSellingSortField, 排序字段, 默認賣空變化量
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,35], 默認10
repeated Qot_Common.Security plateList = 6; // 行業板塊列表, 空=全部
}
// 賣空異動數據項
message ShortSellingRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double closePrice = 10; // 收盤價
optional double changeRatio = 11; // 漲跌幅(%)
optional double changeRatio5D = 12; // 5日漲跌幅(%)
optional double changeRatio10D = 13; // 10日漲跌幅(%)
optional int64 volume = 14; // 成交量
optional int64 shortNumber = 20; // 賣空數量
optional int64 shortNumberChange = 21; // 賣空變化量
optional double shortRatio = 22; // 賣空比例(%)
optional double shortRatioChange = 23; // 賣空變化比例(%)
optional int64 shortPositionVolume = 24; // 空頭持倉數量
optional double shortPositionRatio = 25; // 空頭持倉比例(%)
optional double daysToCover = 26; // 回補天數
optional int64 weekAvgShortNumber = 27; // 近一週日均賣空
optional double weekAvgShortRatio = 28; // 近一週日均賣空比例(%)
optional int64 monthAvgShortNumber = 29; // 近一月日均賣空
optional double monthAvgShortRatio = 30; // 近一月日均賣空比例(%)
}
message S2C {
repeated ShortSellingRankItem 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
- 接口調用結果,結構參見 RetType
協議 ID
3415
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;
QotGetShortSellingRank.C2S c2s = QotGetShortSellingRank.C2S.CreateBuilder()
.SetMarket(11)
.SetCount(3)
.Build();
QotGetShortSellingRank.Request req = QotGetShortSellingRank.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetShortSellingRank(req);
Console.Write("Send QotGetShortSellingRank: {0}
", seqNo);
}
public void OnDisconnect(FTAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}
", errCode);
}
public void OnReply_GetShortSellingRank(FTAPI_Conn client, uint nSerialNo, QotGetShortSellingRank.Response rsp)
{
Console.Write("Reply: QotGetShortSellingRank: {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 QotGetShortSellingRank: 3
Reply: QotGetShortSellingRank: 3
GetShortSellingRank: errCode 0, retMsg , retType 0
{
"allCount": 3,
"dataList": [
{ "security": { "market": 11, "code": "ADTX" }, "name": "Aditxt", "shortRatio": 5.42, "shortRatioChange": 62.78 },
{ "security": { "market": 11, "code": "CDE" }, "name": "科爾黛倫礦業", "shortRatio": 39.44, "shortRatioChange": 779.14 },
{ "security": { "market": 11, "code": "PFE" }, "name": "輝瑞", "shortRatio": 31.48, "shortRatioChange": 466.48 }
]
}
2
3
4
5
6
7
8
9
10
11
int getShortSellingRank(Qot_GetShortSellingRank.Request req);
onReply_GetShortSellingRank(FTAPI_Conn client, int nSerialNo, Qot_GetShortSellingRank.Response rsp)
介紹
獲取賣空異動榜,返回美股/港股賣空數據排行,支持14種排序維度和行業板塊篩選,包含賣空數量、比例、空頭持倉、回補天數等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序字段
enum ShortSellingSortField {
ShortSellingSortField_Unknown = 0; // 默認(賣空變化量)
ShortSellingSortField_ShortNumberChange = 1; // 賣空變化量
ShortSellingSortField_ShortRatioChange = 2; // 賣空變化比例
ShortSellingSortField_ShortNumber = 3; // 賣空數量
ShortSellingSortField_ShortRatio = 4; // 賣空比例
ShortSellingSortField_Volume = 5; // 成交量
ShortSellingSortField_PositionVolume = 6; // 空頭持倉數量
ShortSellingSortField_PositionRatio = 7; // 空頭持倉比例
ShortSellingSortField_DaysToCover = 8; // 回補天數
ShortSellingSortField_WeekAvgVolume = 9; // 近一週日均成交量
ShortSellingSortField_WeekAvgShortNumber = 10; // 近一週日均賣空數量
ShortSellingSortField_WeekAvgShortRatio = 11; // 近一週日均賣空比例
ShortSellingSortField_MonthAvgVolume = 12; // 近一月日均成交量
ShortSellingSortField_MonthAvgShortNumber = 13; // 近一月日均賣空數量
ShortSellingSortField_MonthAvgShortRatio = 14; // 近一月日均賣空比例
}
message C2S {
optional int32 market = 1; // Qot_Common.QotMarket, 市場(HK=1, US=11), 默認US
optional int32 sortField = 2; // ShortSellingSortField, 排序字段, 默認賣空變化量
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,35], 默認10
repeated Qot_Common.Security plateList = 6; // 行業板塊列表, 空=全部
}
// 賣空異動數據項
message ShortSellingRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double closePrice = 10; // 收盤價
optional double changeRatio = 11; // 漲跌幅(%)
optional double changeRatio5D = 12; // 5日漲跌幅(%)
optional double changeRatio10D = 13; // 10日漲跌幅(%)
optional int64 volume = 14; // 成交量
optional int64 shortNumber = 20; // 賣空數量
optional int64 shortNumberChange = 21; // 賣空變化量
optional double shortRatio = 22; // 賣空比例(%)
optional double shortRatioChange = 23; // 賣空變化比例(%)
optional int64 shortPositionVolume = 24; // 空頭持倉數量
optional double shortPositionRatio = 25; // 空頭持倉比例(%)
optional double daysToCover = 26; // 回補天數
optional int64 weekAvgShortNumber = 27; // 近一週日均賣空
optional double weekAvgShortRatio = 28; // 近一週日均賣空比例(%)
optional int64 monthAvgShortNumber = 29; // 近一月日均賣空
optional double monthAvgShortRatio = 30; // 近一月日均賣空比例(%)
}
message S2C {
repeated ShortSellingRankItem 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
- 接口調用結果,結構參見 RetType
協議 ID
3415
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;
QotGetShortSellingRank.C2S c2s = QotGetShortSellingRank.C2S.newBuilder()
.setMarket(11)
.setCount(3)
.build();
QotGetShortSellingRank.Request req = QotGetShortSellingRank.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getShortSellingRank(req);
System.out.printf("Send QotGetShortSellingRank: %d
", seqNo);
}
@Override
public void onDisconnect(FTAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d
", errCode);
}
@Override
public void onReply_GetShortSellingRank(FTAPI_Conn client, int nSerialNo, QotGetShortSellingRank.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetShortSellingRank failed: %s
", rsp.getRetMsg());
} else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetShortSellingRank: %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 QotGetShortSellingRank: 3
Receive QotGetShortSellingRank: {
"allCount": 3,
"dataList": [
{ "security": { "market": 11, "code": "ADTX" }, "name": "Aditxt", "shortRatio": 5.42, "shortRatioChange": 62.78 },
{ "security": { "market": 11, "code": "CDE" }, "name": "科爾黛倫礦業", "shortRatio": 39.44, "shortRatioChange": 779.14 },
{ "security": { "market": 11, "code": "PFE" }, "name": "輝瑞", "shortRatio": 31.48, "shortRatioChange": 466.48 }
]
}
2
3
4
5
6
7
8
9
Futu::u32_t GetShortSellingRank(const Qot_GetShortSellingRank::Request &stReq);
virtual void OnReply_GetShortSellingRank(Futu::u32_t nSerialNo, const Qot_GetShortSellingRank::Response &stRsp) = 0;
介紹
協議請求及回應定義
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序字段
enum ShortSellingSortField {
ShortSellingSortField_Unknown = 0; // 默認(賣空變化量)
ShortSellingSortField_ShortNumberChange = 1; // 賣空變化量
ShortSellingSortField_ShortRatioChange = 2; // 賣空變化比例
ShortSellingSortField_ShortNumber = 3; // 賣空數量
ShortSellingSortField_ShortRatio = 4; // 賣空比例
ShortSellingSortField_Volume = 5; // 成交量
ShortSellingSortField_PositionVolume = 6; // 空頭持倉數量
ShortSellingSortField_PositionRatio = 7; // 空頭持倉比例
ShortSellingSortField_DaysToCover = 8; // 回補天數
ShortSellingSortField_WeekAvgVolume = 9; // 近一週日均成交量
ShortSellingSortField_WeekAvgShortNumber = 10; // 近一週日均賣空數量
ShortSellingSortField_WeekAvgShortRatio = 11; // 近一週日均賣空比例
ShortSellingSortField_MonthAvgVolume = 12; // 近一月日均成交量
ShortSellingSortField_MonthAvgShortNumber = 13; // 近一月日均賣空數量
ShortSellingSortField_MonthAvgShortRatio = 14; // 近一月日均賣空比例
}
message C2S {
optional int32 market = 1; // Qot_Common.QotMarket, 市場(HK=1, US=11), 默認US
optional int32 sortField = 2; // ShortSellingSortField, 排序字段, 默認賣空變化量
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,35], 默認10
repeated Qot_Common.Security plateList = 6; // 行業板塊列表, 空=全部
}
// 賣空異動數據項
message ShortSellingRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double closePrice = 10; // 收盤價
optional double changeRatio = 11; // 漲跌幅(%)
optional double changeRatio5D = 12; // 5日漲跌幅(%)
optional double changeRatio10D = 13; // 10日漲跌幅(%)
optional int64 volume = 14; // 成交量
optional int64 shortNumber = 20; // 賣空數量
optional int64 shortNumberChange = 21; // 賣空變化量
optional double shortRatio = 22; // 賣空比例(%)
optional double shortRatioChange = 23; // 賣空變化比例(%)
optional int64 shortPositionVolume = 24; // 空頭持倉數量
optional double shortPositionRatio = 25; // 空頭持倉比例(%)
optional double daysToCover = 26; // 回補天數
optional int64 weekAvgShortNumber = 27; // 近一週日均賣空
optional double weekAvgShortRatio = 28; // 近一週日均賣空比例(%)
optional int64 monthAvgShortNumber = 29; // 近一月日均賣空
optional double monthAvgShortRatio = 30; // 近一月日均賣空比例(%)
}
message S2C {
repeated ShortSellingRankItem 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
- 介面呼叫結果,結構參見 RetType
協議 ID
3415
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_GetShortSellingRank::Request req;
Qot_GetShortSellingRank::C2S *c2s = req.mutable_c2s();
c2s->set_market(Qot_Common::QotMarket::QotMarket_US_Security);
c2s->set_count(50);
m_GetShortSellingRankSerialNo = m_pQotApi->GetShortSellingRank(req);
}
virtual void OnReply_GetShortSellingRank(Futu::u32_t nSerialNo, const Qot_GetShortSellingRank::Response &stRsp) {
if (nSerialNo != m_GetShortSellingRankSerialNo) return;
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_GetShortSellingRankSerialNo = 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": "GME"
},
"name": "GameStop",
"closePrice": 25.5,
"changeRatio": 5.2,
"volume": 85000000,
"shortNumber": 45000000
}
],
"allCount": 50
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
getShortSellingRank(qotGetShortSellingRank)
介紹
獲取賣空異動榜,返回美股/港股賣空數據排行,支持14種排序維度和行業板塊篩選,包含賣空數量、比例、空頭持倉、回補天數等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序字段
enum ShortSellingSortField {
ShortSellingSortField_Unknown = 0; // 默認(賣空變化量)
ShortSellingSortField_ShortNumberChange = 1; // 賣空變化量
ShortSellingSortField_ShortRatioChange = 2; // 賣空變化比例
ShortSellingSortField_ShortNumber = 3; // 賣空數量
ShortSellingSortField_ShortRatio = 4; // 賣空比例
ShortSellingSortField_Volume = 5; // 成交量
ShortSellingSortField_PositionVolume = 6; // 空頭持倉數量
ShortSellingSortField_PositionRatio = 7; // 空頭持倉比例
ShortSellingSortField_DaysToCover = 8; // 回補天數
ShortSellingSortField_WeekAvgVolume = 9; // 近一週日均成交量
ShortSellingSortField_WeekAvgShortNumber = 10; // 近一週日均賣空數量
ShortSellingSortField_WeekAvgShortRatio = 11; // 近一週日均賣空比例
ShortSellingSortField_MonthAvgVolume = 12; // 近一月日均成交量
ShortSellingSortField_MonthAvgShortNumber = 13; // 近一月日均賣空數量
ShortSellingSortField_MonthAvgShortRatio = 14; // 近一月日均賣空比例
}
message C2S {
optional int32 market = 1; // Qot_Common.QotMarket, 市場(HK=1, US=11), 默認US
optional int32 sortField = 2; // ShortSellingSortField, 排序字段, 默認賣空變化量
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,35], 默認10
repeated Qot_Common.Security plateList = 6; // 行業板塊列表, 空=全部
}
// 賣空異動數據項
message ShortSellingRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double closePrice = 10; // 收盤價
optional double changeRatio = 11; // 漲跌幅(%)
optional double changeRatio5D = 12; // 5日漲跌幅(%)
optional double changeRatio10D = 13; // 10日漲跌幅(%)
optional int64 volume = 14; // 成交量
optional int64 shortNumber = 20; // 賣空數量
optional int64 shortNumberChange = 21; // 賣空變化量
optional double shortRatio = 22; // 賣空比例(%)
optional double shortRatioChange = 23; // 賣空變化比例(%)
optional int64 shortPositionVolume = 24; // 空頭持倉數量
optional double shortPositionRatio = 25; // 空頭持倉比例(%)
optional double daysToCover = 26; // 回補天數
optional int64 weekAvgShortNumber = 27; // 近一週日均賣空
optional double weekAvgShortRatio = 28; // 近一週日均賣空比例(%)
optional int64 monthAvgShortNumber = 29; // 近一月日均賣空
optional double monthAvgShortRatio = 30; // 近一月日均賣空比例(%)
}
message S2C {
repeated ShortSellingRankItem 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
- 接口調用結果,結構參見 RetType
協議 ID
3415
Example
import ftWebsocket from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
import beautify from "js-beautify";
function QotGetShortSellingRank(){
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.GetShortSellingRank(req)
.then((res)=>{
let { errCode, retMsg, retType, s2c } = res
console.log("GetShortSellingRank: 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);
}
QotGetShortSellingRank()
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
GetShortSellingRank: errCode 0, retMsg , retType 0
{
"allCount": 3,
"dataList": [
{ "security": { "market": 11, "code": "ADTX" }, "name": "Aditxt", "shortRatio": 5.42, "shortRatioChange": 62.78 },
{ "security": { "market": 11, "code": "CDE" }, "name": "科爾黛倫礦業", "shortRatio": 39.44, "shortRatioChange": 779.14 },
{ "security": { "market": 11, "code": "PFE" }, "name": "輝瑞", "shortRatio": 31.48, "shortRatioChange": 466.48 }
]
}
2
3
4
5
6
7
8
9
接口限制
- 30 秒內最多 60 次請求
- 分頁請求僅首頁計入限頻統計
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_short_selling_rank(market=None, sort_field=None, sort_dir=None, count=10, offset=None, plate_list=None)
介紹
獲取賣空異動榜,返回美股/港股賣空數據排行,支持14種排序維度和行業板塊篩選,包含賣空數量、比例、空頭持倉、回補天數等數據。
參數
參數 類型 說明 market Market 市場類型(HK/US),默認 US sort_field ShortSellingSortField 排序字段,默認賣空變化量 sort_dir RankSortDir 排序方向,默認降序 count int 返回數量 [1, 35],默認 10 offset int 起始位置,默認 0 plate_list list[str] 行業板塊代碼列表(如 ['US.BK2024']),空=全部返回
參數 類型 說明 ret RET_CODE 接口調用結果 data pd.DataFrame 當 ret == RET_OK,返回 (all_count, DataFrame) 元組 str 當 ret != RET_OK,返回錯誤描述 - 數據格式如下:
字段 類型 說明 security str 股票代碼(如 'US.GME')name str 股票名稱 close_price float 收盤價 change_ratio float 漲跌幅(%) change_ratio_5d float 5日漲跌幅(%) change_ratio_10d float 10日漲跌幅(%) volume int 成交量 short_number int 賣空數量 short_number_change int 賣空變化量 short_ratio float 賣空比例(%) short_ratio_change float 賣空變化比例(%) short_position_volume int 空頭持倉數量 short_position_ratio float 空頭持倉比例(%) days_to_cover float 回補天數 week_avg_short_number int 近一週日均賣空 week_avg_short_ratio float 近一週日均賣空比例(%) month_avg_short_number int 近一月日均賣空 month_avg_short_ratio float 近一月日均賣空比例(%)
- 數據格式如下:
Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.get_short_selling_rank(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
總數據量: 0
security name close_price change_ratio change_ratio_5d change_ratio_10d volume short_number short_number_change short_ratio short_ratio_change short_position_volume short_position_ratio days_to_cover week_avg_short_number week_avg_short_ratio month_avg_short_number month_avg_short_ratio
0 US.SKYQ Sky Quarry 1.9000 62.39 45.03 4.39 221413731 20302431 20226903 9.16 26780.66 327119 6.82 1.0 4111613 9.19 1136188 8.26
1 US.TNON Tenon Medical 0.6215 77.57 0.72 2.89 271138156 15289764 15273389 5.63 93272.60 149174 1.28 2.9 3063337 5.01 772705 5.04
2
3
4
# Qot_GetShortSellingRank.proto
介紹
獲取賣空異動榜,返回美股/港股賣空數據排行,支持14種排序維度和行業板塊篩選,包含賣空數量、比例、空頭持倉、回補天數等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序字段
enum ShortSellingSortField {
ShortSellingSortField_Unknown = 0; // 默認(賣空變化量)
ShortSellingSortField_ShortNumberChange = 1; // 賣空變化量
ShortSellingSortField_ShortRatioChange = 2; // 賣空變化比例
ShortSellingSortField_ShortNumber = 3; // 賣空數量
ShortSellingSortField_ShortRatio = 4; // 賣空比例
ShortSellingSortField_Volume = 5; // 成交量
ShortSellingSortField_PositionVolume = 6; // 空頭持倉數量
ShortSellingSortField_PositionRatio = 7; // 空頭持倉比例
ShortSellingSortField_DaysToCover = 8; // 回補天數
ShortSellingSortField_WeekAvgVolume = 9; // 近一週日均成交量
ShortSellingSortField_WeekAvgShortNumber = 10; // 近一週日均賣空數量
ShortSellingSortField_WeekAvgShortRatio = 11; // 近一週日均賣空比例
ShortSellingSortField_MonthAvgVolume = 12; // 近一月日均成交量
ShortSellingSortField_MonthAvgShortNumber = 13; // 近一月日均賣空數量
ShortSellingSortField_MonthAvgShortRatio = 14; // 近一月日均賣空比例
}
message C2S {
optional int32 market = 1; // Qot_Common.QotMarket, 市場(HK=1, US=11), 默認US
optional int32 sortField = 2; // ShortSellingSortField, 排序字段, 默認賣空變化量
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,35], 默認10
repeated Qot_Common.Security plateList = 6; // 行業板塊列表, 空=全部
}
// 賣空異動數據項
message ShortSellingRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double closePrice = 10; // 收盤價
optional double changeRatio = 11; // 漲跌幅(%)
optional double changeRatio5D = 12; // 5日漲跌幅(%)
optional double changeRatio10D = 13; // 10日漲跌幅(%)
optional int64 volume = 14; // 成交量
optional int64 shortNumber = 20; // 賣空數量
optional int64 shortNumberChange = 21; // 賣空變化量
optional double shortRatio = 22; // 賣空比例(%)
optional double shortRatioChange = 23; // 賣空變化比例(%)
optional int64 shortPositionVolume = 24; // 空頭持倉數量
optional double shortPositionRatio = 25; // 空頭持倉比例(%)
optional double daysToCover = 26; // 回補天數
optional int64 weekAvgShortNumber = 27; // 近一週日均賣空
optional double weekAvgShortRatio = 28; // 近一週日均賣空比例(%)
optional int64 monthAvgShortNumber = 29; // 近一月日均賣空
optional double monthAvgShortRatio = 30; // 近一月日均賣空比例(%)
}
message S2C {
repeated ShortSellingRankItem 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
協議 ID
3415
uint GetShortSellingRank(Qot_GetShortSellingRank.Request req);
virtual void OnReply_GetShortSellingRank(FTAPI_Conn client, uint nSerialNo, Qot_GetShortSellingRank.Response rsp);
介紹
獲取賣空異動榜,返回美股/港股賣空數據排行,支持14種排序維度和行業板塊篩選,包含賣空數量、比例、空頭持倉、回補天數等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序字段
enum ShortSellingSortField {
ShortSellingSortField_Unknown = 0; // 默認(賣空變化量)
ShortSellingSortField_ShortNumberChange = 1; // 賣空變化量
ShortSellingSortField_ShortRatioChange = 2; // 賣空變化比例
ShortSellingSortField_ShortNumber = 3; // 賣空數量
ShortSellingSortField_ShortRatio = 4; // 賣空比例
ShortSellingSortField_Volume = 5; // 成交量
ShortSellingSortField_PositionVolume = 6; // 空頭持倉數量
ShortSellingSortField_PositionRatio = 7; // 空頭持倉比例
ShortSellingSortField_DaysToCover = 8; // 回補天數
ShortSellingSortField_WeekAvgVolume = 9; // 近一週日均成交量
ShortSellingSortField_WeekAvgShortNumber = 10; // 近一週日均賣空數量
ShortSellingSortField_WeekAvgShortRatio = 11; // 近一週日均賣空比例
ShortSellingSortField_MonthAvgVolume = 12; // 近一月日均成交量
ShortSellingSortField_MonthAvgShortNumber = 13; // 近一月日均賣空數量
ShortSellingSortField_MonthAvgShortRatio = 14; // 近一月日均賣空比例
}
message C2S {
optional int32 market = 1; // Qot_Common.QotMarket, 市場(HK=1, US=11), 默認US
optional int32 sortField = 2; // ShortSellingSortField, 排序字段, 默認賣空變化量
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,35], 默認10
repeated Qot_Common.Security plateList = 6; // 行業板塊列表, 空=全部
}
// 賣空異動數據項
message ShortSellingRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double closePrice = 10; // 收盤價
optional double changeRatio = 11; // 漲跌幅(%)
optional double changeRatio5D = 12; // 5日漲跌幅(%)
optional double changeRatio10D = 13; // 10日漲跌幅(%)
optional int64 volume = 14; // 成交量
optional int64 shortNumber = 20; // 賣空數量
optional int64 shortNumberChange = 21; // 賣空變化量
optional double shortRatio = 22; // 賣空比例(%)
optional double shortRatioChange = 23; // 賣空變化比例(%)
optional int64 shortPositionVolume = 24; // 空頭持倉數量
optional double shortPositionRatio = 25; // 空頭持倉比例(%)
optional double daysToCover = 26; // 回補天數
optional int64 weekAvgShortNumber = 27; // 近一週日均賣空
optional double weekAvgShortRatio = 28; // 近一週日均賣空比例(%)
optional int64 monthAvgShortNumber = 29; // 近一月日均賣空
optional double monthAvgShortRatio = 30; // 近一月日均賣空比例(%)
}
message S2C {
repeated ShortSellingRankItem 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
- 接口調用結果,結構參見 RetType
協議 ID
3415
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;
QotGetShortSellingRank.C2S c2s = QotGetShortSellingRank.C2S.CreateBuilder()
.SetMarket(11)
.SetCount(3)
.Build();
QotGetShortSellingRank.Request req = QotGetShortSellingRank.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetShortSellingRank(req);
Console.Write("Send QotGetShortSellingRank: {0}
", seqNo);
}
public void OnDisconnect(MMAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}
", errCode);
}
public void OnReply_GetShortSellingRank(MMAPI_Conn client, uint nSerialNo, QotGetShortSellingRank.Response rsp)
{
Console.Write("Reply: QotGetShortSellingRank: {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 QotGetShortSellingRank: 3
Reply: QotGetShortSellingRank: 3
GetShortSellingRank: errCode 0, retMsg , retType 0
{
"allCount": 3,
"dataList": [
{ "security": { "market": 11, "code": "ADTX" }, "name": "Aditxt", "shortRatio": 5.42, "shortRatioChange": 62.78 },
{ "security": { "market": 11, "code": "CDE" }, "name": "科爾黛倫礦業", "shortRatio": 39.44, "shortRatioChange": 779.14 },
{ "security": { "market": 11, "code": "PFE" }, "name": "輝瑞", "shortRatio": 31.48, "shortRatioChange": 466.48 }
]
}
2
3
4
5
6
7
8
9
10
11
int getShortSellingRank(Qot_GetShortSellingRank.Request req);
onReply_GetShortSellingRank(FTAPI_Conn client, int nSerialNo, Qot_GetShortSellingRank.Response rsp)
介紹
獲取賣空異動榜,返回美股/港股賣空數據排行,支持14種排序維度和行業板塊篩選,包含賣空數量、比例、空頭持倉、回補天數等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序字段
enum ShortSellingSortField {
ShortSellingSortField_Unknown = 0; // 默認(賣空變化量)
ShortSellingSortField_ShortNumberChange = 1; // 賣空變化量
ShortSellingSortField_ShortRatioChange = 2; // 賣空變化比例
ShortSellingSortField_ShortNumber = 3; // 賣空數量
ShortSellingSortField_ShortRatio = 4; // 賣空比例
ShortSellingSortField_Volume = 5; // 成交量
ShortSellingSortField_PositionVolume = 6; // 空頭持倉數量
ShortSellingSortField_PositionRatio = 7; // 空頭持倉比例
ShortSellingSortField_DaysToCover = 8; // 回補天數
ShortSellingSortField_WeekAvgVolume = 9; // 近一週日均成交量
ShortSellingSortField_WeekAvgShortNumber = 10; // 近一週日均賣空數量
ShortSellingSortField_WeekAvgShortRatio = 11; // 近一週日均賣空比例
ShortSellingSortField_MonthAvgVolume = 12; // 近一月日均成交量
ShortSellingSortField_MonthAvgShortNumber = 13; // 近一月日均賣空數量
ShortSellingSortField_MonthAvgShortRatio = 14; // 近一月日均賣空比例
}
message C2S {
optional int32 market = 1; // Qot_Common.QotMarket, 市場(HK=1, US=11), 默認US
optional int32 sortField = 2; // ShortSellingSortField, 排序字段, 默認賣空變化量
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,35], 默認10
repeated Qot_Common.Security plateList = 6; // 行業板塊列表, 空=全部
}
// 賣空異動數據項
message ShortSellingRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double closePrice = 10; // 收盤價
optional double changeRatio = 11; // 漲跌幅(%)
optional double changeRatio5D = 12; // 5日漲跌幅(%)
optional double changeRatio10D = 13; // 10日漲跌幅(%)
optional int64 volume = 14; // 成交量
optional int64 shortNumber = 20; // 賣空數量
optional int64 shortNumberChange = 21; // 賣空變化量
optional double shortRatio = 22; // 賣空比例(%)
optional double shortRatioChange = 23; // 賣空變化比例(%)
optional int64 shortPositionVolume = 24; // 空頭持倉數量
optional double shortPositionRatio = 25; // 空頭持倉比例(%)
optional double daysToCover = 26; // 回補天數
optional int64 weekAvgShortNumber = 27; // 近一週日均賣空
optional double weekAvgShortRatio = 28; // 近一週日均賣空比例(%)
optional int64 monthAvgShortNumber = 29; // 近一月日均賣空
optional double monthAvgShortRatio = 30; // 近一月日均賣空比例(%)
}
message S2C {
repeated ShortSellingRankItem 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
- 接口調用結果,結構參見 RetType
協議 ID
3415
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;
QotGetShortSellingRank.C2S c2s = QotGetShortSellingRank.C2S.newBuilder()
.setMarket(11)
.setCount(3)
.build();
QotGetShortSellingRank.Request req = QotGetShortSellingRank.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getShortSellingRank(req);
System.out.printf("Send QotGetShortSellingRank: %d
", seqNo);
}
@Override
public void onDisconnect(MMAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d
", errCode);
}
@Override
public void onReply_GetShortSellingRank(MMAPI_Conn client, int nSerialNo, QotGetShortSellingRank.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetShortSellingRank failed: %s
", rsp.getRetMsg());
} else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetShortSellingRank: %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 QotGetShortSellingRank: 3
Receive QotGetShortSellingRank: {
"allCount": 3,
"dataList": [
{ "security": { "market": 11, "code": "ADTX" }, "name": "Aditxt", "shortRatio": 5.42, "shortRatioChange": 62.78 },
{ "security": { "market": 11, "code": "CDE" }, "name": "科爾黛倫礦業", "shortRatio": 39.44, "shortRatioChange": 779.14 },
{ "security": { "market": 11, "code": "PFE" }, "name": "輝瑞", "shortRatio": 31.48, "shortRatioChange": 466.48 }
]
}
2
3
4
5
6
7
8
9
moomoo::u32_t GetShortSellingRank(const Qot_GetShortSellingRank::Request &stReq);
virtual void OnReply_GetShortSellingRank(moomoo::u32_t nSerialNo, const Qot_GetShortSellingRank::Response &stRsp) = 0;
介紹
協議請求及回應定義
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序字段
enum ShortSellingSortField {
ShortSellingSortField_Unknown = 0; // 默認(賣空變化量)
ShortSellingSortField_ShortNumberChange = 1; // 賣空變化量
ShortSellingSortField_ShortRatioChange = 2; // 賣空變化比例
ShortSellingSortField_ShortNumber = 3; // 賣空數量
ShortSellingSortField_ShortRatio = 4; // 賣空比例
ShortSellingSortField_Volume = 5; // 成交量
ShortSellingSortField_PositionVolume = 6; // 空頭持倉數量
ShortSellingSortField_PositionRatio = 7; // 空頭持倉比例
ShortSellingSortField_DaysToCover = 8; // 回補天數
ShortSellingSortField_WeekAvgVolume = 9; // 近一週日均成交量
ShortSellingSortField_WeekAvgShortNumber = 10; // 近一週日均賣空數量
ShortSellingSortField_WeekAvgShortRatio = 11; // 近一週日均賣空比例
ShortSellingSortField_MonthAvgVolume = 12; // 近一月日均成交量
ShortSellingSortField_MonthAvgShortNumber = 13; // 近一月日均賣空數量
ShortSellingSortField_MonthAvgShortRatio = 14; // 近一月日均賣空比例
}
message C2S {
optional int32 market = 1; // Qot_Common.QotMarket, 市場(HK=1, US=11), 默認US
optional int32 sortField = 2; // ShortSellingSortField, 排序字段, 默認賣空變化量
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,35], 默認10
repeated Qot_Common.Security plateList = 6; // 行業板塊列表, 空=全部
}
// 賣空異動數據項
message ShortSellingRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double closePrice = 10; // 收盤價
optional double changeRatio = 11; // 漲跌幅(%)
optional double changeRatio5D = 12; // 5日漲跌幅(%)
optional double changeRatio10D = 13; // 10日漲跌幅(%)
optional int64 volume = 14; // 成交量
optional int64 shortNumber = 20; // 賣空數量
optional int64 shortNumberChange = 21; // 賣空變化量
optional double shortRatio = 22; // 賣空比例(%)
optional double shortRatioChange = 23; // 賣空變化比例(%)
optional int64 shortPositionVolume = 24; // 空頭持倉數量
optional double shortPositionRatio = 25; // 空頭持倉比例(%)
optional double daysToCover = 26; // 回補天數
optional int64 weekAvgShortNumber = 27; // 近一週日均賣空
optional double weekAvgShortRatio = 28; // 近一週日均賣空比例(%)
optional int64 monthAvgShortNumber = 29; // 近一月日均賣空
optional double monthAvgShortRatio = 30; // 近一月日均賣空比例(%)
}
message S2C {
repeated ShortSellingRankItem 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
- 介面呼叫結果,結構參見 RetType
協議 ID
3415
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_GetShortSellingRank::Request req;
Qot_GetShortSellingRank::C2S *c2s = req.mutable_c2s();
c2s->set_market(Qot_Common::QotMarket::QotMarket_US_Security);
c2s->set_count(50);
m_GetShortSellingRankSerialNo = m_pQotApi->GetShortSellingRank(req);
}
virtual void OnReply_GetShortSellingRank(moomoo::u32_t nSerialNo, const Qot_GetShortSellingRank::Response &stRsp) {
if (nSerialNo != m_GetShortSellingRankSerialNo) return;
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
MMAPI_Qot *m_pQotApi;
moomoo::u32_t m_GetShortSellingRankSerialNo = 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": "GME"
},
"name": "GameStop",
"closePrice": 25.5,
"changeRatio": 5.2,
"volume": 85000000,
"shortNumber": 45000000
}
],
"allCount": 50
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
getShortSellingRank(qotGetShortSellingRank)
介紹
獲取賣空異動榜,返回美股/港股賣空數據排行,支持14種排序維度和行業板塊篩選,包含賣空數量、比例、空頭持倉、回補天數等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(默認)
SortDir_Ascending = 1; // 升序
}
// 排序字段
enum ShortSellingSortField {
ShortSellingSortField_Unknown = 0; // 默認(賣空變化量)
ShortSellingSortField_ShortNumberChange = 1; // 賣空變化量
ShortSellingSortField_ShortRatioChange = 2; // 賣空變化比例
ShortSellingSortField_ShortNumber = 3; // 賣空數量
ShortSellingSortField_ShortRatio = 4; // 賣空比例
ShortSellingSortField_Volume = 5; // 成交量
ShortSellingSortField_PositionVolume = 6; // 空頭持倉數量
ShortSellingSortField_PositionRatio = 7; // 空頭持倉比例
ShortSellingSortField_DaysToCover = 8; // 回補天數
ShortSellingSortField_WeekAvgVolume = 9; // 近一週日均成交量
ShortSellingSortField_WeekAvgShortNumber = 10; // 近一週日均賣空數量
ShortSellingSortField_WeekAvgShortRatio = 11; // 近一週日均賣空比例
ShortSellingSortField_MonthAvgVolume = 12; // 近一月日均成交量
ShortSellingSortField_MonthAvgShortNumber = 13; // 近一月日均賣空數量
ShortSellingSortField_MonthAvgShortRatio = 14; // 近一月日均賣空比例
}
message C2S {
optional int32 market = 1; // Qot_Common.QotMarket, 市場(HK=1, US=11), 默認US
optional int32 sortField = 2; // ShortSellingSortField, 排序字段, 默認賣空變化量
optional int32 sortDir = 3; // SortDir, 排序方向, 默認降序
optional int32 offset = 4; // 起始位置, 默認0
optional int32 count = 5; // 返回數量 [1,35], 默認10
repeated Qot_Common.Security plateList = 6; // 行業板塊列表, 空=全部
}
// 賣空異動數據項
message ShortSellingRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double closePrice = 10; // 收盤價
optional double changeRatio = 11; // 漲跌幅(%)
optional double changeRatio5D = 12; // 5日漲跌幅(%)
optional double changeRatio10D = 13; // 10日漲跌幅(%)
optional int64 volume = 14; // 成交量
optional int64 shortNumber = 20; // 賣空數量
optional int64 shortNumberChange = 21; // 賣空變化量
optional double shortRatio = 22; // 賣空比例(%)
optional double shortRatioChange = 23; // 賣空變化比例(%)
optional int64 shortPositionVolume = 24; // 空頭持倉數量
optional double shortPositionRatio = 25; // 空頭持倉比例(%)
optional double daysToCover = 26; // 回補天數
optional int64 weekAvgShortNumber = 27; // 近一週日均賣空
optional double weekAvgShortRatio = 28; // 近一週日均賣空比例(%)
optional int64 monthAvgShortNumber = 29; // 近一月日均賣空
optional double monthAvgShortRatio = 30; // 近一月日均賣空比例(%)
}
message S2C {
repeated ShortSellingRankItem 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
- 接口調用結果,結構參見 RetType
協議 ID
3415
Example
import mmWebsocket from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function QotGetShortSellingRank(){
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.GetShortSellingRank(req)
.then((res)=>{
let { errCode, retMsg, retType, s2c } = res
console.log("GetShortSellingRank: 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);
}
QotGetShortSellingRank()
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
GetShortSellingRank: errCode 0, retMsg , retType 0
{
"allCount": 3,
"dataList": [
{ "security": { "market": 11, "code": "ADTX" }, "name": "Aditxt", "shortRatio": 5.42, "shortRatioChange": 62.78 },
{ "security": { "market": 11, "code": "CDE" }, "name": "科爾黛倫礦業", "shortRatio": 39.44, "shortRatioChange": 779.14 },
{ "security": { "market": 11, "code": "PFE" }, "name": "輝瑞", "shortRatio": 31.48, "shortRatioChange": 466.48 }
]
}
2
3
4
5
6
7
8
9
接口限制
- 30 秒內最多 60 次請求
- 分頁請求僅首頁計入限頻統計