# 獲取夜盤榜
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_us_overnight_rank(sort_dir=None, count=10, offset=None, filter_list=None)
介紹
獲取美股夜盤榜,返回夜盤交易時段漲跌幅排行,包含夜盤價格、漲跌幅、成交額、成交量等數據。
參數
參數 類型 說明 sort_dir RankSortDir 排序方向,默認降序(領漲) count int 返回數量 [1, 200],默認 10 offset int 起始位置,默認 0 filter_list list[ SimpleRankFilter]篩選條件列表(多條件爲 AND 關係) 輸入限制
filter_list篩選條件(SimpleRankFilter):通過
SimpleRankFilter構造篩選條件:構造參數 說明 indicator_type篩選因子類型( SimpleRankIndicatorType,必填)interval_min範圍最小值(閉區間,MARKET_CAP/PE 使用) interval_max範圍最大值(閉區間,MARKET_CAP/PE 使用) price_filter價格篩選枚舉( PriceFilter,PRICE 類型必填)
返回
參數 類型 說明 ret RET_CODE 接口調用結果 data pd.DataFrame 當 ret == RET_OK,返回 (all_count, DataFrame) 元組 str 當 ret != RET_OK,返回錯誤描述 - 數據格式如下:
字段 類型 說明 security str 股票代碼(如 'US.NVDA')name str 股票名稱 overnight_price float 夜盤價 overnight_change_ratio float 夜盤漲跌幅(%) overnight_change_amount float 夜盤漲跌額 overnight_turnover float 夜盤成交額 overnight_volume int 夜盤成交量 close_price float 收盤價(上一交易日) change_ratio float 盤中漲跌幅(%) change_amount float 盤中漲跌額
- 數據格式如下:
Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.get_us_overnight_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
總數據量: 17728
security name overnight_price overnight_change_ratio overnight_change_amount overnight_turnover overnight_volume close_price change_ratio change_amount
0 US.MGN Megan 0.3128 81.543 1.405000e+08 1681274.123 5102016 0.172 30.303030 0.04
1 US.QNRX Quoin Pharmaceuticals 5.2900 62.769 2.040000e+09 1164463.400 223649 3.250 -26.303855 -1.16
2
3
4
# Qot_GetUSOvernightRank.proto
介紹
獲取美股夜盤榜,返回夜盤交易時段漲跌幅排行,包含夜盤價格、漲跌幅、成交額、成交量等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(領漲,默認)
SortDir_Ascending = 1; // 升序(領跌)
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 價格篩選(枚舉, 參考PriceFilter)
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_PE = 3; // 市盈率區間
}
// 價格篩選枚舉
enum PriceFilter {
PriceFilter_All = 0; // 所有(默認)
PriceFilter_LessThan1 = 1; // 小於1
PriceFilter_Between1And10 = 2; // 1~10之間
PriceFilter_Between10And100 = 3; // 10~100之間
PriceFilter_GreaterThan100 = 4; // 大於100
PriceFilter_Near52WeekHigh = 5; // 接近52周最高
PriceFilter_Near52WeekLow = 6; // 接近52周最低
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間(MarketCap/PE使用)
optional int32 priceFilter = 3; // PriceFilter, 價格篩選枚舉(IndicatorType_Price時使用)
}
message C2S {
optional int32 sortDir = 1; // SortDir, 排序方向, 默認降序(領漲)
optional int32 offset = 2; // 起始位置, 默認0
optional int32 count = 3; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 4; // 篩選條件(AND關係)
}
// 夜盤榜數據項
message OvernightRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double overnightPrice = 10; // 夜盤價
optional double overnightChangeRatio = 11; // 夜盤漲跌幅(%)
optional double overnightChangeAmount = 12; // 夜盤漲跌額
optional double overnightTurnover = 13; // 夜盤成交額
optional int64 overnightVolume = 14; // 夜盤成交量
optional double closePrice = 15; // 收盤價(上一交易日)
optional double changeRatio = 16; // 盤中漲跌幅(%)
optional double changeAmount = 17; // 盤中漲跌額
}
message S2C {
repeated OvernightRankItem 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
協議 ID
3412
uint GetUSOvernightRank(Qot_GetUSOvernightRank.Request req);
virtual void OnReply_GetUSOvernightRank(FTAPI_Conn client, uint nSerialNo, Qot_GetUSOvernightRank.Response rsp);
介紹
獲取美股夜盤榜,返回夜盤交易時段漲跌幅排行,包含夜盤價格、漲跌幅、成交額、成交量等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(領漲,默認)
SortDir_Ascending = 1; // 升序(領跌)
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 價格篩選(枚舉, 參考PriceFilter)
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_PE = 3; // 市盈率區間
}
// 價格篩選枚舉
enum PriceFilter {
PriceFilter_All = 0; // 所有(默認)
PriceFilter_LessThan1 = 1; // 小於1
PriceFilter_Between1And10 = 2; // 1~10之間
PriceFilter_Between10And100 = 3; // 10~100之間
PriceFilter_GreaterThan100 = 4; // 大於100
PriceFilter_Near52WeekHigh = 5; // 接近52周最高
PriceFilter_Near52WeekLow = 6; // 接近52周最低
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間(MarketCap/PE使用)
optional int32 priceFilter = 3; // PriceFilter, 價格篩選枚舉(IndicatorType_Price時使用)
}
message C2S {
optional int32 sortDir = 1; // SortDir, 排序方向, 默認降序(領漲)
optional int32 offset = 2; // 起始位置, 默認0
optional int32 count = 3; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 4; // 篩選條件(AND關係)
}
// 夜盤榜數據項
message OvernightRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double overnightPrice = 10; // 夜盤價
optional double overnightChangeRatio = 11; // 夜盤漲跌幅(%)
optional double overnightChangeAmount = 12; // 夜盤漲跌額
optional double overnightTurnover = 13; // 夜盤成交額
optional int64 overnightVolume = 14; // 夜盤成交量
optional double closePrice = 15; // 收盤價(上一交易日)
optional double changeRatio = 16; // 盤中漲跌幅(%)
optional double changeAmount = 17; // 盤中漲跌額
}
message S2C {
repeated OvernightRankItem 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
- 接口調用結果,結構參見 RetType
協議 ID
3412
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;
QotGetUSOvernightRank.C2S c2s = QotGetUSOvernightRank.C2S.CreateBuilder()
.SetCount(3)
.Build();
QotGetUSOvernightRank.Request req = QotGetUSOvernightRank.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetUSOvernightRank(req);
Console.Write("Send QotGetUSOvernightRank: {0}
", seqNo);
}
public void OnDisconnect(FTAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}
", errCode);
}
public void OnReply_GetUSOvernightRank(FTAPI_Conn client, uint nSerialNo, QotGetUSOvernightRank.Response rsp)
{
Console.Write("Reply: QotGetUSOvernightRank: {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
- Output
Send QotGetUSOvernightRank: 3
Reply: QotGetUSOvernightRank: 3
GetUSOvernightRank: errCode 0, retMsg , retType 0
{
"allCount": 17711,
"dataList": [
{ "security": { "market": 11, "code": "TNON" }, "name": "Tenon Medical", "overnightPrice": 0.7310, "overnightChangeRatio": 108.857 },
{ "security": { "market": 11, "code": "SAGT" }, "name": "Sagtec Global", "overnightPrice": 2.0500, "overnightChangeRatio": 107.070 },
{ "security": { "market": 11, "code": "CANG" }, "name": "燦谷", "overnightPrice": 0.3212, "overnightChangeRatio": 69.052 }
]
}
2
3
4
5
6
7
8
9
10
11
int getUSOvernightRank(Qot_GetUSOvernightRank.Request req);
onReply_GetUSOvernightRank(FTAPI_Conn client, int nSerialNo, Qot_GetUSOvernightRank.Response rsp)
介紹
獲取美股夜盤榜,返回夜盤交易時段漲跌幅排行,包含夜盤價格、漲跌幅、成交額、成交量等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(領漲,默認)
SortDir_Ascending = 1; // 升序(領跌)
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 價格篩選(枚舉, 參考PriceFilter)
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_PE = 3; // 市盈率區間
}
// 價格篩選枚舉
enum PriceFilter {
PriceFilter_All = 0; // 所有(默認)
PriceFilter_LessThan1 = 1; // 小於1
PriceFilter_Between1And10 = 2; // 1~10之間
PriceFilter_Between10And100 = 3; // 10~100之間
PriceFilter_GreaterThan100 = 4; // 大於100
PriceFilter_Near52WeekHigh = 5; // 接近52周最高
PriceFilter_Near52WeekLow = 6; // 接近52周最低
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間(MarketCap/PE使用)
optional int32 priceFilter = 3; // PriceFilter, 價格篩選枚舉(IndicatorType_Price時使用)
}
message C2S {
optional int32 sortDir = 1; // SortDir, 排序方向, 默認降序(領漲)
optional int32 offset = 2; // 起始位置, 默認0
optional int32 count = 3; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 4; // 篩選條件(AND關係)
}
// 夜盤榜數據項
message OvernightRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double overnightPrice = 10; // 夜盤價
optional double overnightChangeRatio = 11; // 夜盤漲跌幅(%)
optional double overnightChangeAmount = 12; // 夜盤漲跌額
optional double overnightTurnover = 13; // 夜盤成交額
optional int64 overnightVolume = 14; // 夜盤成交量
optional double closePrice = 15; // 收盤價(上一交易日)
optional double changeRatio = 16; // 盤中漲跌幅(%)
optional double changeAmount = 17; // 盤中漲跌額
}
message S2C {
repeated OvernightRankItem 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
- 接口調用結果,結構參見 RetType
協議 ID
3412
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;
QotGetUSOvernightRank.C2S c2s = QotGetUSOvernightRank.C2S.newBuilder()
.setCount(3)
.build();
QotGetUSOvernightRank.Request req = QotGetUSOvernightRank.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getUSOvernightRank(req);
System.out.printf("Send QotGetUSOvernightRank: %d
", seqNo);
}
@Override
public void onDisconnect(FTAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d
", errCode);
}
@Override
public void onReply_GetUSOvernightRank(FTAPI_Conn client, int nSerialNo, QotGetUSOvernightRank.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetUSOvernightRank failed: %s
", rsp.getRetMsg());
} else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetUSOvernightRank: %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
- Output
Send QotGetUSOvernightRank: 3
Receive QotGetUSOvernightRank: {
"allCount": 17711,
"dataList": [
{ "security": { "market": 11, "code": "TNON" }, "name": "Tenon Medical", "overnightPrice": 0.7310, "overnightChangeRatio": 108.857 },
{ "security": { "market": 11, "code": "SAGT" }, "name": "Sagtec Global", "overnightPrice": 2.0500, "overnightChangeRatio": 107.070 },
{ "security": { "market": 11, "code": "CANG" }, "name": "燦谷", "overnightPrice": 0.3212, "overnightChangeRatio": 69.052 }
]
}
2
3
4
5
6
7
8
9
Futu::u32_t GetUSOvernightRank(const Qot_GetUSOvernightRank::Request &stReq);
virtual void OnReply_GetUSOvernightRank(Futu::u32_t nSerialNo, const Qot_GetUSOvernightRank::Response &stRsp) = 0;
介紹
協議請求及回應定義
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(領漲,默認)
SortDir_Ascending = 1; // 升序(領跌)
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 價格篩選(枚舉, 參考PriceFilter)
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_PE = 3; // 市盈率區間
}
// 價格篩選枚舉
enum PriceFilter {
PriceFilter_All = 0; // 所有(默認)
PriceFilter_LessThan1 = 1; // 小於1
PriceFilter_Between1And10 = 2; // 1~10之間
PriceFilter_Between10And100 = 3; // 10~100之間
PriceFilter_GreaterThan100 = 4; // 大於100
PriceFilter_Near52WeekHigh = 5; // 接近52周最高
PriceFilter_Near52WeekLow = 6; // 接近52周最低
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間(MarketCap/PE使用)
optional int32 priceFilter = 3; // PriceFilter, 價格篩選枚舉(IndicatorType_Price時使用)
}
message C2S {
optional int32 sortDir = 1; // SortDir, 排序方向, 默認降序(領漲)
optional int32 offset = 2; // 起始位置, 默認0
optional int32 count = 3; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 4; // 篩選條件(AND關係)
}
// 夜盤榜數據項
message OvernightRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double overnightPrice = 10; // 夜盤價
optional double overnightChangeRatio = 11; // 夜盤漲跌幅(%)
optional double overnightChangeAmount = 12; // 夜盤漲跌額
optional double overnightTurnover = 13; // 夜盤成交額
optional int64 overnightVolume = 14; // 夜盤成交量
optional double closePrice = 15; // 收盤價(上一交易日)
optional double changeRatio = 16; // 盤中漲跌幅(%)
optional double changeAmount = 17; // 盤中漲跌額
}
message S2C {
repeated OvernightRankItem 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
- 介面呼叫結果,結構參見 RetType
協議 ID
3412
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_GetUSOvernightRank::Request req;
Qot_GetUSOvernightRank::C2S *c2s = req.mutable_c2s();
c2s->set_count(50);
m_GetUSOvernightRankSerialNo = m_pQotApi->GetUSOvernightRank(req);
}
virtual void OnReply_GetUSOvernightRank(Futu::u32_t nSerialNo, const Qot_GetUSOvernightRank::Response &stRsp) {
if (nSerialNo != m_GetUSOvernightRankSerialNo) return;
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_GetUSOvernightRankSerialNo = 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
- Output
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"dataList": [
{
"security": {
"market": 11,
"code": "TSLA"
},
"name": "Tesla",
"overnightPrice": 182.5,
"overnightChangeRatio": 2.35,
"overnightChangeAmount": 4.18,
"closePrice": 178.32
}
],
"allCount": 50
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
getUSOvernightRank(qotGetUSOvernightRank)
介紹
獲取美股夜盤榜,返回夜盤交易時段漲跌幅排行,包含夜盤價格、漲跌幅、成交額、成交量等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(領漲,默認)
SortDir_Ascending = 1; // 升序(領跌)
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 價格篩選(枚舉, 參考PriceFilter)
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_PE = 3; // 市盈率區間
}
// 價格篩選枚舉
enum PriceFilter {
PriceFilter_All = 0; // 所有(默認)
PriceFilter_LessThan1 = 1; // 小於1
PriceFilter_Between1And10 = 2; // 1~10之間
PriceFilter_Between10And100 = 3; // 10~100之間
PriceFilter_GreaterThan100 = 4; // 大於100
PriceFilter_Near52WeekHigh = 5; // 接近52周最高
PriceFilter_Near52WeekLow = 6; // 接近52周最低
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間(MarketCap/PE使用)
optional int32 priceFilter = 3; // PriceFilter, 價格篩選枚舉(IndicatorType_Price時使用)
}
message C2S {
optional int32 sortDir = 1; // SortDir, 排序方向, 默認降序(領漲)
optional int32 offset = 2; // 起始位置, 默認0
optional int32 count = 3; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 4; // 篩選條件(AND關係)
}
// 夜盤榜數據項
message OvernightRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double overnightPrice = 10; // 夜盤價
optional double overnightChangeRatio = 11; // 夜盤漲跌幅(%)
optional double overnightChangeAmount = 12; // 夜盤漲跌額
optional double overnightTurnover = 13; // 夜盤成交額
optional int64 overnightVolume = 14; // 夜盤成交量
optional double closePrice = 15; // 收盤價(上一交易日)
optional double changeRatio = 16; // 盤中漲跌幅(%)
optional double changeAmount = 17; // 盤中漲跌額
}
message S2C {
repeated OvernightRankItem 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
- 接口調用結果,結構參見 RetType
協議 ID
3412
Example
import ftWebsocket from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
import beautify from "js-beautify";
function QotGetUSOvernightRank(){
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: { count: 3 },
};
websocket.GetUSOvernightRank(req)
.then((res)=>{
let { errCode, retMsg, retType, s2c } = res
console.log("GetUSOvernightRank: 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);
}
QotGetUSOvernightRank()
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
GetUSOvernightRank: errCode 0, retMsg , retType 0
{
"allCount": 17711,
"dataList": [
{ "security": { "market": 11, "code": "TNON" }, "name": "Tenon Medical", "overnightPrice": 0.7310, "overnightChangeRatio": 108.857 },
{ "security": { "market": 11, "code": "SAGT" }, "name": "Sagtec Global", "overnightPrice": 2.0500, "overnightChangeRatio": 107.070 },
{ "security": { "market": 11, "code": "CANG" }, "name": "燦谷", "overnightPrice": 0.3212, "overnightChangeRatio": 69.052 }
]
}
2
3
4
5
6
7
8
9
接口限制
- 30 秒內最多 60 次請求
- 分頁請求僅首頁計入限頻統計
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_us_overnight_rank(sort_dir=None, count=10, offset=None, filter_list=None)
介紹
獲取美股夜盤榜,返回夜盤交易時段漲跌幅排行,包含夜盤價格、漲跌幅、成交額、成交量等數據。
參數
參數 類型 說明 sort_dir RankSortDir 排序方向,默認降序(領漲) count int 返回數量 [1, 200],默認 10 offset int 起始位置,默認 0 filter_list list[ SimpleRankFilter]篩選條件列表(多條件爲 AND 關係) 輸入限制
filter_list篩選條件(SimpleRankFilter):通過
SimpleRankFilter構造篩選條件:構造參數 說明 indicator_type篩選因子類型( SimpleRankIndicatorType,必填)interval_min範圍最小值(閉區間,MARKET_CAP/PE 使用) interval_max範圍最大值(閉區間,MARKET_CAP/PE 使用) price_filter價格篩選枚舉( PriceFilter,PRICE 類型必填)
返回
參數 類型 說明 ret RET_CODE 接口調用結果 data pd.DataFrame 當 ret == RET_OK,返回 (all_count, DataFrame) 元組 str 當 ret != RET_OK,返回錯誤描述 - 數據格式如下:
字段 類型 說明 security str 股票代碼(如 'US.NVDA')name str 股票名稱 overnight_price float 夜盤價 overnight_change_ratio float 夜盤漲跌幅(%) overnight_change_amount float 夜盤漲跌額 overnight_turnover float 夜盤成交額 overnight_volume int 夜盤成交量 close_price float 收盤價(上一交易日) change_ratio float 盤中漲跌幅(%) change_amount float 盤中漲跌額
- 數據格式如下:
Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.get_us_overnight_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
總數據量: 17728
security name overnight_price overnight_change_ratio overnight_change_amount overnight_turnover overnight_volume close_price change_ratio change_amount
0 US.MGN Megan 0.3128 81.543 1.405000e+08 1681274.123 5102016 0.172 30.303030 0.04
1 US.QNRX Quoin Pharmaceuticals 5.2900 62.769 2.040000e+09 1164463.400 223649 3.250 -26.303855 -1.16
2
3
4
# Qot_GetUSOvernightRank.proto
介紹
獲取美股夜盤榜,返回夜盤交易時段漲跌幅排行,包含夜盤價格、漲跌幅、成交額、成交量等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(領漲,默認)
SortDir_Ascending = 1; // 升序(領跌)
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 價格篩選(枚舉, 參考PriceFilter)
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_PE = 3; // 市盈率區間
}
// 價格篩選枚舉
enum PriceFilter {
PriceFilter_All = 0; // 所有(默認)
PriceFilter_LessThan1 = 1; // 小於1
PriceFilter_Between1And10 = 2; // 1~10之間
PriceFilter_Between10And100 = 3; // 10~100之間
PriceFilter_GreaterThan100 = 4; // 大於100
PriceFilter_Near52WeekHigh = 5; // 接近52周最高
PriceFilter_Near52WeekLow = 6; // 接近52周最低
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間(MarketCap/PE使用)
optional int32 priceFilter = 3; // PriceFilter, 價格篩選枚舉(IndicatorType_Price時使用)
}
message C2S {
optional int32 sortDir = 1; // SortDir, 排序方向, 默認降序(領漲)
optional int32 offset = 2; // 起始位置, 默認0
optional int32 count = 3; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 4; // 篩選條件(AND關係)
}
// 夜盤榜數據項
message OvernightRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double overnightPrice = 10; // 夜盤價
optional double overnightChangeRatio = 11; // 夜盤漲跌幅(%)
optional double overnightChangeAmount = 12; // 夜盤漲跌額
optional double overnightTurnover = 13; // 夜盤成交額
optional int64 overnightVolume = 14; // 夜盤成交量
optional double closePrice = 15; // 收盤價(上一交易日)
optional double changeRatio = 16; // 盤中漲跌幅(%)
optional double changeAmount = 17; // 盤中漲跌額
}
message S2C {
repeated OvernightRankItem 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
協議 ID
3412
uint GetUSOvernightRank(Qot_GetUSOvernightRank.Request req);
virtual void OnReply_GetUSOvernightRank(FTAPI_Conn client, uint nSerialNo, Qot_GetUSOvernightRank.Response rsp);
介紹
獲取美股夜盤榜,返回夜盤交易時段漲跌幅排行,包含夜盤價格、漲跌幅、成交額、成交量等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(領漲,默認)
SortDir_Ascending = 1; // 升序(領跌)
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 價格篩選(枚舉, 參考PriceFilter)
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_PE = 3; // 市盈率區間
}
// 價格篩選枚舉
enum PriceFilter {
PriceFilter_All = 0; // 所有(默認)
PriceFilter_LessThan1 = 1; // 小於1
PriceFilter_Between1And10 = 2; // 1~10之間
PriceFilter_Between10And100 = 3; // 10~100之間
PriceFilter_GreaterThan100 = 4; // 大於100
PriceFilter_Near52WeekHigh = 5; // 接近52周最高
PriceFilter_Near52WeekLow = 6; // 接近52周最低
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間(MarketCap/PE使用)
optional int32 priceFilter = 3; // PriceFilter, 價格篩選枚舉(IndicatorType_Price時使用)
}
message C2S {
optional int32 sortDir = 1; // SortDir, 排序方向, 默認降序(領漲)
optional int32 offset = 2; // 起始位置, 默認0
optional int32 count = 3; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 4; // 篩選條件(AND關係)
}
// 夜盤榜數據項
message OvernightRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double overnightPrice = 10; // 夜盤價
optional double overnightChangeRatio = 11; // 夜盤漲跌幅(%)
optional double overnightChangeAmount = 12; // 夜盤漲跌額
optional double overnightTurnover = 13; // 夜盤成交額
optional int64 overnightVolume = 14; // 夜盤成交量
optional double closePrice = 15; // 收盤價(上一交易日)
optional double changeRatio = 16; // 盤中漲跌幅(%)
optional double changeAmount = 17; // 盤中漲跌額
}
message S2C {
repeated OvernightRankItem 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
- 接口調用結果,結構參見 RetType
協議 ID
3412
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;
QotGetUSOvernightRank.C2S c2s = QotGetUSOvernightRank.C2S.CreateBuilder()
.SetCount(3)
.Build();
QotGetUSOvernightRank.Request req = QotGetUSOvernightRank.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetUSOvernightRank(req);
Console.Write("Send QotGetUSOvernightRank: {0}
", seqNo);
}
public void OnDisconnect(MMAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}
", errCode);
}
public void OnReply_GetUSOvernightRank(MMAPI_Conn client, uint nSerialNo, QotGetUSOvernightRank.Response rsp)
{
Console.Write("Reply: QotGetUSOvernightRank: {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
- Output
Send QotGetUSOvernightRank: 3
Reply: QotGetUSOvernightRank: 3
GetUSOvernightRank: errCode 0, retMsg , retType 0
{
"allCount": 17711,
"dataList": [
{ "security": { "market": 11, "code": "TNON" }, "name": "Tenon Medical", "overnightPrice": 0.7310, "overnightChangeRatio": 108.857 },
{ "security": { "market": 11, "code": "SAGT" }, "name": "Sagtec Global", "overnightPrice": 2.0500, "overnightChangeRatio": 107.070 },
{ "security": { "market": 11, "code": "CANG" }, "name": "燦谷", "overnightPrice": 0.3212, "overnightChangeRatio": 69.052 }
]
}
2
3
4
5
6
7
8
9
10
11
int getUSOvernightRank(Qot_GetUSOvernightRank.Request req);
onReply_GetUSOvernightRank(FTAPI_Conn client, int nSerialNo, Qot_GetUSOvernightRank.Response rsp)
介紹
獲取美股夜盤榜,返回夜盤交易時段漲跌幅排行,包含夜盤價格、漲跌幅、成交額、成交量等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(領漲,默認)
SortDir_Ascending = 1; // 升序(領跌)
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 價格篩選(枚舉, 參考PriceFilter)
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_PE = 3; // 市盈率區間
}
// 價格篩選枚舉
enum PriceFilter {
PriceFilter_All = 0; // 所有(默認)
PriceFilter_LessThan1 = 1; // 小於1
PriceFilter_Between1And10 = 2; // 1~10之間
PriceFilter_Between10And100 = 3; // 10~100之間
PriceFilter_GreaterThan100 = 4; // 大於100
PriceFilter_Near52WeekHigh = 5; // 接近52周最高
PriceFilter_Near52WeekLow = 6; // 接近52周最低
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間(MarketCap/PE使用)
optional int32 priceFilter = 3; // PriceFilter, 價格篩選枚舉(IndicatorType_Price時使用)
}
message C2S {
optional int32 sortDir = 1; // SortDir, 排序方向, 默認降序(領漲)
optional int32 offset = 2; // 起始位置, 默認0
optional int32 count = 3; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 4; // 篩選條件(AND關係)
}
// 夜盤榜數據項
message OvernightRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double overnightPrice = 10; // 夜盤價
optional double overnightChangeRatio = 11; // 夜盤漲跌幅(%)
optional double overnightChangeAmount = 12; // 夜盤漲跌額
optional double overnightTurnover = 13; // 夜盤成交額
optional int64 overnightVolume = 14; // 夜盤成交量
optional double closePrice = 15; // 收盤價(上一交易日)
optional double changeRatio = 16; // 盤中漲跌幅(%)
optional double changeAmount = 17; // 盤中漲跌額
}
message S2C {
repeated OvernightRankItem 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
- 接口調用結果,結構參見 RetType
協議 ID
3412
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;
QotGetUSOvernightRank.C2S c2s = QotGetUSOvernightRank.C2S.newBuilder()
.setCount(3)
.build();
QotGetUSOvernightRank.Request req = QotGetUSOvernightRank.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getUSOvernightRank(req);
System.out.printf("Send QotGetUSOvernightRank: %d
", seqNo);
}
@Override
public void onDisconnect(MMAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d
", errCode);
}
@Override
public void onReply_GetUSOvernightRank(MMAPI_Conn client, int nSerialNo, QotGetUSOvernightRank.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetUSOvernightRank failed: %s
", rsp.getRetMsg());
} else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetUSOvernightRank: %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
- Output
Send QotGetUSOvernightRank: 3
Receive QotGetUSOvernightRank: {
"allCount": 17711,
"dataList": [
{ "security": { "market": 11, "code": "TNON" }, "name": "Tenon Medical", "overnightPrice": 0.7310, "overnightChangeRatio": 108.857 },
{ "security": { "market": 11, "code": "SAGT" }, "name": "Sagtec Global", "overnightPrice": 2.0500, "overnightChangeRatio": 107.070 },
{ "security": { "market": 11, "code": "CANG" }, "name": "燦谷", "overnightPrice": 0.3212, "overnightChangeRatio": 69.052 }
]
}
2
3
4
5
6
7
8
9
moomoo::u32_t GetUSOvernightRank(const Qot_GetUSOvernightRank::Request &stReq);
virtual void OnReply_GetUSOvernightRank(moomoo::u32_t nSerialNo, const Qot_GetUSOvernightRank::Response &stRsp) = 0;
介紹
協議請求及回應定義
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(領漲,默認)
SortDir_Ascending = 1; // 升序(領跌)
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 價格篩選(枚舉, 參考PriceFilter)
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_PE = 3; // 市盈率區間
}
// 價格篩選枚舉
enum PriceFilter {
PriceFilter_All = 0; // 所有(默認)
PriceFilter_LessThan1 = 1; // 小於1
PriceFilter_Between1And10 = 2; // 1~10之間
PriceFilter_Between10And100 = 3; // 10~100之間
PriceFilter_GreaterThan100 = 4; // 大於100
PriceFilter_Near52WeekHigh = 5; // 接近52周最高
PriceFilter_Near52WeekLow = 6; // 接近52周最低
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間(MarketCap/PE使用)
optional int32 priceFilter = 3; // PriceFilter, 價格篩選枚舉(IndicatorType_Price時使用)
}
message C2S {
optional int32 sortDir = 1; // SortDir, 排序方向, 默認降序(領漲)
optional int32 offset = 2; // 起始位置, 默認0
optional int32 count = 3; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 4; // 篩選條件(AND關係)
}
// 夜盤榜數據項
message OvernightRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double overnightPrice = 10; // 夜盤價
optional double overnightChangeRatio = 11; // 夜盤漲跌幅(%)
optional double overnightChangeAmount = 12; // 夜盤漲跌額
optional double overnightTurnover = 13; // 夜盤成交額
optional int64 overnightVolume = 14; // 夜盤成交量
optional double closePrice = 15; // 收盤價(上一交易日)
optional double changeRatio = 16; // 盤中漲跌幅(%)
optional double changeAmount = 17; // 盤中漲跌額
}
message S2C {
repeated OvernightRankItem 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
- 介面呼叫結果,結構參見 RetType
協議 ID
3412
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_GetUSOvernightRank::Request req;
Qot_GetUSOvernightRank::C2S *c2s = req.mutable_c2s();
c2s->set_count(50);
m_GetUSOvernightRankSerialNo = m_pQotApi->GetUSOvernightRank(req);
}
virtual void OnReply_GetUSOvernightRank(moomoo::u32_t nSerialNo, const Qot_GetUSOvernightRank::Response &stRsp) {
if (nSerialNo != m_GetUSOvernightRankSerialNo) return;
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
MMAPI_Qot *m_pQotApi;
moomoo::u32_t m_GetUSOvernightRankSerialNo = 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
- Output
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"dataList": [
{
"security": {
"market": 11,
"code": "TSLA"
},
"name": "Tesla",
"overnightPrice": 182.5,
"overnightChangeRatio": 2.35,
"overnightChangeAmount": 4.18,
"closePrice": 178.32
}
],
"allCount": 50
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
getUSOvernightRank(qotGetUSOvernightRank)
介紹
獲取美股夜盤榜,返回夜盤交易時段漲跌幅排行,包含夜盤價格、漲跌幅、成交額、成交量等數據。
參數
// 排序方向
enum SortDir {
SortDir_Descending = 0; // 降序(領漲,默認)
SortDir_Ascending = 1; // 升序(領跌)
}
// 篩選條件類型
enum IndicatorType {
IndicatorType_Unknown = 0;
IndicatorType_Price = 1; // 價格篩選(枚舉, 參考PriceFilter)
IndicatorType_MarketCap = 2; // 市值區間
IndicatorType_PE = 3; // 市盈率區間
}
// 價格篩選枚舉
enum PriceFilter {
PriceFilter_All = 0; // 所有(默認)
PriceFilter_LessThan1 = 1; // 小於1
PriceFilter_Between1And10 = 2; // 1~10之間
PriceFilter_Between10And100 = 3; // 10~100之間
PriceFilter_GreaterThan100 = 4; // 大於100
PriceFilter_Near52WeekHigh = 5; // 接近52周最高
PriceFilter_Near52WeekLow = 6; // 接近52周最低
}
// 篩選條件
message Indicator {
required int32 indicatorType = 1; // IndicatorType
optional Qot_OptionCommon.Interval indicatorValue = 2; // 篩選區間(MarketCap/PE使用)
optional int32 priceFilter = 3; // PriceFilter, 價格篩選枚舉(IndicatorType_Price時使用)
}
message C2S {
optional int32 sortDir = 1; // SortDir, 排序方向, 默認降序(領漲)
optional int32 offset = 2; // 起始位置, 默認0
optional int32 count = 3; // 返回數量 [1,200], 默認50
repeated Indicator filterList = 4; // 篩選條件(AND關係)
}
// 夜盤榜數據項
message OvernightRankItem {
required Qot_Common.Security security = 1; // 股票
optional string name = 2; // 名稱
optional double overnightPrice = 10; // 夜盤價
optional double overnightChangeRatio = 11; // 夜盤漲跌幅(%)
optional double overnightChangeAmount = 12; // 夜盤漲跌額
optional double overnightTurnover = 13; // 夜盤成交額
optional int64 overnightVolume = 14; // 夜盤成交量
optional double closePrice = 15; // 收盤價(上一交易日)
optional double changeRatio = 16; // 盤中漲跌幅(%)
optional double changeAmount = 17; // 盤中漲跌額
}
message S2C {
repeated OvernightRankItem 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
- 接口調用結果,結構參見 RetType
協議 ID
3412
Example
import mmWebsocket from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function QotGetUSOvernightRank(){
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: { count: 3 },
};
websocket.GetUSOvernightRank(req)
.then((res)=>{
let { errCode, retMsg, retType, s2c } = res
console.log("GetUSOvernightRank: 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);
}
QotGetUSOvernightRank()
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
GetUSOvernightRank: errCode 0, retMsg , retType 0
{
"allCount": 17711,
"dataList": [
{ "security": { "market": 11, "code": "TNON" }, "name": "Tenon Medical", "overnightPrice": 0.7310, "overnightChangeRatio": 108.857 },
{ "security": { "market": 11, "code": "SAGT" }, "name": "Sagtec Global", "overnightPrice": 2.0500, "overnightChangeRatio": 107.070 },
{ "security": { "market": 11, "code": "CANG" }, "name": "燦谷", "overnightPrice": 0.3212, "overnightChangeRatio": 69.052 }
]
}
2
3
4
5
6
7
8
9
接口限制
- 30 秒內最多 60 次請求
- 分頁請求僅首頁計入限頻統計