# コンボ注文の取引可能情報照会
- 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 で、最初の取引口座を指定戻り値
パラメータ 型 説明 ret RET_CODE API呼び出し結果 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
- API 呼び出し結果の構造は 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
- API 呼び出し結果の構造は 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
- API 呼び出し結果の構造は 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
- API 呼び出し結果の構造は 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: AAPL 原資産 100 株買い + AAPL Call 1 枚売り
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
- API 呼び出し結果の構造は 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 接続に制限されています
//1 ページまたは 1 プロジェクトで 1 接続を維持することもできます。この例は 1 リクエストごとに 1 接続を作成します
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
APIレート制限
- 同一口座 ID(acc_id)につき、30 秒以内に最大売買可能数量照会系 API を 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 で、最初の取引口座を指定戻り値
パラメータ 型 説明 ret RET_CODE API呼び出し結果 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
- API 呼び出し結果の構造は 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
- API 呼び出し結果の構造は 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
- API 呼び出し結果の構造は 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
- API 呼び出し結果の構造は 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: AAPL 原資産 100 株買い + AAPL Call 1 枚売り
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
- API 呼び出し結果の構造は 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 接続に制限されています
//1 ページまたは 1 プロジェクトで 1 接続を維持することもできます。この例は 1 リクエストごとに 1 接続を作成します
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
APIレート制限
- 同一口座 ID(acc_id)につき、30 秒以内に最大売買可能数量照会系 API を 10 回までリクエスト可能です。