74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
测试策略文件是否可以正常加载
|
|
"""
|
|
import sys
|
|
import os
|
|
|
|
# 添加freqtrade到Python路径
|
|
sys.path.insert(0, '/Users/zhangkun/myTestFreqAI')
|
|
|
|
from freqtrade.resolvers.strategy_resolver import StrategyResolver
|
|
from freqtrade.configuration import Configuration
|
|
|
|
def test_strategy_loading():
|
|
"""测试策略加载"""
|
|
try:
|
|
# 创建最小配置
|
|
config = {
|
|
'strategy': 'freqaiprimer',
|
|
'strategy_path': '/Users/zhangkun/myTestFreqAI/freqtrade/templates',
|
|
'stake_currency': 'USDT',
|
|
'stake_amount': 10,
|
|
'exchange': {
|
|
'name': 'binance',
|
|
'key': '',
|
|
'secret': '',
|
|
'ccxt_config': {},
|
|
'ccxt_async_config': {}
|
|
},
|
|
'pairlists': [{'method': 'StaticPairList'}],
|
|
'datadir': '/Users/zhangkun/myTestFreqAI/user_data/data',
|
|
'timeframe': '3m',
|
|
'freqai': {
|
|
'enabled': True,
|
|
'identifier': 'test',
|
|
'feature_parameters': {
|
|
'include_timeframes': ['3m'],
|
|
'label_period_candles': 12,
|
|
'include_shifted_candles': 3,
|
|
}
|
|
}
|
|
}
|
|
|
|
# 尝试加载策略
|
|
strategy = StrategyResolver.load_strategy(config)
|
|
print("✅ 策略加载成功!")
|
|
print(f"策略名称: {strategy.__class__.__name__}")
|
|
print(f"接口版本: {getattr(strategy, 'INTERFACE_VERSION', '未设置')}")
|
|
|
|
# 检查必需的方法
|
|
methods_to_check = [
|
|
'populate_indicators',
|
|
'populate_entry_trend',
|
|
'populate_exit_trend',
|
|
'feature_engineering_expand_all',
|
|
'set_freqai_targets'
|
|
]
|
|
|
|
for method in methods_to_check:
|
|
if hasattr(strategy, method):
|
|
print(f"✅ 找到方法: {method}")
|
|
else:
|
|
print(f"❌ 缺少方法: {method}")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ 策略加载失败: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
test_strategy_loading() |