# 銘柄スクリーニング V2
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_stock_screen(request)
説明
条件付き銘柄スクリーニング V2。旧 API get_stock_filter と比較して、指標カバレッジがより広く(11 種類で計 244+ 個の指標)、数値はすべて原始値で渡します(OpenD が自動的に倍率変換)。単一フィールドまたは複数フィールドのソートに対応し、取得属性を明示的に宣言します。結果は
value_typeに応じてsval/ival/aval/dvalに振り分けられます。パラメータ
パラメータ タイプ 説明 request StockScreenRequest 条件付きスクリーニングリクエストオブジェクト。builder 方式で構築 StockScreenRequest フィールド:
フィールド タイプ 説明 page_from int ページング開始位置 デフォルトは 0page_count int 1 ページあたりの最大返却件数 デフォルトは 200フィルタ条件 builder メソッド(呼び出すごとにフィルタ条件を 1 件追加。すべての数値フィールドは原始値を直接渡し、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 は累積期間。変動率系(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 / Position から取得add_indicator_pattern(name, period_type, ...) テクニカル指標形態(ゴールデンクロス、デッドクロス、ダイバージェンスなど) name は Pattern から取得add_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) ローソク足形態(ダブルボトム、ヘッドアンドショルダーなど) 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 は SimpleProperty から取得add_retrieve_cumulative(name, days=1, period_average=None) 累積属性 name は CumulativeProperty から取得add_retrieve_financial(name, term=None, year=None, ...) 財務属性 name は FinancialProperty から取得add_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) ローソク足形態 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 API 呼び出し結果 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) # PER(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;
}
// ===== 1 つのフィルタ条件 (oneof いずれか 1 つ) =====
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
- API 呼び出し結果、構造は 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。