# 查询组合可交易信息
- Python
- Proto
- C#
- Java
- C++
- JavaScript
comboorder_tradinginfo_query(combo_leg_list, price, qty, order_type=OrderType.NORMAL, order_id=None, trd_env=TrdEnv.REAL, acc_id=0, acc_index=0)
介绍
查询指定组合订单在指定价格、数量下的可交易信息(如保证金、购买力等变动),亦可传入订单号查询改单场景下的可交易信息。
参数
参数 类型 说明 combo_leg_list list 组合腿列表 - 列表元素为 ComboLeg 对象,字段说明参见 place_combo_order 中的 ComboLeg 表
price float 报价 如果是竞价、市价单,请也填入一个当前价格,服务器才好计算qty float 数量 组合数量;每条腿的实际数量为 qty × 该腿的 qty_ratioorder_type OrderType 订单类型 order_id str 订单号 - 默认传 None,查询的是新下单的可交易信息
- 改单时传入服务器订单号 orderIDEx,返回该订单可改成的相关信息
trd_env TrdEnv 交易环境 acc_id int 交易业务账户 ID - acc_id 和 acc_index 二选一即可,推荐使用 acc_id
- 当 acc_id 传 0 时,以 acc_index 指定的账户为准
acc_index int 交易业务账户列表中的账户序号 默认为 0,表示第 1 个交易业务账户返回
参数 类型 说明 ret RET_CODE 接口调用结果 data pd.DataFrame 当 ret == RET_OK 时,返回可交易信息 str 当 ret != RET_OK 时,返回错误描述 - 可交易信息格式如下:
字段 类型 说明 nlv_change float 综合净资产变动 initial_margin_change float 初始保证金变动 maintenance_margin_change float 维持保证金变动 option_bp float 期权购买力 max_withdraw_change float 最大可提变动 bp_decrease float 消耗购买力
- 可交易信息格式如下:
Example
from futu import *
trd_ctx = OpenSecTradeContext(filter_trdmarket=TrdMarket.US, host='127.0.0.1', port=11111, security_firm=SecurityFirm.FUTUSECURITIES)
leg1 = ComboLeg()
leg1.code = 'US.AAPL260529C302500'
leg1.trd_side = TrdSide.BUY
leg1.qty_ratio = 1
leg2 = ComboLeg()
leg2.code = 'US.AAPL'
leg2.trd_side = TrdSide.SELL
leg2.qty_ratio = 100
combo_legs = [leg1, leg2]
ret, data = trd_ctx.comboorder_tradinginfo_query(combo_legs, price=100, qty=1, order_type=OrderType.NORMAL, trd_env=TrdEnv.SIMULATE)
if ret == RET_OK:
print(data)
else:
print('comboorder_tradinginfo_query error: ', data)
trd_ctx.close()
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- Output
nlv_change initial_margin_change maintenance_margin_change option_bp max_withdraw_change bp_decrease
0 ... ... ... ... ... ...
2
# Trd_GetComboMaxTrdQtys.proto
介绍
查询组合订单的最大可交易数量及相关资金、保证金变动信息
参数
message C2S
{
required Trd_Common.TrdHeader header = 1; //交易公共参数头
repeated Qot_Common.ComboLeg comboLegs = 2; //组合的腿信息
required double qty = 4; //数量,实际数量为 qty * 腿的 qty_ratio
optional double price = 5; //价格
required int32 orderType = 6; //订单类型, 参见Trd_Common.OrderType的枚举定义
optional string orderIDEx = 7; //订单号,改单时使用
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 返回
message S2C
{
required Trd_Common.TrdHeader header = 1; //交易公共参数头
optional Trd_Common.ComboMaxTrdQtys maxTrdQtys = 2; //组合最大可交易数量结构
}
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
- 交易公共参数头结构参见 TrdHeader
- 组合可交易信息结构参见 ComboMaxTrdQtys
- 接口调用结果,结构参见 RetType
协议 ID
2112
uint GetComboMaxTrdQtys(TrdGetComboMaxTrdQtys.Request req);
virtual void OnReply_GetComboMaxTrdQtys(FTAPI_Conn client, uint nSerialNo, TrdGetComboMaxTrdQtys.Response rsp);
介绍
查询组合订单的可交易信息
参数
message C2S
{
required Trd_Common.TrdHeader header = 1;
repeated Qot_Common.ComboLeg comboLegs = 2;
required double qty = 4;
optional double price = 5;
required int32 orderType = 6;
optional string orderIDEx = 7;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 回调
message S2C
{
required Trd_Common.TrdHeader header = 1;
optional Trd_Common.ComboMaxTrdQtys maxTrdQtys = 2;
}
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
- 组合可交易信息结构参见 ComboMaxTrdQtys
- 接口调用结果,结构参见 RetType
- Example
public class Program : FTSPI_Trd, FTSPI_Conn {
FTAPI_Trd trd = new FTAPI_Trd();
public Program() {
trd.SetClientInfo("csharp", 1); //设置客户端信息
trd.SetConnCallback(this); //设置连接回调
trd.SetTrdCallback(this); //设置交易回调
}
public void Start() {
trd.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(FTAPI_Conn client, long errCode, String desc)
{
Console.Write("Trd onInitConnect: ret={0} desc={1} connID={2}\n", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
TrdCommon.TrdHeader header = TrdCommon.TrdHeader.CreateBuilder()
.SetAccID(281756457888247915L)
.SetTrdEnv((int)TrdCommon.TrdEnv.TrdEnv_Simulate)
.SetTrdMarket((int)TrdCommon.TrdMarket.TrdMarket_US)
.Build();
QotCommon.ComboLeg leg1 = QotCommon.ComboLeg.CreateBuilder()
.SetSecurity(QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_US_Security)
.SetCode("AAPL260529C302500")
.Build())
.SetSide((int)TrdCommon.TrdSide.TrdSide_Buy)
.SetQtyRatio(1)
.Build();
QotCommon.ComboLeg leg2 = QotCommon.ComboLeg.CreateBuilder()
.SetSecurity(QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_US_Security)
.SetCode("AAPL")
.Build())
.SetSide((int)TrdCommon.TrdSide.TrdSide_Sell)
.SetQtyRatio(100)
.Build();
TrdGetComboMaxTrdQtys.C2S c2s = TrdGetComboMaxTrdQtys.C2S.CreateBuilder()
.SetHeader(header)
.AddComboLegs(leg1)
.AddComboLegs(leg2)
.SetQty(1)
.SetPrice(100)
.SetOrderType((int)TrdCommon.OrderType.OrderType_Normal)
.Build();
TrdGetComboMaxTrdQtys.Request req = TrdGetComboMaxTrdQtys.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = trd.GetComboMaxTrdQtys(req);
Console.Write("Send TrdGetComboMaxTrdQtys: {0}\n", seqNo);
}
public void OnDisconnect(FTAPI_Conn client, long errCode) {
Console.Write("Trd onDisConnect: {0}\n", errCode);
}
public void OnReply_GetComboMaxTrdQtys(FTAPI_Conn client, uint nSerialNo, TrdGetComboMaxTrdQtys.Response rsp)
{
Console.Write("Reply: TrdGetComboMaxTrdQtys: {0}\n", nSerialNo);
Console.Write("accID: {0}\n", rsp.S2C.Header.AccID);
}
public static void Main(String[] args) {
FTAPI.Init();
Program trd = new Program();
trd.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
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
- Output
Trd onInitConnect: ret=0 desc= connID=6826812678028044696
Send TrdGetComboMaxTrdQtys: 3
Reply: TrdGetComboMaxTrdQtys: 3
accID: 281756457888247915
2
3
4
int getComboMaxTrdQtys(TrdGetComboMaxTrdQtys.Request req);
void onReply_GetComboMaxTrdQtys(FTAPI_Conn client, int nSerialNo, TrdGetComboMaxTrdQtys.Response rsp);
介绍
查询组合订单的可交易信息
参数
message C2S
{
required Trd_Common.TrdHeader header = 1;
repeated Qot_Common.ComboLeg comboLegs = 2;
required double qty = 4;
optional double price = 5;
required int32 orderType = 6;
optional string orderIDEx = 7;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 回调
message S2C
{
required Trd_Common.TrdHeader header = 1;
optional Trd_Common.ComboMaxTrdQtys maxTrdQtys = 2;
}
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
- 组合可交易信息结构参见 ComboMaxTrdQtys
- 接口调用结果,结构参见 RetType
- Example
public class TrdDemo implements FTSPI_Trd, FTSPI_Conn {
FTAPI_Conn_Trd trd = new FTAPI_Conn_Trd();
public TrdDemo() {
trd.setClientInfo("javaclient", 1); //设置客户端信息
trd.setConnSpi(this); //设置连接回调
trd.setTrdSpi(this); //设置交易回调
}
public void start() {
trd.initConnect("127.0.0.1", (short)11111, false);
}
@Override
public void onInitConnect(FTAPI_Conn client, long errCode, String desc)
{
System.out.printf("Trd onInitConnect: ret=%b desc=%s connID=%d\n", errCode, desc, client.getConnectID());
if (errCode != 0)
return;
TrdCommon.TrdHeader header = TrdCommon.TrdHeader.newBuilder()
.setAccID(281756457888247915L)
.setTrdEnv(TrdCommon.TrdEnv.TrdEnv_Simulate_VALUE)
.setTrdMarket(TrdCommon.TrdMarket.TrdMarket_US_VALUE)
.build();
QotCommon.ComboLeg leg1 = QotCommon.ComboLeg.newBuilder()
.setSecurity(QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_US_Security_VALUE)
.setCode("AAPL260529C302500")
.build())
.setSide(TrdCommon.TrdSide.TrdSide_Buy_VALUE)
.setQtyRatio(1)
.build();
QotCommon.ComboLeg leg2 = QotCommon.ComboLeg.newBuilder()
.setSecurity(QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_US_Security_VALUE)
.setCode("AAPL")
.build())
.setSide(TrdCommon.TrdSide.TrdSide_Sell_VALUE)
.setQtyRatio(100)
.build();
TrdGetComboMaxTrdQtys.C2S c2s = TrdGetComboMaxTrdQtys.C2S.newBuilder()
.setHeader(header)
.addComboLegs(leg1)
.addComboLegs(leg2)
.setQty(1)
.setPrice(100)
.setOrderType(TrdCommon.OrderType.OrderType_Normal_VALUE)
.build();
TrdGetComboMaxTrdQtys.Request req = TrdGetComboMaxTrdQtys.Request.newBuilder().setC2S(c2s).build();
int seqNo = trd.getComboMaxTrdQtys(req);
System.out.printf("Send TrdGetComboMaxTrdQtys: %d\n", seqNo);
}
@Override
public void onDisconnect(FTAPI_Conn client, long errCode) {
System.out.printf("Trd onDisConnect: %d\n", errCode);
}
@Override
public void onReply_GetComboMaxTrdQtys(FTAPI_Conn client, int nSerialNo, TrdGetComboMaxTrdQtys.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("TrdGetComboMaxTrdQtys failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive TrdGetComboMaxTrdQtys: %s\n", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
FTAPI.init();
TrdDemo trd = new TrdDemo();
trd.start();
while (true) {
try {
Thread.sleep(1000 * 600);
} catch (InterruptedException exc) {
}
}
}
}
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
83
84
85
86
87
88
- Output
Send TrdGetComboMaxTrdQtys: 2
Receive TrdGetComboMaxTrdQtys: {
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"header": {
"trdEnv": 0,
"accID": "281756457888247915",
"trdMarket": 2
},
"maxTrdQtys": {
"nlvChange": -125.3,
"initialMarginChange": 320.0,
"maintenanceMarginChange": 300.0,
"optionBuyPower": 18600.0,
"maxWithDrawChange": -320.0,
"buyPowerDecrease": 410.0
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Futu::u32_t GetComboMaxTrdQtys(const Trd_GetComboMaxTrdQtys::Request &stReq);
virtual void OnReply_GetComboMaxTrdQtys(Futu::u32_t nSerialNo, const Trd_GetComboMaxTrdQtys::Response &stRsp) = 0;
介绍
获取组合策略下单的最大可交易数量、最大可下单数量对账户综合净资产、保证金、期权购买力等指标的预估影响。下单前调用,可以在不真正占用资金的情况下预估单笔组合的成本。
参数
message C2S
{
required Trd_Common.TrdHeader header = 1; //交易公共参数头
repeated Qot_Common.ComboLeg comboLegs = 2; //组合的腿信息
required double qty = 4; //数量,实际数量为 qty * 腿的 qty_ratio
optional double price = 5; //价格
required int32 orderType = 6; //OrderType,订单类型
optional string orderIDEx = 7; //订单号,改单时使用
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 返回
message ComboMaxTrdQtys
{
optional double nlvChange = 1; //综合净资产
optional double initialMarginChange = 2; //初始保证金
optional double maintenanceMarginChange = 3; //维持保证金
optional double optionBuyPower = 4; //期权购买力
optional double maxWithDrawChange = 5; //最大可提
optional double buyPowerDecrease = 6; //消耗购买力
}
message S2C
{
required Trd_Common.TrdHeader header = 1; //交易公共参数头
optional Trd_Common.ComboMaxTrdQtys maxTrdQtys = 2; //组合最大可交易数量结构
}
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
15
16
17
18
19
20
21
22
23
- 接口调用结果,结构参见 RetType
- Example
class Program : public FTSPI_Qot, public FTSPI_Trd, public FTSPI_Conn
{
public:
Program() {
m_pTrdApi = FTAPI::CreateTrdApi();
m_pTrdApi->RegisterTrdSpi(this);
m_pTrdApi->RegisterConnSpi(this);
}
~Program() {
if (m_pTrdApi != nullptr)
{
m_pTrdApi->UnregisterTrdSpi();
m_pTrdApi->UnregisterConnSpi();
FTAPI::ReleaseTrdApi(m_pTrdApi);
m_pTrdApi = nullptr;
}
}
void Start() {
m_pTrdApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(FTAPI_Conn* pConn, Futu::i64_t nErrCode, const char* strDesc) {
cout << "connect" << endl;
// 组包
Trd_GetComboMaxTrdQtys::Request req;
Trd_GetComboMaxTrdQtys::C2S *c2s = req.mutable_c2s();
Trd_Common::TrdHeader *header = c2s->mutable_header();
header->set_accid(3637840);
header->set_trdenv(0); // TrdEnv,0 真实 / 1 模拟
header->set_trdmarket(2); // TrdMarket,2 美股
// 本例为 Covered Call:买入 100 股 AAPL 正股 + 卖出 1 张 AAPL Call
Qot_Common::ComboLeg *leg1 = c2s->add_combolegs();
leg1->mutable_security()->set_market(Qot_Common::QotMarket_US_Security);
leg1->mutable_security()->set_code("AAPL260529C302500");
leg1->set_side(Trd_Common::TrdSide_Sell); // 卖出 Call
leg1->set_qtyratio(1);
Qot_Common::ComboLeg *leg2 = c2s->add_combolegs();
leg2->mutable_security()->set_market(Qot_Common::QotMarket_US_Security);
leg2->mutable_security()->set_code("AAPL");
leg2->set_side(Trd_Common::TrdSide_Buy); // 买入正股
leg2->set_qtyratio(100);
c2s->set_qty(1); // 实际下单 = qty × 各腿 qty_ratio(1 张 Call + 100 股正股)
c2s->set_price(190.1); // 组合净限价(净支出 = 正股买入价 − 卖出 Call 权利金)
c2s->set_ordertype(Trd_Common::OrderType_Normal);
m_GetComboMaxTrdQtysSerialNo = m_pTrdApi->GetComboMaxTrdQtys(req);
cout << "Request GetComboMaxTrdQtys SerialNo: " << m_GetComboMaxTrdQtysSerialNo << endl;
}
virtual void OnReply_GetComboMaxTrdQtys(Futu::u32_t nSerialNo, const Trd_GetComboMaxTrdQtys::Response &stRsp) {
if (nSerialNo != m_GetComboMaxTrdQtysSerialNo) return;
cout << "OnReply_GetComboMaxTrdQtys SerialNo: " << nSerialNo << endl;
// 解析内部结构打印出来
// ProtoBufToBodyData 和 UTF8ToLocal 函数的定义参见 Sample 中的 tool.h 文件
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
FTAPI_Trd *m_pTrdApi;
Futu::u32_t m_GetComboMaxTrdQtysSerialNo = 0;
};
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
83
84
85
86
87
88
- Output
connect
Request GetComboMaxTrdQtys SerialNo: 3
OnReply_GetComboMaxTrdQtys SerialNo: 3
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"header": { "trdEnv": 0, "accID": "3637840", "trdMarket": 2 },
"maxTrdQtys": {
"nlvChange": 0,
"initialMarginChange": 10000.0,
"maintenanceMarginChange": 5000.0,
"optionBuyPower": 12500.0,
"maxWithDrawChange": -10000.0,
"buyPowerDecrease": 10000.0
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
GetComboMaxTrdQtys(req);
介绍
查询组合订单的可交易信息
参数
message C2S
{
required Trd_Common.TrdHeader header = 1;
repeated Qot_Common.ComboLeg comboLegs = 2;
required double qty = 4;
optional double price = 5;
required int32 orderType = 6;
optional string orderIDEx = 7;
}
2
3
4
5
6
7
8
9
- 返回
message S2C
{
required Trd_Common.TrdHeader header = 1;
optional Trd_Common.ComboMaxTrdQtys maxTrdQtys = 2;
}
2
3
4
5
- 组合可交易信息结构参见 ComboMaxTrdQtys
- 接口调用结果,结构参见 RetType
- Example
import ftWebsocket from "futu-api";
import { ftCmdID } from "futu-api";
import { Common, Qot_Common, Trd_Common } from "futu-api/proto";
import beautify from "js-beautify";
function TrdGetComboMaxTrdQtys(){
const { RetType } = Common
const { TrdEnv, OrderType, TrdMarket } = Trd_Common
const { QotMarket } = Qot_Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new ftWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) { // 登录成功
websocket.GetAccList({
c2s: {
userID: 0,
},
}).then((res) => {
let { retType, s2c: { accList } } = res
if(retType == RetType.RetType_Succeed){
let acc = accList.filter((item)=>{
return item.trdEnv == TrdEnv.TrdEnv_Simulate && item.trdMarketAuthList.some((auth)=>{ return auth == TrdMarket.TrdMarket_US})
})[0]; // 样例取第一个美国市场虚拟环境账户
const req = {
c2s: {
header: {
trdEnv: acc.trdEnv,
accID: acc.accID,
trdMarket: TrdMarket.TrdMarket_US,
},
comboLegs: [
{
security: { market: QotMarket.QotMarket_US_Security, code: "AAPL260529C302500" },
side: Trd_Common.TrdSide.TrdSide_Buy,
qtyRatio: 1,
},
{
security: { market: QotMarket.QotMarket_US_Security, code: "AAPL" },
side: Trd_Common.TrdSide.TrdSide_Sell,
qtyRatio: 100,
},
],
qty: 1,
price: 100,
orderType: OrderType.OrderType_Normal,
},
};
websocket.GetComboMaxTrdQtys(req)
.then((res) => {
let { errCode, retMsg, retType,s2c } = res
console.log("GetComboMaxTrdQtys: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
let data = beautify(JSON.stringify(s2c), {
indent_size: 2,
space_in_empty_paren: true,
});
console.log(data);
}
})
.catch((error) => {
console.log("error:", error);
});
}
})
.catch((error) => {
console.log("GetAccList error:", error);
});
} else {
console.log("error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
//关闭行情连接,连接不再使用之后,要关闭,否则占用不必要资源
//同时OpenD也限制了最多128条连接
//也可以一个页面或者一个项目维护一条连接,这里范例请求一次创建一条连接
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // 5秒后断开
}
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
83
84
85
86
- Output
GetComboMaxTrdQtys: errCode 0, retMsg , retType 0
{
"header": {
"trdEnv": 0,
"accID": "6684972",
"trdMarket": 2
},
"maxTrdQtys": {
"nlvChange": -125.3,
"initialMarginChange": 320.0,
"maintenanceMarginChange": 300.0,
"optionBuyPower": 18600.0,
"maxWithDrawChange": -320.0,
"buyPowerDecrease": 410.0
}
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
接口限制
- 同一账户 ID(acc_id) 每 30 秒内最多请求 10 次查询最大可买可卖类接口。
- Python
- Proto
- C#
- Java
- C++
- JavaScript
comboorder_tradinginfo_query(combo_leg_list, price, qty, order_type=OrderType.NORMAL, order_id=None, trd_env=TrdEnv.REAL, acc_id=0, acc_index=0)
介绍
查询指定组合订单在指定价格、数量下的可交易信息(如保证金、购买力等变动),亦可传入订单号查询改单场景下的可交易信息。
参数
参数 类型 说明 combo_leg_list list 组合腿列表 - 列表元素为 ComboLeg 对象,字段说明参见 place_combo_order 中的 ComboLeg 表
price float 报价 如果是竞价、市价单,请也填入一个当前价格,服务器才好计算qty float 数量 组合数量;每条腿的实际数量为 qty × 该腿的 qty_ratioorder_type OrderType 订单类型 order_id str 订单号 - 默认传 None,查询的是新下单的可交易信息
- 改单时传入服务器订单号 orderIDEx,返回该订单可改成的相关信息
trd_env TrdEnv 交易环境 acc_id int 交易业务账户 ID - acc_id 和 acc_index 二选一即可,推荐使用 acc_id
- 当 acc_id 传 0 时,以 acc_index 指定的账户为准
acc_index int 交易业务账户列表中的账户序号 默认为 0,表示第 1 个交易业务账户返回
参数 类型 说明 ret RET_CODE 接口调用结果 data pd.DataFrame 当 ret == RET_OK 时,返回可交易信息 str 当 ret != RET_OK 时,返回错误描述 - 可交易信息格式如下:
字段 类型 说明 nlv_change float 综合净资产变动 initial_margin_change float 初始保证金变动 maintenance_margin_change float 维持保证金变动 option_bp float 期权购买力 max_withdraw_change float 最大可提变动 bp_decrease float 消耗购买力
- 可交易信息格式如下:
Example
from moomoo import *
trd_ctx = OpenSecTradeContext(filter_trdmarket=TrdMarket.US, host='127.0.0.1', port=11111, security_firm=SecurityFirm.FUTUINC)
leg1 = ComboLeg()
leg1.code = 'US.AAPL260529C302500'
leg1.trd_side = TrdSide.BUY
leg1.qty_ratio = 1
leg2 = ComboLeg()
leg2.code = 'US.AAPL'
leg2.trd_side = TrdSide.SELL
leg2.qty_ratio = 100
combo_legs = [leg1, leg2]
ret, data = trd_ctx.comboorder_tradinginfo_query(combo_legs, price=100, qty=1, order_type=OrderType.NORMAL, trd_env=TrdEnv.SIMULATE)
if ret == RET_OK:
print(data)
else:
print('comboorder_tradinginfo_query error: ', data)
trd_ctx.close()
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- Output
nlv_change initial_margin_change maintenance_margin_change option_bp max_withdraw_change bp_decrease
0 ... ... ... ... ... ...
2
# Trd_GetComboMaxTrdQtys.proto
介绍
查询组合订单的最大可交易数量及相关资金、保证金变动信息
参数
message C2S
{
required Trd_Common.TrdHeader header = 1; //交易公共参数头
repeated Qot_Common.ComboLeg comboLegs = 2; //组合的腿信息
required double qty = 4; //数量,实际数量为 qty * 腿的 qty_ratio
optional double price = 5; //价格
required int32 orderType = 6; //订单类型, 参见Trd_Common.OrderType的枚举定义
optional string orderIDEx = 7; //订单号,改单时使用
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 返回
message S2C
{
required Trd_Common.TrdHeader header = 1; //交易公共参数头
optional Trd_Common.ComboMaxTrdQtys maxTrdQtys = 2; //组合最大可交易数量结构
}
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
- 交易公共参数头结构参见 TrdHeader
- 组合可交易信息结构参见 ComboMaxTrdQtys
- 接口调用结果,结构参见 RetType
协议 ID
2112
uint GetComboMaxTrdQtys(TrdGetComboMaxTrdQtys.Request req);
virtual void OnReply_GetComboMaxTrdQtys(MMAPI_Conn client, uint nSerialNo, TrdGetComboMaxTrdQtys.Response rsp);
介绍
查询组合订单的可交易信息
参数
message C2S
{
required Trd_Common.TrdHeader header = 1;
repeated Qot_Common.ComboLeg comboLegs = 2;
required double qty = 4;
optional double price = 5;
required int32 orderType = 6;
optional string orderIDEx = 7;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 回调
message S2C
{
required Trd_Common.TrdHeader header = 1;
optional Trd_Common.ComboMaxTrdQtys maxTrdQtys = 2;
}
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
- 组合可交易信息结构参见 ComboMaxTrdQtys
- 接口调用结果,结构参见 RetType
- Example
public class Program : MMSPI_Trd, MMSPI_Conn {
MMAPI_Trd trd = new MMAPI_Trd();
public Program() {
trd.SetClientInfo("csharp", 1); //设置客户端信息
trd.SetConnCallback(this); //设置连接回调
trd.SetTrdCallback(this); //设置交易回调
}
public void Start() {
trd.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(MMAPI_Conn client, long errCode, String desc)
{
Console.Write("Trd onInitConnect: ret={0} desc={1} connID={2}\n", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
TrdCommon.TrdHeader header = TrdCommon.TrdHeader.CreateBuilder()
.SetAccID(281756457888247915L)
.SetTrdEnv((int)TrdCommon.TrdEnv.TrdEnv_Simulate)
.SetTrdMarket((int)TrdCommon.TrdMarket.TrdMarket_US)
.Build();
QotCommon.ComboLeg leg1 = QotCommon.ComboLeg.CreateBuilder()
.SetSecurity(QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_US_Security)
.SetCode("AAPL260529C302500")
.Build())
.SetSide((int)TrdCommon.TrdSide.TrdSide_Buy)
.SetQtyRatio(1)
.Build();
QotCommon.ComboLeg leg2 = QotCommon.ComboLeg.CreateBuilder()
.SetSecurity(QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_US_Security)
.SetCode("AAPL")
.Build())
.SetSide((int)TrdCommon.TrdSide.TrdSide_Sell)
.SetQtyRatio(100)
.Build();
TrdGetComboMaxTrdQtys.C2S c2s = TrdGetComboMaxTrdQtys.C2S.CreateBuilder()
.SetHeader(header)
.AddComboLegs(leg1)
.AddComboLegs(leg2)
.SetQty(1)
.SetPrice(100)
.SetOrderType((int)TrdCommon.OrderType.OrderType_Normal)
.Build();
TrdGetComboMaxTrdQtys.Request req = TrdGetComboMaxTrdQtys.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = trd.GetComboMaxTrdQtys(req);
Console.Write("Send TrdGetComboMaxTrdQtys: {0}\n", seqNo);
}
public void OnDisconnect(MMAPI_Conn client, long errCode) {
Console.Write("Trd onDisConnect: {0}\n", errCode);
}
public void OnReply_GetComboMaxTrdQtys(MMAPI_Conn client, uint nSerialNo, TrdGetComboMaxTrdQtys.Response rsp)
{
Console.Write("Reply: TrdGetComboMaxTrdQtys: {0}\n", nSerialNo);
Console.Write("accID: {0}\n", rsp.S2C.Header.AccID);
}
public static void Main(String[] args) {
MMAPI.Init();
Program trd = new Program();
trd.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
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
- Output
Trd onInitConnect: ret=0 desc= connID=6826812678028044696
Send TrdGetComboMaxTrdQtys: 3
Reply: TrdGetComboMaxTrdQtys: 3
accID: 281756457888247915
2
3
4
int getComboMaxTrdQtys(TrdGetComboMaxTrdQtys.Request req);
void onReply_GetComboMaxTrdQtys(MMAPI_Conn client, int nSerialNo, TrdGetComboMaxTrdQtys.Response rsp);
介绍
查询组合订单的可交易信息
参数
message C2S
{
required Trd_Common.TrdHeader header = 1;
repeated Qot_Common.ComboLeg comboLegs = 2;
required double qty = 4;
optional double price = 5;
required int32 orderType = 6;
optional string orderIDEx = 7;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 回调
message S2C
{
required Trd_Common.TrdHeader header = 1;
optional Trd_Common.ComboMaxTrdQtys maxTrdQtys = 2;
}
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
- 组合可交易信息结构参见 ComboMaxTrdQtys
- 接口调用结果,结构参见 RetType
- Example
public class TrdDemo implements MMSPI_Trd, MMSPI_Conn {
MMAPI_Conn_Trd trd = new MMAPI_Conn_Trd();
public TrdDemo() {
trd.setClientInfo("javaclient", 1); //设置客户端信息
trd.setConnSpi(this); //设置连接回调
trd.setTrdSpi(this); //设置交易回调
}
public void start() {
trd.initConnect("127.0.0.1", (short)11111, false);
}
@Override
public void onInitConnect(MMAPI_Conn client, long errCode, String desc)
{
System.out.printf("Trd onInitConnect: ret=%b desc=%s connID=%d\n", errCode, desc, client.getConnectID());
if (errCode != 0)
return;
TrdCommon.TrdHeader header = TrdCommon.TrdHeader.newBuilder()
.setAccID(281756457888247915L)
.setTrdEnv(TrdCommon.TrdEnv.TrdEnv_Simulate_VALUE)
.setTrdMarket(TrdCommon.TrdMarket.TrdMarket_US_VALUE)
.build();
QotCommon.ComboLeg leg1 = QotCommon.ComboLeg.newBuilder()
.setSecurity(QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_US_Security_VALUE)
.setCode("AAPL260529C302500")
.build())
.setSide(TrdCommon.TrdSide.TrdSide_Buy_VALUE)
.setQtyRatio(1)
.build();
QotCommon.ComboLeg leg2 = QotCommon.ComboLeg.newBuilder()
.setSecurity(QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_US_Security_VALUE)
.setCode("AAPL")
.build())
.setSide(TrdCommon.TrdSide.TrdSide_Sell_VALUE)
.setQtyRatio(100)
.build();
TrdGetComboMaxTrdQtys.C2S c2s = TrdGetComboMaxTrdQtys.C2S.newBuilder()
.setHeader(header)
.addComboLegs(leg1)
.addComboLegs(leg2)
.setQty(1)
.setPrice(100)
.setOrderType(TrdCommon.OrderType.OrderType_Normal_VALUE)
.build();
TrdGetComboMaxTrdQtys.Request req = TrdGetComboMaxTrdQtys.Request.newBuilder().setC2S(c2s).build();
int seqNo = trd.getComboMaxTrdQtys(req);
System.out.printf("Send TrdGetComboMaxTrdQtys: %d\n", seqNo);
}
@Override
public void onDisconnect(MMAPI_Conn client, long errCode) {
System.out.printf("Trd onDisConnect: %d\n", errCode);
}
@Override
public void onReply_GetComboMaxTrdQtys(MMAPI_Conn client, int nSerialNo, TrdGetComboMaxTrdQtys.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("TrdGetComboMaxTrdQtys failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive TrdGetComboMaxTrdQtys: %s\n", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
MMAPI.init();
TrdDemo trd = new TrdDemo();
trd.start();
while (true) {
try {
Thread.sleep(1000 * 600);
} catch (InterruptedException exc) {
}
}
}
}
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
83
84
85
86
87
88
- Output
Send TrdGetComboMaxTrdQtys: 2
Receive TrdGetComboMaxTrdQtys: {
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"header": {
"trdEnv": 0,
"accID": "281756457888247915",
"trdMarket": 2
},
"maxTrdQtys": {
"nlvChange": -125.3,
"initialMarginChange": 320.0,
"maintenanceMarginChange": 300.0,
"optionBuyPower": 18600.0,
"maxWithDrawChange": -320.0,
"buyPowerDecrease": 410.0
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
moomoo::u32_t GetComboMaxTrdQtys(const Trd_GetComboMaxTrdQtys::Request &stReq);
virtual void OnReply_GetComboMaxTrdQtys(moomoo::u32_t nSerialNo, const Trd_GetComboMaxTrdQtys::Response &stRsp) = 0;
介绍
获取组合策略下单的最大可交易数量、最大可下单数量对账户综合净资产、保证金、期权购买力等指标的预估影响。下单前调用,可以在不真正占用资金的情况下预估单笔组合的成本。
参数
message C2S
{
required Trd_Common.TrdHeader header = 1; //交易公共参数头
repeated Qot_Common.ComboLeg comboLegs = 2; //组合的腿信息
required double qty = 4; //数量,实际数量为 qty * 腿的 qty_ratio
optional double price = 5; //价格
required int32 orderType = 6; //OrderType,订单类型
optional string orderIDEx = 7; //订单号,改单时使用
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
- 返回
message ComboMaxTrdQtys
{
optional double nlvChange = 1; //综合净资产
optional double initialMarginChange = 2; //初始保证金
optional double maintenanceMarginChange = 3; //维持保证金
optional double optionBuyPower = 4; //期权购买力
optional double maxWithDrawChange = 5; //最大可提
optional double buyPowerDecrease = 6; //消耗购买力
}
message S2C
{
required Trd_Common.TrdHeader header = 1; //交易公共参数头
optional Trd_Common.ComboMaxTrdQtys maxTrdQtys = 2; //组合最大可交易数量结构
}
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
15
16
17
18
19
20
21
22
23
- 接口调用结果,结构参见 RetType
- Example
class Program : public MMSPI_Qot, public MMSPI_Trd, public MMSPI_Conn
{
public:
Program() {
m_pTrdApi = MMAPI::CreateTrdApi();
m_pTrdApi->RegisterTrdSpi(this);
m_pTrdApi->RegisterConnSpi(this);
}
~Program() {
if (m_pTrdApi != nullptr)
{
m_pTrdApi->UnregisterTrdSpi();
m_pTrdApi->UnregisterConnSpi();
MMAPI::ReleaseTrdApi(m_pTrdApi);
m_pTrdApi = nullptr;
}
}
void Start() {
m_pTrdApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(MMAPI_Conn* pConn, moomoo::i64_t nErrCode, const char* strDesc) {
cout << "connect" << endl;
// 组包
Trd_GetComboMaxTrdQtys::Request req;
Trd_GetComboMaxTrdQtys::C2S *c2s = req.mutable_c2s();
Trd_Common::TrdHeader *header = c2s->mutable_header();
header->set_accid(3637840);
header->set_trdenv(0); // TrdEnv,0 真实 / 1 模拟
header->set_trdmarket(2); // TrdMarket,2 美股
// 本例为 Covered Call:买入 100 股 AAPL 正股 + 卖出 1 张 AAPL Call
Qot_Common::ComboLeg *leg1 = c2s->add_combolegs();
leg1->mutable_security()->set_market(Qot_Common::QotMarket_US_Security);
leg1->mutable_security()->set_code("AAPL260529C302500");
leg1->set_side(Trd_Common::TrdSide_Sell); // 卖出 Call
leg1->set_qtyratio(1);
Qot_Common::ComboLeg *leg2 = c2s->add_combolegs();
leg2->mutable_security()->set_market(Qot_Common::QotMarket_US_Security);
leg2->mutable_security()->set_code("AAPL");
leg2->set_side(Trd_Common::TrdSide_Buy); // 买入正股
leg2->set_qtyratio(100);
c2s->set_qty(1); // 实际下单 = qty × 各腿 qty_ratio(1 张 Call + 100 股正股)
c2s->set_price(190.1); // 组合净限价(净支出 = 正股买入价 − 卖出 Call 权利金)
c2s->set_ordertype(Trd_Common::OrderType_Normal);
m_GetComboMaxTrdQtysSerialNo = m_pTrdApi->GetComboMaxTrdQtys(req);
cout << "Request GetComboMaxTrdQtys SerialNo: " << m_GetComboMaxTrdQtysSerialNo << endl;
}
virtual void OnReply_GetComboMaxTrdQtys(moomoo::u32_t nSerialNo, const Trd_GetComboMaxTrdQtys::Response &stRsp) {
if (nSerialNo != m_GetComboMaxTrdQtysSerialNo) return;
cout << "OnReply_GetComboMaxTrdQtys SerialNo: " << nSerialNo << endl;
// 解析内部结构打印出来
// ProtoBufToBodyData 和 UTF8ToLocal 函数的定义参见 Sample 中的 tool.h 文件
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
MMAPI_Trd *m_pTrdApi;
moomoo::u32_t m_GetComboMaxTrdQtysSerialNo = 0;
};
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
83
84
85
86
87
88
- Output
connect
Request GetComboMaxTrdQtys SerialNo: 3
OnReply_GetComboMaxTrdQtys SerialNo: 3
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"header": { "trdEnv": 0, "accID": "3637840", "trdMarket": 2 },
"maxTrdQtys": {
"nlvChange": 0,
"initialMarginChange": 10000.0,
"maintenanceMarginChange": 5000.0,
"optionBuyPower": 12500.0,
"maxWithDrawChange": -10000.0,
"buyPowerDecrease": 10000.0
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
GetComboMaxTrdQtys(req);
介绍
查询组合订单的可交易信息
参数
message C2S
{
required Trd_Common.TrdHeader header = 1;
repeated Qot_Common.ComboLeg comboLegs = 2;
required double qty = 4;
optional double price = 5;
required int32 orderType = 6;
optional string orderIDEx = 7;
}
2
3
4
5
6
7
8
9
- 返回
message S2C
{
required Trd_Common.TrdHeader header = 1;
optional Trd_Common.ComboMaxTrdQtys maxTrdQtys = 2;
}
2
3
4
5
- 组合可交易信息结构参见 ComboMaxTrdQtys
- 接口调用结果,结构参见 RetType
- Example
import mmWebsocket from "moomoo-api";
import { mmCmdID } from "moomoo-api";
import { Common, Qot_Common, Trd_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function TrdGetComboMaxTrdQtys(){
const { RetType } = Common
const { TrdEnv, OrderType, TrdMarket } = Trd_Common
const { QotMarket } = Qot_Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new mmWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) { // 登录成功
websocket.GetAccList({
c2s: {
userID: 0,
},
}).then((res) => {
let { retType, s2c: { accList } } = res
if(retType == RetType.RetType_Succeed){
let acc = accList.filter((item)=>{
return item.trdEnv == TrdEnv.TrdEnv_Simulate && item.trdMarketAuthList.some((auth)=>{ return auth == TrdMarket.TrdMarket_US})
})[0]; // 样例取第一个美国市场虚拟环境账户
const req = {
c2s: {
header: {
trdEnv: acc.trdEnv,
accID: acc.accID,
trdMarket: TrdMarket.TrdMarket_US,
},
comboLegs: [
{
security: { market: QotMarket.QotMarket_US_Security, code: "AAPL260529C302500" },
side: Trd_Common.TrdSide.TrdSide_Buy,
qtyRatio: 1,
},
{
security: { market: QotMarket.QotMarket_US_Security, code: "AAPL" },
side: Trd_Common.TrdSide.TrdSide_Sell,
qtyRatio: 100,
},
],
qty: 1,
price: 100,
orderType: OrderType.OrderType_Normal,
},
};
websocket.GetComboMaxTrdQtys(req)
.then((res) => {
let { errCode, retMsg, retType,s2c } = res
console.log("GetComboMaxTrdQtys: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
let data = beautify(JSON.stringify(s2c), {
indent_size: 2,
space_in_empty_paren: true,
});
console.log(data);
}
})
.catch((error) => {
console.log("error:", error);
});
}
})
.catch((error) => {
console.log("GetAccList error:", error);
});
} else {
console.log("error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
//关闭行情连接,连接不再使用之后,要关闭,否则占用不必要资源
//同时OpenD也限制了最多128条连接
//也可以一个页面或者一个项目维护一条连接,这里范例请求一次创建一条连接
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // 5秒后断开
}
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
83
84
85
86
- Output
GetComboMaxTrdQtys: errCode 0, retMsg , retType 0
{
"header": {
"trdEnv": 0,
"accID": "6684972",
"trdMarket": 2
},
"maxTrdQtys": {
"nlvChange": -125.3,
"initialMarginChange": 320.0,
"maintenanceMarginChange": 300.0,
"optionBuyPower": 18600.0,
"maxWithDrawChange": -320.0,
"buyPowerDecrease": 410.0
}
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
接口限制
- 同一账户 ID(acc_id) 每 30 秒内最多请求 10 次查询最大可买可卖类接口。