# Get Event Contract Order Book
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_event_contract_order_book(code, num=10)
Description
Get the order book of a single event contract, including YES/NO bid and ask levels.
Parameters
Parameter Type Description code str Event contract code, e.g. 'EC.KXODIMATCH-26JUL140600INDENG-IND'num int Requested order book depth, default 10, must be greater than 0 Return
Parameter Type Description ret RET_CODE API call result data dict When ret == RET_OK, returns order book data, containing code, yes_bids, yes_asks, no_bids, no_asks str When ret != RET_OK, returns error description The fields of the returned dict are as follows:
Field Type Description code str Contract code yes_bids list[tuple] YES bids, [(price, size), ...]yes_asks list[tuple] YES asks, [(price, size), ...]no_bids list[tuple] NO bids, [(price, size), ...]no_asks list[tuple] NO asks, [(price, size), ...]Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# Before querying the order book, you must first subscribe to ORDER_BOOK (otherwise an error is returned)
ret, err = quote_ctx.subscribe_event_contract(
['EC.KXODIMATCH-26JUL140600INDENG-IND'], [SubType.ORDER_BOOK]
)
if ret != RET_OK:
print('subscription failed:', err)
else:
ret, data = quote_ctx.get_event_contract_order_book(
'EC.KXODIMATCH-26JUL140600INDENG-IND', num=5
)
if ret == RET_OK:
print('contract:', data['code'])
print('YES bids:', data['yes_bids'])
print('YES asks:', data['yes_asks'])
print('NO bids:', data['no_bids'])
print('NO asks:', data['no_asks'])
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
24
- Output
contract: 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_GetEventContractOrderBook.proto
Description
Get the order book of a single event contract.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Single contract order book
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bids
repeated OrderBookLevel yesAsks = 3; // YES asks
repeated OrderBookLevel noBids = 4; // NO bids
repeated OrderBookLevel noAsks = 5; // NO asks
}
message C2S {
required Qot_Common.Security security = 1; // Contract security (single, required)
required int32 num = 2; // Requested order book depth (>0; the actual number returned may be less than requested)
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- For the security structure, see Security
- Return
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
- See RetType for the result structure
Protocol ID
3446
Data Type
- For the security structure, see Security
uint GetEventContractOrderBook(GetEventContractOrderBook.Request req);
virtual void OnReply_GetEventContractOrderBook(FTAPI_Conn client, uint nSerialNo, GetEventContractOrderBook.Response rsp);
Description
Get the order book of a single event contract.
Parameters
message OrderBookLevel {
required double price = 1;
required double size = 2;
}
message OrderBookItem {
required Qot_Common.Security code = 1;
repeated OrderBookLevel yesBids = 2;
repeated OrderBookLevel yesAsks = 3;
repeated OrderBookLevel noBids = 4;
repeated OrderBookLevel noAsks = 5;
}
message C2S {
required Qot_Common.Security security = 1;
required int32 num = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
- For the security structure, see Security
- Return
message S2C {
repeated OrderBookItem orderBookList = 1;
}
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
- See RetType for the result structure
- 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 = GetEventContractOrderBook.C2S.CreateBuilder()
.SetSecurity(sec).SetNum(10).Build();
var req = GetEventContractOrderBook.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetEventContractOrderBook(req);
Console.Write("Send GetEventContractOrderBook: {0}\n", seqNo);
}
public void OnReply_GetEventContractOrderBook(FTAPI_Conn client, uint nSerialNo, GetEventContractOrderBook.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
- Output
connect
Request GetEventContractOrderBook SerialNo: 1
OnReply_GetEventContractOrderBook SerialNo: 1
{
"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
int getEventContractOrderBook(QotGetEventContractOrderBook.Request req);
void onReply_GetEventContractOrderBook(FTAPI_Conn client, int nSerialNo, QotGetEventContractOrderBook.Response rsp);
Description
Get the order book of a single event contract.
Parameters
message C2S {
required Qot_Common.Security security = 1;
required int32 num = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- For the security structure, see Security
- Return
message S2C {
repeated OrderBookItem orderBookList = 1;
}
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
- See RetType for the result structure
- 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();
QotGetEventContractOrderBook.C2S c2s = QotGetEventContractOrderBook.C2S.newBuilder()
.setSecurity(sec).setNum(10).build();
QotGetEventContractOrderBook.Request req = QotGetEventContractOrderBook.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.getEventContractOrderBook(req);
System.out.println("Send GetEventContractOrderBook: " + seqNo);
}
@Override
public void onReply_GetEventContractOrderBook(FTAPI_Conn client, int nSerialNo, QotGetEventContractOrderBook.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
- Output
connect
Request GetEventContractOrderBook SerialNo: 1
OnReply_GetEventContractOrderBook SerialNo: 1
{
"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
Futu::u32_t GetEventContractOrderBook(const Qot_GetEventContractOrderBook::Request &stReq);
virtual void OnReply_GetEventContractOrderBook(Futu::u32_t nSerialNo, const Qot_GetEventContractOrderBook::Response &stRsp) = 0;
Description
Get the order book of a single event contract.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Single contract order book
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bids
repeated OrderBookLevel yesAsks = 3; // YES asks
repeated OrderBookLevel noBids = 4; // NO bids
repeated OrderBookLevel noAsks = 5; // NO asks
}
message C2S {
required Qot_Common.Security security = 1; // Contract security (single, required)
required int32 num = 2; // Requested order book depth (>0; the actual number returned may be less than requested)
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- For the security structure, see Security
- Return
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
- See RetType for the result structure
- 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 request
Qot_GetEventContractOrderBook::Request req;
Qot_GetEventContractOrderBook::C2S *c2s = req.mutable_c2s();
Qot_Common::Security *sec = c2s->mutable_security();
sec->set_code("EC.KXODIMATCH-26JUL140600INDENG-IND");
sec->set_market(Qot_Common::QotMarket::QotMarket_EventContract);
c2s->set_num(10);
m_GetEventContractOrderBookSerialNo = m_pQotApi->GetEventContractOrderBook(req);
cout << "Request GetEventContractOrderBook SerialNo: " << m_GetEventContractOrderBookSerialNo << endl;
}
virtual void OnReply_GetEventContractOrderBook(Futu::u32_t nSerialNo, const Qot_GetEventContractOrderBook::Response &stRsp) {
if (nSerialNo == m_GetEventContractOrderBookSerialNo)
{
cout << "OnReply_GetEventContractOrderBook SerialNo: " << nSerialNo << endl;
// Parse and print the inner structure
// For the definitions of ProtoBufToBodyData and UTF8ToLocal, see tool.h in the Sample
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_GetEventContractOrderBookSerialNo;
};
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
- Output
connect
Request GetEventContractOrderBook SerialNo: 1
OnReply_GetEventContractOrderBook SerialNo: 1
{
"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
GetEventContractOrderBook(req);
Description
Get the order book of a single event contract, including YES/NO bid and ask levels.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Single contract order book
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bids
repeated OrderBookLevel yesAsks = 3; // YES asks
repeated OrderBookLevel noBids = 4; // NO bids
repeated OrderBookLevel noAsks = 5; // NO asks
}
message C2S {
required Qot_Common.Security security = 1; // Contract security (single, required)
required int32 num = 2; // Requested order book depth (>0)
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- Return
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
- See RetType for the result structure
- Example
import ftWebsocket from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
import beautify from "js-beautify";
function GetEventContractOrderBook() {
const { RetType } = 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.KXODIMATCH-26JUL140600INDENG-IND" }, num: 10 } };
let { errCode, retMsg, retType, s2c } = await websocket.GetEventContractOrderBook(req);
console.log("GetEventContractOrderBook: 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
- Output
GetEventContractOrderBook: errCode 0, retMsg , retType 0
{
"orderBookList": [{
"code": {
"market": 101,
"code": "EC.KXODIMATCH-26JUL140600INDENG-IND"
},
"yesBids": [{
"price": 0.5,
"size": 1030
}, {
"price": 0.48,
"size": 0.01
}, {
"price": 0.45,
"size": 5
}, {
"price": 0.43,
"size": 1
}, {
"price": 0.42,
"size": 175
}],
"yesAsks": [{
"price": 0.51,
"size": 2633.6
}, {
"price": 0.52,
"size": 15500
}, {
"price": 0.53,
"size": 3000
}, {
"price": 0.54,
"size": 1000
}, {
"price": 0.55,
"size": 2124
}],
"noBids": [{
"price": 0.49,
"size": 2633.6
}, {
"price": 0.48,
"size": 15500
}, {
"price": 0.47,
"size": 3000
}, {
"price": 0.46,
"size": 1000
}, {
"price": 0.45,
"size": 2124
}],
"noAsks": [{
"price": 0.5,
"size": 1030
}, {
"price": 0.52,
"size": 0.01
}, {
"price": 0.55,
"size": 5
}, {
"price": 0.57,
"size": 1
}, {
"price": 0.58,
"size": 175
}]
}]
}
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_event_contract_order_book(code, num=10)
Description
Get the order book of a single event contract, including YES/NO bid and ask levels.
Parameters
Parameter Type Description code str Event contract code, e.g. 'EC.KXODIMATCH-26JUL140600INDENG-IND'num int Requested order book depth, default 10, must be greater than 0 Return
Parameter Type Description ret RET_CODE API call result data dict When ret == RET_OK, returns order book data, containing code, yes_bids, yes_asks, no_bids, no_asks str When ret != RET_OK, returns error description The fields of the returned dict are as follows:
Field Type Description code str Contract code yes_bids list[tuple] YES bids, [(price, size), ...]yes_asks list[tuple] YES asks, [(price, size), ...]no_bids list[tuple] NO bids, [(price, size), ...]no_asks list[tuple] NO asks, [(price, size), ...]Example
from moomoo import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# Before querying the order book, you must first subscribe to ORDER_BOOK (otherwise an error is returned)
ret, err = quote_ctx.subscribe_event_contract(
['EC.KXODIMATCH-26JUL140600INDENG-IND'], [SubType.ORDER_BOOK]
)
if ret != RET_OK:
print('subscription failed:', err)
else:
ret, data = quote_ctx.get_event_contract_order_book(
'EC.KXODIMATCH-26JUL140600INDENG-IND', num=5
)
if ret == RET_OK:
print('contract:', data['code'])
print('YES bids:', data['yes_bids'])
print('YES asks:', data['yes_asks'])
print('NO bids:', data['no_bids'])
print('NO asks:', data['no_asks'])
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
24
- Output
contract: 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_GetEventContractOrderBook.proto
Description
Get the order book of a single event contract.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Single contract order book
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bids
repeated OrderBookLevel yesAsks = 3; // YES asks
repeated OrderBookLevel noBids = 4; // NO bids
repeated OrderBookLevel noAsks = 5; // NO asks
}
message C2S {
required Qot_Common.Security security = 1; // Contract security (single, required)
required int32 num = 2; // Requested order book depth (>0; the actual number returned may be less than requested)
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- For the security structure, see Security
- Return
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
- See RetType for the result structure
Protocol ID
3446
Data Type
- For the security structure, see Security
uint GetEventContractOrderBook(GetEventContractOrderBook.Request req);
virtual void OnReply_GetEventContractOrderBook(MMAPI_Conn client, uint nSerialNo, GetEventContractOrderBook.Response rsp);
Description
Get the order book of a single event contract.
Parameters
message OrderBookLevel {
required double price = 1;
required double size = 2;
}
message OrderBookItem {
required Qot_Common.Security code = 1;
repeated OrderBookLevel yesBids = 2;
repeated OrderBookLevel yesAsks = 3;
repeated OrderBookLevel noBids = 4;
repeated OrderBookLevel noAsks = 5;
}
message C2S {
required Qot_Common.Security security = 1;
required int32 num = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
- For the security structure, see Security
- Return
message S2C {
repeated OrderBookItem orderBookList = 1;
}
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
- See RetType for the result structure
- 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 = GetEventContractOrderBook.C2S.CreateBuilder()
.SetSecurity(sec).SetNum(10).Build();
var req = GetEventContractOrderBook.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetEventContractOrderBook(req);
Console.Write("Send GetEventContractOrderBook: {0}\n", seqNo);
}
public void OnReply_GetEventContractOrderBook(MMAPI_Conn client, uint nSerialNo, GetEventContractOrderBook.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
- Output
connect
Request GetEventContractOrderBook SerialNo: 1
OnReply_GetEventContractOrderBook SerialNo: 1
{
"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
int getEventContractOrderBook(QotGetEventContractOrderBook.Request req);
void onReply_GetEventContractOrderBook(MMAPI_Conn client, int nSerialNo, QotGetEventContractOrderBook.Response rsp);
Description
Get the order book of a single event contract.
Parameters
message C2S {
required Qot_Common.Security security = 1;
required int32 num = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- For the security structure, see Security
- Return
message S2C {
repeated OrderBookItem orderBookList = 1;
}
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
- See RetType for the result structure
- 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();
QotGetEventContractOrderBook.C2S c2s = QotGetEventContractOrderBook.C2S.newBuilder()
.setSecurity(sec).setNum(10).build();
QotGetEventContractOrderBook.Request req = QotGetEventContractOrderBook.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.getEventContractOrderBook(req);
System.out.println("Send GetEventContractOrderBook: " + seqNo);
}
@Override
public void onReply_GetEventContractOrderBook(MMAPI_Conn client, int nSerialNo, QotGetEventContractOrderBook.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
- Output
connect
Request GetEventContractOrderBook SerialNo: 1
OnReply_GetEventContractOrderBook SerialNo: 1
{
"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
moomoo::u32_t GetEventContractOrderBook(const Qot_GetEventContractOrderBook::Request &stReq);
virtual void OnReply_GetEventContractOrderBook(moomoo::u32_t nSerialNo, const Qot_GetEventContractOrderBook::Response &stRsp) = 0;
Description
Get the order book of a single event contract.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Single contract order book
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bids
repeated OrderBookLevel yesAsks = 3; // YES asks
repeated OrderBookLevel noBids = 4; // NO bids
repeated OrderBookLevel noAsks = 5; // NO asks
}
message C2S {
required Qot_Common.Security security = 1; // Contract security (single, required)
required int32 num = 2; // Requested order book depth (>0; the actual number returned may be less than requested)
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- For the security structure, see Security
- Return
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
- See RetType for the result structure
- 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 request
Qot_GetEventContractOrderBook::Request req;
Qot_GetEventContractOrderBook::C2S *c2s = req.mutable_c2s();
Qot_Common::Security *sec = c2s->mutable_security();
sec->set_code("EC.KXODIMATCH-26JUL140600INDENG-IND");
sec->set_market(Qot_Common::QotMarket::QotMarket_EventContract);
c2s->set_num(10);
m_GetEventContractOrderBookSerialNo = m_pQotApi->GetEventContractOrderBook(req);
cout << "Request GetEventContractOrderBook SerialNo: " << m_GetEventContractOrderBookSerialNo << endl;
}
virtual void OnReply_GetEventContractOrderBook(moomoo::u32_t nSerialNo, const Qot_GetEventContractOrderBook::Response &stRsp) {
if (nSerialNo == m_GetEventContractOrderBookSerialNo)
{
cout << "OnReply_GetEventContractOrderBook SerialNo: " << nSerialNo << endl;
// Parse and print the inner structure
// For the definitions of ProtoBufToBodyData and UTF8ToLocal, see tool.h in the Sample
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
protected:
MMAPI_Qot *m_pQotApi;
moomoo::u32_t m_GetEventContractOrderBookSerialNo;
};
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
- Output
connect
Request GetEventContractOrderBook SerialNo: 1
OnReply_GetEventContractOrderBook SerialNo: 1
{
"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
GetEventContractOrderBook(req);
Description
Get the order book of a single event contract, including YES/NO bid and ask levels.
Parameters
// Order book level
message OrderBookLevel {
required double price = 1; // Price
required double size = 2; // Size
}
// Single contract order book
message OrderBookItem {
required Qot_Common.Security code = 1; // Contract code
repeated OrderBookLevel yesBids = 2; // YES bids
repeated OrderBookLevel yesAsks = 3; // YES asks
repeated OrderBookLevel noBids = 4; // NO bids
repeated OrderBookLevel noAsks = 5; // NO asks
}
message C2S {
required Qot_Common.Security security = 1; // Contract security (single, required)
required int32 num = 2; // Requested order book depth (>0)
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- Return
message S2C {
repeated OrderBookItem orderBookList = 1; // Order book list
}
message Response {
required int32 retType = 1 [default = -400]; //RetType, result
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
- See RetType for the result structure
- Example
import mmWebsocket from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function GetEventContractOrderBook() {
const { RetType } = 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.KXODIMATCH-26JUL140600INDENG-IND" }, num: 10 } };
let { errCode, retMsg, retType, s2c } = await websocket.GetEventContractOrderBook(req);
console.log("GetEventContractOrderBook: 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
- Output
GetEventContractOrderBook: errCode 0, retMsg , retType 0
{
"orderBookList": [{
"code": {
"market": 101,
"code": "EC.KXODIMATCH-26JUL140600INDENG-IND"
},
"yesBids": [{
"price": 0.5,
"size": 1030
}, {
"price": 0.48,
"size": 0.01
}, {
"price": 0.45,
"size": 5
}, {
"price": 0.43,
"size": 1
}, {
"price": 0.42,
"size": 175
}],
"yesAsks": [{
"price": 0.51,
"size": 2633.6
}, {
"price": 0.52,
"size": 15500
}, {
"price": 0.53,
"size": 3000
}, {
"price": 0.54,
"size": 1000
}, {
"price": 0.55,
"size": 2124
}],
"noBids": [{
"price": 0.49,
"size": 2633.6
}, {
"price": 0.48,
"size": 15500
}, {
"price": 0.47,
"size": 3000
}, {
"price": 0.46,
"size": 1000
}, {
"price": 0.45,
"size": 2124
}],
"noAsks": [{
"price": 0.5,
"size": 1030
}, {
"price": 0.52,
"size": 0.01
}, {
"price": 0.55,
"size": 5
}, {
"price": 0.57,
"size": 1
}, {
"price": 0.58,
"size": 175
}]
}]
}
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74