# 末日期權合約列表
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_option_zero_dte_contract(owner, strike_date_timestamp, chain_info, sort_type=None, is_asc=None, filter_list=None)
介紹
獲取末日期權合約列表,返回指定標的在指定行權日的 0DTE 期權合約詳情,包含希臘值、盈虧平衡點及盈利概率等數據。
參數
參數 類型 說明 owner str 標的股票代碼 如 'US.AAPL',僅支持美股股票strike_date_timestamp int 行權日期時間戳(Unix 秒) chain_info dict 期權鏈信息 來自 get_option_zero_dte_screener 返回的 chain_infosort_type ZeroDteContractSortType 排序類型 VOLUME=成交量、OPEN_INTEREST=持倉量、IV=隱含波動率、DELTA=Deltais_asc bool 是否升序 默認 False(降序)filter_list list[ZeroDteContractFilter] 篩選條件列表 多條件為 AND 關係。支持 OPTION_TYPE、VOLUME、OPEN_INTEREST、IV、DELTA、GAMMA、THETA、VEGA、RHO、PRICE、CHANGE_RATIO、BREAK_EVEN_POINT、TO_BEP、BUY_PROFIT_PROBABILITY、SELL_PROFIT_PROBABILITY返回
參數 類型 說明 ret RET_CODE 接口調用結果 data pandas.DataFrame 當 ret == RET_OK,返回合約列表 str 當 ret != RET_OK,返回錯誤描述 返回 DataFrame 字段:
字段 類型 說明 option str 期權合約代碼 name str 合約名稱 option_type str 期權類型(CALL/PUT) option_price float 期權價格 change_ratio float 漲跌幅(百分比) volume int 成交量 open_interest int 持倉量 iv float 隱含波動率(百分比) delta float Delta gamma float Gamma vega float Vega theta float Theta rho float Rho buy_break_even_point float 買入盈虧平衡點 buy_to_bep float 到達盈虧平衡點所需漲跌幅(百分比) buy_profit_probability float 買入盈利概率(百分比) sell_profit_probability float 賣出盈利概率(百分比)
Example
from futu import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# 第一步:獲取末日期權標的列表
ret, screener_data = quote_ctx.get_option_zero_dte_screener(
market=OptionMarket.US_SECURITY,
sort_type=ZeroDteSortType.VOLUME,
is_asc=False,
count=1
)
if ret != RET_OK:
print('error:', screener_data)
quote_ctx.close()
exit()
# 第二步:取第一個標的的 chain_info,查詢其合約列表
df = screener_data['item_list']
owner = df.iloc[0]['owner']
chain_info = df.iloc[0]['chain_info']
strike_date_timestamp = chain_info['strike_date_timestamp']
ret, data = quote_ctx.get_option_zero_dte_contract(
owner=owner,
strike_date_timestamp=strike_date_timestamp,
chain_info=chain_info,
sort_type=ZeroDteContractSortType.VOLUME,
is_asc=False
)
if ret == RET_OK:
print(data)
else:
print('error:', data)
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
24
25
26
27
28
29
30
31
32
33
34
35
- Output
option name option_type option_price change_ratio volume open_interest iv delta gamma vega theta rho buy_break_even_point buy_to_bep buy_profit_probability sell_profit_probability
0 US.SPY260612C742000 SPY 260612 C742 CALL 0.58 -67.688 730160 7449 146.5 0.4367 0.2745 0.0039 -455.46 0.000 742.58 0.11 43.5 56.5
1 US.SPY260612C745000 SPY 260612 C745 CALL 0.01 -98.958 617981 17013 87.1 0.0244 0.0350 0.0011 -18.52 0.000 745.01 0.44 2.4 97.6
...
2
3
4
# Qot_GetOptionZeroDteContract.proto
介紹
獲取末日期權合約列表
參數
message C2S {
required Qot_Common.Security owner = 1;
required int64 strikeDateTimestamp = 2;
required Qot_GetOptionZeroDteScreener.OptionChainInfo chainInfo = 3;
optional int32 sortType = 4; // Qot_OptionCommon.ZeroDteContractSortType
optional bool isAsc = 5; // 默認 false
repeated Qot_OptionCommon.ZeroDteContractIndicator filterList = 6;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
- 返回
message ZeroDteContractItem {
required Qot_Common.Security option = 1;
optional string name = 2;
optional int32 optionType = 3; // Qot_Common.OptionType
optional double optionPrice = 4;
optional double changeRate = 5; // 漲跌幅(百分比)
optional int64 volume = 6;
optional int64 openInterest = 7;
optional double iv = 8; // (%)
optional double delta = 9;
optional double gamma = 10;
optional double vega = 11;
optional double theta = 12;
optional double rho = 13;
optional double buyBreakEvenPoint = 14; // 價格
optional double buyToBep = 15; // (%)
optional double buyProfitProbability = 16; // (%)
optional double sellProfitProbability = 17;// (%)
}
message S2C {
repeated ZeroDteContractItem itemList = 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
- 接口調用結果,結構參見 RetType
協議 ID
3312
uint GetOptionZeroDteContract(Qot_GetOptionZeroDteContract.Request req); virtual void OnReply_GetOptionZeroDteContract(FTAPI_Conn client, uint nSerialNo, Qot_GetOptionZeroDteContract.Response rsp);
介紹
獲取末日期權合約列表
參數
message C2S {
required Qot_Common.Security owner = 1;
required int64 strikeDateTimestamp = 2;
required Qot_GetOptionZeroDteScreener.OptionChainInfo chainInfo = 3;
optional int32 sortType = 4; // Qot_OptionCommon.ZeroDteContractSortType
optional bool isAsc = 5; // 默認 false
repeated Qot_OptionCommon.ZeroDteContractIndicator filterList = 6;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
- 返回
message ZeroDteContractItem {
required Qot_Common.Security option = 1;
optional string name = 2;
optional int32 optionType = 3; // Qot_Common.OptionType
optional double optionPrice = 4;
optional double changeRate = 5; // 漲跌幅(百分比)
optional int64 volume = 6;
optional int64 openInterest = 7;
optional double iv = 8; // (%)
optional double delta = 9;
optional double gamma = 10;
optional double vega = 11;
optional double theta = 12;
optional double rho = 13;
optional double buyBreakEvenPoint = 14; // 價格
optional double buyToBep = 15; // (%)
optional double buyProfitProbability = 16; // (%)
optional double sellProfitProbability = 17;// (%)
}
message S2C {
repeated ZeroDteContractItem itemList = 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
- 接口調用結果,結構參見 RetType
協議 ID
3312
int getOptionZeroDteContract(Qot_GetOptionZeroDteContract.Request req) onReply_GetOptionZeroDteContract(FTAPI_Conn client, int nSerialNo, Qot_GetOptionZeroDteContract.Response rsp)
介紹
獲取末日期權合約列表
參數
message C2S {
required Qot_Common.Security owner = 1;
required int64 strikeDateTimestamp = 2;
required Qot_GetOptionZeroDteScreener.OptionChainInfo chainInfo = 3;
optional int32 sortType = 4; // Qot_OptionCommon.ZeroDteContractSortType
optional bool isAsc = 5; // 默認 false
repeated Qot_OptionCommon.ZeroDteContractIndicator filterList = 6;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
- 返回
message ZeroDteContractItem {
required Qot_Common.Security option = 1;
optional string name = 2;
optional int32 optionType = 3; // Qot_Common.OptionType
optional double optionPrice = 4;
optional double changeRate = 5; // 漲跌幅(百分比)
optional int64 volume = 6;
optional int64 openInterest = 7;
optional double iv = 8; // (%)
optional double delta = 9;
optional double gamma = 10;
optional double vega = 11;
optional double theta = 12;
optional double rho = 13;
optional double buyBreakEvenPoint = 14; // 價格
optional double buyToBep = 15; // (%)
optional double buyProfitProbability = 16; // (%)
optional double sellProfitProbability = 17;// (%)
}
message S2C {
repeated ZeroDteContractItem itemList = 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
- 接口調用結果,結構參見 RetType
協議 ID
3312
Futu::u32_t GetOptionZeroDteContract(const Qot_GetOptionZeroDteContract::Request &stReq);
virtual void OnReply_GetOptionZeroDteContract(Futu::u32_t nSerialNo, const Qot_GetOptionZeroDteContract::Response &stRsp) = 0;
介紹
獲取末日期權合約列表
參數
message C2S {
required Qot_Common.Security owner = 1;
required int64 strikeDateTimestamp = 2;
required Qot_GetOptionZeroDteScreener.OptionChainInfo chainInfo = 3;
optional int32 sortType = 4; // Qot_OptionCommon.ZeroDteContractSortType
optional bool isAsc = 5; // 默認 false
repeated Qot_OptionCommon.ZeroDteContractIndicator filterList = 6;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
- 返回
message ZeroDteContractItem {
required Qot_Common.Security option = 1;
optional string name = 2;
optional int32 optionType = 3; // Qot_Common.OptionType
optional double optionPrice = 4;
optional double changeRate = 5; // 漲跌幅(百分比)
optional int64 volume = 6;
optional int64 openInterest = 7;
optional double iv = 8; // (%)
optional double delta = 9;
optional double gamma = 10;
optional double vega = 11;
optional double theta = 12;
optional double rho = 13;
optional double buyBreakEvenPoint = 14; // 價格
optional double buyToBep = 15; // (%)
optional double buyProfitProbability = 16; // (%)
optional double sellProfitProbability = 17;// (%)
}
message S2C {
repeated ZeroDteContractItem itemList = 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
- 接口調用結果,結構參見 RetType
協議 ID
3312
Example
class Program : public FTSPI_Qot, 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) {
Qot_GetOptionZeroDteContract::Request req;
Qot_GetOptionZeroDteContract::C2S *c2s = req.mutable_c2s();
// TODO: 按 proto 填充 c2s 字段
m_GetOptionZeroDteContractSerialNo = m_pQotApi->GetOptionZeroDteContract(req);
}
virtual void OnReply_GetOptionZeroDteContract(Futu::u32_t nSerialNo, const Qot_GetOptionZeroDteContract::Response &stRsp) {
if (nSerialNo != m_GetOptionZeroDteContractSerialNo) return;
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_GetOptionZeroDteContractSerialNo = 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
getOptionZeroDteContract(qotGetOptionZeroDteContract)
介紹
獲取末日期權合約列表
參數
message C2S {
required Qot_Common.Security owner = 1;
required int64 strikeDateTimestamp = 2;
required Qot_GetOptionZeroDteScreener.OptionChainInfo chainInfo = 3;
optional int32 sortType = 4; // Qot_OptionCommon.ZeroDteContractSortType
optional bool isAsc = 5; // 默認 false
repeated Qot_OptionCommon.ZeroDteContractIndicator filterList = 6;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
- 返回
message ZeroDteContractItem {
required Qot_Common.Security option = 1;
optional string name = 2;
optional int32 optionType = 3; // Qot_Common.OptionType
optional double optionPrice = 4;
optional double changeRate = 5; // 漲跌幅(百分比)
optional int64 volume = 6;
optional int64 openInterest = 7;
optional double iv = 8; // (%)
optional double delta = 9;
optional double gamma = 10;
optional double vega = 11;
optional double theta = 12;
optional double rho = 13;
optional double buyBreakEvenPoint = 14; // 價格
optional double buyToBep = 15; // (%)
optional double buyProfitProbability = 16; // (%)
optional double sellProfitProbability = 17;// (%)
}
message S2C {
repeated ZeroDteContractItem itemList = 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
- 接口調用結果,結構參見 RetType
協議 ID
3312
Example
import ftWebsocket from "futu-api";
import { Common, Qot_OptionCommon } from "futu-api/proto";
import beautify from "js-beautify";
function QotGetOptionZeroDteContract(){
const { RetType } = Common
const { OptionMarket, ZeroDteSortType, ZeroDteContractSortType } = Qot_OptionCommon
let [addr, port, enable_ssl, key] = ["127.0.0.1", 11112, false, ''];
let websocket = new ftWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) {
// 第一步:獲取末日期權標的列表,取第一條的 chainInfo
websocket.GetOptionZeroDteScreener({
c2s: {
optionMarket: OptionMarket.OptionMarket_US_Security,
sortType: ZeroDteSortType.ZeroDteSortType_Volume,
count: 1,
},
})
.then((screenerRes)=>{
let { s2c: screenerS2c } = screenerRes
if (!screenerS2c || !screenerS2c.itemList || screenerS2c.itemList.length === 0) return
let { owner, chainInfo } = screenerS2c.itemList[0]
// 第二步:用 chainInfo 查詢末日期權合約列表
return websocket.GetOptionZeroDteContract({
c2s: {
owner: owner,
strikeDateTimestamp: chainInfo.strikeDateTimestamp,
chainInfo: chainInfo,
sortType: ZeroDteContractSortType.ZeroDteContractSortType_Volume,
},
})
})
.then((res)=>{
if (!res) return
let { errCode, retMsg, retType, s2c } = res
console.log("GetOptionZeroDteContract: 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("start error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{ websocket.stop(); process.exit(); }, 5000);
}
QotGetOptionZeroDteContract()
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
- Output
GetOptionZeroDteContract: errCode 0, retMsg , retType 0
{
"itemList": [
{
"option": { "market": 1, "code": "SPY260612C742000" },
"name": "SPY 260612 C742",
"optionType": 1,
"optionPrice": 0.58,
"changeRate": -67.688,
"volume": 730160,
"openInterest": 7449,
"iv": 146.5,
"delta": 0.4367,
"gamma": 0.2745,
"vega": 0.0039,
"theta": -455.46,
"rho": 0,
"buyBreakEvenPoint": 742.58,
"buyToBep": 0.11,
"buyProfitProbability": 43.5,
"sellProfitProbability": 56.5
},
{
"option": { "market": 1, "code": "SPY260612C745000" },
"name": "SPY 260612 C745",
"optionType": 1,
"optionPrice": 0.01,
"changeRate": -98.958,
"volume": 617981,
"openInterest": 17013,
"iv": 87.1,
"delta": 0.0244,
"gamma": 0.035,
"vega": 0.0011,
"theta": -18.52,
"rho": 0,
"buyBreakEvenPoint": 745.01,
"buyToBep": 0.44,
"buyProfitProbability": 2.4,
"sellProfitProbability": 97.6
}
]
}
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
接口限制
- 30 秒內最多請求 60 次末日期權合約列表接口
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_option_zero_dte_contract(owner, strike_date_timestamp, chain_info, sort_type=None, is_asc=None, filter_list=None)
介紹
獲取末日期權合約列表,返回指定標的在指定行權日的 0DTE 期權合約詳情,包含希臘值、盈虧平衡點及盈利概率等數據。
參數
參數 類型 說明 owner str 標的股票代碼 如 'US.AAPL',僅支持美股股票strike_date_timestamp int 行權日期時間戳(Unix 秒) chain_info dict 期權鏈信息 來自 get_option_zero_dte_screener 返回的 chain_infosort_type ZeroDteContractSortType 排序類型 VOLUME=成交量、OPEN_INTEREST=持倉量、IV=隱含波動率、DELTA=Deltais_asc bool 是否升序 默認 False(降序)filter_list list[ZeroDteContractFilter] 篩選條件列表 多條件為 AND 關係。支持 OPTION_TYPE、VOLUME、OPEN_INTEREST、IV、DELTA、GAMMA、THETA、VEGA、RHO、PRICE、CHANGE_RATIO、BREAK_EVEN_POINT、TO_BEP、BUY_PROFIT_PROBABILITY、SELL_PROFIT_PROBABILITY返回
參數 類型 說明 ret RET_CODE 接口調用結果 data pandas.DataFrame 當 ret == RET_OK,返回合約列表 str 當 ret != RET_OK,返回錯誤描述 返回 DataFrame 字段:
字段 類型 說明 option str 期權合約代碼 name str 合約名稱 option_type str 期權類型(CALL/PUT) option_price float 期權價格 change_ratio float 漲跌幅(百分比) volume int 成交量 open_interest int 持倉量 iv float 隱含波動率(百分比) delta float Delta gamma float Gamma vega float Vega theta float Theta rho float Rho buy_break_even_point float 買入盈虧平衡點 buy_to_bep float 到達盈虧平衡點所需漲跌幅(百分比) buy_profit_probability float 買入盈利概率(百分比) sell_profit_probability float 賣出盈利概率(百分比)
Example
from moomoo import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# 第一步:獲取末日期權標的列表
ret, screener_data = quote_ctx.get_option_zero_dte_screener(
market=OptionMarket.US_SECURITY,
sort_type=ZeroDteSortType.VOLUME,
is_asc=False,
count=1
)
if ret != RET_OK:
print('error:', screener_data)
quote_ctx.close()
exit()
# 第二步:取第一個標的的 chain_info,查詢其合約列表
df = screener_data['item_list']
owner = df.iloc[0]['owner']
chain_info = df.iloc[0]['chain_info']
strike_date_timestamp = chain_info['strike_date_timestamp']
ret, data = quote_ctx.get_option_zero_dte_contract(
owner=owner,
strike_date_timestamp=strike_date_timestamp,
chain_info=chain_info,
sort_type=ZeroDteContractSortType.VOLUME,
is_asc=False
)
if ret == RET_OK:
print(data)
else:
print('error:', data)
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
24
25
26
27
28
29
30
31
32
33
34
35
- Output
option name option_type option_price change_ratio volume open_interest iv delta gamma vega theta rho buy_break_even_point buy_to_bep buy_profit_probability sell_profit_probability
0 US.SPY260612C742000 SPY 260612 C742 CALL 0.58 -67.688 730160 7449 146.5 0.4367 0.2745 0.0039 -455.46 0.000 742.58 0.11 43.5 56.5
1 US.SPY260612C745000 SPY 260612 C745 CALL 0.01 -98.958 617981 17013 87.1 0.0244 0.0350 0.0011 -18.52 0.000 745.01 0.44 2.4 97.6
...
2
3
4
# Qot_GetOptionZeroDteContract.proto
介紹
獲取末日期權合約列表
參數
message C2S {
required Qot_Common.Security owner = 1;
required int64 strikeDateTimestamp = 2;
required Qot_GetOptionZeroDteScreener.OptionChainInfo chainInfo = 3;
optional int32 sortType = 4; // Qot_OptionCommon.ZeroDteContractSortType
optional bool isAsc = 5; // 默認 false
repeated Qot_OptionCommon.ZeroDteContractIndicator filterList = 6;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
- 返回
message ZeroDteContractItem {
required Qot_Common.Security option = 1;
optional string name = 2;
optional int32 optionType = 3; // Qot_Common.OptionType
optional double optionPrice = 4;
optional double changeRate = 5; // 漲跌幅(百分比)
optional int64 volume = 6;
optional int64 openInterest = 7;
optional double iv = 8; // (%)
optional double delta = 9;
optional double gamma = 10;
optional double vega = 11;
optional double theta = 12;
optional double rho = 13;
optional double buyBreakEvenPoint = 14; // 價格
optional double buyToBep = 15; // (%)
optional double buyProfitProbability = 16; // (%)
optional double sellProfitProbability = 17;// (%)
}
message S2C {
repeated ZeroDteContractItem itemList = 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
- 接口調用結果,結構參見 RetType
協議 ID
3312
uint GetOptionZeroDteContract(Qot_GetOptionZeroDteContract.Request req); virtual void OnReply_GetOptionZeroDteContract(MMAPI_Conn client, uint nSerialNo, Qot_GetOptionZeroDteContract.Response rsp);
介紹
獲取末日期權合約列表
參數
message C2S {
required Qot_Common.Security owner = 1;
required int64 strikeDateTimestamp = 2;
required Qot_GetOptionZeroDteScreener.OptionChainInfo chainInfo = 3;
optional int32 sortType = 4; // Qot_OptionCommon.ZeroDteContractSortType
optional bool isAsc = 5; // 默認 false
repeated Qot_OptionCommon.ZeroDteContractIndicator filterList = 6;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
- 返回
message ZeroDteContractItem {
required Qot_Common.Security option = 1;
optional string name = 2;
optional int32 optionType = 3; // Qot_Common.OptionType
optional double optionPrice = 4;
optional double changeRate = 5; // 漲跌幅(百分比)
optional int64 volume = 6;
optional int64 openInterest = 7;
optional double iv = 8; // (%)
optional double delta = 9;
optional double gamma = 10;
optional double vega = 11;
optional double theta = 12;
optional double rho = 13;
optional double buyBreakEvenPoint = 14; // 價格
optional double buyToBep = 15; // (%)
optional double buyProfitProbability = 16; // (%)
optional double sellProfitProbability = 17;// (%)
}
message S2C {
repeated ZeroDteContractItem itemList = 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
- 接口調用結果,結構參見 RetType
協議 ID
3312
int getOptionZeroDteContract(Qot_GetOptionZeroDteContract.Request req) onReply_GetOptionZeroDteContract(MMAPI_Conn client, int nSerialNo, Qot_GetOptionZeroDteContract.Response rsp)
介紹
獲取末日期權合約列表
參數
message C2S {
required Qot_Common.Security owner = 1;
required int64 strikeDateTimestamp = 2;
required Qot_GetOptionZeroDteScreener.OptionChainInfo chainInfo = 3;
optional int32 sortType = 4; // Qot_OptionCommon.ZeroDteContractSortType
optional bool isAsc = 5; // 默認 false
repeated Qot_OptionCommon.ZeroDteContractIndicator filterList = 6;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
- 返回
message ZeroDteContractItem {
required Qot_Common.Security option = 1;
optional string name = 2;
optional int32 optionType = 3; // Qot_Common.OptionType
optional double optionPrice = 4;
optional double changeRate = 5; // 漲跌幅(百分比)
optional int64 volume = 6;
optional int64 openInterest = 7;
optional double iv = 8; // (%)
optional double delta = 9;
optional double gamma = 10;
optional double vega = 11;
optional double theta = 12;
optional double rho = 13;
optional double buyBreakEvenPoint = 14; // 價格
optional double buyToBep = 15; // (%)
optional double buyProfitProbability = 16; // (%)
optional double sellProfitProbability = 17;// (%)
}
message S2C {
repeated ZeroDteContractItem itemList = 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
- 接口調用結果,結構參見 RetType
協議 ID
3312
Moomoo::u32_t GetOptionZeroDteContract(const Qot_GetOptionZeroDteContract::Request &stReq);
virtual void OnReply_GetOptionZeroDteContract(Moomoo::u32_t nSerialNo, const Qot_GetOptionZeroDteContract::Response &stRsp) = 0;
介紹
獲取末日期權合約列表
參數
message C2S {
required Qot_Common.Security owner = 1;
required int64 strikeDateTimestamp = 2;
required Qot_GetOptionZeroDteScreener.OptionChainInfo chainInfo = 3;
optional int32 sortType = 4; // Qot_OptionCommon.ZeroDteContractSortType
optional bool isAsc = 5; // 默認 false
repeated Qot_OptionCommon.ZeroDteContractIndicator filterList = 6;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
- 返回
message ZeroDteContractItem {
required Qot_Common.Security option = 1;
optional string name = 2;
optional int32 optionType = 3; // Qot_Common.OptionType
optional double optionPrice = 4;
optional double changeRate = 5; // 漲跌幅(百分比)
optional int64 volume = 6;
optional int64 openInterest = 7;
optional double iv = 8; // (%)
optional double delta = 9;
optional double gamma = 10;
optional double vega = 11;
optional double theta = 12;
optional double rho = 13;
optional double buyBreakEvenPoint = 14; // 價格
optional double buyToBep = 15; // (%)
optional double buyProfitProbability = 16; // (%)
optional double sellProfitProbability = 17;// (%)
}
message S2C {
repeated ZeroDteContractItem itemList = 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
- 接口調用結果,結構參見 RetType
協議 ID
3312
Example
class Program : public MMSPI_Qot, 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) {
Qot_GetOptionZeroDteContract::Request req;
Qot_GetOptionZeroDteContract::C2S *c2s = req.mutable_c2s();
// TODO: 按 proto 填充 c2s 字段
m_GetOptionZeroDteContractSerialNo = m_pQotApi->GetOptionZeroDteContract(req);
}
virtual void OnReply_GetOptionZeroDteContract(Moomoo::u32_t nSerialNo, const Qot_GetOptionZeroDteContract::Response &stRsp) {
if (nSerialNo != m_GetOptionZeroDteContractSerialNo) return;
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
protected:
MMAPI_Qot *m_pQotApi;
Moomoo::u32_t m_GetOptionZeroDteContractSerialNo = 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
getOptionZeroDteContract(qotGetOptionZeroDteContract)
介紹
獲取末日期權合約列表
參數
message C2S {
required Qot_Common.Security owner = 1;
required int64 strikeDateTimestamp = 2;
required Qot_GetOptionZeroDteScreener.OptionChainInfo chainInfo = 3;
optional int32 sortType = 4; // Qot_OptionCommon.ZeroDteContractSortType
optional bool isAsc = 5; // 默認 false
repeated Qot_OptionCommon.ZeroDteContractIndicator filterList = 6;
}
message Request {
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
- 返回
message ZeroDteContractItem {
required Qot_Common.Security option = 1;
optional string name = 2;
optional int32 optionType = 3; // Qot_Common.OptionType
optional double optionPrice = 4;
optional double changeRate = 5; // 漲跌幅(百分比)
optional int64 volume = 6;
optional int64 openInterest = 7;
optional double iv = 8; // (%)
optional double delta = 9;
optional double gamma = 10;
optional double vega = 11;
optional double theta = 12;
optional double rho = 13;
optional double buyBreakEvenPoint = 14; // 價格
optional double buyToBep = 15; // (%)
optional double buyProfitProbability = 16; // (%)
optional double sellProfitProbability = 17;// (%)
}
message S2C {
repeated ZeroDteContractItem itemList = 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
- 接口調用結果,結構參見 RetType
協議 ID
3312
Example
import mmWebsocket from "moomoo-api";
import { Common, Qot_OptionCommon } from "moomoo-api/proto";
import beautify from "js-beautify";
function QotGetOptionZeroDteContract(){
const { RetType } = Common
const { OptionMarket, ZeroDteSortType, ZeroDteContractSortType } = Qot_OptionCommon
let [addr, port, enable_ssl, key] = ["127.0.0.1", 11112, false, ''];
let websocket = new mmWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) {
// 第一步:獲取末日期權標的列表,取第一條的 chainInfo
websocket.GetOptionZeroDteScreener({
c2s: {
optionMarket: OptionMarket.OptionMarket_US_Security,
sortType: ZeroDteSortType.ZeroDteSortType_Volume,
count: 1,
},
})
.then((screenerRes)=>{
let { s2c: screenerS2c } = screenerRes
if (!screenerS2c || !screenerS2c.itemList || screenerS2c.itemList.length === 0) return
let { owner, chainInfo } = screenerS2c.itemList[0]
// 第二步:用 chainInfo 查詢末日期權合約列表
return websocket.GetOptionZeroDteContract({
c2s: {
owner: owner,
strikeDateTimestamp: chainInfo.strikeDateTimestamp,
chainInfo: chainInfo,
sortType: ZeroDteContractSortType.ZeroDteContractSortType_Volume,
},
})
})
.then((res)=>{
if (!res) return
let { errCode, retMsg, retType, s2c } = res
console.log("GetOptionZeroDteContract: 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("start error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
setTimeout(()=>{ websocket.stop(); process.exit(); }, 5000);
}
QotGetOptionZeroDteContract()
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
- Output
GetOptionZeroDteContract: errCode 0, retMsg , retType 0
{
"itemList": [
{
"option": { "market": 1, "code": "SPY260612C742000" },
"name": "SPY 260612 C742",
"optionType": 1,
"optionPrice": 0.58,
"changeRate": -67.688,
"volume": 730160,
"openInterest": 7449,
"iv": 146.5,
"delta": 0.4367,
"gamma": 0.2745,
"vega": 0.0039,
"theta": -455.46,
"rho": 0,
"buyBreakEvenPoint": 742.58,
"buyToBep": 0.11,
"buyProfitProbability": 43.5,
"sellProfitProbability": 56.5
},
{
"option": { "market": 1, "code": "SPY260612C745000" },
"name": "SPY 260612 C745",
"optionType": 1,
"optionPrice": 0.01,
"changeRate": -98.958,
"volume": 617981,
"openInterest": 17013,
"iv": 87.1,
"delta": 0.0244,
"gamma": 0.035,
"vega": 0.0011,
"theta": -18.52,
"rho": 0,
"buyBreakEvenPoint": 745.01,
"buyToBep": 0.44,
"buyProfitProbability": 2.4,
"sellProfitProbability": 97.6
}
]
}
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
接口限制
- 30 秒內最多請求 60 次末日期權合約列表接口