# 条件选股
# get_stock_filter
get_stock_filter(market, filter_list, plate_code=None, begin=0, num=200)
介绍
条件选股
参数
参数 类型 说明 market Market 市场标识 filter_list list 筛选条件的列表 plate_code str 板块代码 begin int 数据起始点 num int 请求数据个数 SimpleFilter 对象相关参数如下:
字段 类型 说明 stock_field StockField 简单属性 filter_min float 区间下限 filter_max float 区间上限 is_no_filter bool 该字段是否不需要筛选 sort SortDir 排序方向 AccumulateFilter 对象相关参数如下:
字段 类型 说明 stock_field StockField 累积属性 filter_min float 区间下限 filter_max float 区间上限 is_no_filter bool 该字段是否不需要筛选 sort SortDir 排序方向 days int 所筛选的数据的累计天数 FinancialFilter 对象相关参数如下:
字段 类型 说明 stock_field StockField 财务属性 filter_min float 区间下限 filter_max float 区间上限 is_no_filter bool 该字段是否不需要筛选 sort SortDir 排序方向 quarter FinancialQuarter 财报累积时间 CustomIndicatorFilter 对象相关参数如下:
字段 类型 说明 stock_field1 StockField 自定义技术指标属性 stock_field1_para list 自定义技术指标属性参数 relative_position RelativePosition 相对位置 stock_field2 StockField 自定义技术指标属性 stock_field2_para list 自定义技术指标属性参数 value float 自定义数值 ktype KLType K线类型 KLType consecutive_period int 筛选连续周期(consecutive_period)都符合条件的数据 is_no_filter bool 该字段是否不需要筛选 PatternFilter 对象相关参数如下:
字段 类型 说明 stock_field StockField 形态技术指标属性 ktype KLType K线类型 KLType (仅支持K_60M,K_DAY,K_WEEK,K_MON 四种时间周期) consecutive_period int 筛选连续周期(consecutive_period)都符合条件的数据 is_no_filter bool 该字段是否不需要筛选
返回
参数 类型 说明 ret RET_CODE 接口调用结果 data tuple 当 ret == RET_OK,返回选股数据 str 当 ret != RET_OK,返回错误描述 选股数据元组组成如下:
字段 类型 说明 last_page bool 是否是最后一页 all_count int 列表总数量 stock_list list 选股数据 FilterStockData 类型的字段格式:
字段 类型 说明 stock_code str 股票代码 stock_name str 股票名字 cur_price float 最新价 cur_price_to_highest_52weeks_ratio float (现价 - 52周最高)/52周最高 cur_price_to_lowest_52weeks_ratio float (现价 - 52周最低)/52周最低 high_price_to_highest_52weeks_ratio float (今日最高 - 52周最高)/52周最高 low_price_to_lowest_52weeks_ratio float (今日最低 - 52周最低)/52周最低 volume_ratio float 量比 bid_ask_ratio float 委比 lot_price float 每手价格 market_val float 市值 pe_annual float 市盈率 pe_ttm float 市盈率 TTM pb_rate float 市净率 change_rate_5min float 五分钟价格涨跌幅 change_rate_begin_year float 年初至今价格涨跌幅 ps_ttm float 市销率 TTM pcf_ttm float 市现率 TTM total_share float 总股数 float_share float 流通股数 float_market_val float 流通市值 change_rate float 涨跌幅 amplitude float 振幅 volume float 日均成交量 turnover float 日均成交额 turnover_rate float 换手率 net_profit float 净利润 net_profix_growth float 净利润增长率 sum_of_business float 营业收入 sum_of_business_growth float 营业同比增长率 net_profit_rate float 净利率 gross_profit_rate float 毛利率 debt_asset_rate float 资产负债率 return_on_equity_rate float 净资产收益率 roic float 投入资本回报率 roa_ttm float 资产回报率 TTM ebit_ttm float 息税前利润 TTM ebitda float 税息折旧及摊销前利润 operating_margin_ttm float 营业利润率 TTM ebit_margin float EBIT 利润率 ebitda_margin float EBITDA 利润率 financial_cost_rate float 财务成本率 operating_profit_ttm float 营业利润 TTM shareholder_net_profit_ttm float 归属于母公司的净利润 net_profit_cash_cover_ttm float 盈利中的现金收入比例 current_ratio float 流动比率 quick_ratio float 速动比率 current_asset_ratio float 流动资产率 current_debt_ratio float 流动负债率 equity_multiplier float 权益乘数 property_ratio float 产权比率 cash_and_cash_equivalents float 现金和现金等价 total_asset_turnover float 总资产周转率 fixed_asset_turnover float 固定资产周转率 inventory_turnover float 存货周转率 operating_cash_flow_ttm float 经营活动现金流 TTM accounts_receivable float 应收账款净额 ebit_growth_rate float EBIT 同比增长率 operating_profit_growth_rate float 营业利润同比增长率 total_assets_growth_rate float 总资产同比增长率 profit_to_shareholders_growth_rate float 归母净利润同比增长率 profit_before_tax_growth_rate float 总利润同比增长率 eps_growth_rate float EPS 同比增长率 roe_growth_rate float ROE 同比增长率 roic_growth_rate float ROIC 同比增长率 nocf_growth_rate float 经营现金流同比增长率 nocf_per_share_growth_rate float 每股经营现金流同比增长率 operating_revenue_cash_cover float 经营现金收入比 operating_profit_to_total_profit float 营业利润占比 basic_eps float 基本每股收益 diluted_eps float 稀释每股收益 nocf_per_share float 每股经营现金净流量 price float 最新价格 ma float 简单均线 ma5 float 5日简单均线 ma10 float 10日简单均线 ma20 float 20日简单均线 ma30 float 30日简单均线 ma60 float 60日简单均线 ma120 float 120日简单均线 ma250 float 250日简单均线 rsi float RSI的值 ema float 指数移动均线 ema5 float 5日指数移动均线 ema10 float 10日指数移动均线 ema20 float 20日指数移动均线 ema30 float 30日指数移动均线 ema60 float 60日指数移动均线 ema120 float 120日指数移动均线 ema250 float 250日指数移动均线 kdj_k float KDJ 指标的 K 值 kdj_d float KDJ 指标的 D 值 kdj_j float KDJ 指标的 J 值 macd_diff float MACD 指标的 DIFF 值 macd_dea float MACD 指标的 DEA 值 macd float MACD 指标的 MACD 值 boll_upper float BOLL 指标的 UPPER 值 boll_middler float BOLL 指标的 MIDDLER 值 boll_lower float BOLL 指标的 LOWER 值
Example
from futu import *
import time
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
simple_filter = SimpleFilter()
simple_filter.filter_min = 2
simple_filter.filter_max = 1000
simple_filter.stock_field = StockField.CUR_PRICE
simple_filter.is_no_filter = False
# simple_filter.sort = SortDir.ASCEND
financial_filter = FinancialFilter()
financial_filter.filter_min = 0.5
financial_filter.filter_max = 50
financial_filter.stock_field = StockField.CURRENT_RATIO
financial_filter.is_no_filter = False
financial_filter.sort = SortDir.ASCEND
financial_filter.quarter = FinancialQuarter.ANNUAL
custom_filter = CustomIndicatorFilter()
custom_filter.ktype = KLType.K_DAY
custom_filter.stock_field1 = StockField.MA10
custom_filter.stock_field2 = StockField.MA60
custom_filter.relative_position = RelativePosition.MORE
custom_filter.is_no_filter = False
nBegin = 0
last_page = False
ret_list = list()
while not last_page:
nBegin += len(ret_list)
ret, ls = quote_ctx.get_stock_filter(market=Market.HK, filter_list=[simple_filter, financial_filter, custom_filter], begin=nBegin) # 对香港市场的股票做简单、财务和指标筛选
if ret == RET_OK:
last_page, all_count, ret_list = ls
print('all count = ', all_count)
for item in ret_list:
print(item.stock_code) # 取股票代码
print(item.stock_name) # 取股票名称
print(item[simple_filter]) # 取 simple_filter 对应的变量值
print(item.cur_price) # 效果同上,也是取 simple_filter 对应的变量值
print(item[financial_filter]) # 取 financial_filter 对应的变量值
print(item[custom_filter]) # 获取 custom_filter 的数值
else:
print('error: ', ls)
time.sleep(3) # 加入时间间隔,避免触发限频
quote_ctx.close() # 结束后记得关闭当条连接,防止连接条数用尽
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
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
- Output
39 39 [ stock_code:HK.08103 stock_name:HMVOD视频 cur_price:2.69 current_ratio(annual):4.413 , stock_code:HK.00376 stock_name:云锋金融 cur_price:2.96 current_ratio(annual):12.585 , stock_code:HK.09995 stock_name:荣昌生物-B cur_price:92.65 current_ratio(annual):16.054 , stock_code:HK.80737 stock_name:湾区发展-R cur_price:2.8 current_ratio(annual):17.249 , stock_code:HK.00737 stock_name:湾区发展 cur_price:3.25 current_ratio(annual):17.249 , stock_code:HK.03939 stock_name:万国国际矿业 cur_price:2.22 current_ratio(annual):17.323 , stock_code:HK.01055 stock_name:中国南方航空股份 cur_price:5.17 current_ratio(annual):17.529 , stock_code:HK.02638 stock_name:港灯-SS cur_price:7.68 current_ratio(annual):21.255 , stock_code:HK.00670 stock_name:中国东方航空股份 cur_price:3.53 current_ratio(annual):25.194 , stock_code:HK.01952 stock_name:云顶新耀-B cur_price:69.5 current_ratio(annual):26.029 , stock_code:HK.00089 stock_name:大生地产 cur_price:4.22 current_ratio(annual):26.914 , stock_code:HK.00728 stock_name:中国电信 cur_price:2.81 current_ratio(annual):27.651 , stock_code:HK.01372 stock_name:比速科技 cur_price:5.1 current_ratio(annual):28.303 , stock_code:HK.00753 stock_name:中国国航 cur_price:6.38 current_ratio(annual):31.828 , stock_code:HK.01997 stock_name:九龙仓置业 cur_price:43.75 current_ratio(annual):33.239 , stock_code:HK.02158 stock_name:医渡科技 cur_price:39.0 current_ratio(annual):34.046 , stock_code:HK.02588 stock_name:中银航空租赁 cur_price:77.0 current_ratio(annual):34.531 , stock_code:HK.01330 stock_name:绿色动力环保 cur_price:3.36 current_ratio(annual):35.028 , stock_code:HK.01525 stock_name:建桥教育 cur_price:6.28 current_ratio(annual):36.989 , stock_code:HK.09908 stock_name:嘉兴燃气 cur_price:10.02 current_ratio(annual):37.848 , stock_code:HK.06078 stock_name:海吉亚医疗 cur_price:49.8 current_ratio(annual):39.0 , stock_code:HK.01071 stock_name:华电国际电力股份 cur_price:2.16 current_ratio(annual):39.507 , stock_code:HK.00357 stock_name:美兰空港 cur_price:34.15 current_ratio(annual):39.514 , stock_code:HK.00762 stock_name:中国联通 cur_price:5.15 current_ratio(annual):40.74 , stock_code:HK.01787 stock_name:山东黄金 cur_price:15.56 current_ratio(annual):41.604 , stock_code:HK.00902 stock_name:华能国际电力股份 cur_price:2.66 current_ratio(annual):42.919 , stock_code:HK.00934 stock_name:中石化冠德 cur_price:2.96 current_ratio(annual):43.361 , stock_code:HK.01117 stock_name:现代牧业 cur_price:2.3 current_ratio(annual):45.037 , stock_code:HK.00177 stock_name:江苏宁沪高速公路 cur_price:8.78 current_ratio(annual):45.93 , stock_code:HK.01379 stock_name:温岭工量刃具 cur_price:5.71 current_ratio(annual):46.774 , stock_code:HK.01876 stock_name:百威亚太 cur_price:22.5 current_ratio(annual):46.917 , stock_code:HK.01907 stock_name:中国旭阳集团 cur_price:4.38 current_ratio(annual):47.129 , stock_code:HK.02160 stock_name:心通医疗-B cur_price:15.54 current_ratio(annual):47.384 , stock_code:HK.00293 stock_name:国泰航空 cur_price:7.1 current_ratio(annual):47.983 , stock_code:HK.00694 stock_name:北京首都机场股份 cur_price:6.34 current_ratio(annual):47.985 , stock_code:HK.09922 stock_name:九毛九 cur_price:26.65 current_ratio(annual):48.278 , stock_code:HK.01083 stock_name:港华燃气 cur_price:3.39 current_ratio(annual):49.2 , stock_code:HK.00291 stock_name:华润啤酒 cur_price:58.0 current_ratio(annual):49.229 , stock_code:HK.00306 stock_name:冠忠巴士集团 cur_price:2.29 current_ratio(annual):49.769 ]
HK.08103
HMVOD视频
2.69
2.69
4.413
...
HK.00306
冠忠巴士集团
2.29
2.29
49.769
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
提示
- 利用获取子板块列表函数 获取子板块代码,条件选股支持的板块分别为
- 港股的行业板块和概念板块。
- 美股的行业板块
- 沪深的行业板块,概念板块和地域板块
- 支持的板块指数代码
代码 说明 HK.Motherboard 港股主板 HK.GEM 港股创业板 HK.BK1911 H 股主板 HK.BK1912 H 股创业板 US.NYSE 纽交所 US.AMEX 美交所 US.NASDAQ 纳斯达克 SH.3000000 上海主板 SZ.3000001 深证主板 SZ.3000004 深证创业板
接口限制
- 港股 BMP 权限不支持条件选股功能
- 每 30 秒内最多请求 10 次条件选股接口
- 每页返回的筛选结果最多 200 个
- 建议筛选条件不超过 250 个,否则可能会出现“业务处理超时没返回”
- 累积属性的同一筛选条件数量上限 10 个
- 如果使用“最新价”等动态数据作为排序字段,在多页获取的间隙,数据的排序有可能发生变化
- 非同类指标不支持比较,仅限于同类指标之间建立比较关系,跨不同类型的指标比较会报错。例如:MA5 和 MA10 可以建立关系。MA5和EMA10不能建立关系。
- 自定义指标属性的同一类筛选条件超出数量上限10个
- 简单属性,财务属性,形态属性不支持对同一字段重复指定筛选条件