# 获取赛事筛选选项
- Python
- Proto
- C#
- Java
- C++
- JavaScript
filter_competition(category=None, tag=None)
介绍
获取事件合约的赛事筛选选项,按一级分类(category)与二级分类(tag)返回可用赛事名称列表与玩法全集,用于后续查询 Series/Event/合约时的赛事维度过滤。
参数
参数 类型 说明 category str 一级分类,如 'Sports'tag str 二级分类,如 'Baseball'返回
参数 类型 说明 ret RET_CODE 接口调用结果 data pd.DataFrame 当 ret == RET_OK,返回赛事筛选项数据 str 当 ret != RET_OK,返回错误描述 返回的 DataFrame 字段如下:
字段 类型 说明 category str 一级分类标识 tag str 二级分类标识(如 'Football'、'Soccer')competition list 赛事名称列表(如 ['Pro Football', 'EPL'])scope list 该标签下所有可用玩法全集(如 ['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
介绍
获取事件合约的赛事筛选选项。
参数
// 赛事筛选项
message TagFilterItem {
optional string category = 1; // 一级分类标识 ("SPORTS")
required string tag = 2; // 二级分类标识 ("Football", "Soccer")
repeated string competitionList = 3; // 赛事名称列表 ("Pro Football", "EPL")
repeated string scopeList = 4; // 该标签下所有available玩法全集 ("Game", "Future", "Awards")
}
message C2S {
optional string category = 1; // 一级分类标识 ("SPORTS")
optional string tag = 2; // 二级分类标识 ("BASEBALL")
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 返回
message S2C {
repeated TagFilterItem tagFilterList = 1;
}
message Response {
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
- 接口调用结果,结构参见 RetType
协议 ID
3435
uint FilterCompetition(FilterCompetition.Request req);
virtual void OnReply_FilterCompetition(FTAPI_Conn client, uint nSerialNo, FilterCompetition.Response rsp);
介绍
获取事件合约的赛事筛选选项。
参数
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
- 返回
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
- 接口调用结果,结构参见 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);
介绍
获取事件合约的赛事筛选选项。
参数
message C2S {
optional string category = 1;
optional string tag = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- 返回
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
- 接口调用结果,结构参见 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;
介绍
获取事件合约的赛事筛选选项。
参数
// 赛事筛选项
message TagFilterItem {
optional string category = 1; // 一级分类标识 ("SPORTS")
required string tag = 2; // 二级分类标识 ("Football", "Soccer")
repeated string competitionList = 3; // 赛事名称列表 ("Pro Football", "EPL")
repeated string scopeList = 4; // 该标签下所有available玩法全集 ("Game", "Future", "Awards")
}
message C2S {
optional string category = 1; // 一级分类标识 ("SPORTS")
optional string tag = 2; // 二级分类标识 ("BASEBALL")
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 返回
message S2C {
repeated TagFilterItem tagFilterList = 1;
}
message Response {
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
- 接口调用结果,结构参见 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;
// 组包
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;
// 解析内部结构打印出来
// ProtoBufToBodyData和UTF8ToLocal函数的定义参见Sample中的tool.h文件
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);
介绍
获取事件合约的赛事筛选选项,返回各二级分类下的赛事名称与玩法全集。
参数
// 赛事筛选项
message TagFilterItem {
optional string category = 1; // 一级分类标识 ("SPORTS")
required string tag = 2; // 二级分类标识 ("Football", "Soccer")
repeated string competitionList = 3; // 赛事名称列表 ("Pro Football", "EPL")
repeated string scopeList = 4; // 该标签下所有可用玩法全集 ("Game", "Future", "Awards")
}
message C2S {
optional string category = 1; // 一级分类标识 ("SPORTS")
optional string tag = 2; // 二级分类标识 ("BASEBALL")
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 返回
message S2C {
repeated TagFilterItem tagFilterList = 1; // 筛选项列表
}
message Response {
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
- 接口调用结果,结构参见 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
接口限制
- 每 30 秒内最多请求 10 次获取赛事筛选选项接口
- Python
- Proto
- C#
- Java
- C++
- JavaScript
filter_competition(category=None, tag=None)
介绍
获取事件合约的赛事筛选选项,按一级分类(category)与二级分类(tag)返回可用赛事名称列表与玩法全集,用于后续查询 Series/Event/合约时的赛事维度过滤。
参数
参数 类型 说明 category str 一级分类,如 'Sports'tag str 二级分类,如 'Baseball'返回
参数 类型 说明 ret RET_CODE 接口调用结果 data pd.DataFrame 当 ret == RET_OK,返回赛事筛选项数据 str 当 ret != RET_OK,返回错误描述 返回的 DataFrame 字段如下:
字段 类型 说明 category str 一级分类标识 tag str 二级分类标识(如 'Football'、'Soccer')competition list 赛事名称列表(如 ['Pro Football', 'EPL'])scope list 该标签下所有可用玩法全集(如 ['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
介绍
获取事件合约的赛事筛选选项。
参数
// 赛事筛选项
message TagFilterItem {
optional string category = 1; // 一级分类标识 ("SPORTS")
required string tag = 2; // 二级分类标识 ("Football", "Soccer")
repeated string competitionList = 3; // 赛事名称列表 ("Pro Football", "EPL")
repeated string scopeList = 4; // 该标签下所有available玩法全集 ("Game", "Future", "Awards")
}
message C2S {
optional string category = 1; // 一级分类标识 ("SPORTS")
optional string tag = 2; // 二级分类标识 ("BASEBALL")
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 返回
message S2C {
repeated TagFilterItem tagFilterList = 1;
}
message Response {
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
- 接口调用结果,结构参见 RetType
协议 ID
3435
uint FilterCompetition(FilterCompetition.Request req);
virtual void OnReply_FilterCompetition(MMAPI_Conn client, uint nSerialNo, FilterCompetition.Response rsp);
介绍
获取事件合约的赛事筛选选项。
参数
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
- 返回
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
- 接口调用结果,结构参见 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);
介绍
获取事件合约的赛事筛选选项。
参数
message C2S {
optional string category = 1;
optional string tag = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- 返回
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
- 接口调用结果,结构参见 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;
介绍
获取事件合约的赛事筛选选项。
参数
// 赛事筛选项
message TagFilterItem {
optional string category = 1; // 一级分类标识 ("SPORTS")
required string tag = 2; // 二级分类标识 ("Football", "Soccer")
repeated string competitionList = 3; // 赛事名称列表 ("Pro Football", "EPL")
repeated string scopeList = 4; // 该标签下所有available玩法全集 ("Game", "Future", "Awards")
}
message C2S {
optional string category = 1; // 一级分类标识 ("SPORTS")
optional string tag = 2; // 二级分类标识 ("BASEBALL")
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 返回
message S2C {
repeated TagFilterItem tagFilterList = 1;
}
message Response {
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
- 接口调用结果,结构参见 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;
// 组包
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;
// 解析内部结构打印出来
// ProtoBufToBodyData和UTF8ToLocal函数的定义参见Sample中的tool.h文件
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);
介绍
获取事件合约的赛事筛选选项,返回各二级分类下的赛事名称与玩法全集。
参数
// 赛事筛选项
message TagFilterItem {
optional string category = 1; // 一级分类标识 ("SPORTS")
required string tag = 2; // 二级分类标识 ("Football", "Soccer")
repeated string competitionList = 3; // 赛事名称列表 ("Pro Football", "EPL")
repeated string scopeList = 4; // 该标签下所有可用玩法全集 ("Game", "Future", "Awards")
}
message C2S {
optional string category = 1; // 一级分类标识 ("SPORTS")
optional string tag = 2; // 二级分类标识 ("BASEBALL")
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- 返回
message S2C {
repeated TagFilterItem tagFilterList = 1; // 筛选项列表
}
message Response {
required int32 retType = 1 [default = -400]; //RetType,返回结果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
- 接口调用结果,结构参见 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
接口限制
- 每 30 秒内最多请求 10 次获取赛事筛选选项接口
← 拉取事件合约历史K线 获取事件合约分类 →