跳轉到

Block 股池 pool

所屬章節:積木 Block 以 2026-08-20 實際執行結果為準

Overview

screener_tw(block_list, pool=...) 限定選股範圍。只有台股有股池。

api.Block.screener_tw(block_list, pool=['all', '~etf'])
寫法 意思
['all'] 全市場(預設,等同 pool=None)
['tse'] 只有上市
['otc'] 只有上櫃
['tse', 'otc'] 上市 ∪ 上櫃(多個不帶 ~ 的取聯集)
['all', '~etf'] 全市場排除 ETF(~ 前綴是排除)
['all', '~etf', '~KY', '~DR'] 可疊加多個排除

可用的股池名稱來自 api.MSMP.list:

名稱 檔數(2026-08-20) 說明
all 2873 全市場
tse 1125 上市
otc 923 上櫃
esm 412 興櫃
etf 382 ETF
KY 143 KY 股
DR 14 存託憑證
delist 145 已下市

Manual Sample Input/Output

Example 1:同一積木在不同股池

input

b1 = api.Block.con_tw('今日收盤價<>開高低P%',
                      operator='>', ohlc_field='adj_High', percent=3)
for pool in (None, ['all'], ['tse'], ['all', '~etf']):
    r = api.Block.screener_tw([b1], pool=pool)
    print(f"pool={pool!r:22} -> {r['dataframe'].shape[0]} 檔")

output

pool=None                   -> 2343 檔
pool=['all']                -> 2343 檔
pool=['tse']                -> 955 檔
pool=['all', '~etf']        -> 2102 檔

pool=None 與 ['all'] 結果相同,確認預設就是全市場。


Example 2:查股池成員

input

{k: len(v) for k, v in api.MSMP.list.items()}

output

{'all': 2873, 'tse': 1125, 'otc': 923, 'esm': 412,
 'etf': 382, 'KY': 143, 'DR': 14, 'delist': 145}

input

api.MSMP.list['etf'][:5]

output

['00400A', '00401A', '00402A', '00403A', '00404A']

Example 3:美股沒有股池

input

hasattr(api.USMSMP, 'list')

output

False

screener_us() 的簽名裡就沒有 pool 參數,傳進去會 TypeError。 這是刻意的——內部的 _build_pool() 對美股一律回 None, 開放參數只會讓人誤以為有生效。


注意:api.MSMP.list['all'] 目前含一個重複代號(2873 筆但只有 2872 個不同代號, '7834' 出現兩次)。screener 的股池過濾用 columns.isin(pool),不受重複影響; 但若你自己拿 api.MSMP.list['all'] 當 DataFrame 的 columns 使用, 記得先去重(list(dict.fromkeys(...))),否則後續 reindex 會拋 InvalidIndexError: Reindexing only valid with uniquely valued Index objects。