# オプションスナップショットの取得
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_option_quote(combo_leg_list)
説明
コンボレッグリストからオプションスナップショットを取得します。マルチレッグ戦略の一括見積もりに適しています。
パラメータ
パラメータ 型 説明 combo_leg_list list コンボレッグリスト 要素は OptionStrategyLeg;構造は get_option_strategy を参照戻り値
パラメータ 型 説明 ret RET_CODE API呼び出し結果 data pd.DataFrame ret == RET_OK の場合、オプションスナップショットデータを返します str ret != RET_OK の場合、エラー説明を返します DataFrameフィールド:
フィールド 型 説明 price float コンボ価格 change_val float 値幅 change_rate float 騰落率 volume str 出来高 turnover str 売買代金 high_price str 高値 low_price str 安値 mid_price str 仲値 open_price str 始値 last_close_price float 前日終値 open_interest str 建玉 premium str プレミアム implied_volatility str インプライド・ボラティリティ delta float Delta gamma float Gamma vega float Vega theta float Theta rho float Rho option_type str オプションタイプ expire_time str 満期日 strike_price str 行使価格 contract_size float 契約規模 contract_multiplier float 契約乗数 exercise_type str 行使方式 days_to_expiry int 満期までの日数 net_open_interest str ネット建玉 contract_value str 契約価値 equal_underlying str 同等原資産 index_option_type str 指数オプションタイプ intrinsic_value float 内在価値 time_value float 時間価値 breakeven_point list 損益分岐点 dist_to_breakeven list 損益分岐点までの距離 prob_of_profit float 利益確率 このフィールドはパーセントフィールドで、デフォルトでは % を表示しません。20 は実際には 20% に対応しますseller_roi str 売り手ROI このフィールドはパーセントフィールドで、デフォルトでは % を表示しません。20 は実際には 20% に対応しますmark_price float マーク価格 leverage_ratio str レバレッジ比率 effective_gearing str 実効ギアリング
Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.get_option_strategy(code='HK.00700', option_strategy=OptionStrategyType.STRADDLE)
if ret == RET_OK:
index=0
print(data['legs'][index])
ret2,data2 = quote_ctx.get_option_quote(data['legs'][index])
if ret2 == RET_OK:
print(data2)
else:
print("get_analysis,error:",data2)
else:
print('error:', data)
quote_ctx.close() # 接続上限を避けるため、終了後は接続を閉じてください
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Output
[OptionStrategyLeg(code=HK.TCH260522P330000, action=BUY, quantity=1.0), OptionStrategyLeg(code=HK.TCH260522C330000, action=BUY, quantity=1.0)]
price change_val change_rate volume turnover high_price low_price mid_price open_price last_close_price open_interest premium implied_volatility delta gamma vega theta rho option_type expire_time strike_price contract_size contract_multiplier exercise_type days_to_expiry net_open_interest contract_value equal_underlying index_option_type intrinsic_value time_value breakeven_point dist_to_breakeven prob_of_profit seller_roi mark_price leverage_ratio effective_gearing
0 131.65 0.0 0.0 N/A N/A N/A N/A N/A N/A 131.65 N/A N/A N/A 0.974369 0.000797 0.019825 -0.785757 0.016246 N/A 2026-05-22 N/A 100.0 100.0 N/A 2 N/A N/A N/A N/A 125.2 6.45 [199.56, 460.44] [255.64, -5.240000000000009] 0.315418 N/A 130.4 N/A N/A
2
3
# Qot_GetOptionQuote.proto
説明
オプションコンボスナップショットを取得
パラメータ
message C2S
{
repeated OptionStrategyLeg comboLegList = 1; // コンボレッグリスト
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
- コンボレッグ構造体: OptionStrategyLeg
- 戻り値
message S2C
{
// オプションスナップショット一覧(フィールドはプロトコル定義に準拠)
}
message Response
{
required int32 retType = 1 [default = -400]; // 戻り値,详见 Common.RetType
optional string retMsg = 2; // 戻り値の説明
optional int32 errCode = 3; // エラーコード
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
- API呼び出し結果の構造体: RetType
- OptionType列挙型: OptionType
- IndexOptionType列挙型: IndexOptionType
uint GetOptionQuote(QotGetOptionQuote.Request req);
virtual void OnReply_GetOptionQuote(FTAPI_Conn client, uint nSerialNo, QotGetOptionQuote.Response rsp);
説明
オプションコンボのスナップショットを取得します。リクエストに multi_legs を渡します。オプション戦略取得 の戻り値から取得できます。単一レッグは 1 件、複数レッグは戦略集約後 1 件を返します。
パラメータ
message C2S
{
repeated Qot_Common.ComboLeg multi_legs = 1;
optional Qot_Common.QotHeader header = 100;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
- multi_legs は オプション戦略取得 の戻り値から取得できます
- 戻り値
message OptionQuote
{
optional double price = 1;
optional double chg = 2;
optional double chg_rate = 3;
optional int64 vol = 4;
optional double turnover = 5;
optional double high = 6;
optional double low = 7;
optional double mid = 8;
optional double open = 9;
optional double pre_close = 10;
optional int32 open_interest = 11;
optional double premium = 12;
optional double IV = 13;
optional double delta = 14;
optional double gamma = 15;
optional double vega = 16;
optional double theta = 17;
optional double rho = 18;
optional int32 option_type = 19;
optional string expire_time = 20;
optional double strike = 21;
optional double contract_size = 22;
optional double contract_multiplier = 23;
optional int32 exercise_type = 24;
optional int32 days_to_expiry = 25;
optional int32 net_open_interest = 26;
optional double contract_value = 27;
optional double equal_underlying = 28;
optional int32 index_option_type = 29;
optional double intrinsic_value = 30;
optional double time_value = 31;
repeated double breakeven_point = 32;
repeated double dist_to_breakeven = 33;
optional double prob_of_profit = 34;
optional double seller_roi = 35;
optional double mark_price = 36;
optional double leverage_ratio = 37;
optional double effective_gearing = 38;
}
message S2C
{
repeated OptionQuote optionQuoteList = 1;
}
message Response
{
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
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
- Example
public class Program : FTSPI_Qot, FTSPI_Conn
{
FTAPI_Qot qot = new FTAPI_Qot();
public Program()
{
qot.SetClientInfo("csharp", 1);
qot.SetConnCallback(this);
qot.SetQotCallback(this);
}
public void Start()
{
qot.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(FTAPI_Conn client, long errCode, String desc)
{
Console.Write("Qot onInitConnect: ret={0} desc={1} connID={2}\n", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
QotCommon.ComboLeg leg = QotCommon.ComboLeg.CreateBuilder()
.SetSecurity(QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_HK_Security)
.SetCode("TCH260622C330000")
.Build())
.SetSide((int)TrdCommon.TrdSide.TrdSide_Buy)
.SetQtyRatio(1)
.Build();
QotGetOptionQuote.C2S c2s = QotGetOptionQuote.C2S.CreateBuilder()
.AddMultiLegs(leg)
.Build();
QotGetOptionQuote.Request req = QotGetOptionQuote.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetOptionQuote(req);
Console.Write("Send QotGetOptionQuote: {0}\n", seqNo);
}
public void OnDisconnect(FTAPI_Conn client, long errCode)
{
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_GetOptionQuote(FTAPI_Conn client, uint nSerialNo, QotGetOptionQuote.Response rsp)
{
Console.Write("Reply: QotGetOptionQuote: {0} {1}\n", nSerialNo, rsp.ToString());
}
public static void Main(String[] args)
{
FTAPI.Init();
Program qot = new Program();
qot.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
- Output
Qot onInitConnect: ret=0 desc= connID=7459213669204006063
Send QotGetOptionQuote: 3
Reply: QotGetOptionQuote: 3 retType: 0 ...
2
3
int getOptionQuote(QotGetOptionQuote.Request req);
void onReply_GetOptionQuote(FTAPI_Conn client, int nSerialNo, QotGetOptionQuote.Response rsp);
説明
オプションコンボのスナップショットを取得します。リクエストに multi_legs を渡します。オプション戦略取得 の戻り値から取得できます。単一レッグは 1 件、複数レッグは戦略集約後 1 件を返します。
パラメータ
message C2S
{
repeated Qot_Common.ComboLeg multi_legs = 1;
optional Qot_Common.QotHeader header = 100;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
- multi_legs は オプション戦略取得 の戻り値から取得できます
- 戻り値
message OptionQuote
{
optional double price = 1;
optional double chg = 2;
optional double chg_rate = 3;
optional int64 vol = 4;
optional double turnover = 5;
optional double high = 6;
optional double low = 7;
optional double mid = 8;
optional double open = 9;
optional double pre_close = 10;
optional int32 open_interest = 11;
optional double premium = 12;
optional double IV = 13;
optional double delta = 14;
optional double gamma = 15;
optional double vega = 16;
optional double theta = 17;
optional double rho = 18;
optional int32 option_type = 19;
optional string expire_time = 20;
optional double strike = 21;
optional double contract_size = 22;
optional double contract_multiplier = 23;
optional int32 exercise_type = 24;
optional int32 days_to_expiry = 25;
optional int32 net_open_interest = 26;
optional double contract_value = 27;
optional double equal_underlying = 28;
optional int32 index_option_type = 29;
optional double intrinsic_value = 30;
optional double time_value = 31;
repeated double breakeven_point = 32;
repeated double dist_to_breakeven = 33;
optional double prob_of_profit = 34;
optional double seller_roi = 35;
optional double mark_price = 36;
optional double leverage_ratio = 37;
optional double effective_gearing = 38;
}
message S2C
{
repeated OptionQuote optionQuoteList = 1;
}
message Response
{
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
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
- Example
public class QotDemo implements FTSPI_Qot, FTSPI_Conn {
FTAPI_Conn_Qot qot = new FTAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1);
qot.setConnSpi(this);
qot.setQotSpi(this);
}
public void start() {
qot.initConnect("127.0.0.1", (short)11111, false);
}
@Override
public void onInitConnect(FTAPI_Conn client, long errCode, String desc)
{
System.out.printf("Qot onInitConnect: ret=%b desc=%s connID=%d\n", errCode, desc, client.getConnectID());
if (errCode != 0)
return;
QotCommon.ComboLeg leg = QotCommon.ComboLeg.newBuilder()
.setSecurity(QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_HK_Security_VALUE)
.setCode("TCH260622C330000")
.build())
.setSide(TrdCommon.TrdSide.TrdSide_Buy_VALUE)
.setQtyRatio(1)
.build();
QotGetOptionQuote.C2S c2s = QotGetOptionQuote.C2S.newBuilder()
.addMultiLegs(leg)
.build();
QotGetOptionQuote.Request req = QotGetOptionQuote.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getOptionQuote(req);
System.out.printf("Send QotGetOptionQuote: %d\n", seqNo);
}
@Override
public void onDisconnect(FTAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onReply_GetOptionQuote(FTAPI_Conn client, int nSerialNo, QotGetOptionQuote.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetOptionQuote failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetOptionQuote: %s\n", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
FTAPI.init()
QotDemo qot = new QotDemo();
qot.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
- Output
Qot onInitConnect: ret=0 desc= connID=7459213669204006063
Send QotGetOptionQuote: 2
Receive QotGetOptionQuote: {
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"optionQuoteList": [
{
"strike": 330,
"price": 131.65,
"chg": 0,
"chgRate": 0,
"delta": 0.974369,
"gamma": 0.000797,
"vega": 0.019825,
"theta": -0.785757,
"rho": 0.016246,
"expireTime": "2026-06-22",
"contractSize": 100,
"contractMultiplier": 100,
"daysToExpiry": 21,
"intrinsicValue": 125.2,
"timeValue": 6.45,
"breakevenPoint": [460.44],
"distToBreakeven": [-5.24],
"probOfProfit": 0.315418,
"markPrice": 130.4
}
]
}
}
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
Futu::u32_t GetOptionQuote(const Qot_GetOptionQuote::Request &stReq);
virtual void OnReply_GetOptionQuote(Futu::u32_t nSerialNo, const Qot_GetOptionQuote::Response &stRsp) = 0;
説明
オプションコンボのスナップショット相場を取得します。リクエストにコンボレッグリスト
multi_legsを渡します。これは オプション戦略取得 インターフェースが返すmulti_legsから取得できます。単一レッグの場合はそのレッグに対応する 1 件、複数レッグの場合は戦略単位で集約された 1 件のレコードを返します。パラメータ
message C2S
{
repeated Qot_Common.ComboLeg multi_legs = 1; //コンボ戦略契約レッグリスト(実際の注文数量 = 外側 qty × レッグの qty_ratio)
optional Qot_Common.QotHeader header = 100; //相場共通ヘッダ
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
multi_legsは オプション戦略取得 が返すmulti_legsから取得できます
- 戻り値
message OptionQuote
{
//--- 基本相場 ---
optional double price = 1; //最新値
optional double chg = 2; //変動額
optional double chg_rate = 3; //変動率(百分率、例:20 は 20% を意味)
optional int64 vol = 4; //出来高
optional double turnover = 5; //売買代金
optional double high = 6; //高値
optional double low = 7; //安値
optional double mid = 8; //中値(買気配 1 と売気配 1 の平均)
optional double open = 9; //始値
optional double pre_close = 10; //前日終値
//--- オプション派生データ ---
optional int32 open_interest = 11; //未決済建玉
optional double premium = 12; //プレミアム(百分率)
optional double IV = 13; //インプライドボラティリティ(百分率)
optional double delta = 14; //Delta
optional double gamma = 15; //Gamma
optional double vega = 16; //Vega
optional double theta = 17; //Theta
optional double rho = 18; //Rho
//--- オプション契約静的属性 ---
optional int32 option_type = 19; //Qot_Common.OptionType、CALL/PUT
optional string expire_time = 20; //満期日
optional double strike = 21; //行使価格
optional double contract_size = 22; //契約サイズ
optional double contract_multiplier = 23; //契約乗数
optional int32 exercise_type = 24; //Qot_Common.OptionAreaType、行使タイプ(米国式/欧州式/バミューダ式)
optional int32 days_to_expiry = 25; //満期までの日数、負数は満期済を意味
optional int32 net_open_interest = 26; //純未決済建玉(香港株オプションのみ)
optional double contract_value = 27; //契約金額(香港株オプションのみ)
optional double equal_underlying = 28; //相当する原資産株数(香港株オプションのみ)
optional int32 index_option_type = 29; //Qot_Common.IndexOptionType、指数オプションタイプ
//--- オプション固有分析データ ---
optional double intrinsic_value = 30; //本質的価値
optional double time_value = 31; //時間価値
repeated double breakeven_point = 32; //損益分岐点リスト
repeated double dist_to_breakeven = 33; //breakeven_point とインデックス対応の距離
optional double prob_of_profit = 34; //利益確率
optional double seller_roi = 35; //売り手リターン率(百分率)
optional double mark_price = 36; //マーク価格
optional double leverage_ratio = 37; //レバレッジ倍率
optional double effective_gearing = 38; //実効ギアリング
}
message S2C
{
repeated OptionQuote optionQuoteList = 1; //オプションリアルタイム相場リスト
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType、戻り値
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
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
- API呼び出し結果の構造体: RetType
- OptionType列挙型: OptionType
- IndexOptionType列挙型: IndexOptionType
- Example
class Program : public FTSPI_Qot, public FTSPI_Trd, public FTSPI_Conn
{
public:
Program() {
m_pQotApi = FTAPI::CreateQotApi();
m_pQotApi->RegisterQotSpi(this);
m_pQotApi->RegisterConnSpi(this);
}
~Program() {
if (m_pQotApi != nullptr)
{
m_pQotApi->UnregisterQotSpi();
m_pQotApi->UnregisterConnSpi();
FTAPI::ReleaseQotApi(m_pQotApi);
m_pQotApi = nullptr;
}
}
void Start() {
m_pQotApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(FTAPI_Conn* pConn, Futu::i64_t nErrCode, const char* strDesc) {
cout << "connect" << endl;
// リクエストを構築
Qot_GetOptionQuote::Request req;
Qot_GetOptionQuote::C2S *c2s = req.mutable_c2s();
// コンボレッグリスト(通常 GetOptionStrategy が返す multi_legs から取得)
Qot_Common::ComboLeg *leg = c2s->add_multi_legs();
Qot_Common::Security *sec = leg->mutable_security();
sec->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
sec->set_code("TCH260622C330000"); // オプションコード:テンセント Call、2026-06-22 満期、行使価格 330
leg->set_side(Trd_Common::TrdSide::TrdSide_Buy);
leg->set_qtyratio(1);
m_GetOptionQuoteSerialNo = m_pQotApi->GetOptionQuote(req);
cout << "Request GetOptionQuote SerialNo: " << m_GetOptionQuoteSerialNo << endl;
}
virtual void OnReply_GetOptionQuote(Futu::u32_t nSerialNo, const Qot_GetOptionQuote::Response &stRsp) {
if (nSerialNo != m_GetOptionQuoteSerialNo) return;
cout << "OnReply_GetOptionQuote SerialNo: " << nSerialNo << endl;
// 内部構造を解析して出力
// ProtoBufToBodyData と UTF8ToLocal は Sample の tool.h を参照
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_GetOptionQuoteSerialNo = 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
- Output
connect
Request GetOptionQuote SerialNo: 3
OnReply_GetOptionQuote SerialNo: 3
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"optionQuoteList": [
{
"strike": 330,
"price": 131.65,
"chg": 0,
"chgRate": 0,
"delta": 0.974369,
"gamma": 0.000797,
"vega": 0.019825,
"theta": -0.785757,
"rho": 0.016246,
"expireTime": "2026-06-22",
"contractSize": 100,
"contractMultiplier": 100,
"daysToExpiry": 21,
"intrinsicValue": 125.2,
"timeValue": 6.45,
"breakevenPoint": [460.44],
"distToBreakeven": [-5.24],
"probOfProfit": 0.315418,
"markPrice": 130.4
}
]
}
}
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
GetOptionQuote(req);
説明
オプションコンボスナップショットを取得
パラメータ
message C2S
{
repeated Qot_Common.ComboLeg multi_legs = 1; //コンボ戦略の脚リスト
optional Qot_Common.QotHeader header = 100; //相場共通ヘッダー
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
- multiLegs は GetOptionStrategy が返す multiLegs から取得できます
- 戻り値
message OptionQuote
{
optional double price = 1; //最新値
optional double chg = 2; //騰落額
optional double chg_rate = 3; //騰落率(パーセント)
optional int64 vol = 4; //出来高
optional double turnover = 5; //売買代金
optional double high = 6; //高値
optional double low = 7; //安値
optional double mid = 8; //仲値
optional double open = 9; //始値
optional double pre_close = 10; //前日終値
optional int32 open_interest = 11; //建玉数
optional double premium = 12; //プレミアム(パーセント)
optional double IV = 13; //インプライドボラティリティ(パーセント)
optional double delta = 14; //Delta
optional double gamma = 15; //Gamma
optional double vega = 16; //Vega
optional double theta = 17; //Theta
optional double rho = 18; //Rho
optional int32 option_type = 19; //OptionType、CALL/PUT
optional string expire_time = 20; //満期日
optional double strike = 21; //権利行使価格
optional double contract_size = 22; //契約サイズ
optional double contract_multiplier = 23; //契約乗数
optional int32 exercise_type = 24; //権利行使タイプ
optional int32 days_to_expiry = 25; //満期までの日数
optional int32 net_open_interest = 26; //ネット建玉数
optional double contract_value = 27; //契約金額
optional double equal_underlying = 28; //原資産換算ロット数
optional int32 index_option_type = 29; //指数オプションタイプ
optional double intrinsic_value = 30; //本質的価値
optional double time_value = 31; //時間的価値
repeated double breakeven_point = 32; //損益分岐点リスト
repeated double dist_to_breakeven = 33; //損益分岐点までの距離
optional double prob_of_profit = 34; //利益確率
optional double seller_roi = 35; //売り手ROI(パーセント)
optional double mark_price = 36; //マーク価格
optional double leverage_ratio = 37; //レバレッジ倍率
optional double effective_gearing = 38; //実効ギアリング
}
message S2C
{
repeated OptionQuote optionQuoteList = 1; //オプションのリアルタイム相場リスト
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
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
- API呼び出し結果の構造体: RetType
- OptionType列挙型: OptionType
- IndexOptionType列挙型: IndexOptionType
- Example
import ftWebsocket from "futu-api";
import { ftCmdID } from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
import beautify from "js-beautify";
function QotGetOptionQuote(){
const { RetType } = Common
const { QotMarket, OptionStrategyType } = 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.GetOptionStrategy({
c2s: {
owner: { market: QotMarket.QotMarket_HK_Security, code: "00700" },
optionStrategy: OptionStrategyType.OptionStrategyType_Straddle,
},
})
.then((res) => {
let { retType, s2c: { strategyList } } = res
if(retType == RetType.RetType_Succeed && strategyList.length > 0){
const req = {
c2s: {
multiLegs: strategyList[0].multiLegs,
},
};
websocket.GetOptionQuote(req)
.then((res) => {
let { errCode, retMsg, retType, s2c } = res
console.log("GetOptionQuote: 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("GetOptionStrategy error:", error);
});
} else {
console.log("start 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
- Output
GetOptionQuote: errCode 0, retMsg , retType 0
{
"optionQuoteList": [{
"price": 131.65,
"chg": 0,
"chgRate": 0,
"delta": 0.974369,
"gamma": 0.000797,
"vega": 0.019825,
"theta": -0.785757,
"rho": 0.016246,
"expireTime": "2026-05-22",
"contractSize": 100,
"contractMultiplier": 100,
"daysToExpiry": 2,
"intrinsicValue": 125.2,
"timeValue": 6.45,
"breakevenPoint": [199.56, 460.44],
"distToBreakeven": [255.64, -5.24],
"probOfProfit": 0.315418,
"markPrice": 130.4
}]
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
API制限
- 30秒あたり最大120回までリクエスト可能。
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_option_quote(combo_leg_list)
説明
コンボレッグリストからオプションスナップショットを取得します。マルチレッグ戦略の一括見積もりに適しています。
パラメータ
パラメータ 型 説明 combo_leg_list list コンボレッグリスト 要素は OptionStrategyLeg;構造は get_option_strategy を参照戻り値
パラメータ 型 説明 ret RET_CODE API呼び出し結果 data pd.DataFrame ret == RET_OK の場合、オプションスナップショットデータを返します str ret != RET_OK の場合、エラー説明を返します DataFrameフィールド:
フィールド 型 説明 price float コンボ価格 change_val float 値幅 change_rate float 騰落率 volume str 出来高 turnover str 売買代金 high_price str 高値 low_price str 安値 mid_price str 仲値 open_price str 始値 last_close_price float 前日終値 open_interest str 建玉 premium str プレミアム implied_volatility str インプライド・ボラティリティ delta float Delta gamma float Gamma vega float Vega theta float Theta rho float Rho option_type str オプションタイプ expire_time str 満期日 strike_price str 行使価格 contract_size float 契約規模 contract_multiplier float 契約乗数 exercise_type str 行使方式 days_to_expiry int 満期までの日数 net_open_interest str ネット建玉 contract_value str 契約価値 equal_underlying str 同等原資産 index_option_type str 指数オプションタイプ intrinsic_value float 内在価値 time_value float 時間価値 breakeven_point list 損益分岐点 dist_to_breakeven list 損益分岐点までの距離 prob_of_profit float 利益確率 このフィールドはパーセントフィールドで、デフォルトでは % を表示しません。20 は実際には 20% に対応しますseller_roi str 売り手ROI このフィールドはパーセントフィールドで、デフォルトでは % を表示しません。20 は実際には 20% に対応しますmark_price float マーク価格 leverage_ratio str レバレッジ比率 effective_gearing str 実効ギアリング
Example
from moomoo import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret, data = quote_ctx.get_option_strategy(code='HK.00700', option_strategy=OptionStrategyType.STRADDLE)
if ret == RET_OK:
index=0
print(data['legs'][index])
ret2,data2 = quote_ctx.get_option_quote(data['legs'][index])
if ret2 == RET_OK:
print(data2)
else:
print("get_analysis,error:",data2)
else:
print('error:', data)
quote_ctx.close() # 接続上限を避けるため、終了後は接続を閉じてください
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- Output
[OptionStrategyLeg(code=HK.TCH260522P330000, action=BUY, quantity=1.0), OptionStrategyLeg(code=HK.TCH260522C330000, action=BUY, quantity=1.0)]
price change_val change_rate volume turnover high_price low_price mid_price open_price last_close_price open_interest premium implied_volatility delta gamma vega theta rho option_type expire_time strike_price contract_size contract_multiplier exercise_type days_to_expiry net_open_interest contract_value equal_underlying index_option_type intrinsic_value time_value breakeven_point dist_to_breakeven prob_of_profit seller_roi mark_price leverage_ratio effective_gearing
0 131.65 0.0 0.0 N/A N/A N/A N/A N/A N/A 131.65 N/A N/A N/A 0.974369 0.000797 0.019825 -0.785757 0.016246 N/A 2026-05-22 N/A 100.0 100.0 N/A 2 N/A N/A N/A N/A 125.2 6.45 [199.56, 460.44] [255.64, -5.240000000000009] 0.315418 N/A 130.4 N/A N/A
2
3
# Qot_GetOptionQuote.proto
説明
オプションコンボスナップショットを取得
パラメータ
message C2S
{
repeated OptionStrategyLeg comboLegList = 1; // コンボレッグリスト
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
- コンボレッグ構造体: OptionStrategyLeg
- 戻り値
message S2C
{
// オプションスナップショット一覧(フィールドはプロトコル定義に準拠)
}
message Response
{
required int32 retType = 1 [default = -400]; // 戻り値,详见 Common.RetType
optional string retMsg = 2; // 戻り値の説明
optional int32 errCode = 3; // エラーコード
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
- API呼び出し結果の構造体: RetType
- OptionType列挙型: OptionType
- IndexOptionType列挙型: IndexOptionType
uint GetOptionQuote(QotGetOptionQuote.Request req);
virtual void OnReply_GetOptionQuote(MMAPI_Conn client, uint nSerialNo, QotGetOptionQuote.Response rsp);
説明
オプションコンボのスナップショットを取得します。リクエストに multi_legs を渡します。オプション戦略取得 の戻り値から取得できます。単一レッグは 1 件、複数レッグは戦略集約後 1 件を返します。
パラメータ
message C2S
{
repeated Qot_Common.ComboLeg multi_legs = 1;
optional Qot_Common.QotHeader header = 100;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
- multi_legs は オプション戦略取得 の戻り値から取得できます
- 戻り値
message OptionQuote
{
optional double price = 1;
optional double chg = 2;
optional double chg_rate = 3;
optional int64 vol = 4;
optional double turnover = 5;
optional double high = 6;
optional double low = 7;
optional double mid = 8;
optional double open = 9;
optional double pre_close = 10;
optional int32 open_interest = 11;
optional double premium = 12;
optional double IV = 13;
optional double delta = 14;
optional double gamma = 15;
optional double vega = 16;
optional double theta = 17;
optional double rho = 18;
optional int32 option_type = 19;
optional string expire_time = 20;
optional double strike = 21;
optional double contract_size = 22;
optional double contract_multiplier = 23;
optional int32 exercise_type = 24;
optional int32 days_to_expiry = 25;
optional int32 net_open_interest = 26;
optional double contract_value = 27;
optional double equal_underlying = 28;
optional int32 index_option_type = 29;
optional double intrinsic_value = 30;
optional double time_value = 31;
repeated double breakeven_point = 32;
repeated double dist_to_breakeven = 33;
optional double prob_of_profit = 34;
optional double seller_roi = 35;
optional double mark_price = 36;
optional double leverage_ratio = 37;
optional double effective_gearing = 38;
}
message S2C
{
repeated OptionQuote optionQuoteList = 1;
}
message Response
{
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
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
- Example
public class Program : MMSPI_Qot, MMSPI_Conn
{
MMAPI_Qot qot = new MMAPI_Qot();
public Program()
{
qot.SetClientInfo("csharp", 1);
qot.SetConnCallback(this);
qot.SetQotCallback(this);
}
public void Start()
{
qot.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(MMAPI_Conn client, long errCode, String desc)
{
Console.Write("Qot onInitConnect: ret={0} desc={1} connID={2}\n", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
QotCommon.ComboLeg leg = QotCommon.ComboLeg.CreateBuilder()
.SetSecurity(QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_HK_Security)
.SetCode("TCH260622C330000")
.Build())
.SetSide((int)TrdCommon.TrdSide.TrdSide_Buy)
.SetQtyRatio(1)
.Build();
QotGetOptionQuote.C2S c2s = QotGetOptionQuote.C2S.CreateBuilder()
.AddMultiLegs(leg)
.Build();
QotGetOptionQuote.Request req = QotGetOptionQuote.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetOptionQuote(req);
Console.Write("Send QotGetOptionQuote: {0}\n", seqNo);
}
public void OnDisconnect(MMAPI_Conn client, long errCode)
{
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_GetOptionQuote(MMAPI_Conn client, uint nSerialNo, QotGetOptionQuote.Response rsp)
{
Console.Write("Reply: QotGetOptionQuote: {0} {1}\n", nSerialNo, rsp.ToString());
}
public static void Main(String[] args)
{
MMAPI.Init();
Program qot = new Program();
qot.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
- Output
Qot onInitConnect: ret=0 desc= connID=7459213669204006063
Send QotGetOptionQuote: 3
Reply: QotGetOptionQuote: 3 retType: 0 ...
2
3
int getOptionQuote(QotGetOptionQuote.Request req);
void onReply_GetOptionQuote(MMAPI_Conn client, int nSerialNo, QotGetOptionQuote.Response rsp);
説明
オプションコンボのスナップショットを取得します。リクエストに multi_legs を渡します。オプション戦略取得 の戻り値から取得できます。単一レッグは 1 件、複数レッグは戦略集約後 1 件を返します。
パラメータ
message C2S
{
repeated Qot_Common.ComboLeg multi_legs = 1;
optional Qot_Common.QotHeader header = 100;
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
- multi_legs は オプション戦略取得 の戻り値から取得できます
- 戻り値
message OptionQuote
{
optional double price = 1;
optional double chg = 2;
optional double chg_rate = 3;
optional int64 vol = 4;
optional double turnover = 5;
optional double high = 6;
optional double low = 7;
optional double mid = 8;
optional double open = 9;
optional double pre_close = 10;
optional int32 open_interest = 11;
optional double premium = 12;
optional double IV = 13;
optional double delta = 14;
optional double gamma = 15;
optional double vega = 16;
optional double theta = 17;
optional double rho = 18;
optional int32 option_type = 19;
optional string expire_time = 20;
optional double strike = 21;
optional double contract_size = 22;
optional double contract_multiplier = 23;
optional int32 exercise_type = 24;
optional int32 days_to_expiry = 25;
optional int32 net_open_interest = 26;
optional double contract_value = 27;
optional double equal_underlying = 28;
optional int32 index_option_type = 29;
optional double intrinsic_value = 30;
optional double time_value = 31;
repeated double breakeven_point = 32;
repeated double dist_to_breakeven = 33;
optional double prob_of_profit = 34;
optional double seller_roi = 35;
optional double mark_price = 36;
optional double leverage_ratio = 37;
optional double effective_gearing = 38;
}
message S2C
{
repeated OptionQuote optionQuoteList = 1;
}
message Response
{
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
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
- Example
public class QotDemo implements MMSPI_Qot, MMSPI_Conn {
MMAPI_Conn_Qot qot = new MMAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1);
qot.setConnSpi(this);
qot.setQotSpi(this);
}
public void start() {
qot.initConnect("127.0.0.1", (short)11111, false);
}
@Override
public void onInitConnect(MMAPI_Conn client, long errCode, String desc)
{
System.out.printf("Qot onInitConnect: ret=%b desc=%s connID=%d\n", errCode, desc, client.getConnectID());
if (errCode != 0)
return;
QotCommon.ComboLeg leg = QotCommon.ComboLeg.newBuilder()
.setSecurity(QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_HK_Security_VALUE)
.setCode("TCH260622C330000")
.build())
.setSide(TrdCommon.TrdSide.TrdSide_Buy_VALUE)
.setQtyRatio(1)
.build();
QotGetOptionQuote.C2S c2s = QotGetOptionQuote.C2S.newBuilder()
.addMultiLegs(leg)
.build();
QotGetOptionQuote.Request req = QotGetOptionQuote.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getOptionQuote(req);
System.out.printf("Send QotGetOptionQuote: %d\n", seqNo);
}
@Override
public void onDisconnect(MMAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onReply_GetOptionQuote(MMAPI_Conn client, int nSerialNo, QotGetOptionQuote.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetOptionQuote failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetOptionQuote: %s\n", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
MMAPI.init()
QotDemo qot = new QotDemo();
qot.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
- Output
Qot onInitConnect: ret=0 desc= connID=7459213669204006063
Send QotGetOptionQuote: 2
Receive QotGetOptionQuote: {
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"optionQuoteList": [
{
"strike": 330,
"price": 131.65,
"chg": 0,
"chgRate": 0,
"delta": 0.974369,
"gamma": 0.000797,
"vega": 0.019825,
"theta": -0.785757,
"rho": 0.016246,
"expireTime": "2026-06-22",
"contractSize": 100,
"contractMultiplier": 100,
"daysToExpiry": 21,
"intrinsicValue": 125.2,
"timeValue": 6.45,
"breakevenPoint": [460.44],
"distToBreakeven": [-5.24],
"probOfProfit": 0.315418,
"markPrice": 130.4
}
]
}
}
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
moomoo::u32_t GetOptionQuote(const Qot_GetOptionQuote::Request &stReq);
virtual void OnReply_GetOptionQuote(moomoo::u32_t nSerialNo, const Qot_GetOptionQuote::Response &stRsp) = 0;
説明
オプションコンボのスナップショット相場を取得します。リクエストにコンボレッグリスト
multi_legsを渡します。これは オプション戦略取得 インターフェースが返すmulti_legsから取得できます。単一レッグの場合はそのレッグに対応する 1 件、複数レッグの場合は戦略単位で集約された 1 件のレコードを返します。パラメータ
message C2S
{
repeated Qot_Common.ComboLeg multi_legs = 1; //コンボ戦略契約レッグリスト(実際の注文数量 = 外側 qty × レッグの qty_ratio)
optional Qot_Common.QotHeader header = 100; //相場共通ヘッダ
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
multi_legsは オプション戦略取得 が返すmulti_legsから取得できます
- 戻り値
message OptionQuote
{
//--- 基本相場 ---
optional double price = 1; //最新値
optional double chg = 2; //変動額
optional double chg_rate = 3; //変動率(百分率、例:20 は 20% を意味)
optional int64 vol = 4; //出来高
optional double turnover = 5; //売買代金
optional double high = 6; //高値
optional double low = 7; //安値
optional double mid = 8; //中値(買気配 1 と売気配 1 の平均)
optional double open = 9; //始値
optional double pre_close = 10; //前日終値
//--- オプション派生データ ---
optional int32 open_interest = 11; //未決済建玉
optional double premium = 12; //プレミアム(百分率)
optional double IV = 13; //インプライドボラティリティ(百分率)
optional double delta = 14; //Delta
optional double gamma = 15; //Gamma
optional double vega = 16; //Vega
optional double theta = 17; //Theta
optional double rho = 18; //Rho
//--- オプション契約静的属性 ---
optional int32 option_type = 19; //Qot_Common.OptionType、CALL/PUT
optional string expire_time = 20; //満期日
optional double strike = 21; //行使価格
optional double contract_size = 22; //契約サイズ
optional double contract_multiplier = 23; //契約乗数
optional int32 exercise_type = 24; //Qot_Common.OptionAreaType、行使タイプ(米国式/欧州式/バミューダ式)
optional int32 days_to_expiry = 25; //満期までの日数、負数は満期済を意味
optional int32 net_open_interest = 26; //純未決済建玉(香港株オプションのみ)
optional double contract_value = 27; //契約金額(香港株オプションのみ)
optional double equal_underlying = 28; //相当する原資産株数(香港株オプションのみ)
optional int32 index_option_type = 29; //Qot_Common.IndexOptionType、指数オプションタイプ
//--- オプション固有分析データ ---
optional double intrinsic_value = 30; //本質的価値
optional double time_value = 31; //時間価値
repeated double breakeven_point = 32; //損益分岐点リスト
repeated double dist_to_breakeven = 33; //breakeven_point とインデックス対応の距離
optional double prob_of_profit = 34; //利益確率
optional double seller_roi = 35; //売り手リターン率(百分率)
optional double mark_price = 36; //マーク価格
optional double leverage_ratio = 37; //レバレッジ倍率
optional double effective_gearing = 38; //実効ギアリング
}
message S2C
{
repeated OptionQuote optionQuoteList = 1; //オプションリアルタイム相場リスト
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType、戻り値
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
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
- API呼び出し結果の構造体: RetType
- OptionType列挙型: OptionType
- IndexOptionType列挙型: IndexOptionType
- Example
class Program : public MMSPI_Qot, public MMSPI_Trd, public MMSPI_Conn
{
public:
Program() {
m_pQotApi = MMAPI::CreateQotApi();
m_pQotApi->RegisterQotSpi(this);
m_pQotApi->RegisterConnSpi(this);
}
~Program() {
if (m_pQotApi != nullptr)
{
m_pQotApi->UnregisterQotSpi();
m_pQotApi->UnregisterConnSpi();
MMAPI::ReleaseQotApi(m_pQotApi);
m_pQotApi = nullptr;
}
}
void Start() {
m_pQotApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(MMAPI_Conn* pConn, moomoo::i64_t nErrCode, const char* strDesc) {
cout << "connect" << endl;
// リクエストを構築
Qot_GetOptionQuote::Request req;
Qot_GetOptionQuote::C2S *c2s = req.mutable_c2s();
// コンボレッグリスト(通常 GetOptionStrategy が返す multi_legs から取得)
Qot_Common::ComboLeg *leg = c2s->add_multi_legs();
Qot_Common::Security *sec = leg->mutable_security();
sec->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
sec->set_code("TCH260622C330000"); // オプションコード:テンセント Call、2026-06-22 満期、行使価格 330
leg->set_side(Trd_Common::TrdSide::TrdSide_Buy);
leg->set_qtyratio(1);
m_GetOptionQuoteSerialNo = m_pQotApi->GetOptionQuote(req);
cout << "Request GetOptionQuote SerialNo: " << m_GetOptionQuoteSerialNo << endl;
}
virtual void OnReply_GetOptionQuote(moomoo::u32_t nSerialNo, const Qot_GetOptionQuote::Response &stRsp) {
if (nSerialNo != m_GetOptionQuoteSerialNo) return;
cout << "OnReply_GetOptionQuote SerialNo: " << nSerialNo << endl;
// 内部構造を解析して出力
// ProtoBufToBodyData と UTF8ToLocal は Sample の tool.h を参照
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
MMAPI_Qot *m_pQotApi;
moomoo::u32_t m_GetOptionQuoteSerialNo = 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
- Output
connect
Request GetOptionQuote SerialNo: 3
OnReply_GetOptionQuote SerialNo: 3
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"optionQuoteList": [
{
"strike": 330,
"price": 131.65,
"chg": 0,
"chgRate": 0,
"delta": 0.974369,
"gamma": 0.000797,
"vega": 0.019825,
"theta": -0.785757,
"rho": 0.016246,
"expireTime": "2026-06-22",
"contractSize": 100,
"contractMultiplier": 100,
"daysToExpiry": 21,
"intrinsicValue": 125.2,
"timeValue": 6.45,
"breakevenPoint": [460.44],
"distToBreakeven": [-5.24],
"probOfProfit": 0.315418,
"markPrice": 130.4
}
]
}
}
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
GetOptionQuote(req);
説明
オプションコンボスナップショットを取得
パラメータ
message C2S
{
repeated Qot_Common.ComboLeg multi_legs = 1; //コンボ戦略の脚リスト
optional Qot_Common.QotHeader header = 100; //相場共通ヘッダー
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
- multiLegs は GetOptionStrategy が返す multiLegs から取得できます
- 戻り値
message OptionQuote
{
optional double price = 1; //最新値
optional double chg = 2; //騰落額
optional double chg_rate = 3; //騰落率(パーセント)
optional int64 vol = 4; //出来高
optional double turnover = 5; //売買代金
optional double high = 6; //高値
optional double low = 7; //安値
optional double mid = 8; //仲値
optional double open = 9; //始値
optional double pre_close = 10; //前日終値
optional int32 open_interest = 11; //建玉数
optional double premium = 12; //プレミアム(パーセント)
optional double IV = 13; //インプライドボラティリティ(パーセント)
optional double delta = 14; //Delta
optional double gamma = 15; //Gamma
optional double vega = 16; //Vega
optional double theta = 17; //Theta
optional double rho = 18; //Rho
optional int32 option_type = 19; //OptionType、CALL/PUT
optional string expire_time = 20; //満期日
optional double strike = 21; //権利行使価格
optional double contract_size = 22; //契約サイズ
optional double contract_multiplier = 23; //契約乗数
optional int32 exercise_type = 24; //権利行使タイプ
optional int32 days_to_expiry = 25; //満期までの日数
optional int32 net_open_interest = 26; //ネット建玉数
optional double contract_value = 27; //契約金額
optional double equal_underlying = 28; //原資産換算ロット数
optional int32 index_option_type = 29; //指数オプションタイプ
optional double intrinsic_value = 30; //本質的価値
optional double time_value = 31; //時間的価値
repeated double breakeven_point = 32; //損益分岐点リスト
repeated double dist_to_breakeven = 33; //損益分岐点までの距離
optional double prob_of_profit = 34; //利益確率
optional double seller_roi = 35; //売り手ROI(パーセント)
optional double mark_price = 36; //マーク価格
optional double leverage_ratio = 37; //レバレッジ倍率
optional double effective_gearing = 38; //実効ギアリング
}
message S2C
{
repeated OptionQuote optionQuoteList = 1; //オプションのリアルタイム相場リスト
}
message Response
{
required int32 retType = 1 [default = -400]; //RetType
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
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
- API呼び出し結果の構造体: RetType
- OptionType列挙型: OptionType
- IndexOptionType列挙型: IndexOptionType
- Example
import mmWebsocket from "moomoo-api";
import { mmCmdID } from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function QotGetOptionQuote(){
const { RetType } = Common
const { QotMarket, OptionStrategyType } = 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.GetOptionStrategy({
c2s: {
owner: { market: QotMarket.QotMarket_HK_Security, code: "00700" },
optionStrategy: OptionStrategyType.OptionStrategyType_Straddle,
},
})
.then((res) => {
let { retType, s2c: { strategyList } } = res
if(retType == RetType.RetType_Succeed && strategyList.length > 0){
const req = {
c2s: {
multiLegs: strategyList[0].multiLegs,
},
};
websocket.GetOptionQuote(req)
.then((res) => {
let { errCode, retMsg, retType, s2c } = res
console.log("GetOptionQuote: 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("GetOptionStrategy error:", error);
});
} else {
console.log("start 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
- Output
GetOptionQuote: errCode 0, retMsg , retType 0
{
"optionQuoteList": [{
"price": 131.65,
"chg": 0,
"chgRate": 0,
"delta": 0.974369,
"gamma": 0.000797,
"vega": 0.019825,
"theta": -0.785757,
"rho": 0.016246,
"expireTime": "2026-05-22",
"contractSize": 100,
"contractMultiplier": 100,
"daysToExpiry": 2,
"intrinsicValue": 125.2,
"timeValue": 6.45,
"breakevenPoint": [199.56, 460.44],
"distToBreakeven": [255.64, -5.24],
"probOfProfit": 0.315418,
"markPrice": 130.4
}]
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
API制限
- 30秒あたり最大120回までリクエスト可能。