# 獲取期權鏈
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_option_chain(code, index_option_type=IndexOptionType.NORMAL, start=None, end=None, option_type=OptionType.ALL, option_cond_type=OptionCondType.ALL, data_filter=None)
介紹
透過標的股票查詢期權鏈。此介面僅返回期權鏈的靜態資訊,如需獲取報價或擺盤等動態資訊,請用此介面返回的股票代碼,自行 訂閱 所需要的類型。
參數
參數 類型 説明 code str 標的股票代碼 index_option_type IndexOptionType 指數期權類型 僅對港股指數期權篩選有效,正股、ETFs、美股指數期權可忽略此參數start str 開始日期,該日期指到期日 例如:“2017-08-01”end str 結束日期(包括這一天),該日期指到期日 例如:“2017-08-30”option_type OptionType 期權看漲看跌類型 預設為全部option_cond_type OptionCondType 期權價內外類型 預設為全部data_filter OptionDataFilter 數據篩選條件 預設為不篩選start 和 end 的組合如下:
Start 類型 End 類型 説明 str str start 和 end 分別為指定的日期 None str start 為 end 往前 30 天 str None end 為 start 往後30天 None None start 為當前日期,end 往後 30 天 OptionDataFilter 欄位如下
欄位 類型 説明 implied_volatility_min float 隱含波動率過濾起點 精確到小數點後 0 位,超出部分會被捨棄
該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%implied_volatility_max float 隱含波動率過濾終點 精確到小數點後 0 位,超出部分會被捨棄
該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%delta_min float 希臘值 Delta 過濾起點 精確到小數點後 3 位,超出部分會被捨棄delta_max float 希臘值 Delta 過濾終點 精確到小數點後 3 位,超出部分會被捨棄gamma_min float 希臘值 Gamma 過濾起點 精確到小數點後 3 位,超出部分會被捨棄gamma_max float 希臘值 Gamma 過濾終點 精確到小數點後 3 位,超出部分會被捨棄vega_min float 希臘值 Vega 過濾起點 精確到小數點後 3 位,超出部分會被捨棄vega_max float 希臘值 Vega 過濾終點 精確到小數點後 3 位,超出部分會被捨棄theta_min float 希臘值 Theta 過濾起點 精確到小數點後 3 位,超出部分會被捨棄theta_max float 希臘值 Theta 過濾終點 精確到小數點後 3 位,超出部分會被捨棄rho_min float 希臘值 Rho 過濾起點 精確到小數點後 3 位,超出部分會被捨棄rho_max float 希臘值 Rho 過濾終點 精確到小數點後 3 位,超出部分會被捨棄net_open_interest_min float 淨未平倉合約數過濾起點 精確到小數點後 0 位,超出部分會被捨棄net_open_interest_max float 淨未平倉合約數過濾終點 精確到小數點後 0 位,超出部分會被捨棄open_interest_min float 未平倉合約數過濾起點 精確到小數點後 0 位,超出部分會被捨棄open_interest_max float 未平倉合約數過濾終點 精確到小數點後 0 位,超出部分會被捨棄vol_min float 成交量過濾起點 精確到小數點後 0 位,超出部分會被捨棄vol_max float 成交量過濾終點 精確到小數點後 0 位,超出部分會被捨棄
返回
參數 類型 説明 ret RET_CODE 介面呼叫結果 data pd.DataFrame 當 ret == RET_OK,返回期權鏈數據 str 當 ret != RET_OK,返回錯誤描述 - 期權鏈數據格式如下:
欄位 類型 説明 code str 股票代碼 name str 名字 lot_size int 每手股數,期權表示每份合約股數 指數期權無該欄位stock_type SecurityType 股票類型 option_type OptionType 期權類型 stock_owner str 標的股 strike_time str 行權日 格式:yyyy-MM-dd
港股和 A 股市場預設是北京時間,美股市場預設是美東時間strike_price float 行權價 suspension bool 是否停牌 True:停牌
False:未停牌stock_id int 股票 ID index_option_type IndexOptionType 指數期權類型 expiration_cycle ExpirationCycle 交割週期 option_standard_type OptionStandardType 期權標準類型 option_settlement_mode OptionSettlementMode 期權結算方式
- 期權鏈數據格式如下:
Example
from futu import *
import time
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret1, data1 = quote_ctx.get_option_expiration_date(code='HK.00700')
filter1 = OptionDataFilter()
filter1.delta_min = 0
filter1.delta_max = 0.1
if ret1 == RET_OK:
expiration_date_list = data1['strike_time'].values.tolist()
for date in expiration_date_list:
ret2, data2 = quote_ctx.get_option_chain(code='HK.00700', start=date, end=date, data_filter=filter1)
if ret2 == RET_OK:
print(data2)
print(data2['code'][0]) # 取第一條的股票代碼
print(data2['code'].values.tolist()) # 轉為 list
else:
print('error:', data2)
time.sleep(3)
else:
print('error:', data1)
quote_ctx.close() # 結束後記得關閉當條連線,防止連線條數用盡
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- Output
code name lot_size stock_type option_type stock_owner strike_time strike_price suspension stock_id index_option_type expiration_cycle option_standard_type option_settlement_mode
0 HK.TCH210429C350000 騰訊 210429 350.00 購 100 DRVT CALL HK.00700 2021-04-29 350.0 False 80235167 N/A WEEK STANDARD N/A
1 HK.TCH210429P350000 騰訊 210429 350.00 沽 100 DRVT PUT HK.00700 2021-04-29 350.0 False 80235247 N/A WEEK STANDARD N/A
2 HK.TCH210429C360000 騰訊 210429 360.00 購 100 DRVT CALL HK.00700 2021-04-29 360.0 False 80235163 N/A WEEK STANDARD N/A
3 HK.TCH210429P360000 騰訊 210429 360.00 沽 100 DRVT PUT HK.00700 2021-04-29 360.0 False 80235246 N/A WEEK STANDARD N/A
4 HK.TCH210429C370000 騰訊 210429 370.00 購 100 DRVT CALL HK.00700 2021-04-29 370.0 False 80235165 N/A WEEK STANDARD N/A
5 HK.TCH210429P370000 騰訊 210429 370.00 沽 100 DRVT PUT HK.00700 2021-04-29 370.0 False 80235248 N/A WEEK STANDARD N/A
HK.TCH210429C350000
['HK.TCH210429C350000', 'HK.TCH210429P350000', 'HK.TCH210429C360000', 'HK.TCH210429P360000', 'HK.TCH210429C370000', 'HK.TCH210429P370000']
...
code name lot_size stock_type option_type stock_owner strike_time strike_price suspension stock_id index_option_type expiration_cycle option_standard_type option_settlement_mode
0 HK.TCH220330C490000 騰訊 220330 490.00 購 100 DRVT CALL HK.00700 2022-03-30 490.0 False 80235143 N/A WEEK STANDARD N/A
1 HK.TCH220330P490000 騰訊 220330 490.00 沽 100 DRVT PUT HK.00700 2022-03-30 490.0 False 80235193 N/A WEEK STANDARD N/A
2 HK.TCH220330C500000 騰訊 220330 500.00 購 100 DRVT CALL HK.00700 2022-03-30 500.0 False 80233887 N/A WEEK STANDARD N/A
3 HK.TCH220330P500000 騰訊 220330 500.00 沽 100 DRVT PUT HK.00700 2022-03-30 500.0 False 80233912 N/A WEEK STANDARD N/A
4 HK.TCH220330C510000 騰訊 220330 510.00 購 100 DRVT CALL HK.00700 2022-03-30 510.0 False 80233747 N/A WEEK STANDARD N/A
5 HK.TCH220330P510000 騰訊 220330 510.00 沽 100 DRVT PUT HK.00700 2022-03-30 510.0 False 80233766 N/A WEEK STANDARD N/A
HK.TCH220330C490000
['HK.TCH220330C490000', 'HK.TCH220330P490000', 'HK.TCH220330C500000', 'HK.TCH220330P500000', 'HK.TCH220330C510000', 'HK.TCH220330P510000']
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Qot_GetOptionChain.proto
介紹
透過標的股票查詢期權鏈。此介面僅返回期權鏈的靜態資訊,如需獲取報價或擺盤等動態資訊,請用此介面返回的股票代碼,自行 訂閱 所需要的類型。
協議 ID
3209
參數
enum OptionCondType
{
OptionCondType_Unknow = 0;
OptionCondType_WithIn = 1; //價內
OptionCondType_Outside = 2; //價外
}
//以下為數據欄位篩選,可選欄位,不填表示不過濾
message DataFilter
{
optional double impliedVolatilityMin = 1; //隱含波動率過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double impliedVolatilityMax = 2; //隱含波動率過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double deltaMin = 3; //希臘值 Delta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double deltaMax = 4; //希臘值 Delta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMin = 5; //希臘值 Gamma 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMax = 6; //希臘值 Gamma 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMin = 7; //希臘值 Vega 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMax = 8; //希臘值 Vega 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMin = 9; //希臘值 Theta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMax = 10; //希臘值 Theta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMin = 11; //希臘值 Rho 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMax = 12; //希臘值 Rho 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double netOpenInterestMin = 13; //淨未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double netOpenInterestMax = 14; //淨未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMin = 15; //未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMax = 16; //未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMin = 17; //成交量過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMax = 18; //成交量過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
}
message C2S
{
required Qot_Common.Security owner = 1; //期權標的股,目前僅支援傳入港美正股以及恒指國指美指
optional int32 indexOptionType = 6; //Qot_Common.IndexOptionType,指數期權的類型,僅用於恒指國指
optional int32 type = 2; //Qot_Common.OptionType,期權類型,可選欄位,不指定則表示都返回
optional int32 condition = 3; //OptionCondType,價內價外,可選欄位,不指定則表示都返回
required string beginTime = 4; //期權到期日開始時間(格式:yyyy-MM-dd)
required string endTime = 5; //期權到期日結束時間,時間跨度最多一個月(格式:yyyy-MM-dd)
optional DataFilter dataFilter = 7; //數據欄位篩選
}
message Request
{
required C2S c2s = 1;
}
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
- 股票結構參見 Security
- 期權類型列舉參見 OptionType
- 指數期權類別列舉參見 IndexOptionType
- 返回
message OptionItem
{
optional Qot_Common.SecurityStaticInfo call = 1; //看漲期權,不一定有該欄位,由請求條件決定
optional Qot_Common.SecurityStaticInfo put = 2; //看跌期權,不一定有該欄位,由請求條件決定
}
message OptionChain
{
required string strikeTime = 1; //行權日(格式:yyyy-MM-dd)
repeated OptionItem option = 2; //期權資訊
optional double strikeTimestamp = 3; //行權日時間戳記
}
message S2C
{
repeated OptionChain optionChain = 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
- 股票靜態資訊結構參見 SecurityStaticInfo
- 介面呼叫結果,結構參見 RetType
協議 ID
3209
uint GetOptionChain(QotGetOptionChain.Request req);
virtual void OnReply_GetOptionChain(FTAPI_Conn client, uint nSerialNo, QotGetOptionChain.Response rsp);
介紹
透過標的股票查詢期權鏈。此介面僅返回期權鏈的靜態資訊,如需獲取報價或擺盤等動態資訊,請用此介面返回的股票代碼,自行 訂閱 所需要的類型。
參數
enum OptionCondType
{
OptionCondType_Unknow = 0;
OptionCondType_WithIn = 1; //價內
OptionCondType_Outside = 2; //價外
}
//以下為數據欄位篩選,可選欄位,不填表示不過濾
message DataFilter
{
optional double impliedVolatilityMin = 1; //隱含波動率過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double impliedVolatilityMax = 2; //隱含波動率過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double deltaMin = 3; //希臘值 Delta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double deltaMax = 4; //希臘值 Delta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMin = 5; //希臘值 Gamma 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMax = 6; //希臘值 Gamma 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMin = 7; //希臘值 Vega 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMax = 8; //希臘值 Vega 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMin = 9; //希臘值 Theta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMax = 10; //希臘值 Theta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMin = 11; //希臘值 Rho 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMax = 12; //希臘值 Rho 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double netOpenInterestMin = 13; //淨未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double netOpenInterestMax = 14; //淨未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMin = 15; //未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMax = 16; //未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMin = 17; //成交量過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMax = 18; //成交量過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
}
message C2S
{
required Qot_Common.Security owner = 1; //期權標的股,目前僅支援傳入港美正股以及恒指國指美指
optional int32 indexOptionType = 6; //Qot_Common.IndexOptionType,指數期權的類型,僅用於恒指國指
optional int32 type = 2; //Qot_Common.OptionType,期權類型,可選欄位,不指定則表示都返回
optional int32 condition = 3; //OptionCondType,價內價外,可選欄位,不指定則表示都返回
required string beginTime = 4; //期權到期日開始時間(格式:yyyy-MM-dd)
required string endTime = 5; //期權到期日結束時間,時間跨度最多一個月(格式:yyyy-MM-dd)
optional DataFilter dataFilter = 7; //數據欄位篩選
}
message Request
{
required C2S c2s = 1;
}
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
- 股票結構參見 Security
- 期權類型列舉參見 OptionType
- 指數期權類別列舉參見 IndexOptionType
- 返回
message OptionItem
{
optional Qot_Common.SecurityStaticInfo call = 1; //看漲期權,不一定有該欄位,由請求條件決定
optional Qot_Common.SecurityStaticInfo put = 2; //看跌期權,不一定有該欄位,由請求條件決定
}
message OptionChain
{
required string strikeTime = 1; //行權日(格式:yyyy-MM-dd)
repeated OptionItem option = 2; //期權資訊
optional double strikeTimestamp = 3; //行權日時間戳記
}
message S2C
{
repeated OptionChain optionChain = 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
- 股票靜態資訊結構參見 SecurityStaticInfo
- 介面呼叫結果,結構參見 RetType
- Example
public class Program : FTSPI_Qot, FTSPI_Conn {
FTAPI_Qot qot = new FTAPI_Qot();
public Program() {
qot.SetClientInfo("csharp", 1); //設定用戶端資訊
qot.SetConnCallback(this); //設定連線回呼
qot.SetQotCallback(this); //設定交易回呼
}
public void Start() {
qot.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(FTAPI_Conn client, long errCode, String desc)
{
Console.Write("Qot onInitConnect: ret={0} desc={1} connID={2}\n", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
QotCommon.Security sec = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_HK_Security)
.SetCode("00700")
.Build();
QotGetOptionChain.C2S c2s = QotGetOptionChain.C2S.CreateBuilder()
.SetOwner(sec)
.SetBeginTime("2020-11-01")
.SetEndTime("2020-12-01")
.Build();
QotGetOptionChain.Request req = QotGetOptionChain.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetOptionChain(req);
Console.Write("Send QotGetOptionChain: {0}\n", seqNo);
}
public void OnDisconnect(FTAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_GetOptionChain(FTAPI_Conn client, uint nSerialNo, QotGetOptionChain.Response rsp)
{
Console.Write("Reply: QotGetOptionChain: {0}\n", nSerialNo);
Console.Write("strikeTime: {0}, name: {1} \n",
rsp.S2C.OptionChainList[0].StrikeTime,
rsp.S2C.OptionChainList[0].OptionList[0].Call.Basic.Name);
}
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
- Output
Qot onInitConnect: ret=0 desc= connID=6825705573658441031
Send QotGetOptionChain: 3
Reply: QotGetOptionChain: 3
strikeTime: 2021-07-29, name: 騰訊 210729 400.00 購
2
3
4
int getOptionChain(QotGetOptionChain.Request req);
void onReply_GetOptionChain(FTAPI_Conn client, int nSerialNo, QotGetOptionChain.Response rsp);
介紹
透過標的股票查詢期權鏈。此介面僅返回期權鏈的靜態資訊,如需獲取報價或擺盤等動態資訊,請用此介面返回的股票代碼,自行 訂閱 所需要的類型。
參數
enum OptionCondType
{
OptionCondType_Unknow = 0;
OptionCondType_WithIn = 1; //價內
OptionCondType_Outside = 2; //價外
}
//以下為數據欄位篩選,可選欄位,不填表示不過濾
message DataFilter
{
optional double impliedVolatilityMin = 1; //隱含波動率過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double impliedVolatilityMax = 2; //隱含波動率過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double deltaMin = 3; //希臘值 Delta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double deltaMax = 4; //希臘值 Delta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMin = 5; //希臘值 Gamma 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMax = 6; //希臘值 Gamma 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMin = 7; //希臘值 Vega 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMax = 8; //希臘值 Vega 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMin = 9; //希臘值 Theta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMax = 10; //希臘值 Theta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMin = 11; //希臘值 Rho 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMax = 12; //希臘值 Rho 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double netOpenInterestMin = 13; //淨未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double netOpenInterestMax = 14; //淨未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMin = 15; //未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMax = 16; //未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMin = 17; //成交量過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMax = 18; //成交量過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
}
message C2S
{
required Qot_Common.Security owner = 1; //期權標的股,目前僅支援傳入港美正股以及恒指國指美指
optional int32 indexOptionType = 6; //Qot_Common.IndexOptionType,指數期權的類型,僅用於恒指國指
optional int32 type = 2; //Qot_Common.OptionType,期權類型,可選欄位,不指定則表示都返回
optional int32 condition = 3; //OptionCondType,價內價外,可選欄位,不指定則表示都返回
required string beginTime = 4; //期權到期日開始時間(格式:yyyy-MM-dd)
required string endTime = 5; //期權到期日結束時間,時間跨度最多一個月(格式:yyyy-MM-dd)
optional DataFilter dataFilter = 7; //數據欄位篩選
}
message Request
{
required C2S c2s = 1;
}
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
- 股票結構參見 Security
- 期權類型列舉參見 OptionType
- 指數期權類別列舉參見 IndexOptionType
- 返回
message OptionItem
{
optional Qot_Common.SecurityStaticInfo call = 1; //看漲期權,不一定有該欄位,由請求條件決定
optional Qot_Common.SecurityStaticInfo put = 2; //看跌期權,不一定有該欄位,由請求條件決定
}
message OptionChain
{
required string strikeTime = 1; //行權日(格式:yyyy-MM-dd)
repeated OptionItem option = 2; //期權資訊
optional double strikeTimestamp = 3; //行權日時間戳記
}
message S2C
{
repeated OptionChain optionChain = 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
- 股票靜態資訊結構參見 SecurityStaticInfo
- 介面呼叫結果,結構參見 RetType
- 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.Security sec = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_HK_Security_VALUE)
.setCode("00700")
.build();
QotGetOptionChain.C2S c2s = QotGetOptionChain.C2S.newBuilder()
.setOwner(sec)
.setBeginTime("2021-06-01")
.setEndTime("2021-07-01")
.build();
QotGetOptionChain.Request req = QotGetOptionChain.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getOptionChain(req);
System.out.printf("Send QotGetOptionChain: %d\n", seqNo);
}
@Override
public void onDisconnect(FTAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onReply_GetOptionChain(FTAPI_Conn client, int nSerialNo, QotGetOptionChain.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetOptionChain failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetOptionChain: %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
- Output
Send QotGetOptionChain: 2
Receive QotGetOptionChain: {
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"optionChain": [{
"strikeTime": "2021-06-29",
"option": [{
"call": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629C295000"
},
"id": "80143386",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 295.00 購",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 1,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 295.0,
"suspend": false,
"market": "",
"strikeTimestamp": 1.624896E9,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
},
"put": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629P295000"
},
"id": "80143074",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 295.00 沽",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 2,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 295.0,
"suspend": false,
"market": "",
"strikeTimestamp": 1.624896E9,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
}
}, ... {
"call": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629C1050000"
},
"id": "80223489",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 1050.00 購",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 1,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 1050.0,
"suspend": false,
"market": "",
"strikeTimestamp": 1.624896E9,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
},
"put": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629P1050000"
},
"id": "80223488",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 1050.00 沽",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 2,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 1050.0,
"suspend": false,
"market": "",
"strikeTimestamp": 1.624896E9,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
}
}],
"strikeTimestamp": 1.624896E9
}]
}
}
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
Futu::u32_t GetOptionChain(const Qot_GetOptionChain::Request &stReq);
virtual void OnReply_GetOptionChain(Futu::u32_t nSerialNo, const Qot_GetOptionChain::Response &stRsp) = 0;
介紹
透過標的股票查詢期權鏈。此介面僅返回期權鏈的靜態資訊,如需獲取報價或擺盤等動態資訊,請用此介面返回的股票代碼,自行 訂閱 所需要的類型。
參數
enum OptionCondType
{
OptionCondType_Unknow = 0;
OptionCondType_WithIn = 1; //價內
OptionCondType_Outside = 2; //價外
}
//以下為數據欄位篩選,可選欄位,不填表示不過濾
message DataFilter
{
optional double impliedVolatilityMin = 1; //隱含波動率過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double impliedVolatilityMax = 2; //隱含波動率過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double deltaMin = 3; //希臘值 Delta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double deltaMax = 4; //希臘值 Delta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMin = 5; //希臘值 Gamma 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMax = 6; //希臘值 Gamma 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMin = 7; //希臘值 Vega 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMax = 8; //希臘值 Vega 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMin = 9; //希臘值 Theta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMax = 10; //希臘值 Theta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMin = 11; //希臘值 Rho 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMax = 12; //希臘值 Rho 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double netOpenInterestMin = 13; //淨未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double netOpenInterestMax = 14; //淨未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMin = 15; //未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMax = 16; //未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMin = 17; //成交量過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMax = 18; //成交量過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
}
message C2S
{
required Qot_Common.Security owner = 1; //期權標的股,目前僅支援傳入港美正股以及恒指國指美指
optional int32 indexOptionType = 6; //Qot_Common.IndexOptionType,指數期權的類型,僅用於恒指國指
optional int32 type = 2; //Qot_Common.OptionType,期權類型,可選欄位,不指定則表示都返回
optional int32 condition = 3; //OptionCondType,價內價外,可選欄位,不指定則表示都返回
required string beginTime = 4; //期權到期日開始時間(格式:yyyy-MM-dd)
required string endTime = 5; //期權到期日結束時間,時間跨度最多一個月(格式:yyyy-MM-dd)
optional DataFilter dataFilter = 7; //數據欄位篩選
}
message Request
{
required C2S c2s = 1;
}
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
- 股票結構參見 Security
- 期權類型列舉參見 OptionType
- 指數期權類別列舉參見 IndexOptionType
- 返回
message OptionItem
{
optional Qot_Common.SecurityStaticInfo call = 1; //看漲期權,不一定有該欄位,由請求條件決定
optional Qot_Common.SecurityStaticInfo put = 2; //看跌期權,不一定有該欄位,由請求條件決定
}
message OptionChain
{
required string strikeTime = 1; //行權日(格式:yyyy-MM-dd)
repeated OptionItem option = 2; //期權資訊
optional double strikeTimestamp = 3; //行權日時間戳記
}
message S2C
{
repeated OptionChain optionChain = 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
- 股票靜態資訊結構參見 SecurityStaticInfo
- 介面呼叫結果,結構參見 RetType
- Example
class Program : public FTSPI_Qot, public FTSPI_Trd, public FTSPI_Conn
{
public:
Program() {
m_pQotApi = FTAPI::CreateQotApi();
m_pQotApi->RegisterQotSpi(this);
m_pQotApi->RegisterConnSpi(this);
}
~Program() {
if (m_pQotApi != nullptr)
{
m_pQotApi->UnregisterQotSpi();
m_pQotApi->UnregisterConnSpi();
FTAPI::ReleaseQotApi(m_pQotApi);
m_pQotApi = nullptr;
}
}
void Start() {
m_pQotApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(FTAPI_Conn* pConn, Futu::i64_t nErrCode, const char* strDesc) {
cout << "connect" << endl;
// 組包
Qot_GetOptionChain::Request req;
Qot_GetOptionChain::C2S *c2s = req.mutable_c2s();
Qot_Common::Security *sec = c2s->mutable_owner();
sec->set_code("00700");
sec->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
c2s->set_begintime("2021-06-07");
c2s->set_endtime("2021-07-01");
m_GetOptionChainSerialNo = m_pQotApi->GetOptionChain(req);
cout << "Request GetOptionChain SerialNo: " << m_GetOptionChainSerialNo << endl;
}
virtual void OnReply_GetOptionChain(Futu::u32_t nSerialNo, const Qot_GetOptionChain::Response &stRsp){
if(nSerialNo == m_GetOptionChainSerialNo)
{
cout << "OnReply_GetOptionChain 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_GetOptionChainSerialNo;
};
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
- Output
connect
Request GetOptionChain SerialNo: 4
OnReply_GetOptionChain SerialNo: 4
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"optionChain": [
{
"strikeTime": "2021-06-29",
"option": [
{
"call": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629C295000"
},
"id": "80143386",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 295.00 購",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 1,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 295,
"suspend": false,
"market": "",
"strikeTimestamp": 1624896000,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
},
"put": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629P295000"
},
"id": "80143074",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 295.00 沽",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 2,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 295,
"suspend": false,
"market": "",
"strikeTimestamp": 1624896000,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
}
},
...
{
"call": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629C1050000"
},
"id": "80223489",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 1050.00 購",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 1,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 1050,
"suspend": false,
"market": "",
"strikeTimestamp": 1624896000,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
},
"put": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629P1050000"
},
"id": "80223488",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 1050.00 沽",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 2,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 1050,
"suspend": false,
"market": "",
"strikeTimestamp": 1624896000,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
}
}
],
"strikeTimestamp": 1624896000
}
]
}
}
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
GetOptionChain(req);
介紹
透過標的股票查詢期權鏈。此介面僅返回期權鏈的靜態資訊,如需獲取報價或擺盤等動態資訊,請用此介面返回的股票代碼,自行 訂閱 所需要的類型。
參數
enum OptionCondType
{
OptionCondType_Unknow = 0;
OptionCondType_WithIn = 1; //價內
OptionCondType_Outside = 2; //價外
}
//以下為數據欄位篩選,可選欄位,不填表示不過濾
message DataFilter
{
optional double impliedVolatilityMin = 1; //隱含波動率過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double impliedVolatilityMax = 2; //隱含波動率過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double deltaMin = 3; //希臘值 Delta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double deltaMax = 4; //希臘值 Delta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMin = 5; //希臘值 Gamma 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMax = 6; //希臘值 Gamma 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMin = 7; //希臘值 Vega 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMax = 8; //希臘值 Vega 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMin = 9; //希臘值 Theta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMax = 10; //希臘值 Theta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMin = 11; //希臘值 Rho 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMax = 12; //希臘值 Rho 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double netOpenInterestMin = 13; //淨未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double netOpenInterestMax = 14; //淨未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMin = 15; //未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMax = 16; //未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMin = 17; //成交量過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMax = 18; //成交量過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
}
message C2S
{
required Qot_Common.Security owner = 1; //期權標的股,目前僅支援傳入港美正股以及恒指國指美指
optional int32 indexOptionType = 6; //Qot_Common.IndexOptionType,指數期權的類型,僅用於恒指國指
optional int32 type = 2; //Qot_Common.OptionType,期權類型,可選欄位,不指定則表示都返回
optional int32 condition = 3; //OptionCondType,價內價外,可選欄位,不指定則表示都返回
required string beginTime = 4; //期權到期日開始時間(格式:yyyy-MM-dd)
required string endTime = 5; //期權到期日結束時間,時間跨度最多一個月(格式:yyyy-MM-dd)
optional DataFilter dataFilter = 7; //數據欄位篩選
}
message Request
{
required C2S c2s = 1;
}
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
- 股票結構參見 Security
- 期權類型列舉參見 OptionType
- 指數期權類別列舉參見 IndexOptionType
- 返回
message OptionItem
{
optional Qot_Common.SecurityStaticInfo call = 1; //看漲期權,不一定有該欄位,由請求條件決定
optional Qot_Common.SecurityStaticInfo put = 2; //看跌期權,不一定有該欄位,由請求條件決定
}
message OptionChain
{
required string strikeTime = 1; //行權日(格式:yyyy-MM-dd)
repeated OptionItem option = 2; //期權資訊
optional double strikeTimestamp = 3; //行權日時間戳記
}
message S2C
{
repeated OptionChain optionChain = 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
- 股票靜態資訊結構參見 SecurityStaticInfo
- 介面呼叫結果,結構參見 RetType
- 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 QotGetOptionChain(){
const { RetType } = 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) { // 登入成功
const req = {
c2s: {
owner:{
market: QotMarket.QotMarket_HK_Security,
code: "00700",
},
beginTime: "2021-09-01",
endTime: "2021-09-30",
},
};
websocket.GetOptionChain(req)
.then((res) => {
let { errCode, retMsg, retType,s2c } = res
console.log("OptionChain: 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);
});
} 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
- Output
OptionChain: errCode 0, retMsg , retType 0
{
"optionChain": [{
"strikeTime": "2021-09-29",
"option": [{
"call": {
"basic": {
"security": {
"market": 1,
"code": "TCH210929C300000"
},
"id": "80287116",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210929 300.00 購",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 1,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-09-29",
"strikePrice": 300,
"suspend": false,
"market": "",
"strikeTimestamp": 1632844800,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
},
"put": {
"basic": {
"security": {
"market": 1,
"code": "TCH210929P300000"
},
"id": "80287124",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210929 300.00 沽",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 2,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-09-29",
"strikePrice": 300,
"suspend": false,
"market": "",
"strikeTimestamp": 1632844800,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
}
}, ..., {
"call": {
"basic": {
"security": {
"market": 1,
"code": "TCH210929C950000"
},
"id": "80215136",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210929 950.00 購",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 1,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-09-29",
"strikePrice": 950,
"suspend": false,
"market": "",
"strikeTimestamp": 1632844800,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
},
"put": {
"basic": {
"security": {
"market": 1,
"code": "TCH210929P950000"
},
"id": "80215157",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210929 950.00 沽",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 2,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-09-29",
"strikePrice": 950,
"suspend": false,
"market": "",
"strikeTimestamp": 1632844800,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
}
}],
"strikeTimestamp": 1632844800
}]
}
stop
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
介面限制
- 每 30 秒內最多請求 10 次獲取期權鏈介面
- 傳入的時間跨度上限為 30 天
提示
- 此介面不支援查詢已過期的期權鏈,結束日期 參數請輸入今天或未來的日期
- Open interest (OI) 數據每日更新,更新時點取決於具體交易所。美股期權在盤前時段更新,港股期權在盤後更新。
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_option_chain(code, index_option_type=IndexOptionType.NORMAL, start=None, end=None, option_type=OptionType.ALL, option_cond_type=OptionCondType.ALL, data_filter=None)
介紹
透過標的股票查詢期權鏈。此介面僅返回期權鏈的靜態資訊,如需獲取報價或擺盤等動態資訊,請用此介面返回的股票代碼,自行 訂閱 所需要的類型。
參數
參數 類型 説明 code str 標的股票代碼 index_option_type IndexOptionType 指數期權類型 僅對港股指數期權篩選有效,正股、ETFs、美股指數期權可忽略此參數start str 開始日期,該日期指到期日 例如:“2017-08-01”end str 結束日期(包括這一天),該日期指到期日 例如:“2017-08-30”option_type OptionType 期權看漲看跌類型 預設為全部option_cond_type OptionCondType 期權價內外類型 預設為全部data_filter OptionDataFilter 數據篩選條件 預設為不篩選start 和 end 的組合如下:
Start 類型 End 類型 説明 str str start 和 end 分別為指定的日期 None str start 為 end 往前 30 天 str None end 為 start 往後30天 None None start 為當前日期,end 往後 30 天 OptionDataFilter 欄位如下
欄位 類型 説明 implied_volatility_min float 隱含波動率過濾起點 精確到小數點後 0 位,超出部分會被捨棄
該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%implied_volatility_max float 隱含波動率過濾終點 精確到小數點後 0 位,超出部分會被捨棄
該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%delta_min float 希臘值 Delta 過濾起點 精確到小數點後 3 位,超出部分會被捨棄delta_max float 希臘值 Delta 過濾終點 精確到小數點後 3 位,超出部分會被捨棄gamma_min float 希臘值 Gamma 過濾起點 精確到小數點後 3 位,超出部分會被捨棄gamma_max float 希臘值 Gamma 過濾終點 精確到小數點後 3 位,超出部分會被捨棄vega_min float 希臘值 Vega 過濾起點 精確到小數點後 3 位,超出部分會被捨棄vega_max float 希臘值 Vega 過濾終點 精確到小數點後 3 位,超出部分會被捨棄theta_min float 希臘值 Theta 過濾起點 精確到小數點後 3 位,超出部分會被捨棄theta_max float 希臘值 Theta 過濾終點 精確到小數點後 3 位,超出部分會被捨棄rho_min float 希臘值 Rho 過濾起點 精確到小數點後 3 位,超出部分會被捨棄rho_max float 希臘值 Rho 過濾終點 精確到小數點後 3 位,超出部分會被捨棄net_open_interest_min float 淨未平倉合約數過濾起點 精確到小數點後 0 位,超出部分會被捨棄net_open_interest_max float 淨未平倉合約數過濾終點 精確到小數點後 0 位,超出部分會被捨棄open_interest_min float 未平倉合約數過濾起點 精確到小數點後 0 位,超出部分會被捨棄open_interest_max float 未平倉合約數過濾終點 精確到小數點後 0 位,超出部分會被捨棄vol_min float 成交量過濾起點 精確到小數點後 0 位,超出部分會被捨棄vol_max float 成交量過濾終點 精確到小數點後 0 位,超出部分會被捨棄
返回
參數 類型 説明 ret RET_CODE 介面呼叫結果 data pd.DataFrame 當 ret == RET_OK,返回期權鏈數據 str 當 ret != RET_OK,返回錯誤描述 - 期權鏈數據格式如下:
欄位 類型 説明 code str 股票代碼 name str 名字 lot_size int 每手股數,期權表示每份合約股數 指數期權無該欄位stock_type SecurityType 股票類型 option_type OptionType 期權類型 stock_owner str 標的股 strike_time str 行權日 格式:yyyy-MM-dd
港股和 A 股市場預設是北京時間,美股市場預設是美東時間strike_price float 行權價 suspension bool 是否停牌 True:停牌
False:未停牌stock_id int 股票 ID index_option_type IndexOptionType 指數期權類型 expiration_cycle ExpirationCycle 交割週期 option_standard_type OptionStandardType 期權標準類型 option_settlement_mode OptionSettlementMode 期權結算方式
- 期權鏈數據格式如下:
Example
from moomoo import *
import time
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
ret1, data1 = quote_ctx.get_option_expiration_date(code='HK.00700')
filter1 = OptionDataFilter()
filter1.delta_min = 0
filter1.delta_max = 0.1
if ret1 == RET_OK:
expiration_date_list = data1['strike_time'].values.tolist()
for date in expiration_date_list:
ret2, data2 = quote_ctx.get_option_chain(code='HK.00700', start=date, end=date, data_filter=filter1)
if ret2 == RET_OK:
print(data2)
print(data2['code'][0]) # 取第一條的股票代碼
print(data2['code'].values.tolist()) # 轉為 list
else:
print('error:', data2)
time.sleep(3)
else:
print('error:', data1)
quote_ctx.close() # 結束後記得關閉當條連線,防止連線條數用盡
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- Output
code name lot_size stock_type option_type stock_owner strike_time strike_price suspension stock_id index_option_type expiration_cycle option_standard_type option_settlement_mode
0 HK.TCH210429C350000 騰訊 210429 350.00 購 100 DRVT CALL HK.00700 2021-04-29 350.0 False 80235167 N/A WEEK STANDARD N/A
1 HK.TCH210429P350000 騰訊 210429 350.00 沽 100 DRVT PUT HK.00700 2021-04-29 350.0 False 80235247 N/A WEEK STANDARD N/A
2 HK.TCH210429C360000 騰訊 210429 360.00 購 100 DRVT CALL HK.00700 2021-04-29 360.0 False 80235163 N/A WEEK STANDARD N/A
3 HK.TCH210429P360000 騰訊 210429 360.00 沽 100 DRVT PUT HK.00700 2021-04-29 360.0 False 80235246 N/A WEEK STANDARD N/A
4 HK.TCH210429C370000 騰訊 210429 370.00 購 100 DRVT CALL HK.00700 2021-04-29 370.0 False 80235165 N/A WEEK STANDARD N/A
5 HK.TCH210429P370000 騰訊 210429 370.00 沽 100 DRVT PUT HK.00700 2021-04-29 370.0 False 80235248 N/A WEEK STANDARD N/A
HK.TCH210429C350000
['HK.TCH210429C350000', 'HK.TCH210429P350000', 'HK.TCH210429C360000', 'HK.TCH210429P360000', 'HK.TCH210429C370000', 'HK.TCH210429P370000']
...
code name lot_size stock_type option_type stock_owner strike_time strike_price suspension stock_id index_option_type expiration_cycle option_standard_type option_settlement_mode
0 HK.TCH220330C490000 騰訊 220330 490.00 購 100 DRVT CALL HK.00700 2022-03-30 490.0 False 80235143 N/A WEEK STANDARD N/A
1 HK.TCH220330P490000 騰訊 220330 490.00 沽 100 DRVT PUT HK.00700 2022-03-30 490.0 False 80235193 N/A WEEK STANDARD N/A
2 HK.TCH220330C500000 騰訊 220330 500.00 購 100 DRVT CALL HK.00700 2022-03-30 500.0 False 80233887 N/A WEEK STANDARD N/A
3 HK.TCH220330P500000 騰訊 220330 500.00 沽 100 DRVT PUT HK.00700 2022-03-30 500.0 False 80233912 N/A WEEK STANDARD N/A
4 HK.TCH220330C510000 騰訊 220330 510.00 購 100 DRVT CALL HK.00700 2022-03-30 510.0 False 80233747 N/A WEEK STANDARD N/A
5 HK.TCH220330P510000 騰訊 220330 510.00 沽 100 DRVT PUT HK.00700 2022-03-30 510.0 False 80233766 N/A WEEK STANDARD N/A
HK.TCH220330C490000
['HK.TCH220330C490000', 'HK.TCH220330P490000', 'HK.TCH220330C500000', 'HK.TCH220330P500000', 'HK.TCH220330C510000', 'HK.TCH220330P510000']
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Qot_GetOptionChain.proto
介紹
透過標的股票查詢期權鏈。此介面僅返回期權鏈的靜態資訊,如需獲取報價或擺盤等動態資訊,請用此介面返回的股票代碼,自行 訂閱 所需要的類型。
協議 ID
3209
參數
enum OptionCondType
{
OptionCondType_Unknow = 0;
OptionCondType_WithIn = 1; //價內
OptionCondType_Outside = 2; //價外
}
//以下為數據欄位篩選,可選欄位,不填表示不過濾
message DataFilter
{
optional double impliedVolatilityMin = 1; //隱含波動率過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double impliedVolatilityMax = 2; //隱含波動率過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double deltaMin = 3; //希臘值 Delta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double deltaMax = 4; //希臘值 Delta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMin = 5; //希臘值 Gamma 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMax = 6; //希臘值 Gamma 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMin = 7; //希臘值 Vega 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMax = 8; //希臘值 Vega 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMin = 9; //希臘值 Theta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMax = 10; //希臘值 Theta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMin = 11; //希臘值 Rho 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMax = 12; //希臘值 Rho 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double netOpenInterestMin = 13; //淨未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double netOpenInterestMax = 14; //淨未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMin = 15; //未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMax = 16; //未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMin = 17; //成交量過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMax = 18; //成交量過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
}
message C2S
{
required Qot_Common.Security owner = 1; //期權標的股,目前僅支援傳入港美正股以及恒指國指美指
optional int32 indexOptionType = 6; //Qot_Common.IndexOptionType,指數期權的類型,僅用於恒指國指
optional int32 type = 2; //Qot_Common.OptionType,期權類型,可選欄位,不指定則表示都返回
optional int32 condition = 3; //OptionCondType,價內價外,可選欄位,不指定則表示都返回
required string beginTime = 4; //期權到期日開始時間(格式:yyyy-MM-dd)
required string endTime = 5; //期權到期日結束時間,時間跨度最多一個月(格式:yyyy-MM-dd)
optional DataFilter dataFilter = 7; //數據欄位篩選
}
message Request
{
required C2S c2s = 1;
}
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
- 股票結構參見 Security
- 期權類型列舉參見 OptionType
- 指數期權類別列舉參見 IndexOptionType
- 返回
message OptionItem
{
optional Qot_Common.SecurityStaticInfo call = 1; //看漲期權,不一定有該欄位,由請求條件決定
optional Qot_Common.SecurityStaticInfo put = 2; //看跌期權,不一定有該欄位,由請求條件決定
}
message OptionChain
{
required string strikeTime = 1; //行權日(格式:yyyy-MM-dd)
repeated OptionItem option = 2; //期權資訊
optional double strikeTimestamp = 3; //行權日時間戳記
}
message S2C
{
repeated OptionChain optionChain = 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
- 股票靜態資訊結構參見 SecurityStaticInfo
- 介面呼叫結果,結構參見 RetType
協議 ID
3209
uint GetOptionChain(QotGetOptionChain.Request req);
virtual void OnReply_GetOptionChain(MMAPI_Conn client, uint nSerialNo, QotGetOptionChain.Response rsp);
介紹
透過標的股票查詢期權鏈。此介面僅返回期權鏈的靜態資訊,如需獲取報價或擺盤等動態資訊,請用此介面返回的股票代碼,自行 訂閱 所需要的類型。
參數
enum OptionCondType
{
OptionCondType_Unknow = 0;
OptionCondType_WithIn = 1; //價內
OptionCondType_Outside = 2; //價外
}
//以下為數據欄位篩選,可選欄位,不填表示不過濾
message DataFilter
{
optional double impliedVolatilityMin = 1; //隱含波動率過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double impliedVolatilityMax = 2; //隱含波動率過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double deltaMin = 3; //希臘值 Delta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double deltaMax = 4; //希臘值 Delta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMin = 5; //希臘值 Gamma 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMax = 6; //希臘值 Gamma 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMin = 7; //希臘值 Vega 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMax = 8; //希臘值 Vega 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMin = 9; //希臘值 Theta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMax = 10; //希臘值 Theta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMin = 11; //希臘值 Rho 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMax = 12; //希臘值 Rho 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double netOpenInterestMin = 13; //淨未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double netOpenInterestMax = 14; //淨未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMin = 15; //未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMax = 16; //未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMin = 17; //成交量過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMax = 18; //成交量過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
}
message C2S
{
required Qot_Common.Security owner = 1; //期權標的股,目前僅支援傳入港美正股以及恒指國指美指
optional int32 indexOptionType = 6; //Qot_Common.IndexOptionType,指數期權的類型,僅用於恒指國指
optional int32 type = 2; //Qot_Common.OptionType,期權類型,可選欄位,不指定則表示都返回
optional int32 condition = 3; //OptionCondType,價內價外,可選欄位,不指定則表示都返回
required string beginTime = 4; //期權到期日開始時間(格式:yyyy-MM-dd)
required string endTime = 5; //期權到期日結束時間,時間跨度最多一個月(格式:yyyy-MM-dd)
optional DataFilter dataFilter = 7; //數據欄位篩選
}
message Request
{
required C2S c2s = 1;
}
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
- 股票結構參見 Security
- 期權類型列舉參見 OptionType
- 指數期權類別列舉參見 IndexOptionType
- 返回
message OptionItem
{
optional Qot_Common.SecurityStaticInfo call = 1; //看漲期權,不一定有該欄位,由請求條件決定
optional Qot_Common.SecurityStaticInfo put = 2; //看跌期權,不一定有該欄位,由請求條件決定
}
message OptionChain
{
required string strikeTime = 1; //行權日(格式:yyyy-MM-dd)
repeated OptionItem option = 2; //期權資訊
optional double strikeTimestamp = 3; //行權日時間戳記
}
message S2C
{
repeated OptionChain optionChain = 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
- 股票靜態資訊結構參見 SecurityStaticInfo
- 介面呼叫結果,結構參見 RetType
- Example
public class Program : MMSPI_Qot, MMSPI_Conn {
MMAPI_Qot qot = new MMAPI_Qot();
public Program() {
qot.SetClientInfo("csharp", 1); //設定用戶端資訊
qot.SetConnCallback(this); //設定連線回呼
qot.SetQotCallback(this); //設定交易回呼
}
public void Start() {
qot.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(MMAPI_Conn client, long errCode, String desc)
{
Console.Write("Qot onInitConnect: ret={0} desc={1} connID={2}\n", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
QotCommon.Security sec = QotCommon.Security.CreateBuilder()
.SetMarket((int)QotCommon.QotMarket.QotMarket_HK_Security)
.SetCode("00700")
.Build();
QotGetOptionChain.C2S c2s = QotGetOptionChain.C2S.CreateBuilder()
.SetOwner(sec)
.SetBeginTime("2020-11-01")
.SetEndTime("2020-12-01")
.Build();
QotGetOptionChain.Request req = QotGetOptionChain.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.GetOptionChain(req);
Console.Write("Send QotGetOptionChain: {0}\n", seqNo);
}
public void OnDisconnect(MMAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_GetOptionChain(MMAPI_Conn client, uint nSerialNo, QotGetOptionChain.Response rsp)
{
Console.Write("Reply: QotGetOptionChain: {0}\n", nSerialNo);
Console.Write("strikeTime: {0}, name: {1} \n",
rsp.S2C.OptionChainList[0].StrikeTime,
rsp.S2C.OptionChainList[0].OptionList[0].Call.Basic.Name);
}
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
- Output
Qot onInitConnect: ret=0 desc= connID=6825705573658441031
Send QotGetOptionChain: 3
Reply: QotGetOptionChain: 3
strikeTime: 2021-07-29, name: 騰訊 210729 400.00 購
2
3
4
int getOptionChain(QotGetOptionChain.Request req);
void onReply_GetOptionChain(MMAPI_Conn client, int nSerialNo, QotGetOptionChain.Response rsp);
介紹
透過標的股票查詢期權鏈。此介面僅返回期權鏈的靜態資訊,如需獲取報價或擺盤等動態資訊,請用此介面返回的股票代碼,自行 訂閱 所需要的類型。
參數
enum OptionCondType
{
OptionCondType_Unknow = 0;
OptionCondType_WithIn = 1; //價內
OptionCondType_Outside = 2; //價外
}
//以下為數據欄位篩選,可選欄位,不填表示不過濾
message DataFilter
{
optional double impliedVolatilityMin = 1; //隱含波動率過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double impliedVolatilityMax = 2; //隱含波動率過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double deltaMin = 3; //希臘值 Delta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double deltaMax = 4; //希臘值 Delta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMin = 5; //希臘值 Gamma 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMax = 6; //希臘值 Gamma 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMin = 7; //希臘值 Vega 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMax = 8; //希臘值 Vega 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMin = 9; //希臘值 Theta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMax = 10; //希臘值 Theta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMin = 11; //希臘值 Rho 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMax = 12; //希臘值 Rho 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double netOpenInterestMin = 13; //淨未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double netOpenInterestMax = 14; //淨未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMin = 15; //未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMax = 16; //未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMin = 17; //成交量過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMax = 18; //成交量過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
}
message C2S
{
required Qot_Common.Security owner = 1; //期權標的股,目前僅支援傳入港美正股以及恒指國指美指
optional int32 indexOptionType = 6; //Qot_Common.IndexOptionType,指數期權的類型,僅用於恒指國指
optional int32 type = 2; //Qot_Common.OptionType,期權類型,可選欄位,不指定則表示都返回
optional int32 condition = 3; //OptionCondType,價內價外,可選欄位,不指定則表示都返回
required string beginTime = 4; //期權到期日開始時間(格式:yyyy-MM-dd)
required string endTime = 5; //期權到期日結束時間,時間跨度最多一個月(格式:yyyy-MM-dd)
optional DataFilter dataFilter = 7; //數據欄位篩選
}
message Request
{
required C2S c2s = 1;
}
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
- 股票結構參見 Security
- 期權類型列舉參見 OptionType
- 指數期權類別列舉參見 IndexOptionType
- 返回
message OptionItem
{
optional Qot_Common.SecurityStaticInfo call = 1; //看漲期權,不一定有該欄位,由請求條件決定
optional Qot_Common.SecurityStaticInfo put = 2; //看跌期權,不一定有該欄位,由請求條件決定
}
message OptionChain
{
required string strikeTime = 1; //行權日(格式:yyyy-MM-dd)
repeated OptionItem option = 2; //期權資訊
optional double strikeTimestamp = 3; //行權日時間戳記
}
message S2C
{
repeated OptionChain optionChain = 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
- 股票靜態資訊結構參見 SecurityStaticInfo
- 介面呼叫結果,結構參見 RetType
- 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.Security sec = QotCommon.Security.newBuilder()
.setMarket(QotCommon.QotMarket.QotMarket_HK_Security_VALUE)
.setCode("00700")
.build();
QotGetOptionChain.C2S c2s = QotGetOptionChain.C2S.newBuilder()
.setOwner(sec)
.setBeginTime("2021-06-01")
.setEndTime("2021-07-01")
.build();
QotGetOptionChain.Request req = QotGetOptionChain.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.getOptionChain(req);
System.out.printf("Send QotGetOptionChain: %d\n", seqNo);
}
@Override
public void onDisconnect(MMAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onReply_GetOptionChain(MMAPI_Conn client, int nSerialNo, QotGetOptionChain.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotGetOptionChain failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotGetOptionChain: %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
- Output
Send QotGetOptionChain: 2
Receive QotGetOptionChain: {
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"optionChain": [{
"strikeTime": "2021-06-29",
"option": [{
"call": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629C295000"
},
"id": "80143386",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 295.00 購",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 1,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 295.0,
"suspend": false,
"market": "",
"strikeTimestamp": 1.624896E9,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
},
"put": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629P295000"
},
"id": "80143074",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 295.00 沽",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 2,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 295.0,
"suspend": false,
"market": "",
"strikeTimestamp": 1.624896E9,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
}
}, ... {
"call": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629C1050000"
},
"id": "80223489",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 1050.00 購",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 1,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 1050.0,
"suspend": false,
"market": "",
"strikeTimestamp": 1.624896E9,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
},
"put": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629P1050000"
},
"id": "80223488",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 1050.00 沽",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 2,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 1050.0,
"suspend": false,
"market": "",
"strikeTimestamp": 1.624896E9,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
}
}],
"strikeTimestamp": 1.624896E9
}]
}
}
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
moomoo::u32_t GetOptionChain(const Qot_GetOptionChain::Request &stReq);
virtual void OnReply_GetOptionChain(moomoo::u32_t nSerialNo, const Qot_GetOptionChain::Response &stRsp) = 0;
介紹
透過標的股票查詢期權鏈。此介面僅返回期權鏈的靜態資訊,如需獲取報價或擺盤等動態資訊,請用此介面返回的股票代碼,自行 訂閱 所需要的類型。
參數
enum OptionCondType
{
OptionCondType_Unknow = 0;
OptionCondType_WithIn = 1; //價內
OptionCondType_Outside = 2; //價外
}
//以下為數據欄位篩選,可選欄位,不填表示不過濾
message DataFilter
{
optional double impliedVolatilityMin = 1; //隱含波動率過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double impliedVolatilityMax = 2; //隱含波動率過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double deltaMin = 3; //希臘值 Delta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double deltaMax = 4; //希臘值 Delta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMin = 5; //希臘值 Gamma 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMax = 6; //希臘值 Gamma 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMin = 7; //希臘值 Vega 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMax = 8; //希臘值 Vega 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMin = 9; //希臘值 Theta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMax = 10; //希臘值 Theta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMin = 11; //希臘值 Rho 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMax = 12; //希臘值 Rho 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double netOpenInterestMin = 13; //淨未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double netOpenInterestMax = 14; //淨未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMin = 15; //未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMax = 16; //未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMin = 17; //成交量過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMax = 18; //成交量過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
}
message C2S
{
required Qot_Common.Security owner = 1; //期權標的股,目前僅支援傳入港美正股以及恒指國指美指
optional int32 indexOptionType = 6; //Qot_Common.IndexOptionType,指數期權的類型,僅用於恒指國指
optional int32 type = 2; //Qot_Common.OptionType,期權類型,可選欄位,不指定則表示都返回
optional int32 condition = 3; //OptionCondType,價內價外,可選欄位,不指定則表示都返回
required string beginTime = 4; //期權到期日開始時間(格式:yyyy-MM-dd)
required string endTime = 5; //期權到期日結束時間,時間跨度最多一個月(格式:yyyy-MM-dd)
optional DataFilter dataFilter = 7; //數據欄位篩選
}
message Request
{
required C2S c2s = 1;
}
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
- 股票結構參見 Security
- 期權類型列舉參見 OptionType
- 指數期權類別列舉參見 IndexOptionType
- 返回
message OptionItem
{
optional Qot_Common.SecurityStaticInfo call = 1; //看漲期權,不一定有該欄位,由請求條件決定
optional Qot_Common.SecurityStaticInfo put = 2; //看跌期權,不一定有該欄位,由請求條件決定
}
message OptionChain
{
required string strikeTime = 1; //行權日(格式:yyyy-MM-dd)
repeated OptionItem option = 2; //期權資訊
optional double strikeTimestamp = 3; //行權日時間戳記
}
message S2C
{
repeated OptionChain optionChain = 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
- 股票靜態資訊結構參見 SecurityStaticInfo
- 介面呼叫結果,結構參見 RetType
- Example
class Program : public MMSPI_Qot, public MMSPI_Trd, public MMSPI_Conn
{
public:
Program() {
m_pQotApi = MMAPI::CreateQotApi();
m_pQotApi->RegisterQotSpi(this);
m_pQotApi->RegisterConnSpi(this);
}
~Program() {
if (m_pQotApi != nullptr)
{
m_pQotApi->UnregisterQotSpi();
m_pQotApi->UnregisterConnSpi();
MMAPI::ReleaseQotApi(m_pQotApi);
m_pQotApi = nullptr;
}
}
void Start() {
m_pQotApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(MMAPI_Conn* pConn, moomoo::i64_t nErrCode, const char* strDesc) {
cout << "connect" << endl;
// 組包
Qot_GetOptionChain::Request req;
Qot_GetOptionChain::C2S *c2s = req.mutable_c2s();
Qot_Common::Security *sec = c2s->mutable_owner();
sec->set_code("00700");
sec->set_market(Qot_Common::QotMarket::QotMarket_HK_Security);
c2s->set_begintime("2021-06-07");
c2s->set_endtime("2021-07-01");
m_GetOptionChainSerialNo = m_pQotApi->GetOptionChain(req);
cout << "Request GetOptionChain SerialNo: " << m_GetOptionChainSerialNo << endl;
}
virtual void OnReply_GetOptionChain(moomoo::u32_t nSerialNo, const Qot_GetOptionChain::Response &stRsp){
if(nSerialNo == m_GetOptionChainSerialNo)
{
cout << "OnReply_GetOptionChain 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_GetOptionChainSerialNo;
};
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
- Output
connect
Request GetOptionChain SerialNo: 4
OnReply_GetOptionChain SerialNo: 4
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"optionChain": [
{
"strikeTime": "2021-06-29",
"option": [
{
"call": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629C295000"
},
"id": "80143386",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 295.00 購",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 1,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 295,
"suspend": false,
"market": "",
"strikeTimestamp": 1624896000,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
},
"put": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629P295000"
},
"id": "80143074",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 295.00 沽",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 2,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 295,
"suspend": false,
"market": "",
"strikeTimestamp": 1624896000,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
}
},
...
{
"call": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629C1050000"
},
"id": "80223489",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 1050.00 購",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 1,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 1050,
"suspend": false,
"market": "",
"strikeTimestamp": 1624896000,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
},
"put": {
"basic": {
"security": {
"market": 1,
"code": "TCH210629P1050000"
},
"id": "80223488",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210629 1050.00 沽",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 2,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-06-29",
"strikePrice": 1050,
"suspend": false,
"market": "",
"strikeTimestamp": 1624896000,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
}
}
],
"strikeTimestamp": 1624896000
}
]
}
}
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
GetOptionChain(req);
介紹
透過標的股票查詢期權鏈。此介面僅返回期權鏈的靜態資訊,如需獲取報價或擺盤等動態資訊,請用此介面返回的股票代碼,自行 訂閱 所需要的類型。
參數
enum OptionCondType
{
OptionCondType_Unknow = 0;
OptionCondType_WithIn = 1; //價內
OptionCondType_Outside = 2; //價外
}
//以下為數據欄位篩選,可選欄位,不填表示不過濾
message DataFilter
{
optional double impliedVolatilityMin = 1; //隱含波動率過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double impliedVolatilityMax = 2; //隱含波動率過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double deltaMin = 3; //希臘值 Delta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double deltaMax = 4; //希臘值 Delta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMin = 5; //希臘值 Gamma 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double gammaMax = 6; //希臘值 Gamma 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMin = 7; //希臘值 Vega 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double vegaMax = 8; //希臘值 Vega 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMin = 9; //希臘值 Theta 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double thetaMax = 10; //希臘值 Theta 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMin = 11; //希臘值 Rho 過濾起點(精確到小數點後 3 位,超出部分會被捨棄)
optional double rhoMax = 12; //希臘值 Rho 過濾終點(精確到小數點後 3 位,超出部分會被捨棄)
optional double netOpenInterestMin = 13; //淨未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double netOpenInterestMax = 14; //淨未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMin = 15; //未平倉合約數過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double openInterestMax = 16; //未平倉合約數過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMin = 17; //成交量過濾起點(精確到小數點後 0 位,超出部分會被捨棄)
optional double volMax = 18; //成交量過濾終點(精確到小數點後 0 位,超出部分會被捨棄)
}
message C2S
{
required Qot_Common.Security owner = 1; //期權標的股,目前僅支援傳入港美正股以及恒指國指美指
optional int32 indexOptionType = 6; //Qot_Common.IndexOptionType,指數期權的類型,僅用於恒指國指
optional int32 type = 2; //Qot_Common.OptionType,期權類型,可選欄位,不指定則表示都返回
optional int32 condition = 3; //OptionCondType,價內價外,可選欄位,不指定則表示都返回
required string beginTime = 4; //期權到期日開始時間(格式:yyyy-MM-dd)
required string endTime = 5; //期權到期日結束時間,時間跨度最多一個月(格式:yyyy-MM-dd)
optional DataFilter dataFilter = 7; //數據欄位篩選
}
message Request
{
required C2S c2s = 1;
}
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
- 股票結構參見 Security
- 期權類型列舉參見 OptionType
- 指數期權類別列舉參見 IndexOptionType
- 返回
message OptionItem
{
optional Qot_Common.SecurityStaticInfo call = 1; //看漲期權,不一定有該欄位,由請求條件決定
optional Qot_Common.SecurityStaticInfo put = 2; //看跌期權,不一定有該欄位,由請求條件決定
}
message OptionChain
{
required string strikeTime = 1; //行權日(格式:yyyy-MM-dd)
repeated OptionItem option = 2; //期權資訊
optional double strikeTimestamp = 3; //行權日時間戳記
}
message S2C
{
repeated OptionChain optionChain = 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
- 股票靜態資訊結構參見 SecurityStaticInfo
- 介面呼叫結果,結構參見 RetType
- 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 QotGetOptionChain(){
const { RetType } = 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) { // 登入成功
const req = {
c2s: {
owner:{
market: QotMarket.QotMarket_HK_Security,
code: "00700",
},
beginTime: "2021-09-01",
endTime: "2021-09-30",
},
};
websocket.GetOptionChain(req)
.then((res) => {
let { errCode, retMsg, retType,s2c } = res
console.log("OptionChain: 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);
});
} 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
- Output
OptionChain: errCode 0, retMsg , retType 0
{
"optionChain": [{
"strikeTime": "2021-09-29",
"option": [{
"call": {
"basic": {
"security": {
"market": 1,
"code": "TCH210929C300000"
},
"id": "80287116",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210929 300.00 購",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 1,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-09-29",
"strikePrice": 300,
"suspend": false,
"market": "",
"strikeTimestamp": 1632844800,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
},
"put": {
"basic": {
"security": {
"market": 1,
"code": "TCH210929P300000"
},
"id": "80287124",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210929 300.00 沽",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 2,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-09-29",
"strikePrice": 300,
"suspend": false,
"market": "",
"strikeTimestamp": 1632844800,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
}
}, ..., {
"call": {
"basic": {
"security": {
"market": 1,
"code": "TCH210929C950000"
},
"id": "80215136",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210929 950.00 購",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 1,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-09-29",
"strikePrice": 950,
"suspend": false,
"market": "",
"strikeTimestamp": 1632844800,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
},
"put": {
"basic": {
"security": {
"market": 1,
"code": "TCH210929P950000"
},
"id": "80215157",
"lotSize": 100,
"secType": 8,
"name": "騰訊 210929 950.00 沽",
"listTime": "",
"delisting": false
},
"optionExData": {
"type": 2,
"owner": {
"market": 1,
"code": "00700"
},
"strikeTime": "2021-09-29",
"strikePrice": 950,
"suspend": false,
"market": "",
"strikeTimestamp": 1632844800,
"expirationCycle": 1,
"optionStandardType": 1,
"optionSettlementMode": 2,
}
}
}],
"strikeTimestamp": 1632844800
}]
}
stop
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
介面限制
- 每 30 秒內最多請求 10 次獲取期權鏈介面
- 傳入的時間跨度上限為 30 天
提示
- 此介面不支援查詢已過期的期權鏈,結束日期 參數請輸入今天或未來的日期
- Open interest (OI) 數據每日更新,更新時點取決於具體交易所。美股期權在盤前時段更新,港股期權在盤後更新。