# Request Historical K-line of Event Contract
- Python
- Proto
- C#
- Java
- C++
- JavaScript
request_history_event_contract_kline(code, start=None, end=None, pre_side=None, ktype=KLType.K_DAY, kline_source=None, max_count=1000, page_req_key=None)
Description
Pull the historical K-line of an event contract without downloading historical data first. Supports querying by time range, direction and K-line source, and handles pagination automatically (loops to pull when
max_countexceeds the single-package limit).Parameters
Parameter Type Description code str Required. Event contract code, e.g. 'EC.KXNFLAFCCHAMP-27-CIN'start str Optional. Start time, e.g. '2026-07-05'end str Optional. End time, e.g. '2026-07-09'pre_side PredSide Optional. Contract direction ktype KLType Optional. K-line type, only K_1M/K_5M/K_60M/K_DAYsupported, defaultK_DAYkline_source ECKlineSource Optional. K-line source max_count int Optional. Max number of data points returned in this request, Nonemeans all within the rangepage_req_key str Optional. Pagination key, pass Nonefor the first request and the previous return value for subsequent requestsReturn
Parameter Type Description ret RET_CODE API call result data pd.DataFrame When ret == RET_OK, returns the historical K-line data str When ret != RET_OK, returns the error description page_req_key str Pagination key, None when there is no more data The DataFrame fields are as follows:
Field Type Description code str Contract code pre_side str Contract direction (YES/NO/N/A) name str Contract name time_key str K-line time open float Open price high float High price low float Low price close float Close price volume float Volume Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# Subscribe the corresponding K-line type before pulling the historical K-line
ret, err = quote_ctx.subscribe_event_contract(
['EC.KXNFLAFCCHAMP-27-CIN'], [SubType.K_DAY]
)
if ret != RET_OK:
print('subscribe failed:', err)
else:
ret, data, page_req_key = quote_ctx.request_history_event_contract_kline(
'EC.KXNFLAFCCHAMP-27-CIN',
start='2026-07-05', end='2026-07-09',
pre_side=PredSide.YES, ktype=KLType.K_DAY, max_count=10
)
if ret == RET_OK:
print(data)
print('page_req_key:', page_req_key)
else:
print('error:', data)
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
- Output
code pre_side name time_key open high low close volume
0 EC.KXNFLAFCCHAMP-27-CIN YES Will Cincinnati win the Pro Football AFC Championship? 2026-07-05 00:00:00 0.92 0.92 0.92 0.92 201.0
1 EC.KXNFLAFCCHAMP-27-CIN YES Will Cincinnati win the Pro Football AFC Championship? 2026-07-06 00:00:00 0.93 0.93 0.92 0.92 659.0
2 EC.KXNFLAFCCHAMP-27-CIN YES Will Cincinnati win the Pro Football AFC Championship? 2026-07-07 00:00:00 0.93 0.93 0.92 0.92 490.0
3 EC.KXNFLAFCCHAMP-27-CIN YES Will Cincinnati win the Pro Football AFC Championship? 2026-07-08 00:00:00 0.93 0.93 0.92 0.92 669.0
4 EC.KXNFLAFCCHAMP-27-CIN YES Will Cincinnati win the Pro Football AFC Championship? 2026-07-09 00:00:00 0.92 0.92 0.92 0.92 343.0
page_req_key: None
2
3
4
5
6
7
# Qot_RequestHistoryEventContractKL.proto
Description
Pull the historical K-line of an event contract.
Parameters
// Pull historical K-line of event contract
// Difference from the generic Qot_RequestHistoryKL: input adds klineSource/preSide direction fields, response structure is ECKLine(6 fields) + KlineItem.pre_side
// KLType only supports 1Min/5Min/60Min/Day
message C2S
{
required Qot_Common.Security security = 1; // Contract underlying (contract_id or sub_contract_id)
optional Qot_Common.EC_KlineSource klineSource = 2; // K-line source (None/OrderBookYes); default None (contract-level K-line), priority higher than preSide, aligned with real-time EC
optional Common.PredSide preSide = 3; // Direction (Yes/No); effective when klineSource=None and the input is a contract-level underlying, default Yes
required Qot_Common.KLType klType = 4; // Generic K-line type, EC only supports 1Min/5Min/60Min/Day
required string beginTime = 5; // Start time string
required string endTime = 6; // End time string
optional int32 maxAckKLNum = 7; // Max number of K-lines returned, unlimited if not specified
optional bytes nextReqKey = 8; // Pagination request key
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- For the stock structure, see Security
- For the event contract prediction direction, see PredSide
- For the K-line source, see ECKlineSource
- For the K-line type, see KLType
- Return
message S2C
{
repeated Qot_GetEventContractKline.KlineItem klineList = 1; // K-line list (reuses shared KlineItem, contains ECKLine data point and pre_side)
optional bytes nextReqKey = 2; // Pagination request key. When one request does not return all data, pass this key in the next request to continue
}
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
- For the API call result structure, see RetType
Protocol ID
3456
Data Type
- For the stock structure, see Security
- For the event contract prediction direction, see PredSide
- For the K-line source, see ECKlineSource
- For the K-line type, see KLType
uint RequestHistoryEventContractKL(Qot_RequestHistoryEventContractKL.Request req);
virtual void OnReply_RequestHistoryEventContractKL(FTAPI_Conn client, uint nSerialNo, Qot_RequestHistoryEventContractKL.Response rsp);
Description
Pull the historical K-line of an event contract.
Parameters
message C2S
{
required Qot_Common.Security security = 1;
optional Qot_Common.EC_KlineSource klineSource = 2;
optional Common.PredSide preSide = 3;
required Qot_Common.KLType klType = 4;
required string beginTime = 5;
required string endTime = 6;
optional int32 maxAckKLNum = 7;
optional bytes nextReqKey = 8;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- For the stock structure, see Security
- Return
message S2C
{
repeated Qot_GetEventContractKline.KlineItem klineList = 1;
optional bytes nextReqKey = 2;
}
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
12
13
- For the API call result structure, 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.KXNFLAFCCHAMP-27-CIN").Build();
var c2s = Qot_RequestHistoryEventContractKL.C2S.CreateBuilder()
.SetSecurity(sec)
.SetPreSide(Common.PredSide.PredSide_Yes)
.SetKlType((int)QotCommon.KLType.KLType_Day)
.SetBeginTime("2026-07-05")
.SetEndTime("2026-07-09")
.SetMaxAckKLNum(10).Build();
var req = Qot_RequestHistoryEventContractKL.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.RequestHistoryEventContractKL(req);
Console.Write("Send RequestHistoryEventContractKL: {0}\n", seqNo);
}
public void OnReply_RequestHistoryEventContractKL(FTAPI_Conn client, uint nSerialNo, Qot_RequestHistoryEventContractKL.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
40
41
int requestHistoryEventContractKL(QotRequestHistoryEventContractKL.Request req);
void onReply_RequestHistoryEventContractKL(FTAPI_Conn client, int nSerialNo, QotRequestHistoryEventContractKL.Response rsp);
Description
Pull the historical K-line of an event contract.
Parameters
message C2S
{
required Qot_Common.Security security = 1;
optional Qot_Common.EC_KlineSource klineSource = 2;
optional Common.PredSide preSide = 3;
required Qot_Common.KLType klType = 4;
required string beginTime = 5;
required string endTime = 6;
optional int32 maxAckKLNum = 7;
optional bytes nextReqKey = 8;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- For the stock structure, see Security
- Return
message S2C
{
repeated Qot_GetEventContractKline.KlineItem klineList = 1;
optional bytes nextReqKey = 2;
}
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
12
13
- For the API call result structure, 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.KXNFLAFCCHAMP-27-CIN").build();
QotRequestHistoryEventContractKL.C2S c2s = QotRequestHistoryEventContractKL.C2S.newBuilder()
.setSecurity(sec)
.setPreSide(Common.PredSide.PredSide_Yes)
.setKlType(QotCommon.KLType.KLType_Day_VALUE)
.setBeginTime("2026-07-05")
.setEndTime("2026-07-09")
.setMaxAckKLNum(10).build();
QotRequestHistoryEventContractKL.Request req = QotRequestHistoryEventContractKL.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.requestHistoryEventContractKL(req);
System.out.println("Send RequestHistoryEventContractKL: " + seqNo);
}
@Override
public void onReply_RequestHistoryEventContractKL(FTAPI_Conn client, int nSerialNo, QotRequestHistoryEventContractKL.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
45
46
Futu::u32_t RequestHistoryEventContractKL(const Qot_RequestHistoryEventContractKL::Request &stReq);
virtual void OnReply_RequestHistoryEventContractKL(Futu::u32_t nSerialNo, const Qot_RequestHistoryEventContractKL::Response &stRsp) = 0;
Description
Pull the historical K-line of an event contract.
Parameters
// Pull historical K-line of event contract
// Difference from the generic Qot_RequestHistoryKL: input adds klineSource/preSide direction fields, response structure is ECKLine(6 fields) + KlineItem.pre_side
// KLType only supports 1Min/5Min/60Min/Day
message C2S
{
required Qot_Common.Security security = 1; // Contract underlying (contract_id or sub_contract_id)
optional Qot_Common.EC_KlineSource klineSource = 2; // K-line source (None/OrderBookYes); default None (contract-level K-line), priority higher than preSide, aligned with real-time EC
optional Common.PredSide preSide = 3; // Direction (Yes/No); effective when klineSource=None and the input is a contract-level underlying, default Yes
required Qot_Common.KLType klType = 4; // Generic K-line type, EC only supports 1Min/5Min/60Min/Day
required string beginTime = 5; // Start time string
required string endTime = 6; // End time string
optional int32 maxAckKLNum = 7; // Max number of K-lines returned, unlimited if not specified
optional bytes nextReqKey = 8; // Pagination request key
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- For the stock structure, see Security
- For the event contract prediction direction, see PredSide
- For the K-line source, see ECKlineSource
- For the K-line type, see KLType
- Return
message S2C
{
repeated Qot_GetEventContractKline.KlineItem klineList = 1; // K-line list (reuses shared KlineItem, contains ECKLine data point and pre_side)
optional bytes nextReqKey = 2; // Pagination request key. When one request does not return all data, pass this key in the next request to continue
}
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
- For the API call result structure, 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 the packet
Qot_RequestHistoryEventContractKL::Request req;
Qot_RequestHistoryEventContractKL::C2S *c2s = req.mutable_c2s();
Qot_Common::Security *sec = c2s->mutable_security();
sec->set_code("EC.KXNFLAFCCHAMP-27-CIN");
sec->set_market(Qot_Common::QotMarket::QotMarket_EventContract);
c2s->set_preside(Common::PredSide::PredSide_Yes);
c2s->set_kltype(Qot_Common::KLType::KLType_Day);
c2s->set_begintime("2026-07-05");
c2s->set_endtime("2026-07-09");
c2s->set_maxackklnum(10);
m_RequestHistoryEventContractKLSerialNo = m_pQotApi->RequestHistoryEventContractKL(req);
cout << "Request RequestHistoryEventContractKL SerialNo: " << m_RequestHistoryEventContractKLSerialNo << endl;
}
virtual void OnReply_RequestHistoryEventContractKL(Futu::u32_t nSerialNo, const Qot_RequestHistoryEventContractKL::Response &stRsp) {
if (nSerialNo == m_RequestHistoryEventContractKLSerialNo)
{
cout << "OnReply_RequestHistoryEventContractKL SerialNo: " << nSerialNo << endl;
// Parse the internal structure and print
// The definitions of ProtoBufToBodyData and UTF8ToLocal are in the tool.h file in the Sample
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_RequestHistoryEventContractKLSerialNo;
};
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
- Output
connect
Request RequestHistoryEventContractKL SerialNo: 1
OnReply_RequestHistoryEventContractKL SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"klineList": [
{
"code": {"market": 101, "code": "EC.KXNFLAFCCHAMP-27-CIN"},
"pre_side": 1,
"name": "Will Cincinnati win the Pro Football AFC Championship?",
"klineList": [
{
"time_key": "2026-07-05 00:00:00",
"open": 0.92,
"high": 0.92,
"low": 0.92,
"close": 0.92,
"volume": 201.0
},
{
"time_key": "2026-07-06 00:00:00",
"open": 0.93,
"high": 0.93,
"low": 0.92,
"close": 0.92,
"volume": 659.0
},
{
"time_key": "2026-07-07 00:00:00",
"open": 0.93,
"high": 0.93,
"low": 0.92,
"close": 0.92,
"volume": 490.0
},
{
"time_key": "2026-07-08 00:00:00",
"open": 0.93,
"high": 0.93,
"low": 0.92,
"close": 0.92,
"volume": 669.0
},
{
"time_key": "2026-07-09 00:00:00",
"open": 0.92,
"high": 0.92,
"low": 0.92,
"close": 0.92,
"volume": 343.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
RequestHistoryEventContractKL(req);
Description
Pull the historical K-line of an event contract, supporting K-line source, contract direction and time range.
Parameters
message C2S
{
required Qot_Common.Security security = 1; // Contract underlying (contract_id or sub_contract_id)
optional Qot_Common.EC_KlineSource klineSource = 2; // K-line source (None/OrderBookYes), default None if not specified
optional Common.PredSide preSide = 3; // Direction (Yes/No), effective when klineSource=None and the underlying is contract-level, default Yes
required Qot_Common.KLType klType = 4; // Generic K-line type, EC only supports 1Min/5Min/60Min/Day
required string beginTime = 5; // Start time string
required string endTime = 6; // End time string
optional int32 maxAckKLNum = 7; // Max number of K-lines returned, unlimited if not specified
optional bytes nextReqKey = 8; // Pagination request key
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Return
message S2C
{
repeated Qot_GetEventContractKline.KlineItem klineList = 1; // K-line list (reuses shared KlineItem)
optional bytes nextReqKey = 2; // Pagination request key
}
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
- For the API call result structure, see RetType
- Example
import ftWebsocket from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
import beautify from "js-beautify";
function RequestHistoryEventContractKL() {
const { RetType } = Common;
const { PredSide } = Common;
const { QotMarket, KLType } = Qot_Common;
let [addr, port, enable_ssl, key] = ["127.0.0.1", 11111, false, ""];
let websocket = new ftWebsocket();
websocket.onlogin = async (ret, msg) => {
if (!ret) { console.log("start error", msg); return; }
try {
const req = { c2s: { security: { market: QotMarket.QotMarket_EventContract, code: "EC.KXNFLAFCCHAMP-27-CIN" }, preSide: PredSide.PredSide_Yes, klType: KLType.KLType_Day, beginTime: "2026-07-05", endTime: "2026-07-09", maxAckKLNum: 10 } };
let { errCode, retMsg, retType, s2c } = await websocket.RequestHistoryEventContractKL(req);
console.log("RequestHistoryEventContractKL: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if (retType == RetType.RetType_Succeed) {
console.log(beautify(JSON.stringify(s2c), { indent_size: 2, space_in_empty_paren: true }));
}
} catch (error) {
console.log("error:", error);
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(() => { websocket.stop(); console.log("stop"); }, 5000);
}
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
- Output
RequestHistoryEventContractKL: errCode 0, retMsg , retType 0
{
"klineList": [{
"code": {
"market": 101,
"code": "EC.KXNFLAFCCHAMP-27-CIN"
},
"preSide": 1,
"name": "Will Cincinnati win the Pro Football AFC Championship?",
"klineList": [
{
"timeKey": "2026-07-05 00:00:00",
"open": 0.92,
"high": 0.92,
"low": 0.92,
"close": 0.92,
"volume": 201
},
{
"timeKey": "2026-07-06 00:00:00",
"open": 0.93,
"high": 0.93,
"low": 0.92,
"close": 0.92,
"volume": 659
},
{
"timeKey": "2026-07-07 00:00:00",
"open": 0.93,
"high": 0.93,
"low": 0.92,
"close": 0.92,
"volume": 490
},
{
"timeKey": "2026-07-08 00:00:00",
"open": 0.93,
"high": 0.93,
"low": 0.92,
"close": 0.92,
"volume": 669
},
{
"timeKey": "2026-07-09 00:00:00",
"open": 0.92,
"high": 0.92,
"low": 0.92,
"close": 0.92,
"volume": 343
}
]
}]
}
stop
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
Interface Limitations
- Up to 60 requests for pulling the historical K-line of event contracts every 30 seconds
- Python
- Proto
- C#
- Java
- C++
- JavaScript
request_history_event_contract_kline(code, start=None, end=None, pre_side=None, ktype=KLType.K_DAY, kline_source=None, max_count=1000, page_req_key=None)
Description
Pull the historical K-line of an event contract without downloading historical data first. Supports querying by time range, direction and K-line source, and handles pagination automatically (loops to pull when
max_countexceeds the single-package limit).Parameters
Parameter Type Description code str Required. Event contract code, e.g. 'EC.KXNFLAFCCHAMP-27-CIN'start str Optional. Start time, e.g. '2026-07-05'end str Optional. End time, e.g. '2026-07-09'pre_side PredSide Optional. Contract direction ktype KLType Optional. K-line type, only K_1M/K_5M/K_60M/K_DAYsupported, defaultK_DAYkline_source ECKlineSource Optional. K-line source max_count int Optional. Max number of data points returned in this request, Nonemeans all within the rangepage_req_key str Optional. Pagination key, pass Nonefor the first request and the previous return value for subsequent requestsReturn
Parameter Type Description ret RET_CODE API call result data pd.DataFrame When ret == RET_OK, returns the historical K-line data str When ret != RET_OK, returns the error description page_req_key str Pagination key, None when there is no more data The DataFrame fields are as follows:
Field Type Description code str Contract code pre_side str Contract direction (YES/NO/N/A) name str Contract name time_key str K-line time open float Open price high float High price low float Low price close float Close price volume float Volume Example
from moomoo import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# Subscribe the corresponding K-line type before pulling the historical K-line
ret, err = quote_ctx.subscribe_event_contract(
['EC.KXNFLAFCCHAMP-27-CIN'], [SubType.K_DAY]
)
if ret != RET_OK:
print('subscribe failed:', err)
else:
ret, data, page_req_key = quote_ctx.request_history_event_contract_kline(
'EC.KXNFLAFCCHAMP-27-CIN',
start='2026-07-05', end='2026-07-09',
pre_side=PredSide.YES, ktype=KLType.K_DAY, max_count=10
)
if ret == RET_OK:
print(data)
print('page_req_key:', page_req_key)
else:
print('error:', data)
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
- Output
code pre_side name time_key open high low close volume
0 EC.KXNFLAFCCHAMP-27-CIN YES Will Cincinnati win the Pro Football AFC Championship? 2026-07-05 00:00:00 0.92 0.92 0.92 0.92 201.0
1 EC.KXNFLAFCCHAMP-27-CIN YES Will Cincinnati win the Pro Football AFC Championship? 2026-07-06 00:00:00 0.93 0.93 0.92 0.92 659.0
2 EC.KXNFLAFCCHAMP-27-CIN YES Will Cincinnati win the Pro Football AFC Championship? 2026-07-07 00:00:00 0.93 0.93 0.92 0.92 490.0
3 EC.KXNFLAFCCHAMP-27-CIN YES Will Cincinnati win the Pro Football AFC Championship? 2026-07-08 00:00:00 0.93 0.93 0.92 0.92 669.0
4 EC.KXNFLAFCCHAMP-27-CIN YES Will Cincinnati win the Pro Football AFC Championship? 2026-07-09 00:00:00 0.92 0.92 0.92 0.92 343.0
page_req_key: None
2
3
4
5
6
7
# Qot_RequestHistoryEventContractKL.proto
Description
Pull the historical K-line of an event contract.
Parameters
// Pull historical K-line of event contract
// Difference from the generic Qot_RequestHistoryKL: input adds klineSource/preSide direction fields, response structure is ECKLine(6 fields) + KlineItem.pre_side
// KLType only supports 1Min/5Min/60Min/Day
message C2S
{
required Qot_Common.Security security = 1; // Contract underlying (contract_id or sub_contract_id)
optional Qot_Common.EC_KlineSource klineSource = 2; // K-line source (None/OrderBookYes); default None (contract-level K-line), priority higher than preSide, aligned with real-time EC
optional Common.PredSide preSide = 3; // Direction (Yes/No); effective when klineSource=None and the input is a contract-level underlying, default Yes
required Qot_Common.KLType klType = 4; // Generic K-line type, EC only supports 1Min/5Min/60Min/Day
required string beginTime = 5; // Start time string
required string endTime = 6; // End time string
optional int32 maxAckKLNum = 7; // Max number of K-lines returned, unlimited if not specified
optional bytes nextReqKey = 8; // Pagination request key
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- For the stock structure, see Security
- For the event contract prediction direction, see PredSide
- For the K-line source, see ECKlineSource
- For the K-line type, see KLType
- Return
message S2C
{
repeated Qot_GetEventContractKline.KlineItem klineList = 1; // K-line list (reuses shared KlineItem, contains ECKLine data point and pre_side)
optional bytes nextReqKey = 2; // Pagination request key. When one request does not return all data, pass this key in the next request to continue
}
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
- For the API call result structure, see RetType
Protocol ID
3456
Data Type
- For the stock structure, see Security
- For the event contract prediction direction, see PredSide
- For the K-line source, see ECKlineSource
- For the K-line type, see KLType
uint RequestHistoryEventContractKL(Qot_RequestHistoryEventContractKL.Request req);
virtual void OnReply_RequestHistoryEventContractKL(MMAPI_Conn client, uint nSerialNo, Qot_RequestHistoryEventContractKL.Response rsp);
Description
Pull the historical K-line of an event contract.
Parameters
message C2S
{
required Qot_Common.Security security = 1;
optional Qot_Common.EC_KlineSource klineSource = 2;
optional Common.PredSide preSide = 3;
required Qot_Common.KLType klType = 4;
required string beginTime = 5;
required string endTime = 6;
optional int32 maxAckKLNum = 7;
optional bytes nextReqKey = 8;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- For the stock structure, see Security
- Return
message S2C
{
repeated Qot_GetEventContractKline.KlineItem klineList = 1;
optional bytes nextReqKey = 2;
}
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
12
13
- For the API call result structure, 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.KXNFLAFCCHAMP-27-CIN").Build();
var c2s = Qot_RequestHistoryEventContractKL.C2S.CreateBuilder()
.SetSecurity(sec)
.SetPreSide(Common.PredSide.PredSide_Yes)
.SetKlType((int)QotCommon.KLType.KLType_Day)
.SetBeginTime("2026-07-05")
.SetEndTime("2026-07-09")
.SetMaxAckKLNum(10).Build();
var req = Qot_RequestHistoryEventContractKL.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.RequestHistoryEventContractKL(req);
Console.Write("Send RequestHistoryEventContractKL: {0}\n", seqNo);
}
public void OnReply_RequestHistoryEventContractKL(MMAPI_Conn client, uint nSerialNo, Qot_RequestHistoryEventContractKL.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
40
41
int requestHistoryEventContractKL(QotRequestHistoryEventContractKL.Request req);
void onReply_RequestHistoryEventContractKL(MMAPI_Conn client, int nSerialNo, QotRequestHistoryEventContractKL.Response rsp);
Description
Pull the historical K-line of an event contract.
Parameters
message C2S
{
required Qot_Common.Security security = 1;
optional Qot_Common.EC_KlineSource klineSource = 2;
optional Common.PredSide preSide = 3;
required Qot_Common.KLType klType = 4;
required string beginTime = 5;
required string endTime = 6;
optional int32 maxAckKLNum = 7;
optional bytes nextReqKey = 8;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- For the stock structure, see Security
- Return
message S2C
{
repeated Qot_GetEventContractKline.KlineItem klineList = 1;
optional bytes nextReqKey = 2;
}
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
12
13
- For the API call result structure, 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.KXNFLAFCCHAMP-27-CIN").build();
QotRequestHistoryEventContractKL.C2S c2s = QotRequestHistoryEventContractKL.C2S.newBuilder()
.setSecurity(sec)
.setPreSide(Common.PredSide.PredSide_Yes)
.setKlType(QotCommon.KLType.KLType_Day_VALUE)
.setBeginTime("2026-07-05")
.setEndTime("2026-07-09")
.setMaxAckKLNum(10).build();
QotRequestHistoryEventContractKL.Request req = QotRequestHistoryEventContractKL.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.requestHistoryEventContractKL(req);
System.out.println("Send RequestHistoryEventContractKL: " + seqNo);
}
@Override
public void onReply_RequestHistoryEventContractKL(MMAPI_Conn client, int nSerialNo, QotRequestHistoryEventContractKL.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
45
46
moomoo::u32_t RequestHistoryEventContractKL(const Qot_RequestHistoryEventContractKL::Request &stReq);
virtual void OnReply_RequestHistoryEventContractKL(moomoo::u32_t nSerialNo, const Qot_RequestHistoryEventContractKL::Response &stRsp) = 0;
Description
Pull the historical K-line of an event contract.
Parameters
// Pull historical K-line of event contract
// Difference from the generic Qot_RequestHistoryKL: input adds klineSource/preSide direction fields, response structure is ECKLine(6 fields) + KlineItem.pre_side
// KLType only supports 1Min/5Min/60Min/Day
message C2S
{
required Qot_Common.Security security = 1; // Contract underlying (contract_id or sub_contract_id)
optional Qot_Common.EC_KlineSource klineSource = 2; // K-line source (None/OrderBookYes); default None (contract-level K-line), priority higher than preSide, aligned with real-time EC
optional Common.PredSide preSide = 3; // Direction (Yes/No); effective when klineSource=None and the input is a contract-level underlying, default Yes
required Qot_Common.KLType klType = 4; // Generic K-line type, EC only supports 1Min/5Min/60Min/Day
required string beginTime = 5; // Start time string
required string endTime = 6; // End time string
optional int32 maxAckKLNum = 7; // Max number of K-lines returned, unlimited if not specified
optional bytes nextReqKey = 8; // Pagination request key
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- For the stock structure, see Security
- For the event contract prediction direction, see PredSide
- For the K-line source, see ECKlineSource
- For the K-line type, see KLType
- Return
message S2C
{
repeated Qot_GetEventContractKline.KlineItem klineList = 1; // K-line list (reuses shared KlineItem, contains ECKLine data point and pre_side)
optional bytes nextReqKey = 2; // Pagination request key. When one request does not return all data, pass this key in the next request to continue
}
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
- For the API call result structure, 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 the packet
Qot_RequestHistoryEventContractKL::Request req;
Qot_RequestHistoryEventContractKL::C2S *c2s = req.mutable_c2s();
Qot_Common::Security *sec = c2s->mutable_security();
sec->set_code("EC.KXNFLAFCCHAMP-27-CIN");
sec->set_market(Qot_Common::QotMarket::QotMarket_EventContract);
c2s->set_preside(Common::PredSide::PredSide_Yes);
c2s->set_kltype(Qot_Common::KLType::KLType_Day);
c2s->set_begintime("2026-07-05");
c2s->set_endtime("2026-07-09");
c2s->set_maxackklnum(10);
m_RequestHistoryEventContractKLSerialNo = m_pQotApi->RequestHistoryEventContractKL(req);
cout << "Request RequestHistoryEventContractKL SerialNo: " << m_RequestHistoryEventContractKLSerialNo << endl;
}
virtual void OnReply_RequestHistoryEventContractKL(moomoo::u32_t nSerialNo, const Qot_RequestHistoryEventContractKL::Response &stRsp) {
if (nSerialNo == m_RequestHistoryEventContractKLSerialNo)
{
cout << "OnReply_RequestHistoryEventContractKL SerialNo: " << nSerialNo << endl;
// Parse the internal structure and print
// The definitions of ProtoBufToBodyData and UTF8ToLocal are in the tool.h file in the Sample
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
protected:
MMAPI_Qot *m_pQotApi;
moomoo::u32_t m_RequestHistoryEventContractKLSerialNo;
};
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
- Output
connect
Request RequestHistoryEventContractKL SerialNo: 1
OnReply_RequestHistoryEventContractKL SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"klineList": [
{
"code": {"market": 101, "code": "EC.KXNFLAFCCHAMP-27-CIN"},
"pre_side": 1,
"name": "Will Cincinnati win the Pro Football AFC Championship?",
"klineList": [
{
"time_key": "2026-07-05 00:00:00",
"open": 0.92,
"high": 0.92,
"low": 0.92,
"close": 0.92,
"volume": 201.0
},
{
"time_key": "2026-07-06 00:00:00",
"open": 0.93,
"high": 0.93,
"low": 0.92,
"close": 0.92,
"volume": 659.0
},
{
"time_key": "2026-07-07 00:00:00",
"open": 0.93,
"high": 0.93,
"low": 0.92,
"close": 0.92,
"volume": 490.0
},
{
"time_key": "2026-07-08 00:00:00",
"open": 0.93,
"high": 0.93,
"low": 0.92,
"close": 0.92,
"volume": 669.0
},
{
"time_key": "2026-07-09 00:00:00",
"open": 0.92,
"high": 0.92,
"low": 0.92,
"close": 0.92,
"volume": 343.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
RequestHistoryEventContractKL(req);
Description
Pull the historical K-line of an event contract, supporting K-line source, contract direction and time range.
Parameters
message C2S
{
required Qot_Common.Security security = 1; // Contract underlying (contract_id or sub_contract_id)
optional Qot_Common.EC_KlineSource klineSource = 2; // K-line source (None/OrderBookYes), default None if not specified
optional Common.PredSide preSide = 3; // Direction (Yes/No), effective when klineSource=None and the underlying is contract-level, default Yes
required Qot_Common.KLType klType = 4; // Generic K-line type, EC only supports 1Min/5Min/60Min/Day
required string beginTime = 5; // Start time string
required string endTime = 6; // End time string
optional int32 maxAckKLNum = 7; // Max number of K-lines returned, unlimited if not specified
optional bytes nextReqKey = 8; // Pagination request key
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Return
message S2C
{
repeated Qot_GetEventContractKline.KlineItem klineList = 1; // K-line list (reuses shared KlineItem)
optional bytes nextReqKey = 2; // Pagination request key
}
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
- For the API call result structure, see RetType
- Example
import mmWebsocket from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function RequestHistoryEventContractKL() {
const { RetType } = Common;
const { PredSide } = Common;
const { QotMarket, KLType } = Qot_Common;
let [addr, port, enable_ssl, key] = ["127.0.0.1", 11111, false, ""];
let websocket = new mmWebsocket();
websocket.onlogin = async (ret, msg) => {
if (!ret) { console.log("start error", msg); return; }
try {
const req = { c2s: { security: { market: QotMarket.QotMarket_EventContract, code: "EC.KXNFLAFCCHAMP-27-CIN" }, preSide: PredSide.PredSide_Yes, klType: KLType.KLType_Day, beginTime: "2026-07-05", endTime: "2026-07-09", maxAckKLNum: 10 } };
let { errCode, retMsg, retType, s2c } = await websocket.RequestHistoryEventContractKL(req);
console.log("RequestHistoryEventContractKL: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if (retType == RetType.RetType_Succeed) {
console.log(beautify(JSON.stringify(s2c), { indent_size: 2, space_in_empty_paren: true }));
}
} catch (error) {
console.log("error:", error);
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(() => { websocket.stop(); console.log("stop"); }, 5000);
}
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
- Output
RequestHistoryEventContractKL: errCode 0, retMsg , retType 0
{
"klineList": [{
"code": {
"market": 101,
"code": "EC.KXNFLAFCCHAMP-27-CIN"
},
"preSide": 1,
"name": "Will Cincinnati win the Pro Football AFC Championship?",
"klineList": [
{
"timeKey": "2026-07-05 00:00:00",
"open": 0.92,
"high": 0.92,
"low": 0.92,
"close": 0.92,
"volume": 201
},
{
"timeKey": "2026-07-06 00:00:00",
"open": 0.93,
"high": 0.93,
"low": 0.92,
"close": 0.92,
"volume": 659
},
{
"timeKey": "2026-07-07 00:00:00",
"open": 0.93,
"high": 0.93,
"low": 0.92,
"close": 0.92,
"volume": 490
},
{
"timeKey": "2026-07-08 00:00:00",
"open": 0.93,
"high": 0.93,
"low": 0.92,
"close": 0.92,
"volume": 669
},
{
"timeKey": "2026-07-09 00:00:00",
"open": 0.92,
"high": 0.92,
"low": 0.92,
"close": 0.92,
"volume": 343
}
]
}]
}
stop
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
Interface Limitations
- Up to 60 requests for pulling the historical K-line of event contracts every 30 seconds