Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: multica-agent <github@multica.ai>
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""Command-line entry for one-shot datahub operations."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
|
|
from datahub.hub import build_hub
|
|
from datahub.settings import load_settings
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
parser = argparse.ArgumentParser(description="xiaobai-datahub CLI")
|
|
sub = parser.add_subparsers(dest="command", required=True)
|
|
history = sub.add_parser("history-backfill", help="回补 2016 年起交易日历和网站所用指数日 K")
|
|
history.add_argument("--calendar-start", default=None, help="日历起点,默认配置 calendar_start")
|
|
history.add_argument("--index-days", type=int, default=None, help="指数回补交易日数量,默认 260")
|
|
history.add_argument("--force", action="store_true", help="覆盖已发布的指数日期")
|
|
args = parser.parse_args(argv)
|
|
|
|
settings = load_settings()
|
|
hub = build_hub(settings)
|
|
if args.command == "history-backfill":
|
|
result = hub.pipeline.backfill_history(
|
|
calendar_start=args.calendar_start,
|
|
index_days=args.index_days,
|
|
force=args.force,
|
|
)
|
|
json.dump(result, sys.stdout, ensure_ascii=False, indent=2, default=str)
|
|
sys.stdout.write("\n")
|
|
return 0 if result.get("ok") else 1
|
|
parser.error(f"unknown command: {args.command}")
|
|
return 2
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|