Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfe804b794 |
@@ -126,6 +126,7 @@ async def run_script(
|
|||||||
cmd = [script_path]
|
cmd = [script_path]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
print(f"正在执行脚本: {script_path}")
|
||||||
# 执行命令,添加实时输出支持
|
# 执行命令,添加实时输出支持
|
||||||
result_lines = await shell_run_command(
|
result_lines = await shell_run_command(
|
||||||
command=" ".join(cmd),
|
command=" ".join(cmd),
|
||||||
@@ -240,70 +241,3 @@ def merge_params(*param_dicts: dict) -> dict:
|
|||||||
for params in param_dicts:
|
for params in param_dicts:
|
||||||
merged.update(params)
|
merged.update(params)
|
||||||
return merged
|
return merged
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
import json
|
|
||||||
import asyncio
|
|
||||||
import logging
|
|
||||||
|
|
||||||
# 配置日志,确保实时输出
|
|
||||||
logging.basicConfig(
|
|
||||||
level=logging.INFO,
|
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
||||||
handlers=[
|
|
||||||
logging.StreamHandler() # 确保日志输出到控制台
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
# 1. 解析命令行参数
|
|
||||||
args = parse_command_line_args()
|
|
||||||
|
|
||||||
# 2. 从环境变量加载配置
|
|
||||||
env_vars = get_env_vars()
|
|
||||||
|
|
||||||
# 3. 从 Flow 配置文件加载配置(如果提供)
|
|
||||||
flow_config = {}
|
|
||||||
if args.flow_config:
|
|
||||||
flow_config = load_config_file(args.flow_config)
|
|
||||||
|
|
||||||
# 4. 从命令行参数提取参数
|
|
||||||
cli_args = {}
|
|
||||||
if args.script_url:
|
|
||||||
cli_args["script_url"] = args.script_url
|
|
||||||
if args.shell_script:
|
|
||||||
cli_args["shell_script"] = args.shell_script
|
|
||||||
|
|
||||||
# 5. 合并参数(优先级:命令行参数 > Flow 配置文件 > 环境变量)
|
|
||||||
merged_params = merge_params(env_vars, flow_config, cli_args)
|
|
||||||
|
|
||||||
# 6. 验证参数是否提供
|
|
||||||
script_url = merged_params.get("script_url")
|
|
||||||
shell_script = merged_params.get("shell_script")
|
|
||||||
|
|
||||||
if not script_url and not shell_script:
|
|
||||||
print("错误:必须提供 script_url 或 shell_script 参数!")
|
|
||||||
print("使用方法:")
|
|
||||||
print(" 1. 使用 script_url:")
|
|
||||||
print(" python backtest.py --script-url https://example.com/freqtrade_backtest.sh")
|
|
||||||
print(" 2. 使用 shell_script:")
|
|
||||||
print(" python backtest.py --shell-script 'freqtrade backtesting --config config.json --strategy MyStrategy'")
|
|
||||||
print(" 3. 使用环境变量:")
|
|
||||||
print(" export FREQTRADE_SCRIPT_URL=https://example.com/freqtrade_backtest.sh && python backtest.py")
|
|
||||||
print(" 或 export FREQTRADE_SHELL_SCRIPT='freqtrade backtesting --config config.json --strategy MyStrategy' && python backtest.py")
|
|
||||||
print(" 4. 使用配置文件:")
|
|
||||||
print(" python backtest.py --flow-config flow_config.json")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
# 7. 执行 Flow(使用 asyncio.run() 正确调用异步函数)
|
|
||||||
result = asyncio.run(start(
|
|
||||||
script_url=script_url,
|
|
||||||
shell_script=shell_script
|
|
||||||
))
|
|
||||||
|
|
||||||
print("完成!")
|
|
||||||
print(f"命令: {result['command']}")
|
|
||||||
print(f"退出码: {result['exit_code']}")
|
|
||||||
print(f"标准输出: {result['stdout'][:500]}...") # 只显示前500个字符
|
|
||||||
if result['stderr']:
|
|
||||||
print(f"标准错误: {result['stderr']}")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user