# 取消訂閱事件合約
- Python
- Proto
- C#
- Java
- C++
- JavaScript
unsubscribe_event_contract(code_list, subtype_list, kline_source_list=None)
介紹
取消訂閱事件合約的即時行情推送,支援按合約代碼、訂閱類型、K 線來源三個維度精確反訂閱。
參數
參數 類型 說明 code_list list 事件合約代碼列表,例如 ['EC.KXODIMATCH-26JUL140600INDENG-IND']subtype_list SubType 訂閱類型列表 kline_source_list ECKlineSource K 線來源列表 返回
參數 類型 說明 ret RET_CODE 介面調用結果 err_message None 當 ret == RET_OK,返回 None str 當 ret != RET_OK,返回錯誤描述 Example
from futu import *
import time
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# 訂閱:日 K + 逐筆
ret, err = quote_ctx.subscribe_event_contract(
['EC.KXODIMATCH-26JUL140600INDENG-IND'],
[SubType.K_DAY, SubType.TICKER]
)
if ret != RET_OK:
print('訂閱失敗:', err)
quote_ctx.close()
exit()
# 訂閱滿 1 分鐘後才能反訂閱
time.sleep(62)
# 精確取消:只取消逐筆訂閱
ret, err = quote_ctx.unsubscribe_event_contract(
['EC.KXODIMATCH-26JUL140600INDENG-IND'],
[SubType.TICKER]
)
if ret == RET_OK:
print('取消訂閱成功')
else:
print('取消訂閱失敗:', err)
quote_ctx.close()
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
- Output
取消訂閱成功
# Qot_SubEventContract.proto
介紹
取消訂閱事件合約的即時行情推送。複用訂閱介面的 proto,C2S 中 isSubOrUnSub 置 false 表示反訂閱。
參數
// 事件合約訂閱/反訂閱
message C2S
{
repeated Qot_Common.Security securityList = 1; // 合約標的(market+code),反訂閱語義與訂閱一致
repeated int32 subTypeList = 2; // Qot_Common.SubType,複用通用訂閱類型
required bool isSubOrUnSub = 3; // 取消訂閱時固定 false
optional bool isRegOrUnRegPush = 4; // 是否註冊/反註冊推送
optional bool isFirstPush = 5; // 註冊後是否首推已有數據,默認 true
optional bool isUnsubAll = 6; // true 時忽略其他參數,取消該連接所有 EC 訂閱
repeated Qot_Common.EC_KlineSource klineSource = 7; // K線來源列表(None/OrderBookYes),反訂閱 KL_* 時生效,不填忽略該維度
optional Qot_Common.QotHeader header = 100; // 行情公共參數頭
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- 股票結構參見 Security
- 訂閱類型參見 SubType
- K 線來源參見 EC_KlineSource
- 行情公共參數頭參見 QotHeader
- 返回
message S2C
{
}
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
- 介面調用結果,結構參見 RetType
uint SubEventContract(SubEventContract.Request req);
virtual void OnReply_SubEventContract(FTAPI_Conn client, uint nSerialNo, SubEventContract.Response rsp);
介紹
取消訂閱事件合約的即時行情推送。複用訂閱介面,C2S 中 SetIsSubOrUnSub(false) 表示反訂閱。
參數
message C2S
{
repeated Qot_Common.Security securityList = 1;
repeated int32 subTypeList = 2;
required bool isSubOrUnSub = 3;
optional bool isRegOrUnRegPush = 4;
optional bool isFirstPush = 5;
optional bool isUnsubAll = 6;
repeated Qot_Common.EC_KlineSource klineSource = 7;
optional Qot_Common.QotHeader header = 100;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 股票結構參見 Security
- 返回
message S2C
{
}
message Response
{
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
- 介面調用結果,結構參見 RetType
- 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)
{
if (errCode != 0) return;
QotCommon.Security sec = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_EventContract)
.SetCode("EC.KXODIMATCH-26JUL140600INDENG-IND").Build();
var c2s = SubEventContract.C2S.CreateBuilder()
.AddSecurity(sec)
.AddSubType((int)QotCommon.SubType.SubType_Ticker)
.SetIsSubOrUnSub(false)
.SetIsRegOrUnRegPush(false).Build();
var req = SubEventContract.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.SubEventContract(req);
Console.Write("Send SubEventContract(unsub): {0}\n", seqNo);
}
public void OnReply_SubEventContract(FTAPI_Conn client, uint nSerialNo, SubEventContract.Response rsp)
{
Console.Write("Reply: {0} {1}\n", nSerialNo, rsp.ToString());
}
public static void Main(String[] args)
{
FTAPI.Init();
new 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
int subEventContract(QotSubEventContract.Request req);
void onReply_SubEventContract(FTAPI_Conn client, int nSerialNo, QotSubEventContract.Response rsp);
介紹
取消訂閱事件合約的即時行情推送。複用訂閱介面,C2S 中 setIsSubOrUnSub(false) 表示反訂閱。
參數
message C2S
{
repeated Qot_Common.Security securityList = 1;
repeated int32 subTypeList = 2;
required bool isSubOrUnSub = 3;
optional bool isRegOrUnRegPush = 4;
optional bool isFirstPush = 5;
optional bool isUnsubAll = 6;
repeated Qot_Common.EC_KlineSource klineSource = 7;
optional Qot_Common.QotHeader header = 100;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 股票結構參見 Security
- 返回
message S2C
{
}
message Response
{
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
- 介面調用結果,結構參見 RetType
- Example
public class Program implements FTSPI_Qot, FTSPI_Conn {
private FTAPI_Conn_Qot qot = new FTAPI_Conn_Qot();
public Program() {
qot.setClientInfo("java", 1);
qot.setConnCallback(this);
qot.setQotCallback(this);
}
public void start() {
qot.initConnect("127.0.0.1", (short) 11111, false);
}
@Override
public void onInitConnect(FTAPI_Conn client, long errCode, String desc) {
if (errCode != 0) return;
QotCommon.Security sec = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_EventContract_VALUE)
.setCode("EC.KXODIMATCH-26JUL140600INDENG-IND").build();
QotSubEventContract.C2S c2s = QotSubEventContract.C2S.newBuilder()
.addSecurity(sec)
.addSubType(QotCommon.SubType.SubType_Ticker_VALUE)
.setIsSubOrUnSub(false)
.setIsRegOrUnRegPush(false).build();
QotSubEventContract.Request req = QotSubEventContract.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.subEventContract(req);
System.out.println("Send SubEventContract(unsub): " + seqNo);
}
@Override
public void onReply_SubEventContract(FTAPI_Conn client, int nSerialNo, QotSubEventContract.Response rsp) {
System.out.println("Reply: " + nSerialNo + " " + rsp.toString());
}
public static void main(String[] args) {
FTAPI.init();
new Program().start();
while (true) {
try { Thread.sleep(1000 * 600); } catch (InterruptedException e) {}
}
}
}
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
Futu::u32_t SubEventContract(const Qot_SubEventContract::Request &stReq);
virtual void OnReply_SubEventContract(Futu::u32_t nSerialNo, const Qot_SubEventContract::Response &stRsp) = 0;
介紹
取消訂閱事件合約的即時行情推送。複用訂閱介面,C2S 中 set_issuborunsub(false) 表示反訂閱。
參數
// 事件合約訂閱/反訂閱
message C2S
{
repeated Qot_Common.Security securityList = 1; // 合約標的(market+code),反訂閱語義與訂閱一致
repeated int32 subTypeList = 2; // Qot_Common.SubType,複用通用訂閱類型
required bool isSubOrUnSub = 3; // 取消訂閱時固定 false
optional bool isRegOrUnRegPush = 4; // 是否註冊/反註冊推送
optional bool isFirstPush = 5; // 註冊後是否首推已有數據,默認 true
optional bool isUnsubAll = 6; // true 時忽略其他參數,取消該連接所有 EC 訂閱
repeated Qot_Common.EC_KlineSource klineSource = 7; // K線來源列表(None/OrderBookYes),反訂閱 KL_* 時生效,不填忽略該維度
optional Qot_Common.QotHeader header = 100; // 行情公共參數頭
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- 股票結構參見 Security
- 訂閱類型參見 SubType
- K 線來源參見 EC_KlineSource
- 行情公共參數頭參見 QotHeader
- 返回
message S2C
{
}
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
- 介面調用結果,結構參見 RetType
- Example
class Program : public FTSPI_Qot, public FTSPI_Trd, 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) {
cout << "connect" << endl;
// 組包
Qot_SubEventContract::Request req;
Qot_SubEventContract::C2S *c2s = req.mutable_c2s();
Qot_Common::Security *sec = c2s->add_securitylist();
sec->set_code("EC.KXODIMATCH-26JUL140600INDENG-IND");
sec->set_market(Qot_Common::QotMarket::QotMarket_EventContract);
c2s->add_subtypelist(Qot_Common::SubType::SubType_Ticker);
c2s->set_isregorunregpush(false);
c2s->set_issuborunsub(false);
m_SubEventContractSerialNo = m_pQotApi->SubEventContract(req);
cout << "Request SubEventContract(unsub) SerialNo: " << m_SubEventContractSerialNo << endl;
}
virtual void OnReply_SubEventContract(Futu::u32_t nSerialNo, const Qot_SubEventContract::Response &stRsp) {
if (nSerialNo == m_SubEventContractSerialNo)
{
cout << "OnReply_SubEventContract SerialNo: " << nSerialNo << endl;
// 解析內部結構打印出來
// ProtoBufToBodyData和UTF8ToLocal函數的定義參見Sample中的tool.h文件
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_SubEventContractSerialNo;
};
int32_t main(int32_t argc, char** argv)
{
FTAPI::Init();
{
Program program;
program.Start();
getchar();
}
protobuf::ShutdownProtobufLibrary();
FTAPI::UnInit();
return 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
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
- Output
connect
Request SubEventContract(unsub) SerialNo: 1
OnReply_SubEventContract SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0
}
2
3
4
5
6
7
8
SubEventContract(req);
介紹
取消訂閱事件合約的即時行情推送。複用訂閱介面,c2s 中 isSubOrUnSub 置 false 表示反訂閱。
參數
message C2S
{
repeated Qot_Common.Security securityList = 1;
repeated int32 subTypeList = 2;
required bool isSubOrUnSub = 3;
optional bool isRegOrUnRegPush = 4;
optional bool isFirstPush = 5;
optional bool isUnsubAll = 6;
repeated Qot_Common.EC_KlineSource klineSource = 7;
optional Qot_Common.QotHeader header = 100;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 股票結構參見 Security
- 返回
message S2C
{
}
message Response
{
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
- 介面調用結果,結構參見 RetType
- Example
const ftWebsocket = require('futu-api');
let websocket = new ftWebsocket.WebsocketService();
websocket.onlogin = function() {
let req = {
proto: 'Qot_SubEventContract',
req: {
c2s: {
securityList: [{market: 101, code: 'EC.KXODIMATCH-26JUL140600INDENG-IND'}],
subTypeList: [4],
isSubOrUnSub: false,
isRegOrUnRegPush: false
}
}
};
websocket.SubEventContract(req).then(res => {
console.log(JSON.stringify(res));
});
};
websocket.connect('127.0.0.1:11111');
setTimeout(() => websocket.stop(), 60000);
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
- Python
- Proto
- C#
- Java
- C++
- JavaScript
unsubscribe_event_contract(code_list, subtype_list, kline_source_list=None)
介紹
取消訂閱事件合約的即時行情推送,支援按合約代碼、訂閱類型、K 線來源三個維度精確反訂閱。
參數
參數 類型 說明 code_list list 事件合約代碼列表,例如 ['EC.KXODIMATCH-26JUL140600INDENG-IND']subtype_list SubType 訂閱類型列表 kline_source_list ECKlineSource K 線來源列表 返回
參數 類型 說明 ret RET_CODE 介面調用結果 err_message None 當 ret == RET_OK,返回 None str 當 ret != RET_OK,返回錯誤描述 Example
from moomoo import *
import time
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# 訂閱:日 K + 逐筆
ret, err = quote_ctx.subscribe_event_contract(
['EC.KXODIMATCH-26JUL140600INDENG-IND'],
[SubType.K_DAY, SubType.TICKER]
)
if ret != RET_OK:
print('訂閱失敗:', err)
quote_ctx.close()
exit()
# 訂閱滿 1 分鐘後才能反訂閱
time.sleep(62)
# 精確取消:只取消逐筆訂閱
ret, err = quote_ctx.unsubscribe_event_contract(
['EC.KXODIMATCH-26JUL140600INDENG-IND'],
[SubType.TICKER]
)
if ret == RET_OK:
print('取消訂閱成功')
else:
print('取消訂閱失敗:', err)
quote_ctx.close()
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
- Output
取消訂閱成功
# Qot_SubEventContract.proto
介紹
取消訂閱事件合約的即時行情推送。複用訂閱介面的 proto,C2S 中 isSubOrUnSub 置 false 表示反訂閱。
參數
// 事件合約訂閱/反訂閱
message C2S
{
repeated Qot_Common.Security securityList = 1; // 合約標的(market+code),反訂閱語義與訂閱一致
repeated int32 subTypeList = 2; // Qot_Common.SubType,複用通用訂閱類型
required bool isSubOrUnSub = 3; // 取消訂閱時固定 false
optional bool isRegOrUnRegPush = 4; // 是否註冊/反註冊推送
optional bool isFirstPush = 5; // 註冊後是否首推已有數據,默認 true
optional bool isUnsubAll = 6; // true 時忽略其他參數,取消該連接所有 EC 訂閱
repeated Qot_Common.EC_KlineSource klineSource = 7; // K線來源列表(None/OrderBookYes),反訂閱 KL_* 時生效,不填忽略該維度
optional Qot_Common.QotHeader header = 100; // 行情公共參數頭
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- 股票結構參見 Security
- 訂閱類型參見 SubType
- K 線來源參見 EC_KlineSource
- 行情公共參數頭參見 QotHeader
- 返回
message S2C
{
}
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
- 介面調用結果,結構參見 RetType
uint SubEventContract(SubEventContract.Request req);
virtual void OnReply_SubEventContract(MMAPI_Conn client, uint nSerialNo, SubEventContract.Response rsp);
介紹
取消訂閱事件合約的即時行情推送。複用訂閱介面,C2S 中 SetIsSubOrUnSub(false) 表示反訂閱。
參數
message C2S
{
repeated Qot_Common.Security securityList = 1;
repeated int32 subTypeList = 2;
required bool isSubOrUnSub = 3;
optional bool isRegOrUnRegPush = 4;
optional bool isFirstPush = 5;
optional bool isUnsubAll = 6;
repeated Qot_Common.EC_KlineSource klineSource = 7;
optional Qot_Common.QotHeader header = 100;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 股票結構參見 Security
- 返回
message S2C
{
}
message Response
{
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
- 介面調用結果,結構參見 RetType
- 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)
{
if (errCode != 0) return;
QotCommon.Security sec = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_EventContract)
.SetCode("EC.KXODIMATCH-26JUL140600INDENG-IND").Build();
var c2s = SubEventContract.C2S.CreateBuilder()
.AddSecurity(sec)
.AddSubType((int)QotCommon.SubType.SubType_Ticker)
.SetIsSubOrUnSub(false)
.SetIsRegOrUnRegPush(false).Build();
var req = SubEventContract.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.SubEventContract(req);
Console.Write("Send SubEventContract(unsub): {0}\n", seqNo);
}
public void OnReply_SubEventContract(MMAPI_Conn client, uint nSerialNo, SubEventContract.Response rsp)
{
Console.Write("Reply: {0} {1}\n", nSerialNo, rsp.ToString());
}
public static void Main(String[] args)
{
MMAPI.Init();
new 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
int subEventContract(QotSubEventContract.Request req);
void onReply_SubEventContract(MMAPI_Conn client, int nSerialNo, QotSubEventContract.Response rsp);
介紹
取消訂閱事件合約的即時行情推送。複用訂閱介面,C2S 中 setIsSubOrUnSub(false) 表示反訂閱。
參數
message C2S
{
repeated Qot_Common.Security securityList = 1;
repeated int32 subTypeList = 2;
required bool isSubOrUnSub = 3;
optional bool isRegOrUnRegPush = 4;
optional bool isFirstPush = 5;
optional bool isUnsubAll = 6;
repeated Qot_Common.EC_KlineSource klineSource = 7;
optional Qot_Common.QotHeader header = 100;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 股票結構參見 Security
- 返回
message S2C
{
}
message Response
{
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
- 介面調用結果,結構參見 RetType
- Example
public class Program implements MMSPI_Qot, MMSPI_Conn {
private MMAPI_Conn_Qot qot = new MMAPI_Conn_Qot();
public Program() {
qot.setClientInfo("java", 1);
qot.setConnCallback(this);
qot.setQotCallback(this);
}
public void start() {
qot.initConnect("127.0.0.1", (short) 11111, false);
}
@Override
public void onInitConnect(MMAPI_Conn client, long errCode, String desc) {
if (errCode != 0) return;
QotCommon.Security sec = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_EventContract_VALUE)
.setCode("EC.KXODIMATCH-26JUL140600INDENG-IND").build();
QotSubEventContract.C2S c2s = QotSubEventContract.C2S.newBuilder()
.addSecurity(sec)
.addSubType(QotCommon.SubType.SubType_Ticker_VALUE)
.setIsSubOrUnSub(false)
.setIsRegOrUnRegPush(false).build();
QotSubEventContract.Request req = QotSubEventContract.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.subEventContract(req);
System.out.println("Send SubEventContract(unsub): " + seqNo);
}
@Override
public void onReply_SubEventContract(MMAPI_Conn client, int nSerialNo, QotSubEventContract.Response rsp) {
System.out.println("Reply: " + nSerialNo + " " + rsp.toString());
}
public static void main(String[] args) {
MMAPI.init();
new Program().start();
while (true) {
try { Thread.sleep(1000 * 600); } catch (InterruptedException e) {}
}
}
}
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
moomoo::u32_t SubEventContract(const Qot_SubEventContract::Request &stReq);
virtual void OnReply_SubEventContract(moomoo::u32_t nSerialNo, const Qot_SubEventContract::Response &stRsp) = 0;
介紹
取消訂閱事件合約的即時行情推送。複用訂閱介面,C2S 中 set_issuborunsub(false) 表示反訂閱。
參數
// 事件合約訂閱/反訂閱
message C2S
{
repeated Qot_Common.Security securityList = 1; // 合約標的(market+code),反訂閱語義與訂閱一致
repeated int32 subTypeList = 2; // Qot_Common.SubType,複用通用訂閱類型
required bool isSubOrUnSub = 3; // 取消訂閱時固定 false
optional bool isRegOrUnRegPush = 4; // 是否註冊/反註冊推送
optional bool isFirstPush = 5; // 註冊後是否首推已有數據,默認 true
optional bool isUnsubAll = 6; // true 時忽略其他參數,取消該連接所有 EC 訂閱
repeated Qot_Common.EC_KlineSource klineSource = 7; // K線來源列表(None/OrderBookYes),反訂閱 KL_* 時生效,不填忽略該維度
optional Qot_Common.QotHeader header = 100; // 行情公共參數頭
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- 股票結構參見 Security
- 訂閱類型參見 SubType
- K 線來源參見 EC_KlineSource
- 行情公共參數頭參見 QotHeader
- 返回
message S2C
{
}
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
- 介面調用結果,結構參見 RetType
- Example
class Program : public MMSPI_Qot, public MMSPI_Trd, 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) {
cout << "connect" << endl;
// 組包
Qot_SubEventContract::Request req;
Qot_SubEventContract::C2S *c2s = req.mutable_c2s();
Qot_Common::Security *sec = c2s->add_securitylist();
sec->set_code("EC.KXODIMATCH-26JUL140600INDENG-IND");
sec->set_market(Qot_Common::QotMarket::QotMarket_EventContract);
c2s->add_subtypelist(Qot_Common::SubType::SubType_Ticker);
c2s->set_isregorunregpush(false);
c2s->set_issuborunsub(false);
m_SubEventContractSerialNo = m_pQotApi->SubEventContract(req);
cout << "Request SubEventContract(unsub) SerialNo: " << m_SubEventContractSerialNo << endl;
}
virtual void OnReply_SubEventContract(moomoo::u32_t nSerialNo, const Qot_SubEventContract::Response &stRsp) {
if (nSerialNo == m_SubEventContractSerialNo)
{
cout << "OnReply_SubEventContract SerialNo: " << nSerialNo << endl;
// 解析內部結構打印出來
// ProtoBufToBodyData和UTF8ToLocal函數的定義參見Sample中的tool.h文件
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
protected:
MMAPI_Qot *m_pQotApi;
moomoo::u32_t m_SubEventContractSerialNo;
};
int32_t main(int32_t argc, char** argv)
{
MMAPI::Init();
{
Program program;
program.Start();
getchar();
}
protobuf::ShutdownProtobufLibrary();
MMAPI::UnInit();
return 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
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
- Output
connect
Request SubEventContract(unsub) SerialNo: 1
OnReply_SubEventContract SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0
}
2
3
4
5
6
7
8
SubEventContract(req);
介紹
取消訂閱事件合約的即時行情推送。複用訂閱介面,c2s 中 isSubOrUnSub 置 false 表示反訂閱。
參數
message C2S
{
repeated Qot_Common.Security securityList = 1;
repeated int32 subTypeList = 2;
required bool isSubOrUnSub = 3;
optional bool isRegOrUnRegPush = 4;
optional bool isFirstPush = 5;
optional bool isUnsubAll = 6;
repeated Qot_Common.EC_KlineSource klineSource = 7;
optional Qot_Common.QotHeader header = 100;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 股票結構參見 Security
- 返回
message S2C
{
}
message Response
{
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
- 介面調用結果,結構參見 RetType
- Example
const mmWebsocket = require('moomoo-api');
let websocket = new mmWebsocket.WebsocketService();
websocket.onlogin = function() {
let req = {
proto: 'Qot_SubEventContract',
req: {
c2s: {
securityList: [{market: 101, code: 'EC.KXODIMATCH-26JUL140600INDENG-IND'}],
subTypeList: [4],
isSubOrUnSub: false,
isRegOrUnRegPush: false
}
}
};
websocket.SubEventContract(req).then(res => {
console.log(JSON.stringify(res));
});
};
websocket.connect('127.0.0.1:11111');
setTimeout(() => websocket.stop(), 60000);
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
← 訂閱事件合約 取消所有事件合約訂閱 →