# Filter Stocks by Condition

# get_stock_filter

get_stock_filter(market, filter_list, plate_code=None, begin=0, num=200)

  • Description

    Filter stocks by condition

  • Parameters

    Parameter Type Description
    market Market Market identifier.
    filter_list list The list of filter conditions.
    plate_code str Plate code.
    begin int Data starting point.
    num int The number of requested data.
    • The relevant parameters of the SimpleFilter object are as follows:

      Field Type Description
      stock_field StockField Simple filter properties.
      filter_min float The lower limit of the interval (closed interval).
      filter_max float The upper limit of the interval (closed interval).
      is_no_filter bool Whether the field does not require filtering.
      sort SortDir Sort direction.
    • The relevant parameters of the AccumulateFilter object are as follows:

      Field Type Description
      stock_field StockField Cumulative filter properties.
      filter_min float The lower limit of the interval (closed interval).
      filter_max float The upper limit of the interval (closed interval).
      is_no_filter bool Whether the field does not require filtering.
      sort SortDir Sort direction.
      days int Accumulative days of filtering data.
    • The relevant parameters of the FinancialFilter object are as follows:

      Field Type Description
      stock_field StockField Financial filter properties.
      filter_min float The lower limit of the interval (closed interval).
      filter_max float The upper limit of the interval (closed interval).
      is_no_filter bool Whether the field does not require filtering.
      sort SortDir Sort direction.
      quarter FinancialQuarter Accumulation time of financial report.
    • The relevant parameters of the CustomIndicatorFilter object are as follows:

      Field Type Description
      stock_field1 StockField Custom indicator filter properties.
      stock_field1_para list Custom indicator parameter.
      relative_position RelativePosition Relative position.
      stock_field2 StockField Custom indicator filter properties.
      stock_field2_para list Custom indicator parameter.
      value float Custom value.
      ktype KLType K line type KLType (only supports K_60M, K_DAY, K_WEEK, K_MON four time periods).
      consecutive_period int Filters data whose consecutive periods are all eligible.
      is_no_filter bool Whether the field does not require filtering. True: no filtering, False: filtering. No filtering by default.
    • The relevant parameters of the PatternFilter object are as follows:

      Field Type Description
      stock_field StockField Pattern filter properties.
      ktype KLType K line type KLType (only supports K_60M, K_DAY, K_WEEK, K_MON four time periods).
      consecutive_period int Filters data whose consecutive periods are all eligible.
      is_no_filter bool Whether the field does not require filtering. True: no filtering, False: filtering. No filtering by default.
  • Return

    Field Type Description
    ret RET_CODE Interface result.
    data pd.DataFrame If ret == RET_OK, stock selection data is returned.
    str If ret != RET_OK, error description is returned.
    • Stock selection data format as follows:

      Field Type Description
      last_page bool Is it the last page.
      all_count int Total number of lists.
      stock_list list Stock selection data.
      • FilterStockData's data format as follows:

        Field Type Description
        stock_code str Stock code.
        stock_name str Stock name.
        cur_price float Current price.
        cur_price_to_highest_52weeks_ratio float (Current price - high in 52 weeks)/high in 52 weeks.
        cur_price_to_lowest_52weeks_ratio float (Current price - low in 52 weeks)/low in 52 weeks.
        high_price_to_highest_52weeks_ratio float (Today's high - high in 52 weeks)/high in 52 weeks.
        low_price_to_lowest_52weeks_ratio float (Today's low - low in 52 weeks)/low in 52 weeks.
        volume_ratio float Volume ratio.
        bid_ask_ratio float The committee.
        lot_price float Price per lot.
        market_val float Market value.
        pe_annual float P/E ratio.
        pe_ttm float P/E ratio TTM.
        pb_rate float P/B ratio.
        change_rate_5min float Price change in five minutes.
        change_rate_begin_year float Price change of this year.
        ps_ttm float P/S rate TTM.
        pcf_ttm float P/CF rate TTM.
        total_share float Total number of shares.
        float_share float Shares outstanding.
        float_market_val float Market capitalization.
        change_rate float Price change rate.
        amplitude float Amplitude.
        volume float Average daily volume.
        turnover float Average daily turnover.
        turnover_rate float Turnover rate.
        net_profit float Net profit.
        net_profix_growth float Net profit growth rate.
        sum_of_business float Operating income.
        sum_of_business_growth float Year-on-year growth rate of operating income.
        net_profit_rate float Net interest rate.
        gross_profit_rate float Gross profit rate.
        debt_asset_rate float Asset-liability ratio.
        return_on_equity_rate float Return on net assets.
        roic float Return on invested capital.
        roa_ttm float Return on Assets TTM.
        ebit_ttm float Earnings before interest and tax TTM.
        ebitda float Earnings before interest and tax, depreciation and amortization.
        operating_margin_ttm float Operating profit margin TTM.
        ebit_margin float EBIT profit margin.
        ebitda_margin float EBITDA profit margin.
        financial_cost_rate float Financial cost rate.
        operating_profit_ttm float Operating profit TTM.
        shareholder_net_profit_ttm float Net profit attributable to the parent company.
        net_profit_cash_cover_ttm float Proportion of cash income in profit.
        current_ratio float Current ratio.
        quick_ratio float Quick ratio.
        current_asset_ratio float Current asset ratio.
        current_debt_ratio float Current debt ratio.
        equity_multiplier float Equity multiplier.
        property_ratio float Property ratio.
        cash_and_cash_equivalents float Cash and cash equivalents.
        total_asset_turnover float Total asset turnover rate.
        fixed_asset_turnover float Fixed asset turnover rate.
        inventory_turnover float Inventory turnover rate.
        operating_cash_flow_ttm float Operating cash flow TTM.
        accounts_receivable float Net accounts receivable.
        ebit_growth_rate float EBIT year-on-year growth rate.
        operating_profit_growth_rate float Operating profit year-on-year growth rate.
        total_assets_growth_rate float Year-on-year growth rate of total assets.
        profit_to_shareholders_growth_rate float Year-on-year growth rate of net profit attributable to the parent.
        profit_before_tax_growth_rate float Year-on-year growth rate of total profit.
        eps_growth_rate float EPS year-on-year growth rate.
        roe_growth_rate float ROE year-on-year growth rate.
        roic_growth_rate float ROIC year-on-year growth rate.
        nocf_growth_rate float Year-on-year growth rate of operating cash flow.
        nocf_per_share_growth_rate float Year-on-year growth rate of operating cash flow per share.
        operating_revenue_cash_cover float Operating cash income ratio.
        operating_profit_to_total_profit float operating profit percentage.
        basic_eps float Basic earnings per share.
        diluted_eps float Diluted earnings per share.
        nocf_per_share float Net operating cash flow per share.
        price float latest price
        ma float Simple moving average
        ma5 float 5-day simple moving average
        ma10 float 10-day simple moving average
        ma20 float 20-day simple moving average
        ma30 float 30-day simple moving average
        ma60 float 60-day simple moving average
        ma120 float 120-day simple moving average
        ma250 float 250-day simple moving average
        rsi float RSI
        ema float exponential moving average
        ema5 float 5-day exponential moving average
        ema10 float 10-day exponential moving average
        ema20 float 20-day exponential moving average
        ema30 float 30-day exponential moving average
        ema60 float 60-day exponential moving average
        ema120 float 120日-day exponential moving average
        ema250 float 250日-day exponential moving average
        kdj_k float K value of KDJ indicator
        kdj_d float D value of KDJ indicator
        kdj_j float J value of KDJ indicator
        macd_diff float DIFF value of MACD indicator
        macd_dea float DEA value of MACD indicator
        macd float MACD value of MACD indicator
        boll_upper float UPPER value of BOLL indicator
        boll_middler float MIDDLER value of BOLL indicator
        boll_lower float LOWER value of BOLL indicator
  • 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)  # filter with simple, financial and indicator filter for HK market
    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)  # Get the stock code
            print(item.stock_name)  # Get the stock name
            print(item[simple_filter])   # Get the value of the variable corresponding to simple_filter
            print(item[financial_filter])   # Get the value of the variable corresponding to financial_filter 
            print(item[custom_filter])  # Get the value of custom_filter
    else:
        print('error: ', ls)
        break
    time.sleep(3)  # Sleep for 3 seconds to avoid trigger frequency limitation

quote_ctx.close()  # After using the connection, remember to close it to prevent the number of connections from running out
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
  • Output
39 39 [ stock_code:HK.08103  stock_name:hmvod Limited  cur_price:2.69  current_ratio(annual):4.413 ,  stock_code:HK.00376  stock_name:Yunfeng Financial  cur_price:2.96  current_ratio(annual):12.585 ,  stock_code:HK.09995  stock_name:RemeGen Co., Ltd.  cur_price:92.85  current_ratio(annual):16.054 ,  stock_code:HK.80737  stock_name:Shenzhen Investment Holdings Bay Area Development  cur_price:2.8  current_ratio(annual):17.249 ,  stock_code:HK.00737  stock_name:Shenzhen Investment Holdings Bay Area Development  cur_price:3.25  current_ratio(annual):17.249 ,  stock_code:HK.03939  stock_name:Wanguo International Mining  cur_price:2.22  current_ratio(annual):17.323 ,  stock_code:HK.01055  stock_name:China Southern Airlines  cur_price:5.17  current_ratio(annual):17.529 ,  stock_code:HK.02638  stock_name:HK Electric Investments and HK Electric Investments  cur_price:7.68  current_ratio(annual):21.255 ,  stock_code:HK.00670  stock_name:China Eastern Airlines Corporation  cur_price:3.53  current_ratio(annual):25.194 ,  stock_code:HK.01952  stock_name:Everest Medicines  cur_price:69.5  current_ratio(annual):26.029 ,  stock_code:HK.00089  stock_name:Tai Sang Land Development  cur_price:4.22  current_ratio(annual):26.914 ,  stock_code:HK.00728  stock_name:China Telecom Corporation  cur_price:2.84  current_ratio(annual):27.651 ,  stock_code:HK.01372  stock_name:Bisu Technology Group  cur_price:5.63  current_ratio(annual):28.303 ,  stock_code:HK.00753  stock_name:Air China Limited  cur_price:6.37  current_ratio(annual):31.828 ,  stock_code:HK.01997  stock_name:Wharf Real Estate Investment  cur_price:44.15  current_ratio(annual):33.239 ,  stock_code:HK.02158  stock_name:Yidu Tech Inc.  cur_price:38.95  current_ratio(annual):34.046 ,  stock_code:HK.02588  stock_name:BOC Aviation Ltd.  cur_price:76.85  current_ratio(annual):34.531 ,  stock_code:HK.01330  stock_name:Dynagreen Environmental Protection Group  cur_price:3.36  current_ratio(annual):35.028 ,  stock_code:HK.01525  stock_name:SHANGHAI GENCH EDUCATION GROUP LIMITED  cur_price:6.28  current_ratio(annual):36.989 ,  stock_code:HK.09908  stock_name:JiaXing Gas Group  cur_price:10.02  current_ratio(annual):37.848 ,  stock_code:HK.06078  stock_name:Hygeia Healthcare Holdings  cur_price:49.2  current_ratio(annual):39.0 ,  stock_code:HK.01071  stock_name:Huadian Power International Corporation  cur_price:2.16  current_ratio(annual):39.507 ,  stock_code:HK.00357  stock_name:Hainan Meilan International Airport  cur_price:33.65  current_ratio(annual):39.514 ,  stock_code:HK.00762  stock_name:China Unicom  cur_price:5.21  current_ratio(annual):40.74 ,  stock_code:HK.01787  stock_name:Shandong Gold Mining  cur_price:15.62  current_ratio(annual):41.604 ,  stock_code:HK.00902  stock_name:Huaneng Power International,Inc.  cur_price:2.67  current_ratio(annual):42.919 ,  stock_code:HK.00934  stock_name:Sinopec Kantons  cur_price:2.98  current_ratio(annual):43.361 ,  stock_code:HK.01117  stock_name:China Modern Dairy  cur_price:2.29  current_ratio(annual):45.037 ,  stock_code:HK.00177  stock_name:Jiangsu Expressway  cur_price:8.78  current_ratio(annual):45.93 ,  stock_code:HK.01379  stock_name:Wenling Zhejiang Measuring and Cutting Tools Trading Centre Company Limited*  cur_price:5.71  current_ratio(annual):46.774 ,  stock_code:HK.01876  stock_name:Budweiser Brewing Company APAC Limited  cur_price:22.45  current_ratio(annual):46.917 ,  stock_code:HK.01907  stock_name:China Risun  cur_price:4.38  current_ratio(annual):47.129 ,  stock_code:HK.02160  stock_name:MicroPort CardioFlow Medtech Corporation  cur_price:15.52  current_ratio(annual):47.384 ,  stock_code:HK.00293  stock_name:Cathay Pacific Airways  cur_price:7.13  current_ratio(annual):47.983 ,  stock_code:HK.00694  stock_name:Beijing Capital International Airport  cur_price:6.29  current_ratio(annual):47.985 ,  stock_code:HK.09922  stock_name:Jiumaojiu International Holdings Limited  cur_price:26.8  current_ratio(annual):48.278 ,  stock_code:HK.01083  stock_name:Towngas China  cur_price:3.38  current_ratio(annual):49.2 ,  stock_code:HK.00291  stock_name:China Resources Beer  cur_price:58.2  current_ratio(annual):49.229 ,  stock_code:HK.00306  stock_name:Kwoon Chung Bus  cur_price:2.29  current_ratio(annual):49.769 ]
HK.08103
hmvod Limited
2.69
2.69
4.413
...
HK.00306
Kwoon Chung Bus
2.29
2.29
49.769
1
2
3
4
5
6
7
8
9
10
11
12

Tips

  • Use Get sub-plate list function to get the sub-plate code, the plates supported by conditional stock selection are respectively
    1. The industry plate and concept plate of HK market.
    2. Industry plate of US market.
    3. Shanghai and Shenzhen's industry plate, conceptual plate and geographic plate.
  • Supported plate index codes
    Code Description
    HK.Motherboard Main plate of HK market
    HK.GEM Growth Enterprise Market of HK market
    HK.BK1911 Main plate of H-Share
    HK.BK1912 Growth Enterprise Market of H-share
    US.NYSE New York Stock Exchange
    US.AMEX American Exchange
    US.NASDAQ NASDAQ
    SH.3000000 Shanghai main plate
    SZ.3000001 Shenzhen main plate
    SZ.3000004 Shenzhen Growth Enterprise Market

Interface Limitations

  • BMP authority of HK market does not support conditional stock filteration function
  • A maximum of 10 requests per 30 seconds
  • At most 200 filter results are returned per page
  • It is recommended that the filter conditions do not exceed 250, otherwise "business processing timeout did not return" may appear
  • The maximum number of the same filter condition for cumulative filter properties is 10
  • If you use dynamic data such as "current price" as the sorting field, the sorting of the data may change between multiple pages
  • Non-similar indicators do not support comparison, and are limited to the establishment of comparison relationships between similar indicators, and comparisons across different types of indicators will cause errors. For example: MA5 and MA10 can establish a relationship. MA5 and EMA10 cannot establish a relationship.
  • The same type of filter conditions of the custom indicator attribute exceeds the upper limit of 10
  • Simple attributes, financial attributes, and morphological attributes do not support repeated designation of filter conditions for the same field