# 筛选期权
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_option_screen(request)
介绍
期权选股。混合使用标的属性(underlying)与期权属性(option)进行筛选。同一组内不能同时筛选标的属性(underlying)与期权属性(option),SDK 自动按需开新筛选组:默认每条筛选条件 AND 拼接(开新组),同 indicator_type 显式
or_with_previous=True时与上一条件 OR(同组)。参数
参数 类型 说明 request OptionScreenRequest 期权选股请求对象,构造时必传 market_categories OptionScreenRequest 字段:
字段 类型 说明 market_categories list[int] 期权市场品类列表 元素取自 OptMarketCategory:US_STOCK=0、US_INDEX=1、US_FUTURE=2、HK_STOCK=3、HK_INDEX=4、JP_STOCK=5、JP_INDEX=6。其中 US_FUTURE / JP_STOCK / JP_INDEX 后续支持,目前结果为空page_from int 分页起始位置 不传默认为 0page_count int 单页最大返回数 不传默认为 200筛选条件 builder 方法(默认每次调用自动开新筛选组与之前条件 AND;同 indicator_type 显式
or_with_previous=True时与上一条件 OR 同组。同一组内不能同时筛选标的属性(underlying)与期权属性(option)):方法 说明 add_underlying_filter(indicator_type, values=None, lower=None, upper=None, plate_list=None, parent_plate_id=None, or_with_previous=False) 标的属性筛选 indicator_type 取自 OptUnderlyingIndicator。STOCK_LIST 接受标的 stock_id(int,取自快照/订阅返回),不能直接传证券代码。IV / HV / IV_RANK / IV_PERCENTILE 等百分数指标传小数(30% 传 0.3)。PLATE(103) 类型传入会有报错,暂不要使用add_option_filter(indicator_type, values=None, lower=None, upper=None, or_with_previous=False) 期权属性筛选 indicator_type 取自 OptIndicator。DELTA / GAMMA / VEGA / THETA / RHO / 各类概率(如 ITM_PROBABILITY)传 0~1 小数。PREMIUM(2021) 仅支持 sort / retrieve,作为 filter 会有报错;BUY_BREAK_EVEN_POINT(3023) 已废弃,新代码请用 BUY_TO_BEP(3011)new_filter_group() 手动开始新的筛选组 组间 AND,组内 ORadd_sort(indicator_type, desc=False) 排序 desc=True 为降序,默认升序add_option_retrieve(indicator_type) 声明额外要返回的期权字段 不调用则返回默认基础字段add_underlying_retrieve(indicator_type) 声明要返回的标的字段 调用后返回结果中的 underlying dict 字段才会被填充
返回
参数 类型 说明 ret RET_CODE 接口调用结果 data tuple 当 ret == RET_OK,返回 (last_page, all_count, DataFrame) str 当 ret != RET_OK,返回错误描述 返回 DataFrame 字段:
字段 类型 说明 code str 期权代码 option_name str 期权名称 strike_price float 行权价 strike_date str 行权日 option_type int 认购/认沽 1=CALL,2=PUTexercise_type int 行权方式 1=美式,2=欧式expiration_type int 到期类型 1=周,2=月,3=季in_the_money bool 是否价内 left_day int 剩余天数 price float 期权价格 mid_price float 中间价 bid_price float 买价 ask_price float 卖价 bid_ask_spread float 买卖价差 bid_volume int 买量 ask_volume int 卖量 bid_ask_volume_ratio float 买卖量比 change_ratio float 涨跌幅 volume int 成交量 turnover float 成交额 open_interest int 未平仓合约数(持仓量) open_interest_market_cap float 持仓市值 vol_oi_ratio float 成交量/持仓量 premium float 权利金 implied_volatility float 隐含波动率 history_volatility float 历史波动率 iv_hv_ratio float IV/HV delta float 希腊字母 Delta gamma float 希腊字母 Gamma vega float 希腊字母 Vega theta float 希腊字母 Theta rho float 希腊字母 Rho leverage_ratio float 杠杆比率 effective_gearing float 有效杠杆 itm_probability float 价内概率 buy_to_bep float 买入到盈亏平衡点比率 sell_to_bep float 卖出到盈亏平衡点比率 buy_profit_probability float 买入盈利概率 sell_profit_probability float 卖出盈利概率 intrinsic_value_per float 内在价值百分比 time_value_per float 时间价值百分比 itm_degree float 价内程度 otm_degree float 价外程度 otm_probability float 价外概率 sell_annualized_return float 卖出年化收益率 interval_return float 卖出区间收益率 underlying dict 标的信息(仅当调用 add_underlying_retrieve 后返回) dict 含 stock_id / iv / hv / iv_rank / iv_percentile / market_cap / price / change_ratio
Example
from futu import (
OpenQuoteContext, RET_OK, OptionScreenRequest,
OptMarketCategory, OptIndicator, OptUnderlyingIndicator,
)
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
# 示例 1:美股标的 IV>30% + 平值附近 CALL
req = OptionScreenRequest(market_categories=[OptMarketCategory.US_STOCK])
req.add_underlying_filter(OptUnderlyingIndicator.IV, lower=0.3) # 标的 IV ≥ 30%(小数)
req.add_option_filter(OptIndicator.OPTION_TYPE, values=[1]) # CALL
req.add_option_filter(OptIndicator.DELTA, lower=0.3, upper=0.7) # Delta 0.3~0.7
req.add_option_filter(OptIndicator.LEFT_DAY, lower=7, upper=60) # 剩余 7~60 天
req.add_sort(OptIndicator.VOLUME, desc=True) # 成交量降序
req.add_option_retrieve(OptIndicator.DELTA)
req.add_option_retrieve(OptIndicator.VOLUME)
req.page_count = 30
ret, data = quote_ctx.get_option_screen(req)
if ret == RET_OK:
last_page, all_count, df = data
print(df[['code', 'option_name', 'delta', 'volume']].head(10))
else:
print('error: ', data)
# 示例 2:港股按指定标的筛选 + 同时取标的信息
# 注意:STOCK_LIST 接收的是内部 stock_id,需通过 get_market_snapshot/get_static_info 等接口
# 提前取得;下面 54047868453564 即为港股腾讯(00700)的 stock_id
req = OptionScreenRequest(market_categories=[OptMarketCategory.HK_STOCK])
req.add_underlying_filter(OptUnderlyingIndicator.STOCK_LIST,
values=[54047868453564]) # 标的=腾讯
req.add_option_filter(OptIndicator.OPTION_TYPE, values=[1]) # CALL
req.add_option_filter(OptIndicator.OPTION_TYPE, values=[2],
or_with_previous=True) # 与上一条 OR:CALL + PUT
req.add_underlying_retrieve(OptUnderlyingIndicator.IV)
req.add_underlying_retrieve(OptUnderlyingIndicator.MARKET_CAP)
req.add_sort(OptIndicator.OPEN_INTEREST, desc=True) # 持仓量降序
req.page_count = 50
ret, data = quote_ctx.get_option_screen(req)
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
36
37
38
39
40
41
42
- Output
code option_name delta volume
0 US.SLV260529C70000 SLV 260529 70.00C 0.52937 45838
1 US.TZA260612C5500 TZA 260612 5.50C 0.37815 40777
2 US.HIVE260717C5000 HIVE 260717 5.00C 0.36626 31104
3 US.NKE260618C45000 NKE 260618 45.00C 0.32579 24046
4 US.SG260618C9500 SG 260618 9.50C 0.39444 19020
2
3
4
5
6
# Qot_OptionScreen.proto
介绍
期权选股
参数
message Boundary
{
required double value = 1;
optional bool includes = 2; // 是否闭区间,默认 true
}
message ValueInterval
{
optional Boundary filterMin = 1;
optional Boundary filterMax = 2;
}
message OptionIndicatorValue
{
repeated int32 valueList = 1; // 确切值列表 (用于 OPTION_TYPE 等)
optional ValueInterval valueInterval = 2; // 区间筛选
}
message PlateInfo
{
repeated string plateIdList = 1;
optional string parentPlateId = 2;
}
// 标的属性筛选条件
message UnderlyingFilter
{
required int32 indicatorType = 1; // OptUnderlyingIndicator
optional OptionIndicatorValue indicatorValue = 2;
repeated PlateInfo plateList = 3; // 仅 PLATE(103) 时使用
}
// 期权属性筛选条件
message OptionFilter
{
required int32 indicatorType = 1; // OptIndicator
optional OptionIndicatorValue indicatorValue = 2;
}
// 一组筛选条件:组内 OR,组间 AND;同一组内不能同时筛选标的属性(underlying)与期权属性(option)
message FilterGroup
{
repeated UnderlyingFilter underlyingList = 1;
repeated OptionFilter optionList = 2;
}
message Sort
{
required int32 indicatorType = 1;
required int32 direction = 2; // 0=升序, 1=降序
}
message C2S
{
repeated int32 marketCategoryList = 1; // OptMarketCategory:US_STOCK=0、US_INDEX=1、US_FUTURE=2、HK_STOCK=3、HK_INDEX=4、JP_STOCK=5、JP_INDEX=6
repeated FilterGroup filterList = 2;
repeated Sort sortList = 3;
optional int32 pageFrom = 4;
optional int32 pageCount = 5;
repeated int32 optionRetrieveList = 6; // 声明要返回的期权字段,不传则返回默认基础字段
repeated int32 underlyingRetrieveList = 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
- 返回
message Security
{
required int32 market = 1;
required string code = 2;
}
message UnderlyingInfo
{
optional int64 stockID = 1;
optional double iv = 2;
optional double hv = 3;
optional double ivRank = 4;
optional double ivPercentile = 5;
optional double marketCap = 6;
optional double price = 7;
optional double changeRatio = 8;
}
message OptionScreenItem
{
optional Security security = 1;
optional string optionName = 2;
optional double strikePrice = 3;
optional string strikeDate = 4;
optional int32 optionType = 5;
optional int32 exerciseType = 6;
optional int32 expirationType = 7;
optional bool inTheMoney = 8;
optional int32 leftDay = 9;
optional double price = 20;
optional double midPrice = 21;
optional double bidPrice = 22;
optional double askPrice = 23;
optional double bidAskSpread = 24;
optional int64 bidVolume = 25;
optional int64 askVolume = 26;
optional double bidAskVolumeRatio = 27;
optional double changeRatio = 28;
optional int64 volume = 29;
optional double turnover = 30;
optional int64 openInterest = 31;
optional double openInterestMarketCap = 32;
optional double volOIRatio = 33;
optional double premium = 34;
optional double impliedVolatility = 40;
optional double historyVolatility = 41;
optional double ivHvRatio = 42;
optional double delta = 43;
optional double gamma = 44;
optional double vega = 45;
optional double theta = 46;
optional double rho = 47;
optional double leverageRatio = 48;
optional double effectiveGearing = 49;
optional UnderlyingInfo underlyingInfo = 50;
optional double itmProbability = 51;
optional double buyToBep = 52;
optional double sellToBep = 53;
optional double buyProfitProbability = 54;
optional double sellProfitProbability = 55;
optional double intrinsicValuePer = 56;
optional double timeValuePer = 57;
optional double itmDegree = 58;
optional double otmDegree = 59;
optional double otmProbability = 60;
optional double sellAnnualizedReturn = 61;
optional double intervalReturn = 62;
}
message S2C
{
required bool lastPage = 1;
required int32 allCount = 2;
repeated OptionScreenItem dataList = 3;
}
message Response
{
required int32 retType = 1 [default = -400];
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
- 接口调用结果,结构参见 RetType
协议 ID
3253
uint OptionScreen(QotOptionScreen.Request req); virtual void OnReply_OptionScreen(FTAPI_Conn client, uint nSerialNo, QotOptionScreen.Response rsp);
介绍
期权选股
参数
参考 Proto 标签页中 Qot_OptionScreen.proto 的请求结构。
返回
参考 Proto 标签页中 Qot_OptionScreen.proto 的响应结构。
协议 ID
3253
int optionScreen(QotOptionScreen.Request req) onReply_OptionScreen(FTAPI_Conn client, int nSerialNo, QotOptionScreen.Response rsp)
介绍
期权选股
参数
参考 Proto 标签页中 Qot_OptionScreen.proto 的请求结构。
返回
参考 Proto 标签页中 Qot_OptionScreen.proto 的响应结构。
协议 ID
3253
bool OptionScreen(uint32_t & nSerialNo, const Qot_OptionScreen::Request & stReq); virtual void OnReply_OptionScreen(FTAPI_Conn* pConn, uint32_t nSerialNo, const Qot_OptionScreen::Response & stRsp)
介绍
期权选股
参数
参考 Proto 标签页中 Qot_OptionScreen.proto 的请求结构。
返回
参考 Proto 标签页中 Qot_OptionScreen.proto 的响应结构。
协议 ID
3253
optionScreen(qotOptionScreen)
介绍
期权选股
参数
参考 Proto 标签页中 Qot_OptionScreen.proto 的请求结构。
返回
参考 Proto 标签页中 Qot_OptionScreen.proto 的响应结构。
协议 ID
3253
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_option_screen(request)
介绍
期权选股,参数与返回字段同 nn 标签页。
Example
from moomoo import (
OpenQuoteContext, RET_OK, OptionScreenRequest,
OptMarketCategory, OptIndicator, OptUnderlyingIndicator,
)
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
req = OptionScreenRequest(market_categories=[OptMarketCategory.US_STOCK])
req.add_underlying_filter(OptUnderlyingIndicator.IV, lower=0.3) # 30%(小数)
req.add_option_filter(OptIndicator.OPTION_TYPE, values=[1])
req.add_option_filter(OptIndicator.DELTA, lower=0.3, upper=0.7)
req.add_sort(OptIndicator.VOLUME, desc=True)
req.page_count = 30
ret, data = quote_ctx.get_option_screen(req)
if ret == RET_OK:
last_page, all_count, df = data
print(df[['code', 'option_name', 'delta', 'volume']].head(10))
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
# Qot_OptionScreen.proto
参考 nn 标签页 Proto 内容,协议 ID 3253。
uint OptionScreen(QotOptionScreen.Request req); virtual void OnReply_OptionScreen(FTAPI_Conn client, uint nSerialNo, QotOptionScreen.Response rsp);
参考 nn 标签页 Proto 内容,协议 ID 3253。
int optionScreen(QotOptionScreen.Request req) onReply_OptionScreen(FTAPI_Conn client, int nSerialNo, QotOptionScreen.Response rsp)
参考 nn 标签页 Proto 内容,协议 ID 3253。
bool OptionScreen(uint32_t & nSerialNo, const Qot_OptionScreen::Request & stReq); virtual void OnReply_OptionScreen(FTAPI_Conn* pConn, uint32_t nSerialNo, const Qot_OptionScreen::Response & stRsp)
参考 nn 标签页 Proto 内容,协议 ID 3253。
optionScreen(qotOptionScreen)
参考 nn 标签页 Proto 内容,协议 ID 3253。