# Unsubscribe Event Contract
- Python
- Proto
- C#
- Java
- C++
- JavaScript
unsubscribe_event_contract(code_list, subtype_list, kline_source_list=None)
Description
Unsubscribe from real-time event contract market data pushes. Supports precise unsubscription by contract code, subscription type, and K-line source.
Parameters
Parameter Type Description code_list list Event contract code list, e.g. ['EC.KXODIMATCH-26JUL140600INDENG-IND']subtype_list SubType Subscription type list kline_source_list ECKlineSource K-line source list Return
Parameter Type Description ret RET_CODE Interface call result err_message None When ret == RET_OK, returns None str When ret != RET_OK, returns the error description Example
from futu import *
import time
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# Subscribe: Day K + Ticker
ret, err = quote_ctx.subscribe_event_contract(
['EC.KXODIMATCH-26JUL140600INDENG-IND'],
[SubType.K_DAY, SubType.TICKER]
)
if ret != RET_OK:
print('Subscribe failed:', err)
quote_ctx.close()
exit()
# You can only unsubscribe at least 1 minute after subscribing
time.sleep(62)
# Precisely unsubscribe: unsubscribe only ticker
ret, err = quote_ctx.unsubscribe_event_contract(
['EC.KXODIMATCH-26JUL140600INDENG-IND'],
[SubType.TICKER]
)
if ret == RET_OK:
print('Unsubscribe succeeded')
else:
print('Unsubscribe failed:', 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
Unsubscribe succeeded
# Qot_SubEventContract.proto
Description
Unsubscribe from real-time event contract market data pushes. Reuses the subscription proto; set isSubOrUnSub to false in C2S to unsubscribe.
Parameters
// Event contract subscribe/unsubscribe
message C2S
{
repeated Qot_Common.Security securityList = 1; // contract underlying (market+code), unsubscribe semantics match subscribe
repeated int32 subTypeList = 2; // Qot_Common.SubType, reuses common subscription types
required bool isSubOrUnSub = 3; // fixed false when unsubscribing
optional bool isRegOrUnRegPush = 4; // whether to register/unregister push
optional bool isFirstPush = 5; // whether to push existing data first after registration, default true
optional bool isUnsubAll = 6; // when true, ignores other params and unsubscribes all EC subscriptions on the connection
repeated Qot_Common.EC_KlineSource klineSource = 7; // K-line source list (None/OrderBookYes), effective when unsubscribing KL_*; omitted to ignore this dimension
optional Qot_Common.QotHeader header = 100; // quote common header
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- Security structure see Security
- Subscription type see SubType
- K-line source see EC_KlineSource
- Quote common header see QotHeader
- Return
message S2C
{
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, return result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
- Interface call result, see RetType
uint SubEventContract(SubEventContract.Request req);
virtual void OnReply_SubEventContract(FTAPI_Conn client, uint nSerialNo, SubEventContract.Response rsp);
Description
Unsubscribe from real-time event contract market data pushes. Reuses the subscription interface; SetIsSubOrUnSub(false) in C2S means unsubscribe.
Parameters
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 structure see Security
- Return
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
- Interface call result, see 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);
Description
Unsubscribe from real-time event contract market data pushes. Reuses the subscription interface; setIsSubOrUnSub(false) in C2S means unsubscribe.
Parameters
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 structure see Security
- Return
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
- Interface call result, see 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;
Description
Unsubscribe from real-time event contract market data pushes. Reuses the subscription interface; set_issuborunsub(false) in C2S means unsubscribe.
Parameters
// Event contract subscribe/unsubscribe
message C2S
{
repeated Qot_Common.Security securityList = 1; // contract underlying (market+code), unsubscribe semantics match subscribe
repeated int32 subTypeList = 2; // Qot_Common.SubType, reuses common subscription types
required bool isSubOrUnSub = 3; // fixed false when unsubscribing
optional bool isRegOrUnRegPush = 4; // whether to register/unregister push
optional bool isFirstPush = 5; // whether to push existing data first after registration, default true
optional bool isUnsubAll = 6; // when true, ignores other params and unsubscribes all EC subscriptions on the connection
repeated Qot_Common.EC_KlineSource klineSource = 7; // K-line source list (None/OrderBookYes), effective when unsubscribing KL_*; omitted to ignore this dimension
optional Qot_Common.QotHeader header = 100; // quote common header
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- Security structure see Security
- Subscription type see SubType
- K-line source see EC_KlineSource
- Quote common header see QotHeader
- Return
message S2C
{
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, return result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
- Interface call result, see 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;
// build request
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;
// parse inner structure and print
// definitions of ProtoBufToBodyData and UTF8ToLocal see tool.h in Sample
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);
Description
Unsubscribe from real-time event contract market data pushes. Reuses the subscription interface; set isSubOrUnSub to false in c2s to unsubscribe.
Parameters
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 structure see Security
- Return
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
- Interface call result, see 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)
Description
Unsubscribe from real-time event contract market data pushes. Supports precise unsubscription by contract code, subscription type, and K-line source.
Parameters
Parameter Type Description code_list list Event contract code list, e.g. ['EC.KXODIMATCH-26JUL140600INDENG-IND']subtype_list SubType Subscription type list kline_source_list ECKlineSource K-line source list Return
Parameter Type Description ret RET_CODE Interface call result err_message None When ret == RET_OK, returns None str When ret != RET_OK, returns the error description Example
from moomoo import *
import time
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# Subscribe: Day K + Ticker
ret, err = quote_ctx.subscribe_event_contract(
['EC.KXODIMATCH-26JUL140600INDENG-IND'],
[SubType.K_DAY, SubType.TICKER]
)
if ret != RET_OK:
print('Subscribe failed:', err)
quote_ctx.close()
exit()
# You can only unsubscribe at least 1 minute after subscribing
time.sleep(62)
# Precisely unsubscribe: unsubscribe only ticker
ret, err = quote_ctx.unsubscribe_event_contract(
['EC.KXODIMATCH-26JUL140600INDENG-IND'],
[SubType.TICKER]
)
if ret == RET_OK:
print('Unsubscribe succeeded')
else:
print('Unsubscribe failed:', 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
Unsubscribe succeeded
# Qot_SubEventContract.proto
Description
Unsubscribe from real-time event contract market data pushes. Reuses the subscription proto; set isSubOrUnSub to false in C2S to unsubscribe.
Parameters
// Event contract subscribe/unsubscribe
message C2S
{
repeated Qot_Common.Security securityList = 1; // contract underlying (market+code), unsubscribe semantics match subscribe
repeated int32 subTypeList = 2; // Qot_Common.SubType, reuses common subscription types
required bool isSubOrUnSub = 3; // fixed false when unsubscribing
optional bool isRegOrUnRegPush = 4; // whether to register/unregister push
optional bool isFirstPush = 5; // whether to push existing data first after registration, default true
optional bool isUnsubAll = 6; // when true, ignores other params and unsubscribes all EC subscriptions on the connection
repeated Qot_Common.EC_KlineSource klineSource = 7; // K-line source list (None/OrderBookYes), effective when unsubscribing KL_*; omitted to ignore this dimension
optional Qot_Common.QotHeader header = 100; // quote common header
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- Security structure see Security
- Subscription type see SubType
- K-line source see EC_KlineSource
- Quote common header see QotHeader
- Return
message S2C
{
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, return result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
- Interface call result, see RetType
uint SubEventContract(SubEventContract.Request req);
virtual void OnReply_SubEventContract(MMAPI_Conn client, uint nSerialNo, SubEventContract.Response rsp);
Description
Unsubscribe from real-time event contract market data pushes. Reuses the subscription interface; SetIsSubOrUnSub(false) in C2S means unsubscribe.
Parameters
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 structure see Security
- Return
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
- Interface call result, see 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);
Description
Unsubscribe from real-time event contract market data pushes. Reuses the subscription interface; setIsSubOrUnSub(false) in C2S means unsubscribe.
Parameters
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 structure see Security
- Return
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
- Interface call result, see 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;
Description
Unsubscribe from real-time event contract market data pushes. Reuses the subscription interface; set_issuborunsub(false) in C2S means unsubscribe.
Parameters
// Event contract subscribe/unsubscribe
message C2S
{
repeated Qot_Common.Security securityList = 1; // contract underlying (market+code), unsubscribe semantics match subscribe
repeated int32 subTypeList = 2; // Qot_Common.SubType, reuses common subscription types
required bool isSubOrUnSub = 3; // fixed false when unsubscribing
optional bool isRegOrUnRegPush = 4; // whether to register/unregister push
optional bool isFirstPush = 5; // whether to push existing data first after registration, default true
optional bool isUnsubAll = 6; // when true, ignores other params and unsubscribes all EC subscriptions on the connection
repeated Qot_Common.EC_KlineSource klineSource = 7; // K-line source list (None/OrderBookYes), effective when unsubscribing KL_*; omitted to ignore this dimension
optional Qot_Common.QotHeader header = 100; // quote common header
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- Security structure see Security
- Subscription type see SubType
- K-line source see EC_KlineSource
- Quote common header see QotHeader
- Return
message S2C
{
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType, return result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
- Interface call result, see 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;
// build request
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;
// parse inner structure and print
// definitions of ProtoBufToBodyData and UTF8ToLocal see tool.h in Sample
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);
Description
Unsubscribe from real-time event contract market data pushes. Reuses the subscription interface; set isSubOrUnSub to false in c2s to unsubscribe.
Parameters
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 structure see Security
- Return
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
- Interface call result, see 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