# Event Contract K-line Push
- Python
- Proto
- C#
- Java
- C++
- JavaScript
on_recv_rsp(self, rsp_pb)
Description
Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts. After receiving the event contract K-line data push, it will call back to this function. You need to override on_recv_rsp in the derived class.
Parameters
Parameter Type Description rsp_pb Qot_UpdateEventContractKline_pb2.Response This parameter does not need to be processed directly in the derived class. Return
Field Type Description ret RET_CODE Interface result. data pd.DataFrame If ret == RET_OK, event contract K-line data is returned. str If ret != RET_OK, error description is returned. - K-line data format as follows:
Field Type Description code str Contract code. pre_side PredSide Contract direction (YES/NO). Available for contract K-line; for event K-line, subject to the server return value. name str Contract name. time_key str K-line time. Format: yyyy-MM-dd HH:mm:ssopen float Open price. high float Highest price. low float Lowest price. close float Close price. volume float Volume.
- K-line data format as follows:
Example
import time
from futu import *
class EventContractKlineTest(EventContractKlineHandlerBase):
def on_recv_rsp(self, rsp_pb):
ret_code, data = super(EventContractKlineTest, self).on_recv_rsp(rsp_pb)
if ret_code != RET_OK:
print("EventContractKlineTest: error, msg: %s" % data)
return RET_ERROR, data
print("EventContractKlineTest ", data) # EventContractKlineTest custom logic
return RET_OK, data
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = EventContractKlineTest()
quote_ctx.set_handler(handler) # Set event contract K-line push callback
ret, data = quote_ctx.subscribe_event_contract(
code_list=['EC.KXODIMATCH-26JUL140600INDENG-IND'],
subtype_list=[SubType.K_DAY],
kline_source_list=[ECKlineSource.NONE],
subscribe_push=True) # Subscribe to K-line type, OpenD starts receiving continuous push from the server
if ret == RET_OK:
print(data)
else:
print('error:', data)
time.sleep(15) # Set the duration for receiving OpenD push to 15 seconds
quote_ctx.close() # Close the connection, OpenD will automatically unsubscribe the corresponding contract and type after 1 minute
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
- Output
EventContractKlineTest code pre_side name time_key open high low close volume
0 EC.KXODIMATCH-26JUL140600INDENG-IND YES England vs India Winner? 2026-07-13 00:00:00 0.51 0.52 0.48 0.5 7831.0
2
# Qot_UpdateEventContractKline.proto
Description
Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts.
Parameters
// Single contract K-line
message KlineItem
{
required Qot_Common.Security code = 1; // Contract code
optional Common.PredSide pre_side = 2; // Contract direction (available for contract K-line; for event K-line, subject to the server return value)
optional string name = 3; // Contract name
repeated ECKLine klineList = 4; // K-line data
}
// K-line data point
message ECKLine
{
required string time_key = 1; // K-line time (yyyy-MM-dd HH:mm:ss)
optional double open = 2; // Open price
optional double high = 3; // Highest price
optional double low = 4; // Lowest price
optional double close = 5; // Close price
optional double volume = 6; // Volume
}
message S2C
{
repeated KlineItem klineList = 1; // K-line list
}
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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
- Stock structure, see Security
- Event contract prediction direction, see PredSide
- Event contract K-line source, see EC_KlineSource
- Interface result, see RetType
Protocol ID
3451
virtual void OnPush_UpdateEventContractKline(FTAPI_Conn client, QotUpdateEventContractKline.Response rsp);
Description
Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts.
Parameters
message S2C
{
repeated KlineItem klineList = 1; // K-line list
}
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
12
- Stock structure, see Security
- Event contract prediction direction, see PredSide
- Event contract K-line source, see EC_KlineSource
- Interface 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;
// Subscribe to event contract K-line type first; after subscribing, continuous push will be received
QotCommon.Security sec = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_EventContract)
.SetCode("EC.KXODIMATCH-26JUL140600INDENG-IND").Build();
var c2s = QotSubEventContract.C2S.CreateBuilder()
.AddSecurity(sec)
.AddSubType((int)QotCommon.SubType.SubType_KLDay)
.SetIsSubOrUnSub(true)
.SetIsRegOrUnRegPush(true).Build();
var req = QotSubEventContract.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.SubEventContract(req);
Console.Write("Send SubEventContract: {0}\n", seqNo);
}
public void OnPush_UpdateEventContractKline(FTAPI_Conn client, QotUpdateEventContractKline.Response rsp)
{
Console.Write("Push: UpdateEventContractKline: {0}\n", rsp.ToString());
if (rsp.S2C != null && rsp.S2C.KlineListList.Count > 0)
{
var item = rsp.S2C.KlineListList[0];
if (item.KlineListList.Count > 0)
{
var k = item.KlineListList[0];
Console.Write("code: {0} pre_side: {1} time_key: {2} open: {3} close: {4}\n",
item.Code.Code, item.PreSide, k.TimeKey, k.Open, k.Close);
}
}
}
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
40
41
42
43
44
45
46
47
48
49
50
- Output
Send SubEventContract: 1
Push: UpdateEventContractKline: retType: 0
code: EC.KXODIMATCH-26JUL140600INDENG-IND pre_side: 1 time_key: 2026-07-13 00:00:00 open: 0.51 close: 0.5
...
2
3
4
void onPush_UpdateEventContractKline(FTAPI_Conn client, QotUpdateEventContractKline.Response rsp);
Description
Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts.
Parameters
message S2C
{
repeated KlineItem klineList = 1; // K-line list
}
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
12
- Stock structure, see Security
- Event contract prediction direction, see PredSide
- Event contract K-line source, see EC_KlineSource
- Interface 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;
// Subscribe to event contract K-line type first; after subscribing, continuous push will be received
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_KLDay_VALUE)
.setIsSubOrUnSub(true)
.setIsRegOrUnRegPush(true).build();
QotSubEventContract.Request req = QotSubEventContract.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.subEventContract(req);
System.out.println("Send SubEventContract: " + seqNo);
}
@Override
public void onPush_UpdateEventContractKline(FTAPI_Conn client, QotUpdateEventContractKline.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotUpdateEventContractKline failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotUpdateEventContractKline: %s\n", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
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
45
46
47
48
49
50
51
52
53
54
55
- Output
Receive QotUpdateEventContractKline: {
"retType": 0,
"s2c": {
"klineList": [
{
"code": {"market": 101, "code": "EC.KXODIMATCH-26JUL140600INDENG-IND"},
"pre_side": 1,
"name": "England vs India Winner?",
"klineList": [
{
"time_key": "2026-07-13 00:00:00",
"open": 0.51,
"high": 0.52,
"low": 0.48,
"close": 0.5,
"volume": 7831.0
}
]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
virtual void OnPush_UpdateEventContractKline(const Qot_UpdateEventContractKline::Response &stRsp) = 0;
Description
Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts.
Parameters
// Single contract K-line
message KlineItem
{
required Qot_Common.Security code = 1; // Contract code
optional Common.PredSide pre_side = 2; // Contract direction (available for contract K-line; for event K-line, subject to the server return value)
optional string name = 3; // Contract name
repeated ECKLine klineList = 4; // K-line data
}
// K-line data point
message ECKLine
{
required string time_key = 1; // K-line time (yyyy-MM-dd HH:mm:ss)
optional double open = 2; // Open price
optional double high = 3; // Highest price
optional double low = 4; // Lowest price
optional double close = 5; // Close price
optional double volume = 6; // Volume
}
message S2C
{
repeated KlineItem klineList = 1; // K-line list
}
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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
- Stock structure, see Security
- Event contract prediction direction, see PredSide
- Event contract K-line source, see EC_KlineSource
- Interface 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;
// Subscribe to event contract K-line type first; after subscribing, continuous push will be received
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_KLDay);
c2s->add_klinesource(Qot_Common::EC_KlineSource::EC_KlineSource_OrderBookYes);
c2s->set_isregorunregpush(true);
c2s->set_issuborunsub(true);
m_SubEventContractSerialNo = m_pQotApi->SubEventContract(req);
cout << "Request SubEventContract 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;
}
}
virtual void OnPush_UpdateEventContractKline(const Qot_UpdateEventContractKline::Response &stRsp) {
cout << "OnPush_UpdateEventContractKline" << endl;
// Parse internal 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
74
75
76
77
78
- Output
connect
Request SubEventContract SerialNo: 1
OnReply_SubEventContract SerialNo: 1
OnPush_UpdateEventContractKline
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"klineList": [
{
"code": {"market": 101, "code": "EC.KXODIMATCH-26JUL140600INDENG-IND"},
"pre_side": 1,
"name": "England vs India Winner?",
"klineList": [
{
"time_key": "2026-07-13 00:00:00",
"open": 0.51,
"high": 0.52,
"low": 0.48,
"close": 0.5,
"volume": 7831.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
onPush(cmd, res)
Description
Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts.
Parameters
message S2C
{
repeated KlineItem klineList = 1; // K-line list
}
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
12
- Stock structure, see Security
- Event contract prediction direction, see PredSide
- Event contract K-line source, see EC_KlineSource
- Interface result, see RetType
- Example
import ftWebsocket from "futu-api";
import { ftCmdID } from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
function QotUpdateEventContractKline(){
const { RetType } = Common
const { SubType, QotMarket } = Qot_Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new ftWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) { // login success
const req = {
c2s: {
securityList: [
{
market: QotMarket.QotMarket_EventContract,
code: "EC.KXODIMATCH-26JUL140600INDENG-IND",
},
],
subTypeList: [ SubType.SubType_KLDay ], // Subscribe to K-line type
isSubOrUnSub: true, // subscribe true, unsubscribe false
isRegOrUnRegPush: true, // register push true, unregister push false
},
};
websocket.SubEventContract(req) // subscribe, OpenD starts receiving continuous push from the server
.then((res) => { })
.catch((error) => {
if ("retMsg" in error) {
console.log("error:", error.retMsg);
}
});
} else {
console.log("error", msg);
}
};
websocket.onPush = (cmd, res)=>{
if(ftCmdID.QotUpdateEventContractKline.cmd == cmd){ // event contract K-line push logic
let { retType, s2c } = res
if(retType == RetType.RetType_Succeed){
console.log("EventContractKlineTest", JSON.stringify(s2c));
} else {
console.log("EventContractKlineTest: error")
}
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // receive OpenD push for 5 seconds, disconnect after 5 seconds
}
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
- Output
EventContractKlineTest {"klineList":[{"code":{"market":101,"code":"EC.KXODIMATCH-26JUL140600INDENG-IND"},"pre_side":1,"name":"England vs India Winner?","klineList":[{"time_key":"2026-07-13 00:00:00","open":0.51,"high":0.52,"low":0.48,"close":0.5,"volume":7831.0}]}]}
stop
2
- Python
- Proto
- C#
- Java
- C++
- JavaScript
on_recv_rsp(self, rsp_pb)
Description
Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts. After receiving the event contract K-line data push, it will call back to this function. You need to override on_recv_rsp in the derived class.
Parameters
Parameter Type Description rsp_pb Qot_UpdateEventContractKline_pb2.Response This parameter does not need to be processed directly in the derived class. Return
Field Type Description ret RET_CODE Interface result. data pd.DataFrame If ret == RET_OK, event contract K-line data is returned. str If ret != RET_OK, error description is returned. - K-line data format as follows:
Field Type Description code str Contract code. pre_side PredSide Contract direction (YES/NO). Available for contract K-line; for event K-line, subject to the server return value. name str Contract name. time_key str K-line time. Format: yyyy-MM-dd HH:mm:ssopen float Open price. high float Highest price. low float Lowest price. close float Close price. volume float Volume.
- K-line data format as follows:
Example
import time
from moomoo import *
class EventContractKlineTest(EventContractKlineHandlerBase):
def on_recv_rsp(self, rsp_pb):
ret_code, data = super(EventContractKlineTest, self).on_recv_rsp(rsp_pb)
if ret_code != RET_OK:
print("EventContractKlineTest: error, msg: %s" % data)
return RET_ERROR, data
print("EventContractKlineTest ", data) # EventContractKlineTest custom logic
return RET_OK, data
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = EventContractKlineTest()
quote_ctx.set_handler(handler) # Set event contract K-line push callback
ret, data = quote_ctx.subscribe_event_contract(
code_list=['EC.KXODIMATCH-26JUL140600INDENG-IND'],
subtype_list=[SubType.K_DAY],
kline_source_list=[ECKlineSource.NONE],
subscribe_push=True) # Subscribe to K-line type, OpenD starts receiving continuous push from the server
if ret == RET_OK:
print(data)
else:
print('error:', data)
time.sleep(15) # Set the duration for receiving OpenD push to 15 seconds
quote_ctx.close() # Close the connection, OpenD will automatically unsubscribe the corresponding contract and type after 1 minute
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
- Output
EventContractKlineTest code pre_side name time_key open high low close volume
0 EC.KXODIMATCH-26JUL140600INDENG-IND YES England vs India Winner? 2026-07-13 00:00:00 0.51 0.52 0.48 0.5 7831.0
2
# Qot_UpdateEventContractKline.proto
Description
Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts.
Parameters
// Single contract K-line
message KlineItem
{
required Qot_Common.Security code = 1; // Contract code
optional Common.PredSide pre_side = 2; // Contract direction (available for contract K-line; for event K-line, subject to the server return value)
optional string name = 3; // Contract name
repeated ECKLine klineList = 4; // K-line data
}
// K-line data point
message ECKLine
{
required string time_key = 1; // K-line time (yyyy-MM-dd HH:mm:ss)
optional double open = 2; // Open price
optional double high = 3; // Highest price
optional double low = 4; // Lowest price
optional double close = 5; // Close price
optional double volume = 6; // Volume
}
message S2C
{
repeated KlineItem klineList = 1; // K-line list
}
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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
- Stock structure, see Security
- Event contract prediction direction, see PredSide
- Event contract K-line source, see EC_KlineSource
- Interface result, see RetType
Protocol ID
3451
virtual void OnPush_UpdateEventContractKline(MMAPI_Conn client, QotUpdateEventContractKline.Response rsp);
Description
Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts.
Parameters
message S2C
{
repeated KlineItem klineList = 1; // K-line list
}
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
12
- Stock structure, see Security
- Event contract prediction direction, see PredSide
- Event contract K-line source, see EC_KlineSource
- Interface 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;
// Subscribe to event contract K-line type first; after subscribing, continuous push will be received
QotCommon.Security sec = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_EventContract)
.SetCode("EC.KXODIMATCH-26JUL140600INDENG-IND").Build();
var c2s = QotSubEventContract.C2S.CreateBuilder()
.AddSecurity(sec)
.AddSubType((int)QotCommon.SubType.SubType_KLDay)
.SetIsSubOrUnSub(true)
.SetIsRegOrUnRegPush(true).Build();
var req = QotSubEventContract.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.SubEventContract(req);
Console.Write("Send SubEventContract: {0}\n", seqNo);
}
public void OnPush_UpdateEventContractKline(MMAPI_Conn client, QotUpdateEventContractKline.Response rsp)
{
Console.Write("Push: UpdateEventContractKline: {0}\n", rsp.ToString());
if (rsp.S2C != null && rsp.S2C.KlineListList.Count > 0)
{
var item = rsp.S2C.KlineListList[0];
if (item.KlineListList.Count > 0)
{
var k = item.KlineListList[0];
Console.Write("code: {0} pre_side: {1} time_key: {2} open: {3} close: {4}\n",
item.Code.Code, item.PreSide, k.TimeKey, k.Open, k.Close);
}
}
}
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
40
41
42
43
44
45
46
47
48
49
50
- Output
Send SubEventContract: 1
Push: UpdateEventContractKline: retType: 0
code: EC.KXODIMATCH-26JUL140600INDENG-IND pre_side: 1 time_key: 2026-07-13 00:00:00 open: 0.51 close: 0.5
...
2
3
4
void onPush_UpdateEventContractKline(MMAPI_Conn client, QotUpdateEventContractKline.Response rsp);
Description
Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts.
Parameters
message S2C
{
repeated KlineItem klineList = 1; // K-line list
}
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
12
- Stock structure, see Security
- Event contract prediction direction, see PredSide
- Event contract K-line source, see EC_KlineSource
- Interface 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;
// Subscribe to event contract K-line type first; after subscribing, continuous push will be received
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_KLDay_VALUE)
.setIsSubOrUnSub(true)
.setIsRegOrUnRegPush(true).build();
QotSubEventContract.Request req = QotSubEventContract.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.subEventContract(req);
System.out.println("Send SubEventContract: " + seqNo);
}
@Override
public void onPush_UpdateEventContractKline(MMAPI_Conn client, QotUpdateEventContractKline.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotUpdateEventContractKline failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotUpdateEventContractKline: %s\n", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
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
45
46
47
48
49
50
51
52
53
54
55
- Output
Receive QotUpdateEventContractKline: {
"retType": 0,
"s2c": {
"klineList": [
{
"code": {"market": 101, "code": "EC.KXODIMATCH-26JUL140600INDENG-IND"},
"pre_side": 1,
"name": "England vs India Winner?",
"klineList": [
{
"time_key": "2026-07-13 00:00:00",
"open": 0.51,
"high": 0.52,
"low": 0.48,
"close": 0.5,
"volume": 7831.0
}
]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
virtual void OnPush_UpdateEventContractKline(const Qot_UpdateEventContractKline::Response &stRsp) = 0;
Description
Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts.
Parameters
// Single contract K-line
message KlineItem
{
required Qot_Common.Security code = 1; // Contract code
optional Common.PredSide pre_side = 2; // Contract direction (available for contract K-line; for event K-line, subject to the server return value)
optional string name = 3; // Contract name
repeated ECKLine klineList = 4; // K-line data
}
// K-line data point
message ECKLine
{
required string time_key = 1; // K-line time (yyyy-MM-dd HH:mm:ss)
optional double open = 2; // Open price
optional double high = 3; // Highest price
optional double low = 4; // Lowest price
optional double close = 5; // Close price
optional double volume = 6; // Volume
}
message S2C
{
repeated KlineItem klineList = 1; // K-line list
}
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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
- Stock structure, see Security
- Event contract prediction direction, see PredSide
- Event contract K-line source, see EC_KlineSource
- Interface 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;
// Subscribe to event contract K-line type first; after subscribing, continuous push will be received
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_KLDay);
c2s->add_klinesource(Qot_Common::EC_KlineSource::EC_KlineSource_OrderBookYes);
c2s->set_isregorunregpush(true);
c2s->set_issuborunsub(true);
m_SubEventContractSerialNo = m_pQotApi->SubEventContract(req);
cout << "Request SubEventContract 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;
}
}
virtual void OnPush_UpdateEventContractKline(const Qot_UpdateEventContractKline::Response &stRsp) {
cout << "OnPush_UpdateEventContractKline" << endl;
// Parse internal 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
74
75
76
77
78
- Output
connect
Request SubEventContract SerialNo: 1
OnReply_SubEventContract SerialNo: 1
OnPush_UpdateEventContractKline
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"klineList": [
{
"code": {"market": 101, "code": "EC.KXODIMATCH-26JUL140600INDENG-IND"},
"pre_side": 1,
"name": "England vs India Winner?",
"klineList": [
{
"time_key": "2026-07-13 00:00:00",
"open": 0.51,
"high": 0.52,
"low": 0.48,
"close": 0.5,
"volume": 7831.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
onPush(cmd, res)
Description
Event contract K-line push callback, asynchronously processing the real-time K-line push of subscribed event contracts.
Parameters
message S2C
{
repeated KlineItem klineList = 1; // K-line list
}
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
12
- Stock structure, see Security
- Event contract prediction direction, see PredSide
- Event contract K-line source, see EC_KlineSource
- Interface result, see RetType
- Example
import mmWebsocket from "moomoo-api";
import { mmCmdID } from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
function QotUpdateEventContractKline(){
const { RetType } = Common
const { SubType, QotMarket } = Qot_Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new mmWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) { // login success
const req = {
c2s: {
securityList: [
{
market: QotMarket.QotMarket_EventContract,
code: "EC.KXODIMATCH-26JUL140600INDENG-IND",
},
],
subTypeList: [ SubType.SubType_KLDay ], // Subscribe to K-line type
isSubOrUnSub: true, // subscribe true, unsubscribe false
isRegOrUnRegPush: true, // register push true, unregister push false
},
};
websocket.SubEventContract(req) // subscribe, OpenD starts receiving continuous push from the server
.then((res) => { })
.catch((error) => {
if ("retMsg" in error) {
console.log("error:", error.retMsg);
}
});
} else {
console.log("error", msg);
}
};
websocket.onPush = (cmd, res)=>{
if(mmCmdID.QotUpdateEventContractKline.cmd == cmd){ // event contract K-line push logic
let { retType, s2c } = res
if(retType == RetType.RetType_Succeed){
console.log("EventContractKlineTest", JSON.stringify(s2c));
} else {
console.log("EventContractKlineTest: error")
}
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // receive OpenD push for 5 seconds, disconnect after 5 seconds
}
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
- Output
EventContractKlineTest {"klineList":[{"code":{"market":101,"code":"EC.KXODIMATCH-26JUL140600INDENG-IND"},"pre_side":1,"name":"England vs India Winner?","klineList":[{"time_key":"2026-07-13 00:00:00","open":0.51,"high":0.52,"low":0.48,"close":0.5,"volume":7831.0}]}]}
stop
2