运行ContestTrade分析
(
market: Optional[str] = typer.Option(None, "--market", "-m", help="选择市场 (CN-Stock/US-Stock)"),
)
| 906 | |
| 907 | @app.command() |
| 908 | def run( |
| 909 | market: Optional[str] = typer.Option(None, "--market", "-m", help="选择市场 (CN-Stock/US-Stock)"), |
| 910 | ): |
| 911 | """运行ContestTrade分析""" |
| 912 | |
| 913 | # 获取市场选择 |
| 914 | if not market: |
| 915 | market = get_market_selection() |
| 916 | |
| 917 | # 验证市场选择 |
| 918 | if not market: |
| 919 | console.print("[red]未提供市场选择[/red]") |
| 920 | raise typer.Exit(1) |
| 921 | |
| 922 | if market not in ["CN-Stock", "US-Stock"]: |
| 923 | console.print("[red]市场选择错误,请选择 CN-Stock 或 US-Stock[/red]") |
| 924 | raise typer.Exit(1) |
| 925 | |
| 926 | # 设置环境变量 - 这样全局的 cfg 就会读取对应的配置 |
| 927 | os.environ['CONTEST_TRADE_MARKET'] = market |
| 928 | |
| 929 | # 根据市场获取对应的触发时间 |
| 930 | trigger_time = get_trigger_time_for_market(market) |
| 931 | |
| 932 | # 验证触发时间 |
| 933 | if not trigger_time: |
| 934 | console.print("[red]无法获取对应市场的触发时间[/red]") |
| 935 | raise typer.Exit(1) |
| 936 | |
| 937 | console.print(f"[green]已选择市场: {market}[/green]") |
| 938 | console.print(f"[green]触发时间: {trigger_time}[/green]") |
| 939 | |
| 940 | # 验证必需的服务连接 |
| 941 | if not validate_required_services(): |
| 942 | console.print("[red]系统验证失败,无法启动分析[/red]") |
| 943 | raise typer.Exit(1) |
| 944 | |
| 945 | # 主循环 |
| 946 | while True: |
| 947 | try: |
| 948 | result = run_contest_analysis_interactive(trigger_time, market) |
| 949 | except Exception as e: |
| 950 | console.print(f"[red]运行分析时发生错误: {e}[/red]") |
| 951 | break |
| 952 | |
| 953 | if result is None or (isinstance(result, tuple) and result[0] is None): |
| 954 | console.print("[red]❌ 分析失败[/red]") |
| 955 | break |
| 956 | |
| 957 | if isinstance(result, tuple): |
| 958 | final_state, action = result |
| 959 | if action == "new_analysis": |
| 960 | # 重新选择市场 |
| 961 | market = get_market_selection() |
| 962 | if not market: |
| 963 | break |
| 964 | |
| 965 | # 设置环境变量 |
nothing calls this directly
no test coverage detected