# 查詢組合可交易資訊
- 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 次查詢最大可買可賣類介面。