# Get Competition Filter Options
- Python
- Proto
- C#
- Java
- C++
- JavaScript
filter_competition(category=None, tag=None)
Description
Get the competition filter options of event contracts, returning available competition name lists and all play scopes by top-level category (category) and sub-category (tag), for filtering by the competition dimension when subsequently querying Series/Event/contracts.
Parameters
Parameter Type Description category str Top-level category, e.g. 'Sports'tag str Sub-category, e.g. 'Baseball'Return
Parameter Type Description ret RET_CODE API call result data pd.DataFrame When ret == RET_OK, returns competition filter option data str When ret != RET_OK, returns error description The returned DataFrame fields are as follows:
Field Type Description category str Top-level category identifier tag str Sub-category identifier (e.g. 'Football','Soccer')competition list Competition name list (e.g. ['Pro Football', 'EPL'])scope list All available play scopes under this tag (e.g. ['Game', 'Future', 'Awards'])Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.filter_competition(category='Sports')
if ret == RET_OK:
print(data)
else:
print('error:', data)
quote_ctx.close()
2
3
4
5
6
7
8
9
- Output
category tag competition scope
0 Sports Baseball [Pro Baseball, Home Run Derby, All-Star, Japan NPB, Korea KBO] [Game, Future, Awards, Divisions, Season Milestones, Trades, Player Debut]
1 Sports Basketball [Pro Basketball (M), Pro Basketball (W), College Basketball (M), ...] [Future, Awards, Draft, Next Team, Mid-Season Cup, Game, Conference Tournament]
2 Sports Boxing [Mayweather vs Pacquiao, Alvarez vs Mbilli, Boxing, La Velada del Año VI] [Game]
...
2
3
4
5
# Qot_FilterCompetition.proto
Description
Get the competition filter options of event contracts.
Parameters
// Competition filter item
message TagFilterItem {
optional string category = 1; // Top-level category identifier ("SPORTS")
required string tag = 2; // Sub-category identifier ("Football", "Soccer")
repeated string competitionList = 3; // Competition name list ("Pro Football", "EPL")
repeated string scopeList = 4; // All available play scopes under this tag ("Game", "Future", "Awards")
}
message C2S {
optional string category = 1; // Top-level category identifier ("SPORTS")
optional string tag = 2; // Sub-category identifier ("BASEBALL")
}
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 TagFilterItem tagFilterList = 1;
}
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
- For API call result structure, refer to RetType
Protocol ID
3435
uint FilterCompetition(FilterCompetition.Request req);
virtual void OnReply_FilterCompetition(FTAPI_Conn client, uint nSerialNo, FilterCompetition.Response rsp);
Description
Get the competition filter options of event contracts.
Parameters
message TagFilterItem {
optional string category = 1;
required string tag = 2;
repeated string competitionList = 3;
repeated string scopeList = 4;
}
message C2S {
optional string category = 1;
optional string tag = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- Return
message S2C {
repeated TagFilterItem tagFilterList = 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
- For API call result structure, refer to 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;
var c2s = FilterCompetition.C2S.CreateBuilder()
.SetCategory("Sports").Build();
var req = FilterCompetition.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.FilterCompetition(req);
Console.Write("Send FilterCompetition: {0}\n", seqNo);
}
public void OnReply_FilterCompetition(FTAPI_Conn client, uint nSerialNo, FilterCompetition.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
- Output
connect
Request FilterCompetition SerialNo: 1
OnReply_FilterCompetition SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"tagFilterList": [
{
"category": "SPORTS",
"tag": "FOOTBALL",
"competitionList": ["Pro Football", "EPL"],
"scopeList": ["Game", "Future", "Awards"]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int filterCompetition(QotFilterCompetition.Request req);
void onReply_FilterCompetition(FTAPI_Conn client, int nSerialNo, QotFilterCompetition.Response rsp);
Description
Get the competition filter options of event contracts.
Parameters
message C2S {
optional string category = 1;
optional string tag = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- Return
message S2C {
repeated TagFilterItem tagFilterList = 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
- For API call result structure, refer to 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;
QotFilterCompetition.C2S c2s = QotFilterCompetition.C2S.newBuilder()
.setCategory("Sports").build();
QotFilterCompetition.Request req = QotFilterCompetition.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.filterCompetition(req);
System.out.println("Send FilterCompetition: " + seqNo);
}
@Override
public void onReply_FilterCompetition(FTAPI_Conn client, int nSerialNo, QotFilterCompetition.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
- Output
connect
Request FilterCompetition SerialNo: 1
OnReply_FilterCompetition SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"tagFilterList": [
{
"category": "SPORTS",
"tag": "FOOTBALL",
"competitionList": ["Pro Football", "EPL"],
"scopeList": ["Game", "Future", "Awards"]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Futu::u32_t FilterCompetition(const Qot_FilterCompetition::Request &stReq);
virtual void OnReply_FilterCompetition(Futu::u32_t nSerialNo, const Qot_FilterCompetition::Response &stRsp) = 0;
Description
Get the competition filter options of event contracts.
Parameters
// Competition filter item
message TagFilterItem {
optional string category = 1; // Top-level category identifier ("SPORTS")
required string tag = 2; // Sub-category identifier ("Football", "Soccer")
repeated string competitionList = 3; // Competition name list ("Pro Football", "EPL")
repeated string scopeList = 4; // All available play scopes under this tag ("Game", "Future", "Awards")
}
message C2S {
optional string category = 1; // Top-level category identifier ("SPORTS")
optional string tag = 2; // Sub-category identifier ("BASEBALL")
}
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 TagFilterItem tagFilterList = 1;
}
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
- For API call result structure, refer to RetType
- Example
class Program : public FTSPI_Qot, public FTSPI_Trd, public FTSPI_Conn
{
public:
Program() {
m_pQotApi = FTAPI::CreateQotApi();
m_pQotApi->RegisterQotSpi(this);
m_pQotApi->RegisterConnSpi(this);
}
~Program() {
if (m_pQotApi != nullptr)
{
m_pQotApi->UnregisterQotSpi();
m_pQotApi->UnregisterConnSpi();
FTAPI::ReleaseQotApi(m_pQotApi);
m_pQotApi = nullptr;
}
}
void Start() {
m_pQotApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(FTAPI_Conn* pConn, Futu::i64_t nErrCode, const char* strDesc) {
cout << "connect" << endl;
// Build request
Qot_FilterCompetition::Request req;
Qot_FilterCompetition::C2S *c2s = req.mutable_c2s();
c2s->set_category("Sports");
m_FilterCompetitionSerialNo = m_pQotApi->FilterCompetition(req);
cout << "Request FilterCompetition SerialNo: " << m_FilterCompetitionSerialNo << endl;
}
virtual void OnReply_FilterCompetition(Futu::u32_t nSerialNo, const Qot_FilterCompetition::Response &stRsp) {
if (nSerialNo == m_FilterCompetitionSerialNo)
{
cout << "OnReply_FilterCompetition SerialNo: " << nSerialNo << endl;
// Parse and print the internal structure
// For the definitions of ProtoBufToBodyData and UTF8ToLocal, see tool.h in Samples
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_FilterCompetitionSerialNo;
};
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
- Output
connect
Request FilterCompetition SerialNo: 1
OnReply_FilterCompetition SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"tagFilterList": [
{
"category": "Sports",
"tag": "Baseball",
"competitionList": ["Pro Baseball", "Home Run Derby", "All-Star", "Japan NPB", "Korea KBO"],
"scopeList": ["Game", "Future", "Awards", "Divisions", "Season Milestones", "Trades", "Player Debut"]
},
{
"category": "Sports",
"tag": "Basketball",
"competitionList": ["Pro Basketball (M)", "Pro Basketball (W)", "College Basketball (M)", "..."],
"scopeList": ["Future", "Awards", "Draft", "Next Team", "Mid-Season Cup", "Game", "Conference Tournament"]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
FilterCompetition(req);
Description
Get the competition filter options of event contracts, returning competition names and all play scopes under each sub-category.
Parameters
// Competition filter item
message TagFilterItem {
optional string category = 1; // Top-level category identifier ("SPORTS")
required string tag = 2; // Sub-category identifier ("Football", "Soccer")
repeated string competitionList = 3; // Competition name list ("Pro Football", "EPL")
repeated string scopeList = 4; // All available play scopes under this tag ("Game", "Future", "Awards")
}
message C2S {
optional string category = 1; // Top-level category identifier ("SPORTS")
optional string tag = 2; // Sub-category identifier ("BASEBALL")
}
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 TagFilterItem tagFilterList = 1; // Filter item 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
- For API call result structure, refer to RetType
- Example
import ftWebsocket from "futu-api";
import { Common } from "futu-api/proto";
import beautify from "js-beautify";
function FilterCompetition() {
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: { category: "Sports" } };
let { errCode, retMsg, retType, s2c } = await websocket.FilterCompetition(req);
console.log("FilterCompetition: 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
FilterCompetition: errCode 0, retMsg , retType 0
{
"tagFilterList": [{
"category": "Sports",
"tag": "Baseball",
"competitionList": ["Pro Baseball", "Home Run Derby", "All-Star", "Japan NPB", "Korea KBO"],
"scopeList": ["Game", "Future", "Awards", "Divisions", "Season Milestones", "Trades", "Player Debut"]
}, {
"category": "Sports",
"tag": "Basketball",
"competitionList": ["Pro Basketball (M)", "Pro Basketball (W)", "College Basketball (M)", "..."],
"scopeList": ["Future", "Awards", "Draft", "Next Team", "Mid-Season Cup", "Game", "Conference Tournament"]
}]
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Interface Limitations
- A maximum of 10 requests per 30 seconds for the competition filter options interface
- Python
- Proto
- C#
- Java
- C++
- JavaScript
filter_competition(category=None, tag=None)
Description
Get the competition filter options of event contracts, returning available competition name lists and all play scopes by top-level category (category) and sub-category (tag), for filtering by the competition dimension when subsequently querying Series/Event/contracts.
Parameters
Parameter Type Description category str Top-level category, e.g. 'Sports'tag str Sub-category, e.g. 'Baseball'Return
Parameter Type Description ret RET_CODE API call result data pd.DataFrame When ret == RET_OK, returns competition filter option data str When ret != RET_OK, returns error description The returned DataFrame fields are as follows:
Field Type Description category str Top-level category identifier tag str Sub-category identifier (e.g. 'Football','Soccer')competition list Competition name list (e.g. ['Pro Football', 'EPL'])scope list All available play scopes under this tag (e.g. ['Game', 'Future', 'Awards'])Example
from moomoo import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.filter_competition(category='Sports')
if ret == RET_OK:
print(data)
else:
print('error:', data)
quote_ctx.close()
2
3
4
5
6
7
8
9
- Output
category tag competition scope
0 Sports Baseball [Pro Baseball, Home Run Derby, All-Star, Japan NPB, Korea KBO] [Game, Future, Awards, Divisions, Season Milestones, Trades, Player Debut]
1 Sports Basketball [Pro Basketball (M), Pro Basketball (W), College Basketball (M), ...] [Future, Awards, Draft, Next Team, Mid-Season Cup, Game, Conference Tournament]
2 Sports Boxing [Mayweather vs Pacquiao, Alvarez vs Mbilli, Boxing, La Velada del Año VI] [Game]
...
2
3
4
5
# Qot_FilterCompetition.proto
Description
Get the competition filter options of event contracts.
Parameters
// Competition filter item
message TagFilterItem {
optional string category = 1; // Top-level category identifier ("SPORTS")
required string tag = 2; // Sub-category identifier ("Football", "Soccer")
repeated string competitionList = 3; // Competition name list ("Pro Football", "EPL")
repeated string scopeList = 4; // All available play scopes under this tag ("Game", "Future", "Awards")
}
message C2S {
optional string category = 1; // Top-level category identifier ("SPORTS")
optional string tag = 2; // Sub-category identifier ("BASEBALL")
}
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 TagFilterItem tagFilterList = 1;
}
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
- For API call result structure, refer to RetType
Protocol ID
3435
uint FilterCompetition(FilterCompetition.Request req);
virtual void OnReply_FilterCompetition(MMAPI_Conn client, uint nSerialNo, FilterCompetition.Response rsp);
Description
Get the competition filter options of event contracts.
Parameters
message TagFilterItem {
optional string category = 1;
required string tag = 2;
repeated string competitionList = 3;
repeated string scopeList = 4;
}
message C2S {
optional string category = 1;
optional string tag = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- Return
message S2C {
repeated TagFilterItem tagFilterList = 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
- For API call result structure, refer to 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;
var c2s = FilterCompetition.C2S.CreateBuilder()
.SetCategory("Sports").Build();
var req = FilterCompetition.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.FilterCompetition(req);
Console.Write("Send FilterCompetition: {0}\n", seqNo);
}
public void OnReply_FilterCompetition(MMAPI_Conn client, uint nSerialNo, FilterCompetition.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
- Output
connect
Request FilterCompetition SerialNo: 1
OnReply_FilterCompetition SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"tagFilterList": [
{
"category": "SPORTS",
"tag": "FOOTBALL",
"competitionList": ["Pro Football", "EPL"],
"scopeList": ["Game", "Future", "Awards"]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int filterCompetition(QotFilterCompetition.Request req);
void onReply_FilterCompetition(MMAPI_Conn client, int nSerialNo, QotFilterCompetition.Response rsp);
Description
Get the competition filter options of event contracts.
Parameters
message C2S {
optional string category = 1;
optional string tag = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- Return
message S2C {
repeated TagFilterItem tagFilterList = 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
- For API call result structure, refer to 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;
QotFilterCompetition.C2S c2s = QotFilterCompetition.C2S.newBuilder()
.setCategory("Sports").build();
QotFilterCompetition.Request req = QotFilterCompetition.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.filterCompetition(req);
System.out.println("Send FilterCompetition: " + seqNo);
}
@Override
public void onReply_FilterCompetition(MMAPI_Conn client, int nSerialNo, QotFilterCompetition.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
- Output
connect
Request FilterCompetition SerialNo: 1
OnReply_FilterCompetition SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"tagFilterList": [
{
"category": "SPORTS",
"tag": "FOOTBALL",
"competitionList": ["Pro Football", "EPL"],
"scopeList": ["Game", "Future", "Awards"]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
moomoo::u32_t FilterCompetition(const Qot_FilterCompetition::Request &stReq);
virtual void OnReply_FilterCompetition(moomoo::u32_t nSerialNo, const Qot_FilterCompetition::Response &stRsp) = 0;
Description
Get the competition filter options of event contracts.
Parameters
// Competition filter item
message TagFilterItem {
optional string category = 1; // Top-level category identifier ("SPORTS")
required string tag = 2; // Sub-category identifier ("Football", "Soccer")
repeated string competitionList = 3; // Competition name list ("Pro Football", "EPL")
repeated string scopeList = 4; // All available play scopes under this tag ("Game", "Future", "Awards")
}
message C2S {
optional string category = 1; // Top-level category identifier ("SPORTS")
optional string tag = 2; // Sub-category identifier ("BASEBALL")
}
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 TagFilterItem tagFilterList = 1;
}
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
- For API call result structure, refer to RetType
- Example
class Program : public MMSPI_Qot, public MMSPI_Trd, public MMSPI_Conn
{
public:
Program() {
m_pQotApi = MMAPI::CreateQotApi();
m_pQotApi->RegisterQotSpi(this);
m_pQotApi->RegisterConnSpi(this);
}
~Program() {
if (m_pQotApi != nullptr)
{
m_pQotApi->UnregisterQotSpi();
m_pQotApi->UnregisterConnSpi();
MMAPI::ReleaseQotApi(m_pQotApi);
m_pQotApi = nullptr;
}
}
void Start() {
m_pQotApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(MMAPI_Conn* pConn, moomoo::i64_t nErrCode, const char* strDesc) {
cout << "connect" << endl;
// Build request
Qot_FilterCompetition::Request req;
Qot_FilterCompetition::C2S *c2s = req.mutable_c2s();
c2s->set_category("Sports");
m_FilterCompetitionSerialNo = m_pQotApi->FilterCompetition(req);
cout << "Request FilterCompetition SerialNo: " << m_FilterCompetitionSerialNo << endl;
}
virtual void OnReply_FilterCompetition(moomoo::u32_t nSerialNo, const Qot_FilterCompetition::Response &stRsp) {
if (nSerialNo == m_FilterCompetitionSerialNo)
{
cout << "OnReply_FilterCompetition SerialNo: " << nSerialNo << endl;
// Parse and print the internal structure
// For the definitions of ProtoBufToBodyData and UTF8ToLocal, see tool.h in Samples
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
protected:
MMAPI_Qot *m_pQotApi;
moomoo::u32_t m_FilterCompetitionSerialNo;
};
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
- Output
connect
Request FilterCompetition SerialNo: 1
OnReply_FilterCompetition SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"tagFilterList": [
{
"category": "Sports",
"tag": "Baseball",
"competitionList": ["Pro Baseball", "Home Run Derby", "All-Star", "Japan NPB", "Korea KBO"],
"scopeList": ["Game", "Future", "Awards", "Divisions", "Season Milestones", "Trades", "Player Debut"]
},
{
"category": "Sports",
"tag": "Basketball",
"competitionList": ["Pro Basketball (M)", "Pro Basketball (W)", "College Basketball (M)", "..."],
"scopeList": ["Future", "Awards", "Draft", "Next Team", "Mid-Season Cup", "Game", "Conference Tournament"]
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
FilterCompetition(req);
Description
Get the competition filter options of event contracts, returning competition names and all play scopes under each sub-category.
Parameters
// Competition filter item
message TagFilterItem {
optional string category = 1; // Top-level category identifier ("SPORTS")
required string tag = 2; // Sub-category identifier ("Football", "Soccer")
repeated string competitionList = 3; // Competition name list ("Pro Football", "EPL")
repeated string scopeList = 4; // All available play scopes under this tag ("Game", "Future", "Awards")
}
message C2S {
optional string category = 1; // Top-level category identifier ("SPORTS")
optional string tag = 2; // Sub-category identifier ("BASEBALL")
}
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 TagFilterItem tagFilterList = 1; // Filter item 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
- For API call result structure, refer to RetType
- Example
import mmWebsocket from "moomoo-api";
import { Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function FilterCompetition() {
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: { category: "Sports" } };
let { errCode, retMsg, retType, s2c } = await websocket.FilterCompetition(req);
console.log("FilterCompetition: 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
FilterCompetition: errCode 0, retMsg , retType 0
{
"tagFilterList": [{
"category": "Sports",
"tag": "Baseball",
"competitionList": ["Pro Baseball", "Home Run Derby", "All-Star", "Japan NPB", "Korea KBO"],
"scopeList": ["Game", "Future", "Awards", "Divisions", "Season Milestones", "Trades", "Player Debut"]
}, {
"category": "Sports",
"tag": "Basketball",
"competitionList": ["Pro Basketball (M)", "Pro Basketball (W)", "College Basketball (M)", "..."],
"scopeList": ["Future", "Awards", "Draft", "Next Team", "Mid-Season Cup", "Game", "Conference Tournament"]
}]
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Interface Limitations
- A maximum of 10 requests per 30 seconds for the competition filter options interface