# 事件合约Combo询价
- Python
- Proto
- C#
- Java
- C++
- JavaScript
request_combo_quotes(combo_leg_list, mvc)
介绍
提交用户组合的合约腿(
ComboLeg列表)与 MVC 标的,对组合合约进行询价,返回该组合的买卖价(bid/ask)与报价 ID(下单时使用)。参数
参数 类型 说明 combo_leg_list ComboLeg 腿列表,元素须为 ComboLeg对象,非空mvc str MVC 标的,从 get_valid_combo_list返回值透传ComboLeg数据类字段:字段 类型 说明 code str 合约代码,格式 MARKET.codetrd_side TrdSide 枚举 交易方向(BUY/SELL/SELL_SHORT/BUY_BACK) qty_ratio float 数量比例 position_id int 持仓 ID(仅 moomoo JP 平仓时使用) pred_side PredSide 枚举 事件合约预测方向(YES/NO),必填 返回
参数 类型 说明 ret RET_CODE 接口调用结果 data dict 当 ret == RET_OK,返回询价结果 str 当 ret != RET_OK,返回错误描述 返回的 dict 字段如下:
字段 类型 说明 combo_leg_list list[ComboLeg] 回显腿列表( ComboLeg对象列表)bid_price float YES 买价,无对应报价时为 N/Aask_price float YES 卖价 quote_id str 报价 ID,下单时需使用 should_retry bool 是否建议重试( True代表可尝试重新询价),无对应报价时为N/AExample
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# 1. 先获取可 Combo 事件与 mvc
ret, combo_data, mvc, _ = quote_ctx.get_valid_combo_list(category='Sports', count=1)
if ret != RET_OK:
print('获取 combo 列表失败:', combo_data)
quote_ctx.close()
exit()
# 2. 构造腿并询价(两条腿可来自不同 event,pred_side 必填)
leg1 = ComboLeg()
leg1.code = 'EC.KXWCADVANCE-26JUL14FRAESP-FRA'
leg1.trd_side = TrdSide.BUY
leg1.qty_ratio = 1
leg1.pred_side = PredSide.YES
leg2 = ComboLeg()
leg2.code = 'EC.KXWCADVANCE-26JUL15ENGARG-ENG'
leg2.trd_side = TrdSide.BUY
leg2.qty_ratio = 1
leg2.pred_side = PredSide.YES
ret, data = quote_ctx.request_combo_quotes([leg1, leg2], mvc)
if ret == RET_OK:
print('bid:', data['bid_price'], 'ask:', data['ask_price'])
print('quote_id:', data['quote_id'])
print('should_retry:', data['should_retry'])
for leg in data['combo_leg_list']:
print(' leg:', repr(leg))
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
25
26
27
28
29
30
31
32
33
34
- Output
bid: N/A ask: 0.333
quote_id: 3fb44348-83e6-4179-a34a-efb09d7b80e6
should_retry: N/A
leg: ComboLeg(code=EC.KXWCADVANCE-26JUL14FRAESP-FRA, trd_side=BUY, qty_ratio=1.0, pred_side=YES)
leg: ComboLeg(code=EC.KXWCADVANCE-26JUL15ENGARG-ENG, trd_side=BUY, qty_ratio=1.0, pred_side=YES)
2
3
4
5
# Qot_GetEventContractComboRfq.proto
介绍
提交用户组合的合约腿(
ComboLeg列表)与 MVC 标的,对组合合约进行询价。参数
// 组合腿
message ComboLeg
{
required Qot_Common.Security security = 1; // 合约代码
optional int32 side = 2; // 交易方向,取值见 Trd_Common.TrdSide
optional double qtyRatio = 3; // 数量比例
optional uint64 positionID = 4; // 持仓 ID,仅 moomoo JP 平仓时使用
optional int32 predSide = 5; // 事件合约预测方向,取值见 Common.PredSide
}
message C2S {
repeated Qot_Common.ComboLeg comboLegList = 1; // 腿列表(用户组合的合约 + 方向)
required string mvc = 2; // MVC 标的,格式 exchange.origin_symbol(从 combo 列表接口透传)
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- 组合腿结构参见 ComboLeg
- 返回
message S2C {
repeated Qot_Common.ComboLeg comboLegList = 1; // 回显腿列表
optional double bidPrice = 2; // yes 买价
optional double askPrice = 3; // yes 卖价
optional string quoteId = 4; // 报价 ID(下单接口需用到)
optional bool shouldRetry = 5; // 是否建议重试(true 代表可尝试重新询价)
}
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
11
12
13
14
协议 ID
3454
数据类型
- 组合腿结构参见 ComboLeg
uint GetEventContractComboRfq(GetEventContractComboRfq.Request req);
virtual void OnReply_GetEventContractComboRfq(FTAPI_Conn client, uint nSerialNo, GetEventContractComboRfq.Response rsp);
介绍
提交用户组合的合约腿(
ComboLeg列表)与 MVC 标的,对组合合约进行询价。参数
message C2S {
repeated Qot_Common.ComboLeg comboLegList = 1;
required string mvc = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- 组合腿结构参见 ComboLeg
- 返回
message S2C {
repeated Qot_Common.ComboLeg comboLegList = 1;
optional double bidPrice = 2;
optional double askPrice = 3;
optional string quoteId = 4;
optional bool shouldRetry = 5;
}
message Response {
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
- Example
public class Program : FTSPI_Qot, FTSPI_Conn
{
FTAPI_Qot qot = new FTAPI_Qot();
public Program()
{
qot.SetClientInfo("csharp", 1);
qot.SetConnCallback(this);
qot.SetQotCallback(this);
}
public void Start()
{
qot.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(FTAPI_Conn client, long errCode, String desc)
{
if (errCode != 0) return;
QotCommon.Security sec1 = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_EventContract)
.SetCode("EC.KXWCADVANCE-26JUL14FRAESP-FRA").Build();
QotCommon.ComboLeg leg1 = QotCommon.ComboLeg.CreateBuilder()
.SetSecurity(sec1).SetSide(1).SetPredSide(1).Build();
QotCommon.Security sec2 = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_EventContract)
.SetCode("EC.KXWCADVANCE-26JUL15ENGARG-ENG").Build();
QotCommon.ComboLeg leg2 = QotCommon.ComboLeg.CreateBuilder()
.SetSecurity(sec2).SetSide(1).SetPredSide(1).Build();
var c2s = GetEventContractComboRfq.C2S.CreateBuilder()
.AddComboLeg(leg1).AddComboLeg(leg2)
.SetMvc("KALSHI.KXMVECROSSCATEGORY-R").Build();
var req = GetEventContractComboRfq.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetEventContractComboRfq(req);
Console.Write("Send GetEventContractComboRfq: {0}\n", seqNo);
}
public void OnReply_GetEventContractComboRfq(FTAPI_Conn client, uint nSerialNo, GetEventContractComboRfq.Response rsp)
{
Console.Write("Reply: {0} {1}\n", nSerialNo, rsp.ToString());
}
public static void Main(String[] args)
{
FTAPI.Init();
new Program().Start();
while (true) Thread.Sleep(1000 * 600);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
- Output
connect
Request GetEventContractComboRfq SerialNo: 1
OnReply_GetEventContractComboRfq SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"comboLegList": [
{"security": {"market": 101, "code": "EC.xxx"}, "predSide": 1}
],
"bidPrice": 0.54,
"askPrice": 0.56,
"quoteId": "Q-20260713-0001",
"shouldRetry": false
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int getEventContractComboRfq(QotGetEventContractComboRfq.Request req);
void onReply_GetEventContractComboRfq(FTAPI_Conn client, int nSerialNo, QotGetEventContractComboRfq.Response rsp);
介绍
提交用户组合的合约腿(
ComboLeg列表)与 MVC 标的,对组合合约进行询价。参数
message C2S {
repeated Qot_Common.ComboLeg comboLegList = 1;
required string mvc = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- 组合腿结构参见 ComboLeg
- 返回
message S2C {
repeated Qot_Common.ComboLeg comboLegList = 1;
optional double bidPrice = 2;
optional double askPrice = 3;
optional string quoteId = 4;
optional bool shouldRetry = 5;
}
message Response {
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
- Example
public class Program implements FTSPI_Qot, FTSPI_Conn {
private FTAPI_Conn_Qot qot = new FTAPI_Conn_Qot();
public Program() {
qot.setClientInfo("java", 1);
qot.setConnCallback(this);
qot.setQotCallback(this);
}
public void start() {
qot.initConnect("127.0.0.1", (short) 11111, false);
}
@Override
public void onInitConnect(FTAPI_Conn client, long errCode, String desc) {
if (errCode != 0) return;
QotCommon.Security sec1 = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_EventContract_VALUE)
.setCode("EC.KXWCADVANCE-26JUL14FRAESP-FRA").build();
QotCommon.ComboLeg leg1 = QotCommon.ComboLeg.newBuilder()
.setSecurity(sec1).setSide(1).setPredSide(1).build();
QotCommon.Security sec2 = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_EventContract_VALUE)
.setCode("EC.KXWCADVANCE-26JUL15ENGARG-ENG").build();
QotCommon.ComboLeg leg2 = QotCommon.ComboLeg.newBuilder()
.setSecurity(sec2).setSide(1).setPredSide(1).build();
QotGetEventContractComboRfq.C2S c2s = QotGetEventContractComboRfq.C2S.newBuilder()
.addComboLeg(leg1).addComboLeg(leg2)
.setMvc("KALSHI.KXMVECROSSCATEGORY-R").build();
QotGetEventContractComboRfq.Request req = QotGetEventContractComboRfq.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.getEventContractComboRfq(req);
System.out.println("Send GetEventContractComboRfq: " + seqNo);
}
@Override
public void onReply_GetEventContractComboRfq(FTAPI_Conn client, int nSerialNo, QotGetEventContractComboRfq.Response rsp) {
System.out.println("Reply: " + nSerialNo + " " + rsp.toString());
}
public static void main(String[] args) {
FTAPI.init();
new Program().start();
while (true) {
try { Thread.sleep(1000 * 600); } catch (InterruptedException e) {}
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
- Output
connect
Request GetEventContractComboRfq SerialNo: 1
OnReply_GetEventContractComboRfq SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"comboLegList": [
{"security": {"market": 101, "code": "EC.xxx"}, "predSide": 1}
],
"bidPrice": 0.54,
"askPrice": 0.56,
"quoteId": "Q-20260713-0001",
"shouldRetry": false
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Futu::u32_t GetEventContractComboRfq(const Qot_GetEventContractComboRfq::Request &stReq);
virtual void OnReply_GetEventContractComboRfq(Futu::u32_t nSerialNo, const Qot_GetEventContractComboRfq::Response &stRsp) = 0;
介绍
提交用户组合的合约腿(
ComboLeg列表)与 MVC 标的,对组合合约进行询价。参数
message C2S {
repeated Qot_Common.ComboLeg comboLegList = 1; // 腿列表(用户组合的合约 + 方向)
required string mvc = 2; // MVC 标的,格式 exchange.origin_symbol(从 combo 列表接口透传)
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- 组合腿结构参见 ComboLeg
- 返回
message S2C {
repeated Qot_Common.ComboLeg comboLegList = 1; // 回显腿列表
optional double bidPrice = 2; // yes 买价
optional double askPrice = 3; // yes 卖价
optional string quoteId = 4; // 报价 ID(下单接口需用到)
optional bool shouldRetry = 5; // 是否建议重试(true 代表可尝试重新询价)
}
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
11
12
13
14
- 接口调用结果,结构参见 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_GetEventContractComboRfq::Request req;
Qot_GetEventContractComboRfq::C2S *c2s = req.mutable_c2s();
// 第一条腿
Qot_Common::ComboLeg *leg1 = c2s->add_comboleg();
Qot_Common::Security *sec1 = leg1->mutable_security();
sec1->set_code("EC.KXWCADVANCE-26JUL14FRAESP-FRA");
sec1->set_market(Qot_Common::QotMarket::QotMarket_EventContract);
leg1->set_side(1); // BUY
leg1->set_predside(1); // YES
// 第二条腿
Qot_Common::ComboLeg *leg2 = c2s->add_comboleg();
Qot_Common::Security *sec2 = leg2->mutable_security();
sec2->set_code("EC.KXWCADVANCE-26JUL15ENGARG-ENG");
sec2->set_market(Qot_Common::QotMarket::QotMarket_EventContract);
leg2->set_side(1); // BUY
leg2->set_predside(1); // YES
c2s->set_mvc("KALSHI.KXMVECROSSCATEGORY-R");
m_GetEventContractComboRfqSerialNo = m_pQotApi->GetEventContractComboRfq(req);
cout << "Request GetEventContractComboRfq SerialNo: " << m_GetEventContractComboRfqSerialNo << endl;
}
virtual void OnReply_GetEventContractComboRfq(Futu::u32_t nSerialNo, const Qot_GetEventContractComboRfq::Response &stRsp) {
if (nSerialNo == m_GetEventContractComboRfqSerialNo)
{
cout << "OnReply_GetEventContractComboRfq 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_GetEventContractComboRfqSerialNo;
};
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
82
- Output
connect
Request GetEventContractComboRfq SerialNo: 1
OnReply_GetEventContractComboRfq SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"comboLegList": [
{"security": {"market": 101, "code": "EC.KXWCADVANCE-26JUL14FRAESP-FRA"}, "side": 1, "predSide": 1},
{"security": {"market": 101, "code": "EC.KXWCADVANCE-26JUL15ENGARG-ENG"}, "side": 1, "predSide": 1}
],
"bidPrice": null,
"askPrice": 0.333,
"quoteId": "3fb44348-83e6-4179-a34a-efb09d7b80e6",
"shouldRetry": null
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
GetEventContractComboRfq(req);
介绍
提交用户组合的合约腿(
ComboLeg列表)与 MVC 标的,对组合合约进行询价,返回买卖价与报价 ID。参数
message C2S {
repeated Qot_Common.ComboLeg comboLegList = 1; // 腿列表(用户组合的合约 + 方向)
required string mvc = 2; // MVC 标的,格式 exchange.origin_symbol(从 combo 列表接口透传)
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- 返回
message S2C {
repeated Qot_Common.ComboLeg comboLegList = 1; // 回显腿列表
optional double bidPrice = 2; // yes 买价
optional double askPrice = 3; // yes 卖价
optional string quoteId = 4; // 报价 ID(下单接口需用到)
optional bool shouldRetry = 5; // 是否建议重试(true 代表可尝试重新询价)
}
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
11
12
13
14
- 接口调用结果,结构参见 RetType
- Example
import ftWebsocket from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
import beautify from "js-beautify";
function GetEventContractComboRfq() {
const { RetType } = Common;
const { PredSide } = Common;
const { QotMarket } = Qot_Common;
let [addr, port, enable_ssl, key] = ["127.0.0.1", 11111, false, ""];
let websocket = new ftWebsocket();
websocket.onlogin = async (ret, msg) => {
if (!ret) { console.log("start error", msg); return; }
try {
const req = { c2s: { comboLegList: [{ security: { market: QotMarket.QotMarket_EventContract, code: "EC.KXWCADVANCE-26JUL14FRAESP-FRA" }, side: 1, predSide: PredSide.PredSide_Yes }, { security: { market: QotMarket.QotMarket_EventContract, code: "EC.KXWCADVANCE-26JUL15ENGARG-ENG" }, side: 1, predSide: PredSide.PredSide_Yes }], mvc: "KALSHI.KXMVECROSSCATEGORY-R" } };
let { errCode, retMsg, retType, s2c } = await websocket.GetEventContractComboRfq(req);
console.log("GetEventContractComboRfq: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if (retType == RetType.RetType_Succeed) {
console.log(beautify(JSON.stringify(s2c), { indent_size: 2, space_in_empty_paren: true }));
}
} catch (error) {
console.log("error:", error);
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(() => { websocket.stop(); console.log("stop"); }, 5000);
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
- Output
GetEventContractComboRfq: errCode 0, retMsg , retType 0
{
"comboLegList": [{
"security": {
"market": 101,
"code": "EC.KXWCADVANCE-26JUL14FRAESP-FRA"
},
"side": 1,
"predSide": 1
}, {
"security": {
"market": 101,
"code": "EC.KXWCADVANCE-26JUL15ENGARG-ENG"
},
"side": 1,
"predSide": 1
}],
"bidPrice": null,
"askPrice": 0.333,
"quoteId": "3fb44348-83e6-4179-a34a-efb09d7b80e6",
"shouldRetry": null
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
接口限制
- 每 30 秒内最多请求 15 次事件合约 Combo 询价接口
- Python
- Proto
- C#
- Java
- C++
- JavaScript
request_combo_quotes(combo_leg_list, mvc)
介绍
提交用户组合的合约腿(
ComboLeg列表)与 MVC 标的,对组合合约进行询价,返回该组合的买卖价(bid/ask)与报价 ID(下单时使用)。参数
参数 类型 说明 combo_leg_list ComboLeg 腿列表,元素须为 ComboLeg对象,非空mvc str MVC 标的,从 get_valid_combo_list返回值透传返回
参数 类型 说明 ret RET_CODE 接口调用结果 data dict 当 ret == RET_OK,返回询价结果 str 当 ret != RET_OK,返回错误描述 Example
from moomoo import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# 1. 先获取可 Combo 事件与 mvc
ret, combo_data, mvc, _ = quote_ctx.get_valid_combo_list(category='Sports', count=1)
if ret != RET_OK:
print('获取 combo 列表失败:', combo_data)
quote_ctx.close()
exit()
# 2. 构造腿并询价(两条腿可来自不同 event,pred_side 必填)
leg1 = ComboLeg()
leg1.code = 'EC.KXWCADVANCE-26JUL14FRAESP-FRA'
leg1.trd_side = TrdSide.BUY
leg1.qty_ratio = 1
leg1.pred_side = PredSide.YES
leg2 = ComboLeg()
leg2.code = 'EC.KXWCADVANCE-26JUL15ENGARG-ENG'
leg2.trd_side = TrdSide.BUY
leg2.qty_ratio = 1
leg2.pred_side = PredSide.YES
ret, data = quote_ctx.request_combo_quotes([leg1, leg2], mvc)
if ret == RET_OK:
print('bid:', data['bid_price'], 'ask:', data['ask_price'])
print('quote_id:', data['quote_id'])
print('should_retry:', data['should_retry'])
for leg in data['combo_leg_list']:
print(' leg:', repr(leg))
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
25
26
27
28
29
30
31
32
33
34
- Output
bid: N/A ask: 0.333
quote_id: 3fb44348-83e6-4179-a34a-efb09d7b80e6
should_retry: N/A
leg: ComboLeg(code=EC.KXWCADVANCE-26JUL14FRAESP-FRA, trd_side=BUY, qty_ratio=1.0, pred_side=YES)
leg: ComboLeg(code=EC.KXWCADVANCE-26JUL15ENGARG-ENG, trd_side=BUY, qty_ratio=1.0, pred_side=YES)
2
3
4
5
# Qot_GetEventContractComboRfq.proto
介绍
提交用户组合的合约腿(
ComboLeg列表)与 MVC 标的,对组合合约进行询价。参数
// 组合腿
message ComboLeg
{
required Qot_Common.Security security = 1; // 合约代码
optional int32 side = 2; // 交易方向,取值见 Trd_Common.TrdSide
optional double qtyRatio = 3; // 数量比例
optional uint64 positionID = 4; // 持仓 ID,仅 moomoo JP 平仓时使用
optional int32 predSide = 5; // 事件合约预测方向,取值见 Common.PredSide
}
message C2S {
repeated Qot_Common.ComboLeg comboLegList = 1; // 腿列表(用户组合的合约 + 方向)
required string mvc = 2; // MVC 标的,格式 exchange.origin_symbol(从 combo 列表接口透传)
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- 组合腿结构参见 ComboLeg
- 返回
message S2C {
repeated Qot_Common.ComboLeg comboLegList = 1; // 回显腿列表
optional double bidPrice = 2; // yes 买价
optional double askPrice = 3; // yes 卖价
optional string quoteId = 4; // 报价 ID(下单接口需用到)
optional bool shouldRetry = 5; // 是否建议重试(true 代表可尝试重新询价)
}
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
11
12
13
14
协议 ID
3454
数据类型
- 组合腿结构参见 ComboLeg
uint GetEventContractComboRfq(GetEventContractComboRfq.Request req);
virtual void OnReply_GetEventContractComboRfq(MMAPI_Conn client, uint nSerialNo, GetEventContractComboRfq.Response rsp);
介绍
提交用户组合的合约腿(
ComboLeg列表)与 MVC 标的,对组合合约进行询价。参数
message C2S {
repeated Qot_Common.ComboLeg comboLegList = 1;
required string mvc = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- 组合腿结构参见 ComboLeg
- 返回
message S2C {
repeated Qot_Common.ComboLeg comboLegList = 1;
optional double bidPrice = 2;
optional double askPrice = 3;
optional string quoteId = 4;
optional bool shouldRetry = 5;
}
message Response {
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
- Example
public class Program : MMSPI_Qot, MMSPI_Conn
{
MMAPI_Qot qot = new MMAPI_Qot();
public Program()
{
qot.SetClientInfo("csharp", 1);
qot.SetConnCallback(this);
qot.SetQotCallback(this);
}
public void Start()
{
qot.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(MMAPI_Conn client, long errCode, String desc)
{
if (errCode != 0) return;
QotCommon.Security sec1 = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_EventContract)
.SetCode("EC.KXWCADVANCE-26JUL14FRAESP-FRA").Build();
QotCommon.ComboLeg leg1 = QotCommon.ComboLeg.CreateBuilder()
.SetSecurity(sec1).SetSide(1).SetPredSide(1).Build();
QotCommon.Security sec2 = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_EventContract)
.SetCode("EC.KXWCADVANCE-26JUL15ENGARG-ENG").Build();
QotCommon.ComboLeg leg2 = QotCommon.ComboLeg.CreateBuilder()
.SetSecurity(sec2).SetSide(1).SetPredSide(1).Build();
var c2s = GetEventContractComboRfq.C2S.CreateBuilder()
.AddComboLeg(leg1).AddComboLeg(leg2)
.SetMvc("KALSHI.KXMVECROSSCATEGORY-R").Build();
var req = GetEventContractComboRfq.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetEventContractComboRfq(req);
Console.Write("Send GetEventContractComboRfq: {0}\n", seqNo);
}
public void OnReply_GetEventContractComboRfq(MMAPI_Conn client, uint nSerialNo, GetEventContractComboRfq.Response rsp)
{
Console.Write("Reply: {0} {1}\n", nSerialNo, rsp.ToString());
}
public static void Main(String[] args)
{
MMAPI.Init();
new Program().Start();
while (true) Thread.Sleep(1000 * 600);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
- Output
connect
Request GetEventContractComboRfq SerialNo: 1
OnReply_GetEventContractComboRfq SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"comboLegList": [
{"security": {"market": 101, "code": "EC.xxx"}, "predSide": 1}
],
"bidPrice": 0.54,
"askPrice": 0.56,
"quoteId": "Q-20260713-0001",
"shouldRetry": false
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int getEventContractComboRfq(QotGetEventContractComboRfq.Request req);
void onReply_GetEventContractComboRfq(MMAPI_Conn client, int nSerialNo, QotGetEventContractComboRfq.Response rsp);
介绍
提交用户组合的合约腿(
ComboLeg列表)与 MVC 标的,对组合合约进行询价。参数
message C2S {
repeated Qot_Common.ComboLeg comboLegList = 1;
required string mvc = 2;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- 组合腿结构参见 ComboLeg
- 返回
message S2C {
repeated Qot_Common.ComboLeg comboLegList = 1;
optional double bidPrice = 2;
optional double askPrice = 3;
optional string quoteId = 4;
optional bool shouldRetry = 5;
}
message Response {
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 接口调用结果,结构参见 RetType
- Example
public class Program implements MMSPI_Qot, MMSPI_Conn {
private MMAPI_Conn_Qot qot = new MMAPI_Conn_Qot();
public Program() {
qot.setClientInfo("java", 1);
qot.setConnCallback(this);
qot.setQotCallback(this);
}
public void start() {
qot.initConnect("127.0.0.1", (short) 11111, false);
}
@Override
public void onInitConnect(MMAPI_Conn client, long errCode, String desc) {
if (errCode != 0) return;
QotCommon.Security sec1 = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_EventContract_VALUE)
.setCode("EC.KXWCADVANCE-26JUL14FRAESP-FRA").build();
QotCommon.ComboLeg leg1 = QotCommon.ComboLeg.newBuilder()
.setSecurity(sec1).setSide(1).setPredSide(1).build();
QotCommon.Security sec2 = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_EventContract_VALUE)
.setCode("EC.KXWCADVANCE-26JUL15ENGARG-ENG").build();
QotCommon.ComboLeg leg2 = QotCommon.ComboLeg.newBuilder()
.setSecurity(sec2).setSide(1).setPredSide(1).build();
QotGetEventContractComboRfq.C2S c2s = QotGetEventContractComboRfq.C2S.newBuilder()
.addComboLeg(leg1).addComboLeg(leg2)
.setMvc("KALSHI.KXMVECROSSCATEGORY-R").build();
QotGetEventContractComboRfq.Request req = QotGetEventContractComboRfq.Request.newBuilder()
.setC2S(c2s).build();
int seqNo = qot.getEventContractComboRfq(req);
System.out.println("Send GetEventContractComboRfq: " + seqNo);
}
@Override
public void onReply_GetEventContractComboRfq(MMAPI_Conn client, int nSerialNo, QotGetEventContractComboRfq.Response rsp) {
System.out.println("Reply: " + nSerialNo + " " + rsp.toString());
}
public static void main(String[] args) {
MMAPI.init();
new Program().start();
while (true) {
try { Thread.sleep(1000 * 600); } catch (InterruptedException e) {}
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
- Output
connect
Request GetEventContractComboRfq SerialNo: 1
OnReply_GetEventContractComboRfq SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"comboLegList": [
{"security": {"market": 101, "code": "EC.xxx"}, "predSide": 1}
],
"bidPrice": 0.54,
"askPrice": 0.56,
"quoteId": "Q-20260713-0001",
"shouldRetry": false
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
moomoo::u32_t GetEventContractComboRfq(const Qot_GetEventContractComboRfq::Request &stReq);
virtual void OnReply_GetEventContractComboRfq(moomoo::u32_t nSerialNo, const Qot_GetEventContractComboRfq::Response &stRsp) = 0;
介绍
提交用户组合的合约腿(
ComboLeg列表)与 MVC 标的,对组合合约进行询价。参数
message C2S {
repeated Qot_Common.ComboLeg comboLegList = 1; // 腿列表(用户组合的合约 + 方向)
required string mvc = 2; // MVC 标的,格式 exchange.origin_symbol(从 combo 列表接口透传)
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- 组合腿结构参见 ComboLeg
- 返回
message S2C {
repeated Qot_Common.ComboLeg comboLegList = 1; // 回显腿列表
optional double bidPrice = 2; // yes 买价
optional double askPrice = 3; // yes 卖价
optional string quoteId = 4; // 报价 ID(下单接口需用到)
optional bool shouldRetry = 5; // 是否建议重试(true 代表可尝试重新询价)
}
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
11
12
13
14
- 接口调用结果,结构参见 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_GetEventContractComboRfq::Request req;
Qot_GetEventContractComboRfq::C2S *c2s = req.mutable_c2s();
// 第一条腿
Qot_Common::ComboLeg *leg1 = c2s->add_comboleg();
Qot_Common::Security *sec1 = leg1->mutable_security();
sec1->set_code("EC.KXWCADVANCE-26JUL14FRAESP-FRA");
sec1->set_market(Qot_Common::QotMarket::QotMarket_EventContract);
leg1->set_side(1); // BUY
leg1->set_predside(1); // YES
// 第二条腿
Qot_Common::ComboLeg *leg2 = c2s->add_comboleg();
Qot_Common::Security *sec2 = leg2->mutable_security();
sec2->set_code("EC.KXWCADVANCE-26JUL15ENGARG-ENG");
sec2->set_market(Qot_Common::QotMarket::QotMarket_EventContract);
leg2->set_side(1); // BUY
leg2->set_predside(1); // YES
c2s->set_mvc("KALSHI.KXMVECROSSCATEGORY-R");
m_GetEventContractComboRfqSerialNo = m_pQotApi->GetEventContractComboRfq(req);
cout << "Request GetEventContractComboRfq SerialNo: " << m_GetEventContractComboRfqSerialNo << endl;
}
virtual void OnReply_GetEventContractComboRfq(moomoo::u32_t nSerialNo, const Qot_GetEventContractComboRfq::Response &stRsp) {
if (nSerialNo == m_GetEventContractComboRfqSerialNo)
{
cout << "OnReply_GetEventContractComboRfq 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_GetEventContractComboRfqSerialNo;
};
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
82
- Output
connect
Request GetEventContractComboRfq SerialNo: 1
OnReply_GetEventContractComboRfq SerialNo: 1
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"comboLegList": [
{"security": {"market": 101, "code": "EC.KXWCADVANCE-26JUL14FRAESP-FRA"}, "side": 1, "predSide": 1},
{"security": {"market": 101, "code": "EC.KXWCADVANCE-26JUL15ENGARG-ENG"}, "side": 1, "predSide": 1}
],
"bidPrice": null,
"askPrice": 0.333,
"quoteId": "3fb44348-83e6-4179-a34a-efb09d7b80e6",
"shouldRetry": null
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
GetEventContractComboRfq(req);
介绍
提交用户组合的合约腿(
ComboLeg列表)与 MVC 标的,对组合合约进行询价,返回买卖价与报价 ID。参数
message C2S {
repeated Qot_Common.ComboLeg comboLegList = 1; // 腿列表(用户组合的合约 + 方向)
required string mvc = 2; // MVC 标的,格式 exchange.origin_symbol(从 combo 列表接口透传)
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
- 返回
message S2C {
repeated Qot_Common.ComboLeg comboLegList = 1; // 回显腿列表
optional double bidPrice = 2; // yes 买价
optional double askPrice = 3; // yes 卖价
optional string quoteId = 4; // 报价 ID(下单接口需用到)
optional bool shouldRetry = 5; // 是否建议重试(true 代表可尝试重新询价)
}
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
11
12
13
14
- 接口调用结果,结构参见 RetType
- Example
import mmWebsocket from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function GetEventContractComboRfq() {
const { RetType } = Common;
const { PredSide } = Common;
const { QotMarket } = Qot_Common;
let [addr, port, enable_ssl, key] = ["127.0.0.1", 11111, false, ""];
let websocket = new mmWebsocket();
websocket.onlogin = async (ret, msg) => {
if (!ret) { console.log("start error", msg); return; }
try {
const req = { c2s: { comboLegList: [{ security: { market: QotMarket.QotMarket_EventContract, code: "EC.KXWCADVANCE-26JUL14FRAESP-FRA" }, side: 1, predSide: PredSide.PredSide_Yes }, { security: { market: QotMarket.QotMarket_EventContract, code: "EC.KXWCADVANCE-26JUL15ENGARG-ENG" }, side: 1, predSide: PredSide.PredSide_Yes }], mvc: "KALSHI.KXMVECROSSCATEGORY-R" } };
let { errCode, retMsg, retType, s2c } = await websocket.GetEventContractComboRfq(req);
console.log("GetEventContractComboRfq: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if (retType == RetType.RetType_Succeed) {
console.log(beautify(JSON.stringify(s2c), { indent_size: 2, space_in_empty_paren: true }));
}
} catch (error) {
console.log("error:", error);
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(() => { websocket.stop(); console.log("stop"); }, 5000);
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
- Output
GetEventContractComboRfq: errCode 0, retMsg , retType 0
{
"comboLegList": [{
"security": {
"market": 101,
"code": "EC.KXWCADVANCE-26JUL14FRAESP-FRA"
},
"side": 1,
"predSide": 1
}, {
"security": {
"market": 101,
"code": "EC.KXWCADVANCE-26JUL15ENGARG-ENG"
},
"side": 1,
"predSide": 1
}],
"bidPrice": null,
"askPrice": 0.333,
"quoteId": "3fb44348-83e6-4179-a34a-efb09d7b80e6",
"shouldRetry": null
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
接口限制
- 每 30 秒内最多请求 15 次事件合约 Combo 询价接口
← 获取事件合约可Combo列表 条件选股 →