mirror of
https://ghfast.top/https://github.com/aeroxw/easy_tdx_max.git
synced 2026-09-12 16:54:20 +08:00
feat(cli): add 'easy-tdx factor list' command
This commit is contained in:
@@ -19,6 +19,7 @@ from .cmd_board import (
|
||||
from .cmd_capital import capital_flow
|
||||
from .cmd_chanlun import chanlun
|
||||
from .cmd_ex import ex
|
||||
from .cmd_factor import factor
|
||||
from .cmd_finance import f10, fund_flow
|
||||
from .cmd_indicator import indicator, indicator_list
|
||||
from .cmd_info import server_info, symbol_info
|
||||
@@ -81,6 +82,7 @@ cli.add_command(indicator)
|
||||
cli.add_command(indicator_list)
|
||||
cli.add_command(offline)
|
||||
cli.add_command(chanlun)
|
||||
cli.add_command(factor)
|
||||
cli.add_command(backtest)
|
||||
cli.add_command(portfolio)
|
||||
cli.add_command(run_all)
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
"""因子 CLI 命令。"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
import click
|
||||
|
||||
|
||||
@click.group("factor")
|
||||
def factor() -> None:
|
||||
"""因子研究工具。"""
|
||||
pass
|
||||
|
||||
|
||||
@factor.command("list")
|
||||
@click.option(
|
||||
"--category",
|
||||
default=None,
|
||||
help="按类别筛选: momentum/volatility/quality/volume/technical/chanlun/value",
|
||||
)
|
||||
@click.option("--table", "use_table", is_flag=True, help="表格输出")
|
||||
def factor_list(category: str | None, use_table: bool) -> None:
|
||||
"""列出所有已注册的因子。
|
||||
|
||||
示例:
|
||||
|
||||
easy-tdx factor list
|
||||
|
||||
easy-tdx factor list --category momentum --table
|
||||
"""
|
||||
from easy_tdx.factor.builtin import list_factors
|
||||
|
||||
factors = list_factors()
|
||||
|
||||
if category:
|
||||
factors = [f for f in factors if f["category"] == category]
|
||||
|
||||
if use_table:
|
||||
try:
|
||||
from tabulate import tabulate
|
||||
|
||||
rows = [
|
||||
{
|
||||
"name": f["name"],
|
||||
"category": f["category"],
|
||||
"description": f["description"],
|
||||
}
|
||||
for f in factors
|
||||
]
|
||||
click.echo(tabulate(rows, headers="keys", tablefmt="grid"))
|
||||
except ImportError:
|
||||
for f in factors:
|
||||
click.echo(f"{f['name']}\t{f['category']}\t{f['description']}")
|
||||
else:
|
||||
click.echo(json.dumps(factors, ensure_ascii=False, indent=2))
|
||||
Reference in New Issue
Block a user