# 條件選股

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 moomoo 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.KDJ_K
custom_filter.stock_field1_para = [10,4,4]
custom_filter.stock_field2 = StockField.KDJ_K
custom_filter.stock_field2_para = [9,3,3]
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[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
48
  • 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

提示

  • 利用獲取子板塊列表函數 獲取子板塊代碼,條件選股支援的板塊分別為
    1. 港股的行業板塊和概念板塊。
    2. 美股的行業板塊
    3. 滬深的行業板塊,概念板塊和地域板塊
  • 支援的板塊指數代碼
    代碼 説明
    HK.Motherboard 港股主板
    HK.GEM 港股創業板
    HK.BK1911 H 股主板
    HK.BK1912 H 股創業板
    US.NYSE 紐交所
    US.AMEX 美交所
    US.NASDAQ 納斯達克
    SH.3000000 上海主板
    SZ.3000001 深證主板
    SZ.3000004 深證創業板

介面限制

  • 每 30 秒內最多請求 10 次條件選股介面
  • 每頁返回的篩選結果最多 200 個
  • 建議篩選條件不超過 250 個,否則可能會出現“業務處理超時沒返回”
  • 累積屬性的同一篩選條件數量上限 10 個
  • 如果使用“最新價”等動態數據作為排序字段,在多頁獲取的間隙,數據的排序有可能發生變化
  • 非同類指標不支援比較,僅限於同類指標之間建立比較關係,跨不同類型的指標比較會報錯。例如:MA5 和 MA10 可以建立關係。MA5和EMA10不能建立關係。
  • 自定義指標屬性的同一類篩選條件超出數量上限10個
  • 簡單屬性,財務屬性,形態屬性不支援對同一字段重複指定篩選條件
  • 條件選股暫不支援美股盤前盤後、夜盤,篩選結果均按照盤中數據返回