跳轉到

list_conditions 積木清單查詢

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

Overview

列出 condition registry 裡註冊的積木類別與其 metadata。

from snowyowl.blocks import list_conditions

list_conditions(category=None, market='tw')
list_conditions(category=None, market='us')
參數 型態 說明
category str, optional 只列出該分類。吃英文模組名,不是中文次類別
market 'tw' / 'us' 市場,預設台股

這不是 api.Block 的方法。 早期版本掛過 api.Block.list_conditions_tw() / api.Block.list_conditions_us(),現已移除—— 它回的是內部 registry 的 metadata,不是選股會用到的東西。 要列出可用的積木,用 get_table 的 key。

api.Block 現在只有 6 個方法: get_table_tw/us、con_tw/us、screener_tw/us。

回傳 dict[str, ConditionMetadata],key 是積木 id。ConditionMetadata 欄位:

欄位 說明
id 積木編碼,例如 'o1'、'v1'、'dfunc5'
name 積木名稱(con 的第一個參數用這個)
category 英文模組名,例如 'volume'、'ohlc'
path 內部路徑字串(格式不統一,僅供參考)
cls condition 類別本身
defaults __init__ 的預設參數
market 'tw' 或 'us'

Manual Sample Input/Output

Example 1:前三筆

input

d = list_conditions(market='tw')
print(type(d).__name__, len(d))
for k, v in list(d.items())[:3]:
    print(f"{k} -> id={v.id} name={v.name!r} category={v.category!r}")
    print(f"    defaults={v.defaults}")

output

dict 406
v1 -> id=v1 name='短均日數vs長均日數' category='volume'
    defaults={'period1': 5, 'period2': 20, 'operator': '>', 'table': '日_K', 'field': 'Volume', 'data_context': None}
v2 -> id=v2 name='近D日成交量周轉率' category='volume'
    defaults={'period': 10, 'threshold': 50, 'operator': '>', 'volume_table': '日_K', 'volume_field': 'Volume', 'shares_table': '日_三大法人', 'shares_field': '發行總張數', 'data_context': None}
v3 -> id=v3 name='日(週)成交金額>M億' category='volume'
    defaults={'threshold': 10, 'operator': '>', 'table': '日_K', 'field': '成交額_百萬', 'data_context': None}

defaults 裡的 data_context: None 是內部參數,不要傳給 con。


Example 2:category 只接受英文模組名

input

import collections
collections.Counter(m.category for m in list_conditions(market='tw').values())

output

{'financial': 94, 'ohlc': 86, 'technical': 79, 'ranking': 32,
 'moving_average': 25, 'sanda': 20, 'volume': 19, 'margin_trading': 18,
 'dahu': 16, 'industry': 9, 'chips': 8}

美股(7 種):

{'technical': 79, 'ohlc': 78, 'financial': 70, 'moving_average': 25,
 'ranking': 23, 'volume': 17, 'industry': 5}

input

len(list_conditions(category='volume', market='tw'))

output

19

用中文分類會得到空結果,因為 metadata 的 category 是英文:

input

list_conditions(category='漲跌幅', market='tw')

output

{}

中文次類別(漲跌幅、K棒型態、MACD指標 等 37 種)只存在於 block_spec.json,用於 台股積木完整參考 的分組, 不能拿來過濾 list_conditions。


Example 3:list_conditions 比 get_table 多的那些

input

reg = set(list_conditions(market='tw'))
spec_ids = {  # get_table 的 key 是名稱,取其 id
    m.id for n, m in list_conditions(market='tw').items()
    if m.name in api.Block.get_table_tw()}
sorted(reg - spec_ids)

output

['m15', 'o2x', 'r22', 'r23', 'r24', 's9x', 's9y']

這 7 個(美股 42 個)在程式碼裡有註冊,但 Excel 規格把它們標為非啟用, 所以 get_table 與 con 都看不到。列得出來但建不出來,要建會拋 ValueError: 找不到積木 ...。