| .. | ||
| alembic | ||
| app | ||
| alembic.ini | ||
| check_db.py | ||
| DATABASE_SETUP.md | ||
| EXTERNAL_API_INTEGRATION.md | ||
| init_db.py | ||
| main.py | ||
| manage_db.py | ||
| README.md | ||
| requirements.txt | ||
| test_external_apis.py | ||
基本面选股系统 - 后端服务
基于FastAPI的股票基本面分析后端服务,提供报告生成、配置管理和进度追踪功能。
项目结构
backend/
├── main.py # FastAPI应用入口
├── requirements.txt # Python依赖
├── .env.example # 环境变量示例
├── README.md # 项目说明
└── app/
├── __init__.py
├── core/ # 核心模块
│ ├── config.py # 配置管理
│ ├── database.py # 数据库连接
│ └── dependencies.py # 依赖注入
├── models/ # 数据模型
│ ├── report.py
│ ├── analysis_module.py
│ ├── progress_tracking.py
│ └── system_config.py
├── schemas/ # Pydantic模式
│ ├── report.py
│ ├── config.py
│ └── progress.py
├── services/ # 业务服务
│ ├── config_manager.py
│ ├── data_fetcher.py
│ ├── report_generator.py
│ └── progress_tracker.py
└── routers/ # API路由
├── reports.py
├── config.py
└── progress.py
快速开始
- 安装依赖:
pip install -r requirements.txt
- 配置环境变量:
cp .env.example .env
# 编辑 .env 文件,设置数据库连接和API密钥
- 启动服务:
uvicorn main:app --reload --host 0.0.0.0 --port 8000
- 访问API文档:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API端点
报告相关
GET /api/reports/{symbol}?market={market}- 获取或创建报告POST /api/reports/{symbol}/regenerate?market={market}- 重新生成报告GET /api/reports/{report_id}/details- 获取报告详情
配置管理
GET /api/config- 获取系统配置PUT /api/config- 更新系统配置POST /api/config/test- 测试配置连接
进度追踪
GET /api/progress/{report_id}- 获取报告生成进度
数据库
系统使用PostgreSQL数据库,包含以下主要表:
reports- 报告基本信息analysis_modules- 分析模块内容progress_tracking- 进度追踪记录system_config- 系统配置
开发
代码格式化
black app/
isort app/
类型检查
mypy app/
运行测试
pytest