#!/usr/bin/env python3 """ 简单策略检查 - 不依赖freqtrade库 """ import ast import os def check_strategy_structure(): """检查策略文件结构""" strategy_file = '/Users/zhangkun/myTestFreqAI/freqtrade/templates/freqaiprimer.py' try: with open(strategy_file, 'r') as f: content = f.read() # 解析Python代码 tree = ast.parse(content) # 检查必需元素 checks = { 'INTERFACE_VERSION': False, 'populate_indicators': False, 'populate_entry_trend': False, 'populate_exit_trend': False, 'metadata参数': False, 'FreqaiPrimer类': False } # 遍历AST for node in ast.walk(tree): if isinstance(node, ast.Assign): # 检查INTERFACE_VERSION for target in node.targets: if isinstance(target, ast.Name) and target.id == 'INTERFACE_VERSION': checks['INTERFACE_VERSION'] = True elif isinstance(node, ast.ClassDef): if node.name == 'FreqaiPrimer': checks['FreqaiPrimer类'] = True elif isinstance(node, ast.FunctionDef): func_name = node.name if func_name in ['populate_indicators', 'populate_entry_trend', 'populate_exit_trend']: checks[func_name] = True # 检查metadata参数 for arg in node.args.args: if arg.arg == 'metadata': checks['metadata参数'] = True break print("策略结构检查结果:") print("=" * 30) for key, value in checks.items(): status = "✅" if value else "❌" print(f"{status} {key}: {value}") # 检查总体状态 all_passed = all(checks.values()) print("\n" + "=" * 30) if all_passed: print("✅ 策略结构完整,符合Freqtrade要求") else: print("❌ 策略结构存在问题") return all_passed except Exception as e: print(f"❌ 检查失败: {e}") return False if __name__ == "__main__": check_strategy_structure()