# Stock Screening V2

get_stock_screen(request)

  • Description

    Stock screening V2. Compared with the legacy get_stock_filter, this API covers a wider range of factors (11 categories, 244+ factors), accepts raw values for all numeric inputs (OpenD performs magnification conversion automatically), supports single-field or multi-field sorting, requires explicit declaration of retrieve fields, and returns each result through sval / ival / aval / dval according to its value_type.

  • Parameters

    Parameter Type Description
    request StockScreenRequest Stock screening request object, built via builder methods
    • StockScreenRequest fields:

      Field Type Description
      page_from int Pagination start position
      page_count int Maximum results per page
    • Filter builder methods (each call appends one filter condition; all numeric fields accept raw values, OpenD performs magnification automatically):

      Method Description
      add_simple_field(field, values) Filter by enum field such as market / exchange / index / watchlist
      add_plate(plate_ids, parent_plate_id=None) Plate filter
      add_simple_property(name, lower=None, upper=None) Simple property interval filter
      add_cumulative_property(name, days=1, lower=None, upper=None) Cumulative property
      add_financial_property(name, term=None, year=None, lower=None, upper=None, ...) Financial property
      add_indicator_positional(first_indicator_name, period_type, position, second_indicator=None, ...) Indicator position relation
      add_indicator_pattern(name, period_type, ...) Indicator pattern (gold cross, dead cross, divergence, etc.)
      add_featured_property(name, intervals=None, value_set=None, period=None, range_period=None, first_custom_param=None) Featured indicator (chip, hotness, analyst rating, capital flow, etc.)
      add_broker_holdings(name, days=None, param=None, intervals=None) Broker holding factor
      add_kline_shape(name, period=None, value_set=None) K-line shape (double bottom, head & shoulders, etc.)
      add_option(name, intervals=None, param=None, period=None) Option indicator (underlying IV, HV, etc.)
    • Retrieve builder methods (declare which fields to return; if not declared, only stock_id is returned):

      Method Description
      add_retrieve_basic(name) Code / name / industry
      add_retrieve_simple(name) Simple property
      add_retrieve_cumulative(name, days=1, period_average=None) Cumulative property
      add_retrieve_financial(name, term=None, year=None, ...) Financial property
      add_retrieve_indicator(name, period=None, indicator_params=None) Indicator
      add_retrieve_featured(name, period=None, range_period=None, first_custom_param=None) Featured property
      add_retrieve_broker(name, days=None, param=None) Broker
      add_retrieve_option(name, param=None, period=None) Option property
      add_retrieve_kline_shape(name, period=None) K-line shape
    • Sort builder methods:

      Method Description
      set_sort(direction, property_type, property_params) Single-field sort
      add_sort(direction, property_type, property_params) Multi-field sort
  • Returns

    Parameter Type Description
    ret RET_CODE API result
    data tuple When ret == RET_OK, returns (last_page, all_count, items)
    str When ret != RET_OK, an error description is returned
    • Returned tuple fields:

      Field Type Description
      last_page bool Whether this is the last page
      all_count int Total number of records matching the conditions
      items list[dict] Result list for the current page; each element has the structure {'stock_id': int, 'results': [result, ...]}
    • Single result structure:

      Field Type Description
      type str Property type
      property dict Corresponding property descriptor (contains name / days / term, etc.)
      value_type int Value type
      sval str String value (present when value_type=1)
      ival int Integer value (present when value_type=2)
      aval list[int] Integer array value (present when value_type=3)
      dval float Floating-point value (present when value_type=4)
      enum_type_name str When ival is an enum code, the corresponding enum type name (e.g. 'KlineShapeType')
      enum_name str When ival is an enum code, the decoded enum name returned by OpenD/SDK (e.g. 'DOUBLE_BOTTOMS', 'NONE')
      end_time int Financial report end timestamp
  • Example

from futu import OpenQuoteContext, RET_OK, StockScreenRequest
from futu.quote.stock_screen_const import (
    ScrMarket, ScrSortDir, SimpleField, SimpleProperty,
    CumulativeProperty, FinancialProperty, Term,
    Indicator, Period, Position, Pattern,
    BasicProperty, KlineShapeProperty, KlineShapeType,
)

quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)

# Example 1: HK large-cap stocks + MACD golden cross
req = StockScreenRequest()
req.add_simple_field(field=SimpleField.MARKET, values=[ScrMarket.HK])
req.add_simple_property(name=SimpleProperty.PRICE, lower=10.0)                   # Last price >= 10
req.add_simple_property(name=SimpleProperty.MARKET_CAP, lower=10_000_000_000.0)  # Market cap >= 10 billion
req.add_simple_property(name=SimpleProperty.PE_TTM, lower=10.0, upper=50.0)      # PE(TTM) 10~50
req.add_indicator_pattern(name=Pattern.MACD_GOLD_CROSS, period_type=Period.DAY)  # MACD golden cross
# Retrieve fields
req.add_retrieve_basic(name=BasicProperty.CODE)
req.add_retrieve_basic(name=BasicProperty.NAME)
req.add_retrieve_simple(name=SimpleProperty.PRICE)
req.add_retrieve_simple(name=SimpleProperty.MARKET_CAP)
req.add_retrieve_simple(name=SimpleProperty.PE_TTM)
# Sort
req.set_sort(direction=ScrSortDir.DESC, property_type='simple',
             property_params={'name': int(SimpleProperty.MARKET_CAP)})
req.page_count = 50

ret, data = quote_ctx.get_stock_screen(req)
if ret == RET_OK:
    last_page, all_count, items = data
    print(f"Total {all_count}, returned {len(items)} this page")
    for it in items[:3]:
        print(it['stock_id'], it['results'])
else:
    print('error: ', data)

# Example 2: Financial factor + cumulative change ratio
req = StockScreenRequest()
req.add_simple_field(field=SimpleField.MARKET, values=[ScrMarket.HK])
req.add_cumulative_property(name=CumulativeProperty.PRICE_CHANGE_PCT,
                            days=5, lower=-0.05, upper=0.05)                     # 5-day change ratio -5%~5% (decimal)
req.add_financial_property(name=FinancialProperty.NET_PROFIT,
                           term=Term.ANNUAL, lower=0.0)                          # Annual net profit > 0
req.add_retrieve_basic(name=BasicProperty.CODE)
req.add_retrieve_simple(name=SimpleProperty.PRICE)
req.page_count = 200
ret, data = quote_ctx.get_stock_screen(req)

# Example 3: K-line shape (double bottom + head-and-shoulders bottom)
req = StockScreenRequest()
req.add_simple_field(field=SimpleField.MARKET, values=[ScrMarket.HK])
req.add_kline_shape(name=KlineShapeProperty.SHAPE_TYPE, period=Period.DAY,
                    value_set=[KlineShapeType.DOUBLE_BOTTOMS,
                               KlineShapeType.HEAD_SHOULDERS_BOTTOM])
req.add_retrieve_basic(name=BasicProperty.CODE)
req.add_retrieve_kline_shape(name=KlineShapeProperty.SHAPE_TYPE, period=Period.DAY)
ret, data = quote_ctx.get_stock_screen(req)

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
49
50
51
52
53
54
55
56
57
58
59
60
  • Output
Total 1, returned 1
54047868453564 [{'type': 'basic', 'property': {'name': 1101}, 'value_type': 1, 'sval': '00700'},
                {'type': 'basic', 'property': {'name': 1102}, 'value_type': 1, 'sval': 'Tencent Holdings'},
                {'type': 'simple', 'property': {'name': 2201}, 'value_type': 4, 'dval': 460.0},
                {'type': 'simple', 'property': {'name': 2301}, 'value_type': 4, 'dval': 4194280264040.0},
                {'type': 'simple', 'property': {'name': 2303}, 'value_type': 4, 'dval': 15.75126}]
1
2
3
4
5
6