Add JoinQuant env browser login helper
This commit is contained in:
@@ -6,9 +6,11 @@ import click
|
||||
|
||||
from plugins.joinquant.browser import (
|
||||
browser_snapshot,
|
||||
load_env_file,
|
||||
run_browser_backtest,
|
||||
run_browser_sim_trade,
|
||||
save_login_state,
|
||||
save_login_state_from_env,
|
||||
write_browser_config_template,
|
||||
)
|
||||
from plugins.joinquant.export_targets import export_targets
|
||||
@@ -257,6 +259,54 @@ def browser_login_cmd(storage_state, login_url, headless, wait_seconds):
|
||||
click.echo(f"Saved JoinQuant browser state: {path}")
|
||||
|
||||
|
||||
@joinquant.command("browser-login-env")
|
||||
@click.option(
|
||||
"--env-path",
|
||||
default="~/.config/chinese-equity-quant/joinquant.env",
|
||||
show_default=True,
|
||||
help="Env file with JOINQUANT_USERNAME and JOINQUANT_PASSWORD",
|
||||
)
|
||||
@click.option(
|
||||
"--storage-state",
|
||||
default="~/.config/chinese-equity-quant/joinquant_storage_state.json",
|
||||
show_default=True,
|
||||
help="Path where the authenticated browser state is stored",
|
||||
)
|
||||
@click.option(
|
||||
"--login-url",
|
||||
default="https://www.joinquant.com/user/login/index",
|
||||
show_default=True,
|
||||
)
|
||||
@click.option("--headed", is_flag=True, help="Run with a visible browser")
|
||||
@click.option("--out-dir", default=None, help="Login artifact directory")
|
||||
@click.option("--timeout-ms", default=120_000, show_default=True, type=int)
|
||||
def browser_login_env_cmd(env_path, storage_state, login_url, headed, out_dir, timeout_ms):
|
||||
"""Try credential-based JoinQuant login from an env file."""
|
||||
env = load_env_file(env_path)
|
||||
missing = [
|
||||
key for key in ["JOINQUANT_USERNAME", "JOINQUANT_PASSWORD"]
|
||||
if not env.get(key)
|
||||
]
|
||||
if missing:
|
||||
raise click.ClickException(f"Missing required env keys: {', '.join(missing)}")
|
||||
report = save_login_state_from_env(
|
||||
env_path=env_path,
|
||||
storage_state=storage_state,
|
||||
login_url=login_url,
|
||||
headless=not headed,
|
||||
out_dir=out_dir,
|
||||
timeout_ms=timeout_ms,
|
||||
)
|
||||
click.echo(f"Saved login report: {report['report_path']}")
|
||||
if report["logged_in"]:
|
||||
click.echo(f"Saved JoinQuant browser state: {report['storage_state']}")
|
||||
else:
|
||||
raise click.ClickException(
|
||||
"JoinQuant login did not complete. Check the saved screenshot/HTML; "
|
||||
"CAPTCHA/SMS/2FA may require `joinquant browser-login` once."
|
||||
)
|
||||
|
||||
|
||||
@joinquant.command("write-browser-config")
|
||||
@click.option("--out-path", required=True, help="Path for JSON browser automation config")
|
||||
@click.option("--strategy-url", default="", help="JoinQuant strategy edit/backtest/模拟盘 URL")
|
||||
|
||||
Reference in New Issue
Block a user