myTestFreqAI/debug_strategy.py
zhangkun9038@dingtalk.com f9351a7b74 revert to HEAD^^^^
2025-08-19 01:30:20 +08:00

128 lines
4.7 KiB
Python

#!/usr/bin/env python3
"""
策略调试脚本 - 检查策略加载的详细过程
"""
import os
import sys
import inspect
# 添加当前目录到Python路径
sys.path.insert(0, '/Users/zhangkun/myTestFreqAI')
def analyze_strategy_file():
"""分析策略文件结构"""
strategy_path = '/Users/zhangkun/myTestFreqAI/freqtrade/templates/freqaiprimer.py'
print("=== 策略文件分析 ===")
print(f"文件路径: {strategy_path}")
print(f"文件存在: {os.path.exists(strategy_path)}")
if os.path.exists(strategy_path):
with open(strategy_path, 'r') as f:
content = f.read()
print(f"文件大小: {len(content)} 字符")
# 检查关键内容
checks = [
('INTERFACE_VERSION', 'INTERFACE_VERSION = 3'),
('populate_indicators定义', 'def populate_indicators(self, dataframe: DataFrame, metadata: dict)'),
('populate_entry_trend定义', 'def populate_entry_trend(self, dataframe: DataFrame, metadata: dict)'),
('populate_exit_trend定义', 'def populate_exit_trend(self, dataframe: DataFrame, metadata: dict)'),
('类定义', 'class FreqaiPrimer(IStrategy)'),
]
for name, pattern in checks:
found = pattern in content
status = "" if found else ""
print(f"{status} {name}: {'找到' if found else '未找到'}")
# 检查函数签名
lines = content.split('\n')
for i, line in enumerate(lines):
if 'def populate_indicators' in line:
print(f"\n📝 populate_indicators 定义在第 {i+1} 行:")
print(f" {line.strip()}")
# 打印接下来的几行
for j in range(1, 4):
if i+j < len(lines):
print(f" {lines[i+j].strip()}")
elif 'def populate_entry_trend' in line:
print(f"\n📝 populate_entry_trend 定义在第 {i+1} 行:")
print(f" {line.strip()}")
elif 'def populate_exit_trend' in line:
print(f"\n📝 populate_exit_trend 定义在第 {i+1} 行:")
print(f" {line.strip()}")
def check_import_issues():
"""检查导入问题"""
print("\n=== 导入检查 ===")
try:
# 尝试直接导入策略类
import importlib.util
spec = importlib.util.spec_from_file_location(
"freqaiprimer",
"/Users/zhangkun/myTestFreqAI/freqtrade/templates/freqaiprimer.py"
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
# 查找策略类
classes = []
for name, obj in inspect.getmembers(module):
if inspect.isclass(obj) and 'Strategy' in str(obj.__bases__):
classes.append(name)
print(f"找到的策略类: {classes}")
if 'FreqaiPrimer' in classes:
cls = getattr(module, 'FreqaiPrimer')
print(f"✅ FreqaiPrimer类已找到")
# 检查接口版本
interface_version = getattr(cls, 'INTERFACE_VERSION', None)
print(f"接口版本: {interface_version}")
# 检查方法签名
import inspect
methods = ['populate_indicators', 'populate_entry_trend', 'populate_exit_trend']
for method in methods:
if hasattr(cls, method):
sig = inspect.signature(getattr(cls, method))
params = list(sig.parameters.keys())
has_metadata = 'metadata' in params
status = "" if has_metadata else ""
print(f"{status} {method} 参数: {params}")
else:
print(f"{method} 未找到")
except Exception as e:
print(f"❌ 导入失败: {e}")
import traceback
traceback.print_exc()
def check_duplicate_files():
"""检查是否有重复的策略文件"""
print("\n=== 重复文件检查 ===")
import subprocess
try:
result = subprocess.run(
['find', '/Users/zhangkun/myTestFreqAI', '-name', '*freqai*', '-type', 'f'],
capture_output=True, text=True
)
files = result.stdout.strip().split('\n')
print("找到的相关文件:")
for f in files:
if f:
print(f" {f}")
except Exception as e:
print(f"查找文件时出错: {e}")
if __name__ == "__main__":
analyze_strategy_file()
check_import_issues()
check_duplicate_files()