# Event Contract Order Book Push
- Python
- Proto
- C#
- Java
- C++
- JavaScript
on_recv_rsp(self, rsp_pb)
Description
Event contract order book push callback, which asynchronously processes real-time order book data of subscribed event contracts. After subscribing to event contracts of the
SubType.ORDER_BOOKtype, the server will actively push order book data. Upon receiving the push, this function will be called back, and you need to override on_recv_rsp in the derived class.Parameters
Parameter Type Description rsp_pb Qot_UpdateEventContractOrderBook_pb2.Response This parameter does not need to be processed directly in the derived class. Return
Parameter Type Description ret RET_CODE Interface call result. data list If ret == RET_OK, order book data is returned (one dict per contract). str If ret != RET_OK, error description is returned. - The order book data format is as follows (each dict contains the following fields):
Field Type Description code str Event contract code. yes_bids list[tuple] YES bid side [(price, size), ...]yes_asks list[tuple] YES ask side [(price, size), ...]no_bids list[tuple] NO bid side [(price, size), ...]no_asks list[tuple] NO ask side [(price, size), ...]
- The order book data format is as follows (each dict contains the following fields):
Example
import time
from futu import *
class EventContractOrderBookHandler(EventContractOrderBookHandlerBase):
def on_recv_rsp(self, rsp_pb):
ret_code, content = super(EventContractOrderBookHandler, self).on_recv_rsp(rsp_pb)
if ret_code != RET_OK:
print("EventContractOrderBook error:", content)
return RET_ERROR, content
for ob in content:
print("Received order book push:", ob['code'])
print(" YES bids:", ob['yes_bids'])
print(" YES asks:", ob['yes_asks'])
print(" NO bids:", ob['no_bids'])
print(" NO asks:", ob['no_asks'])
return RET_OK, content
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
quote_ctx.set_handler(EventContractOrderBookHandler()) # Register the event contract order book push callback
ret, data = quote_ctx.subscribe_event_contract(
code_list=['EC.KXODIMATCH-26JUL140600INDENG-IND'],
subtype_list=[SubType.ORDER_BOOK]) # Subscribe to the event contract order book type, OpenD starts to receive continuous push from the server
if ret == RET_OK:
print(data)
else:
print('error:', data)
time.sleep(15) # Set the script to receive OpenD push duration to 15 seconds
quote_ctx.close() # Close the current connection, OpenD will automatically cancel the corresponding type of subscription for the corresponding contract 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
27
28
- Output
Received order book push: EC.KXODIMATCH-26JUL140600INDENG-IND
YES bids: [(0.5, 1030.0), (0.48, 0.01), (0.45, 5.0), (0.43, 1.0), (0.42, 175.0)]
YES asks: [(0.51, 2633.6), (0.52, 15500.0), (0.53, 3000.0), (0.54, 1000.0), (0.55, 2124.0)]
NO bids: [(0.49, 2633.6), (0.48, 15500.0), (0.47, 3000.0), (0.46, 1000.0), (0.45, 2124.0)]
NO asks: [(0.5, 1030.0), (0.52, 0.01), (0.55, 5.0), (0.57, 1.0), (0.58, 175.0)]
2
3
4
5
# Qot_UpdateEventContractOrderBook.proto
Description
Event contract order book push callback, which asynchronously processes real-time order book data of subscribed event contracts.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Order book of a single contract
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bid side
repeated OrderBookLevel yesAsks = 3; // YES ask side
repeated OrderBookLevel noBids = 4; // NO bid side
repeated OrderBookLevel noAsks = 5; // NO ask side
}
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, returned 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
Protocol ID
3450
virtual void OnPush_UpdateEventContractOrderBook(FTAPI_Conn client, QotUpdateEventContractOrderBook.Response rsp);
Description
Event contract order book push callback, which asynchronously processes real-time order book data of subscribed event contracts.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Order book of a single contract
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bid side
repeated OrderBookLevel yesAsks = 3; // YES ask side
repeated OrderBookLevel noBids = 4; // NO bid side
repeated OrderBookLevel noAsks = 5; // NO ask side
}
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, returned 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
- 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_OrderBook)
.SetIsSubOrUnSub(true)
.SetIsRegOrUnRegPush(true).Build();
var req = SubEventContract.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.SubEventContract(req);
Console.Write("Send SubEventContract: {0}\n", seqNo);
}
public void OnPush_UpdateEventContractOrderBook(FTAPI_Conn client, QotUpdateEventContractOrderBook.Response rsp)
{
Console.Write("Push EventContractOrderBook: {0}\n", 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
- Output
Send SubEventContract: 1
Push EventContractOrderBook: {
"retType": 0,
"s2c": {
"orderBookList": [
{
"code": {"market": 101, "code": "EC.KXODIMATCH-26JUL140600INDENG-IND"},
"yesBids": [{"price": 0.5, "size": 1030.0}, {"price": 0.48, "size": 0.01}, {"price": 0.45, "size": 5.0}],
"yesAsks": [{"price": 0.51, "size": 2633.6}, {"price": 0.52, "size": 15500.0}],
"noBids": [{"price": 0.49, "size": 2633.6}, {"price": 0.48, "size": 15500.0}],
"noAsks": [{"price": 0.5, "size": 1030.0}, {"price": 0.52, "size": 0.01}]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void onPush_UpdateEventContractOrderBook(FTAPI_Conn client, QotUpdateEventContractOrderBook.Response rsp);
Description
Event contract order book push callback, which asynchronously processes real-time order book data of subscribed event contracts.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Order book of a single contract
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bid side
repeated OrderBookLevel yesAsks = 3; // YES ask side
repeated OrderBookLevel noBids = 4; // NO bid side
repeated OrderBookLevel noAsks = 5; // NO ask side
}
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, returned 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
- 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_OrderBook_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_UpdateEventContractOrderBook(FTAPI_Conn client, QotUpdateEventContractOrderBook.Response rsp) {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Push EventContractOrderBook: %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
virtual void OnPush_UpdateEventContractOrderBook(const Qot_UpdateEventContractOrderBook::Response &stRsp) = 0;
Description
Event contract order book push callback, which asynchronously processes real-time order book data of subscribed event contracts.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Order book of a single contract
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bid side
repeated OrderBookLevel yesAsks = 3; // YES ask side
repeated OrderBookLevel noBids = 4; // NO bid side
repeated OrderBookLevel noAsks = 5; // NO ask side
}
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, returned 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
- 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 the event contract order book type first
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_OrderBook);
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;
// The definitions of ProtoBufToBodyData and UTF8ToLocal functions can be found in the tool.h file in the Sample
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
virtual void OnPush_UpdateEventContractOrderBook(const Qot_UpdateEventContractOrderBook::Response &stRsp) {
cout << "OnPush_UpdateEventContractOrderBook" << endl;
// Parse the internal structure and print it out
// The definitions of ProtoBufToBodyData and UTF8ToLocal functions can be found 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_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
79
80
81
- Output
connect
Request SubEventContract SerialNo: 1
OnReply_SubEventContract SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0
}
OnPush_UpdateEventContractOrderBook
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"orderBookList": [
{
"code": {"market": 101, "code": "EC.KXODIMATCH-26JUL140600INDENG-IND"},
"yesBids": [{"price": 0.5, "size": 1030.0}, {"price": 0.48, "size": 0.01}, {"price": 0.45, "size": 5.0}, {"price": 0.43, "size": 1.0}, {"price": 0.42, "size": 175.0}],
"yesAsks": [{"price": 0.51, "size": 2633.6}, {"price": 0.52, "size": 15500.0}, {"price": 0.53, "size": 3000.0}, {"price": 0.54, "size": 1000.0}, {"price": 0.55, "size": 2124.0}],
"noBids": [{"price": 0.49, "size": 2633.6}, {"price": 0.48, "size": 15500.0}, {"price": 0.47, "size": 3000.0}, {"price": 0.46, "size": 1000.0}, {"price": 0.45, "size": 2124.0}],
"noAsks": [{"price": 0.5, "size": 1030.0}, {"price": 0.52, "size": 0.01}, {"price": 0.55, "size": 5.0}, {"price": 0.57, "size": 1.0}, {"price": 0.58, "size": 175.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
OnPush(cmd,res)
Description
Event contract order book push callback, which asynchronously processes real-time order book data of subscribed event contracts.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Order book of a single contract
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bid side
repeated OrderBookLevel yesAsks = 3; // YES ask side
repeated OrderBookLevel noBids = 4; // NO bid side
repeated OrderBookLevel noAsks = 5; // NO ask side
}
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, returned 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
- Example
import ftWebsocket from "futu-api";
import { ftCmdID } from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
function UpdateEventContractOrderBook(){
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 succeeded
const req = {
c2s: {
securityList: [
{
market: QotMarket.QotMarket_EventContract,
code: "EC.KXODIMATCH-26JUL140600INDENG-IND",
},
],
subTypeList: [ SubType.SubType_OrderBook ], // Subscribe to the event contract order book type
isSubOrUnSub: true, // Subscribe true, unsubscribe false
isRegOrUnRegPush: true, // Register push true, unregister push false
},
}; // Subscription parameters
websocket.SubEventContract(req) // Subscribe, OpenD starts to receive 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.QotUpdateEventContractOrderBook.cmd == cmd){ // Processing logic for the event contract order book push
let { retType, s2c } = res
if(retType == RetType.RetType_Succeed){
console.log("EventContractOrderBookTest", JSON.stringify(s2c));
} else {
console.log("EventContractOrderBookTest: error")
}
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // Set the script to receive OpenD push duration to 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
EventContractOrderBookTest {"orderBookList":[{"code":{"market":101,"code":"EC.KXODIMATCH-26JUL140600INDENG-IND"},"yesBids":[{"price":0.5,"size":1030.0},{"price":0.48,"size":0.01},{"price":0.45,"size":5.0},{"price":0.43,"size":1.0},{"price":0.42,"size":175.0}],"yesAsks":[{"price":0.51,"size":2633.6},{"price":0.52,"size":15500.0},{"price":0.53,"size":3000.0},{"price":0.54,"size":1000.0},{"price":0.55,"size":2124.0}],"noBids":[{"price":0.49,"size":2633.6},{"price":0.48,"size":15500.0},{"price":0.47,"size":3000.0},{"price":0.46,"size":1000.0},{"price":0.45,"size":2124.0}],"noAsks":[{"price":0.5,"size":1030.0},{"price":0.52,"size":0.01},{"price":0.55,"size":5.0},{"price":0.57,"size":1.0},{"price":0.58,"size":175.0}]}]}
stop
2
- Python
- Proto
- C#
- Java
- C++
- JavaScript
on_recv_rsp(self, rsp_pb)
Description
Event contract order book push callback, which asynchronously processes real-time order book data of subscribed event contracts. After subscribing to event contracts of the
SubType.ORDER_BOOKtype, the server will actively push order book data. Upon receiving the push, this function will be called back, and you need to override on_recv_rsp in the derived class.Parameters
Parameter Type Description rsp_pb Qot_UpdateEventContractOrderBook_pb2.Response This parameter does not need to be processed directly in the derived class. Return
Parameter Type Description ret RET_CODE Interface call result. data list If ret == RET_OK, order book data is returned (one dict per contract). str If ret != RET_OK, error description is returned. - The order book data format is as follows (each dict contains the following fields):
Field Type Description code str Event contract code. yes_bids list[tuple] YES bid side [(price, size), ...]yes_asks list[tuple] YES ask side [(price, size), ...]no_bids list[tuple] NO bid side [(price, size), ...]no_asks list[tuple] NO ask side [(price, size), ...]
- The order book data format is as follows (each dict contains the following fields):
Example
import time
from moomoo import *
class EventContractOrderBookHandler(EventContractOrderBookHandlerBase):
def on_recv_rsp(self, rsp_pb):
ret_code, content = super(EventContractOrderBookHandler, self).on_recv_rsp(rsp_pb)
if ret_code != RET_OK:
print("EventContractOrderBook error:", content)
return RET_ERROR, content
for ob in content:
print("Received order book push:", ob['code'])
print(" YES bids:", ob['yes_bids'])
print(" YES asks:", ob['yes_asks'])
print(" NO bids:", ob['no_bids'])
print(" NO asks:", ob['no_asks'])
return RET_OK, content
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
quote_ctx.set_handler(EventContractOrderBookHandler()) # Register the event contract order book push callback
ret, data = quote_ctx.subscribe_event_contract(
code_list=['EC.KXODIMATCH-26JUL140600INDENG-IND'],
subtype_list=[SubType.ORDER_BOOK]) # Subscribe to the event contract order book type, OpenD starts to receive continuous push from the server
if ret == RET_OK:
print(data)
else:
print('error:', data)
time.sleep(15) # Set the script to receive OpenD push duration to 15 seconds
quote_ctx.close() # Close the current connection, OpenD will automatically cancel the corresponding type of subscription for the corresponding contract 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
27
28
- Output
Received order book push: EC.KXODIMATCH-26JUL140600INDENG-IND
YES bids: [(0.5, 1030.0), (0.48, 0.01), (0.45, 5.0), (0.43, 1.0), (0.42, 175.0)]
YES asks: [(0.51, 2633.6), (0.52, 15500.0), (0.53, 3000.0), (0.54, 1000.0), (0.55, 2124.0)]
NO bids: [(0.49, 2633.6), (0.48, 15500.0), (0.47, 3000.0), (0.46, 1000.0), (0.45, 2124.0)]
NO asks: [(0.5, 1030.0), (0.52, 0.01), (0.55, 5.0), (0.57, 1.0), (0.58, 175.0)]
2
3
4
5
# Qot_UpdateEventContractOrderBook.proto
Description
Event contract order book push callback, which asynchronously processes real-time order book data of subscribed event contracts.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Order book of a single contract
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bid side
repeated OrderBookLevel yesAsks = 3; // YES ask side
repeated OrderBookLevel noBids = 4; // NO bid side
repeated OrderBookLevel noAsks = 5; // NO ask side
}
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, returned 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
Protocol ID
3450
virtual void OnPush_UpdateEventContractOrderBook(MMAPI_Conn client, QotUpdateEventContractOrderBook.Response rsp);
Description
Event contract order book push callback, which asynchronously processes real-time order book data of subscribed event contracts.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Order book of a single contract
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bid side
repeated OrderBookLevel yesAsks = 3; // YES ask side
repeated OrderBookLevel noBids = 4; // NO bid side
repeated OrderBookLevel noAsks = 5; // NO ask side
}
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, returned 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
- 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_OrderBook)
.SetIsSubOrUnSub(true)
.SetIsRegOrUnRegPush(true).Build();
var req = SubEventContract.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.SubEventContract(req);
Console.Write("Send SubEventContract: {0}\n", seqNo);
}
public void OnPush_UpdateEventContractOrderBook(MMAPI_Conn client, QotUpdateEventContractOrderBook.Response rsp)
{
Console.Write("Push EventContractOrderBook: {0}\n", 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
- Output
Send SubEventContract: 1
Push EventContractOrderBook: {
"retType": 0,
"s2c": {
"orderBookList": [
{
"code": {"market": 101, "code": "EC.KXODIMATCH-26JUL140600INDENG-IND"},
"yesBids": [{"price": 0.5, "size": 1030.0}, {"price": 0.48, "size": 0.01}, {"price": 0.45, "size": 5.0}],
"yesAsks": [{"price": 0.51, "size": 2633.6}, {"price": 0.52, "size": 15500.0}],
"noBids": [{"price": 0.49, "size": 2633.6}, {"price": 0.48, "size": 15500.0}],
"noAsks": [{"price": 0.5, "size": 1030.0}, {"price": 0.52, "size": 0.01}]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void onPush_UpdateEventContractOrderBook(MMAPI_Conn client, QotUpdateEventContractOrderBook.Response rsp);
Description
Event contract order book push callback, which asynchronously processes real-time order book data of subscribed event contracts.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Order book of a single contract
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bid side
repeated OrderBookLevel yesAsks = 3; // YES ask side
repeated OrderBookLevel noBids = 4; // NO bid side
repeated OrderBookLevel noAsks = 5; // NO ask side
}
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, returned 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
- 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_OrderBook_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_UpdateEventContractOrderBook(MMAPI_Conn client, QotUpdateEventContractOrderBook.Response rsp) {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Push EventContractOrderBook: %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
virtual void OnPush_UpdateEventContractOrderBook(const Qot_UpdateEventContractOrderBook::Response &stRsp) = 0;
Description
Event contract order book push callback, which asynchronously processes real-time order book data of subscribed event contracts.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Order book of a single contract
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bid side
repeated OrderBookLevel yesAsks = 3; // YES ask side
repeated OrderBookLevel noBids = 4; // NO bid side
repeated OrderBookLevel noAsks = 5; // NO ask side
}
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, returned 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
- 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 the event contract order book type first
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_OrderBook);
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;
// The definitions of ProtoBufToBodyData and UTF8ToLocal functions can be found in the tool.h file in the Sample
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
virtual void OnPush_UpdateEventContractOrderBook(const Qot_UpdateEventContractOrderBook::Response &stRsp) {
cout << "OnPush_UpdateEventContractOrderBook" << endl;
// Parse the internal structure and print it out
// The definitions of ProtoBufToBodyData and UTF8ToLocal functions can be found 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_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
79
80
81
- Output
connect
Request SubEventContract SerialNo: 1
OnReply_SubEventContract SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0
}
OnPush_UpdateEventContractOrderBook
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"orderBookList": [
{
"code": {"market": 101, "code": "EC.KXODIMATCH-26JUL140600INDENG-IND"},
"yesBids": [{"price": 0.5, "size": 1030.0}, {"price": 0.48, "size": 0.01}, {"price": 0.45, "size": 5.0}, {"price": 0.43, "size": 1.0}, {"price": 0.42, "size": 175.0}],
"yesAsks": [{"price": 0.51, "size": 2633.6}, {"price": 0.52, "size": 15500.0}, {"price": 0.53, "size": 3000.0}, {"price": 0.54, "size": 1000.0}, {"price": 0.55, "size": 2124.0}],
"noBids": [{"price": 0.49, "size": 2633.6}, {"price": 0.48, "size": 15500.0}, {"price": 0.47, "size": 3000.0}, {"price": 0.46, "size": 1000.0}, {"price": 0.45, "size": 2124.0}],
"noAsks": [{"price": 0.5, "size": 1030.0}, {"price": 0.52, "size": 0.01}, {"price": 0.55, "size": 5.0}, {"price": 0.57, "size": 1.0}, {"price": 0.58, "size": 175.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
OnPush(cmd,res)
Description
Event contract order book push callback, which asynchronously processes real-time order book data of subscribed event contracts.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Order book of a single contract
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bid side
repeated OrderBookLevel yesAsks = 3; // YES ask side
repeated OrderBookLevel noBids = 4; // NO bid side
repeated OrderBookLevel noAsks = 5; // NO ask side
}
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, returned 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
- Example
import mmWebsocket from "moomoo-api";
import { mmCmdID } from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
function UpdateEventContractOrderBook(){
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 succeeded
const req = {
c2s: {
securityList: [
{
market: QotMarket.QotMarket_EventContract,
code: "EC.KXODIMATCH-26JUL140600INDENG-IND",
},
],
subTypeList: [ SubType.SubType_OrderBook ], // Subscribe to the event contract order book type
isSubOrUnSub: true, // Subscribe true, unsubscribe false
isRegOrUnRegPush: true, // Register push true, unregister push false
},
}; // Subscription parameters
websocket.SubEventContract(req) // Subscribe, OpenD starts to receive 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.QotUpdateEventContractOrderBook.cmd == cmd){ // Processing logic for the event contract order book push
let { retType, s2c } = res
if(retType == RetType.RetType_Succeed){
console.log("EventContractOrderBookTest", JSON.stringify(s2c));
} else {
console.log("EventContractOrderBookTest: error")
}
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // Set the script to receive OpenD push duration to 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
EventContractOrderBookTest {"orderBookList":[{"code":{"market":101,"code":"EC.KXODIMATCH-26JUL140600INDENG-IND"},"yesBids":[{"price":0.5,"size":1030.0},{"price":0.48,"size":0.01},{"price":0.45,"size":5.0},{"price":0.43,"size":1.0},{"price":0.42,"size":175.0}],"yesAsks":[{"price":0.51,"size":2633.6},{"price":0.52,"size":15500.0},{"price":0.53,"size":3000.0},{"price":0.54,"size":1000.0},{"price":0.55,"size":2124.0}],"noBids":[{"price":0.49,"size":2633.6},{"price":0.48,"size":15500.0},{"price":0.47,"size":3000.0},{"price":0.46,"size":1000.0},{"price":0.45,"size":2124.0}],"noAsks":[{"price":0.5,"size":1030.0},{"price":0.52,"size":0.01},{"price":0.55,"size":5.0},{"price":0.57,"size":1.0},{"price":0.58,"size":175.0}]}]}
stop
2