Go服务端实现
项目概述
本项目实现了hyperopt工作流的服务端,基于Go语言开发。服务端通过Redis channel接收消息和发布结果,不提供RESTful API接口。
目录结构
goflow/
├── model/ # 共享数据模型
├── server/ # 服务端代码
├── go.mod # Go模块定义
└── README.md # 使用说明
快速开始
启动服务端
cd goflow/server
go run server.go --redis-addr=localhost:6379 --redis-db=0
命令行参数
--redis-addr: Redis服务器地址,默认为localhost:6379--redis-password: Redis密码,默认为空--redis-db: Redis数据库索引,默认为0
Redis频道
服务端使用以下Redis频道:
订阅频道(接收任务)
- hyperopt_channel - 接收hyperopt任务
- backtest_channel - 接收回测任务
发布频道(结果输出)
- hyperopt_result_channel - 发布hyperopt结果
- hyperopt_response_channel - 发布hyperopt完整响应
- backtest_result_channel - 发布回测结果
数据模型
Hyperopt事件
{
"task_id": "task-123",
"strategy_name": "MyStrategy",
"time_frame": "5m",
"start_time": "2023-01-01T00:00:00Z",
"properties_collections": [
{
"buy_rsi": {
"optimize": true,
"min": 20.0,
"max": 40.0,
"step": 1.0
}
}
]
}
回测事件
{
"task_id": "task-456",
"strategy_name": "MyStrategy",
"time_frame": "5m",
"start_time": "2023-01-01T00:00:00Z",
"parameters": {
"buy_rsi": 30.0,
"buy_rsi_enabled": 1.0
},
"is_pre_test": true,
"is_post_test": false
}
工作流程
- 服务端启动后连接到Redis服务器
- 订阅hyperopt_channel和backtest_channel频道
- 接收任务消息并异步处理
- 执行hyperopt或backtest任务(当前为模拟实现)
- 将结果发布到对应的结果频道
注意事项
- 当前实现为模拟版本,实际使用时需要修改服务端代码,集成到freqtrade的hyperopt和回测功能
- 支持多阶段优化策略,每个fullHyperoptEvent会生成多个hyperoptResult子任务
- 所有子任务都关联到同一个fullHyperoptEvent ID
- 生产环境建议使用ElasticSearch存储历史结果
- 需要确保Redis服务器已安装并运行