Skip to content

Alex-Li2018/TradingTools

Repository files navigation

TradingAgent

A 股股票咨询 Agent 系统 - 企业级交易辅助决策平台

基于 Harness Engineering 五层架构构建,为个人投资者提供专业级的股票分析能力和投资建议。

架构

┌─────────────────────────────────────────────────────┐
│                 Evaluation Layer (评估层)            │
│   - 性能监控、决策质量评估、参数优化、反馈循环       │
├─────────────────────────────────────────────────────┤
│                 Memory Layer (记忆层)                │
│   - 历史状态存储、模式识别、知识积累、相似性检索     │
├─────────────────────────────────────────────────────┤
│                 Control Layer (控制层)               │
│   - 工作流编排、智能体协调、决策制定、状态管理       │
├─────────────────────────────────────────────────────┤
│                 Tool Layer (工具层)                  │
│   - 分析工具、计算函数、数据处理器、效用函数        │
├─────────────────────────────────────────────────────┤
│              Environment Layer (环境层)              │
│   - 数据源适配、交易接口、市场规则、事件监听        │
└─────────────────────────────────────────────────────┘

功能特性

  • 多维度分析: 技术面、基本面、资金面、情绪面四个专业 Agent
  • 多模型支持: Claude 为主,国产大模型备选,可配置降级
  • 混合部署: 本地开发 + 云上生产
  • 完整评估闭环: 从分析建议到效果追踪的反馈循环
  • A/B 测试框架: 支持多版本配置并行测试

快速开始

1. 安装依赖

pip install -r requirements.txt

2. 配置环境变量

cp .env.example .env
# 编辑 .env 文件,填入你的 API Key

3. 启动服务

python scripts/run_server.py

4. 访问 API

# 查看文档
http://localhost:8000/docs

# 健康检查
curl http://localhost:8000/health

# 分析股票
curl -X POST http://localhost:8000/api/v1/analyze/stock/000001.SZ \
  -H "Content-Type: application/json" \
  -d '{"user_id": "user_123", "analysis_types": ["technical", "fundamental", "capital", "sentiment"]}'

Docker 部署

# 启动所有服务
docker-compose up -d

# 查看日志
docker-compose logs -f trading-agent

# 停止服务
docker-compose down

项目结构

trading/
├── config/                 # 配置文件
│   ├── config.yaml        # 主配置
│   ├── agents/            # Agent 配置
│   └── tools/             # 工具配置
├── src/                   # 源代码
│   ├── environment/       # 环境层
│   │   └── adapters/      # 数据源适配器
│   ├── tools/             # 工具层
│   │   ├── technical/     # 技术分析工具
│   │   ├── fundamental/   # 基本面分析工具
│   │   ├── capital/       # 资金面工具
│   │   └── sentiment/     # 情绪面工具
│   ├── control/           # 控制层
│   │   ├── agents/        # Agent 实现
│   │   └── workflows/     # 工作流编排
│   ├── memory/            # 记忆层
│   ├── evaluation/        # 评估层
│   ├── api/               # API 层
│   └── main.py           # 主入口
├── tests/                 # 测试
│   ├── unit/             # 单元测试
│   └── integration/       # 集成测试
├── scripts/               # 脚本工具
├── data/                  # 本地数据
├── logs/                  # 日志文件
├── requirements.txt       # 依赖
├── Dockerfile            # 容器化
└── docker-compose.yml    # 容器编排

数据源配置

本项目采用低成本方案,数据源选择:

数据类型 数据源 成本
基础行情 Tushare Pro ~200 元/年
实时行情 新浪财经 免费
Level2 东方财富网(爬取) 免费
舆情数据 财联社/21 世纪/新浪 免费

详见 prototype.md 附录 B。

配置说明

环境变量

变量名 说明 必需
ANTHROPIC_API_KEY Anthropic API Key
TUSHARE_TOKEN Tushare Token
ENVIRONMENT 环境 (development/staging/production)
ALIYUN_API_KEY 阿里云 API Key(可选)
BAIDU_API_KEY 百度 API Key(可选)

权重配置

可在 config/config.yaml 中调整各维度权重:

weights:
  default:
    technical: 0.25
    fundamental: 0.25
    capital: 0.25
    sentiment: 0.25

运行测试

# 单元测试
pytest tests/unit/ -v

# 集成测试
pytest tests/integration/ -v

# 覆盖率
pytest --cov=src tests/

监控

API 文档

启动服务后访问:http://localhost:8000/docs

开发计划

详见 prototype.md 第 10 节里程碑规划。

免责声明

本系统仅供学习和研究使用,不构成任何投资建议。

股市有风险,入市需谨慎。请勿将本系统的分析结果作为唯一决策依据。

License

MIT

About

a tool for assisting trading

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors