# 筛选正股
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_stock_screen(request)
介绍
条件选股 V2。相比旧接口 get_stock_filter,因子覆盖更广(11 类共 244+ 个因子),数值统一传原始值(OpenD 自动倍率转换),支持单字段或多字段排序、显式声明取回属性,结果按
value_type分别填入sval/ival/aval/dval。参数
参数 类型 说明 request StockScreenRequest 条件选股请求对象,通过 builder 方式构建 StockScreenRequest 字段:
字段 类型 说明 page_from int 分页起始位置 不传默认为 0page_count int 单页最大返回数 不传默认为 200筛选条件 builder 方法(每次调用追加一条筛选条件,所有数值字段直接传原始值,OpenD 自动倍率转换):
方法 说明 add_simple_field(field, values) 市场 / 交易所 / 指数 / 自选股等枚举字段筛选 field 取自 SimpleField;values 为枚举值列表(OR 关系)。ScrMarket.MY / JP / SG 后续支持,目前结果为空add_plate(plate_ids, parent_plate_id=None) 板块筛选 plate_ids 形如 ["BK1001"]add_simple_property(name, lower=None, upper=None) 简单行情属性区间筛选 name 取自 SimpleProperty(最新价、市值、PE、量比等);lower / upper 直接传原始值,如最新价 10 元传 10、市值 ≥ 100 亿传 10_000_000_000add_cumulative_property(name, days=1, lower=None, upper=None) 累计行情属性 name 取自 CumulativeProperty;days 用于 N 日累计。涨跌幅类(如 PRICE_CHANGE_PCT)传值为小数(5% 传 0.05,非 5.0)add_financial_property(name, term=None, year=None, lower=None, upper=None, ...) 财务属性 name 取自 FinancialProperty;term 取自 Term 枚举(Q1=1、年报=100、最新单季=10 等)。Term.SURPRISE_LATEST 系列(200~204)实测 HK/US 均会返回数值,但当前数据通常与 ANNUAL 相同,慎用add_indicator_positional(first_indicator_name, period_type, position, second_indicator=None, ...) 技术指标位置关系 如 MA5 上穿 MA20。指标名/周期/位置取自 Indicator / Period / Positionadd_indicator_pattern(name, period_type, ...) 技术指标形态(金叉、死叉、背离等) name 取自 Patternadd_featured_property(name, intervals=None, value_set=None, period=None, range_period=None, first_custom_param=None) 特色指标(筹码、热度、分析师评级、资金流等) add_broker_holdings(name, days=None, param=None, intervals=None) 经纪商持股因子 仅港股。经纪商因子 6101 / 6102 / 6105 / 6106 / 6107 倍率 1000,按百分数传值(如 20% 传 20);days参数不生效add_kline_shape(name, period=None, value_set=None) K 线形态(双底、头肩底等) period 必传,目前仅支持日 K(11) 与 1 小时 K(21)add_option(name, intervals=None, param=None, period=None) 期权指标(正股 IV、HV 等) 取回属性 builder 方法(声明返回哪些字段值;不声明则只返回 stock_id):
方法 说明 add_retrieve_basic(name) 代码 / 名称 / 行业 name 取自 BasicProperty:CODE=1101、NAME=1102、INDUSTRY=1103add_retrieve_simple(name) 简单行情属性 name 取自 SimplePropertyadd_retrieve_cumulative(name, days=1, period_average=None) 累计属性 name 取自 CumulativePropertyadd_retrieve_financial(name, term=None, year=None, ...) 财务属性 name 取自 FinancialPropertyadd_retrieve_indicator(name, period=None, indicator_params=None) 技术指标 add_retrieve_featured(name, period=None, range_period=None, first_custom_param=None) 特色属性 add_retrieve_broker(name, days=None, param=None) 经纪商 add_retrieve_option(name, param=None, period=None) 期权属性 add_retrieve_kline_shape(name, period=None) K 线形态 period 必传,否则不返回结果;目前仅支持日 K(11) 与 1 小时 K(21)排序 builder 方法:
方法 说明 set_sort(direction, property_type, property_params) 单字段排序 direction 取自 ScrSortDir:ASC=1、DESC=2、ABS_ASC=3、ABS_DESC=4。property_type 取 'basic' / 'simple' / 'cumulative' / 'financial' / 'indicator' / 'featured' / 'broker' / 'option' / 'kline_shape'add_sort(direction, property_type, property_params) 多字段排序 按调用顺序生效;与 set_sort 二选一,sortList 非空时优先
返回
参数 类型 说明 ret RET_CODE 接口调用结果 data tuple 当 ret == RET_OK,返回 (last_page, all_count, items) str 当 ret != RET_OK,返回错误描述 返回 tuple 字段:
字段 类型 说明 last_page bool 是否最后一页 all_count int 满足条件的总条数 items list[dict] 当前页结果列表,元素结构为 {'stock_id': int, 'results': [result, ...]}单条 result 结构:
字段 类型 说明 type str 属性类型 'basic' / 'simple' / 'cumulative' / 'financial' / 'indicator' / 'featured' / 'broker' / 'option' / 'kline_shape'property dict 对应 property 描述(含 name / days / term 等) value_type int 值类型 1=string(sval)、2=int64(ival)、3=int64数组(aval)、4=double(dval)。当 OpenD 无数据时仅下发 value_type(多为 2),sval/ival/aval/dval 均缺失,如港股 Q2/Q3/Q4 财务数据sval str 字符串值(value_type=1 时存在) ival int 整型值(value_type=2 时存在) aval list[int] 整型数组值(value_type=3 时存在) dval float 浮点值(value_type=4 时存在) enum_type_name str 当 ival 为枚举码时,对应的枚举类型名(如 'KlineShapeType') enum_name str 当 ival 为枚举码时,OpenD/SDK 解码出的枚举名(如 'DOUBLE_BOTTOMS'、'NONE') end_time int 财报结束时间戳 仅 financial 类型,且当前 OpenD 版本暂未下发,实际返回结果中通常没有该字段
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)
# 示例 1:港股大市值股 + MACD 金叉
req = StockScreenRequest()
req.add_simple_field(field=SimpleField.MARKET, values=[ScrMarket.HK])
req.add_simple_property(name=SimpleProperty.PRICE, lower=10.0) # 最新价 ≥ 10
req.add_simple_property(name=SimpleProperty.MARKET_CAP, lower=10_000_000_000.0) # 市值 ≥ 100 亿
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 金叉
# 取回字段
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)
# 排序
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"总数 {all_count}, 当前返回 {len(items)} 条")
for it in items[:3]:
print(it['stock_id'], it['results'])
else:
print('error: ', data)
# 示例 2:财务因子 + 累计涨跌幅
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 日涨跌幅 -5%~5%(百分数传小数)
req.add_financial_property(name=FinancialProperty.NET_PROFIT,
term=Term.ANNUAL, lower=0.0) # 年报净利润 > 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)
# 示例 3:K 线形态(W 型底 + 头肩底)
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()
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
总数 1, 当前返回 1 条
54047868453564 [{'type': 'basic', 'property': {'name': 1101}, 'value_type': 1, 'sval': '00700'},
{'type': 'basic', 'property': {'name': 1102}, 'value_type': 1, 'sval': '腾讯控股'},
{'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}]
2
3
4
5
6
# Qot_StockScreen.proto
介绍
条件选股 V2
参数
message Boundary
{
required double value = 1;
optional bool includes = 2; // 是否闭区间,默认 true
}
message Interval
{
optional Boundary filterMin = 1;
optional Boundary filterMax = 2;
}
// ===== 各类 PropertyXxx =====
message PropertyBasic { required int32 name = 1; }
message PropertySimple { required int32 name = 1; optional int32 unit = 2; }
message PropertyCumulative {
required int32 name = 1;
required int32 days = 2;
optional int32 periodAverage = 3;
optional int32 unit = 4;
}
message PropertyFinancial {
required int32 name = 1;
optional int32 term = 2;
optional int32 year = 3;
optional int32 duration = 4;
optional int32 periodAverage = 5;
optional int32 futureDuration = 6;
optional int32 unit = 7;
}
message PropertyIndicator {
required int32 name = 1;
optional int32 period = 2;
repeated int32 indicatorParams = 3;
}
message PropertyFeatured {
required int32 name = 1;
optional int32 period = 2;
optional int32 rangePeriod = 3;
optional int32 firstCustomParam = 4;
}
message PropertyBroker {
required int32 name = 1;
optional int32 days = 2;
optional string param = 3;
}
message PropertyOption {
required int32 name = 1;
optional int32 period = 2;
optional string param = 3;
}
message PropertyKlineShape {
required int32 name = 1;
optional int32 period = 2;
}
// ===== 各类 QueryXxx =====
message SimpleFieldQuery
{
required int32 simpleField = 1;
repeated int32 screenValueList = 2;
}
message PlateInfo
{
repeated string plateIdList = 1;
optional string parentPlateId = 2;
}
message PlateQuery { repeated PlateInfo plateList = 1; }
message SimplePropertyQuery
{
required PropertySimple property = 1;
optional Boundary filterMin = 2;
optional Boundary filterMax = 3;
}
message CumulativePropertyQuery
{
required PropertyCumulative property = 1;
optional Boundary filterMin = 2;
optional Boundary filterMax = 3;
optional int32 continuousPeriod = 4;
}
message FinancialPropertyQuery
{
required PropertyFinancial property = 1;
optional Boundary filterMin = 2;
optional Boundary filterMax = 3;
optional int32 continuousPeriod = 4;
}
message IndicatorPositionalQuery
{
required int32 firstIndicatorName = 1;
required int32 periodType = 2;
required int32 position = 3;
optional int32 secondIndicator = 4;
optional int32 secondValue = 5;
repeated int32 firstIndicatorParams = 6;
repeated int32 secondIndicatorParams = 7;
optional int32 continuousPeriod = 8;
repeated Interval intervals = 9;
}
message IndicatorPatternQuery
{
required int32 name = 1;
required int32 periodType = 2;
optional int32 continuousPeriod = 3;
optional bool isMatching = 4;
repeated int32 subPatterns = 5;
}
message FeaturedPropertyQuery
{
required PropertyFeatured property = 1;
repeated Interval intervals = 2;
repeated int32 valueSet = 3;
}
message BrokerHoldingsQuery
{
required PropertyBroker property = 1;
repeated Interval intervals = 2;
}
message KlineShapeQuery
{
required PropertyKlineShape property = 1;
repeated int32 valueSet = 2;
}
message OptionQuery
{
required PropertyOption property = 1;
repeated Interval intervals = 2;
}
// ===== 一条筛选条件 (oneof 多选一) =====
message ScreenQuery
{
optional SimpleFieldQuery simpleFieldQuery = 1;
optional PlateQuery plateQuery = 2;
optional SimplePropertyQuery simplePropertyQuery = 3;
optional CumulativePropertyQuery cumulativePropertyQuery = 4;
optional FinancialPropertyQuery financialPropertyQuery = 5;
optional IndicatorPositionalQuery indicatorPositionalQuery = 6;
optional IndicatorPatternQuery indicatorPatternQuery = 7;
optional FeaturedPropertyQuery featuredPropertyQuery = 8;
optional BrokerHoldingsQuery brokerHoldingsQuery = 9;
optional KlineShapeQuery klineShapeQuery = 10;
optional OptionQuery optionQuery = 11;
}
// ===== 取回字段 =====
message RetrieveQuery
{
optional PropertyBasic basicProperty = 1;
optional PropertySimple simpleProperty = 2;
optional PropertyCumulative cumulativeProperty = 3;
optional PropertyFinancial financialProperty = 4;
optional PropertyIndicator indicatorProperty = 5;
optional PropertyFeatured featuredProperty = 6;
optional PropertyBroker brokerProperty = 7;
optional PropertyOption optionProperty = 8;
optional PropertyKlineShape klineShapeProperty = 9;
}
// ===== 排序定义 =====
message Sort
{
required int32 direction = 1; // 1=ASC, 2=DESC, 3=ABS_ASC, 4=ABS_DESC
optional PropertyBasic basicProperty = 2;
optional PropertySimple simpleProperty = 3;
optional PropertyCumulative cumulativeProperty = 4;
optional PropertyFinancial financialProperty = 5;
optional PropertyIndicator indicatorProperty = 6;
optional PropertyFeatured featuredProperty = 7;
optional PropertyBroker brokerProperty = 8;
optional PropertyOption optionProperty = 9;
optional PropertyKlineShape klineShapeProperty = 10;
}
message C2S
{
repeated ScreenQuery filterList = 1;
repeated RetrieveQuery retrieveList = 2;
repeated int64 watchlistStockIds = 3;
optional Sort sort = 4; // 单字段排序
optional int32 pageFrom = 5;
optional int32 pageCount = 6;
repeated Sort sortList = 7; // 多字段排序,非空时优先于 sort
}
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
- 返回
// 单条结果值: valueType=1 时取 sval, =2 取 ival, =3 取 aval, =4 取 dval
message ResultPropertyBasic
{
required PropertyBasic property = 1;
optional int32 valueType = 2;
optional string sval = 3;
optional int64 ival = 4;
repeated int64 aval = 5;
optional double dval = 6;
optional string enumTypeName = 7;
optional string enumName = 8;
}
// 其余 ResultPropertySimple / Cumulative / Financial / Indicator / Featured / Broker / Option / KlineShape
// 结构与 ResultPropertyBasic 相同,仅 property 类型不同。Financial 额外包含 endTime。
message RspItemResult
{
optional ResultPropertyBasic basicPropertyResult = 1;
optional ResultPropertySimple simplePropertyResult = 2;
optional ResultPropertyCumulative cumulativePropertyResult = 3;
optional ResultPropertyFinancial financialPropertyResult = 4;
optional ResultPropertyIndicator indicatorPropertyResult = 5;
optional ResultPropertyFeatured featuredPropertyResult = 6;
optional ResultPropertyBroker brokerPropertyResult = 7;
optional ResultPropertyOption optionPropertyResult = 8;
optional ResultPropertyKlineShape klineShapePropertyResult = 9;
}
message RspItem
{
required int64 stockId = 1;
repeated RspItemResult results = 2;
}
message S2C
{
required bool lastPage = 1;
required int32 allCount = 2;
repeated RspItem 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
- 接口调用结果,结构参见 RetType
协议 ID
3252
uint StockScreen(QotStockScreen.Request req); virtual void OnReply_StockScreen(FTAPI_Conn client, uint nSerialNo, QotStockScreen.Response rsp);
介绍
条件选股 V2
参数
参考 Proto 标签页中 Qot_StockScreen.proto 的请求结构。
返回
参考 Proto 标签页中 Qot_StockScreen.proto 的响应结构。
协议 ID
3252
int stockScreen(QotStockScreen.Request req) onReply_StockScreen(FTAPI_Conn client, int nSerialNo, QotStockScreen.Response rsp)
介绍
条件选股 V2
参数
参考 Proto 标签页中 Qot_StockScreen.proto 的请求结构。
返回
参考 Proto 标签页中 Qot_StockScreen.proto 的响应结构。
协议 ID
3252
bool StockScreen(uint32_t & nSerialNo, const Qot_StockScreen::Request & stReq); virtual void OnReply_StockScreen(FTAPI_Conn* pConn, uint32_t nSerialNo, const Qot_StockScreen::Response & stRsp)
介绍
条件选股 V2
参数
参考 Proto 标签页中 Qot_StockScreen.proto 的请求结构。
返回
参考 Proto 标签页中 Qot_StockScreen.proto 的响应结构。
协议 ID
3252
stockScreen(qotStockScreen)
介绍
条件选股 V2
参数
参考 Proto 标签页中 Qot_StockScreen.proto 的请求结构。
返回
参考 Proto 标签页中 Qot_StockScreen.proto 的响应结构。
协议 ID
3252
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_stock_screen(request)
介绍
条件选股 V2,参数与返回字段同 nn 标签页。
Example
from moomoo import OpenQuoteContext, RET_OK, StockScreenRequest
from moomoo.quote.stock_screen_const import (
ScrMarket, ScrSortDir, SimpleField, SimpleProperty,
Indicator, Period, Pattern, BasicProperty,
)
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
req = StockScreenRequest()
req.add_simple_field(field=SimpleField.MARKET, values=[ScrMarket.HK])
req.add_simple_property(name=SimpleProperty.PRICE, lower=10.0)
req.add_simple_property(name=SimpleProperty.MARKET_CAP, lower=10_000_000_000.0)
req.add_indicator_pattern(name=Pattern.MACD_GOLD_CROSS, period_type=Period.DAY)
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.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"总数 {all_count}, 当前返回 {len(items)} 条")
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
23
24
25
26
27
28
29
# Qot_StockScreen.proto
参考 nn 标签页 Proto 内容,协议 ID 3252。
uint StockScreen(QotStockScreen.Request req); virtual void OnReply_StockScreen(FTAPI_Conn client, uint nSerialNo, QotStockScreen.Response rsp);
参考 nn 标签页 Proto 内容,协议 ID 3252。
int stockScreen(QotStockScreen.Request req) onReply_StockScreen(FTAPI_Conn client, int nSerialNo, QotStockScreen.Response rsp)
参考 nn 标签页 Proto 内容,协议 ID 3252。
bool StockScreen(uint32_t & nSerialNo, const Qot_StockScreen::Request & stReq); virtual void OnReply_StockScreen(FTAPI_Conn* pConn, uint32_t nSerialNo, const Qot_StockScreen::Response & stRsp)
参考 nn 标签页 Proto 内容,协议 ID 3252。
stockScreen(qotStockScreen)
参考 nn 标签页 Proto 内容,协议 ID 3252。