Intelligent Trading Decision System - Python Stock Trading Analysis Platform Based on Futu OpenAPI
Project description
Decidra - 智能交易决策系统
Intelligent Trading Decision System - 基于富途OpenAPI的Python股票交易分析平台
项目简介
Decidra 是一个现代化的智能交易决策系统,集成了富途 OpenAPI、AI分析引擎和终端监控界面,提供完整的股票交易分析解决方案。
✨ 主要特性
- 🔌 富途API集成: 完整封装富途OpenAPI,支持港股、美股、A股实时数据
- 📊 智能监控界面: 基于Textual框架的现代化终端UI,实时股票监控
- 🤖 AI分析引擎: 集成Claude AI,提供智能股票分析和建议
- 💹 技术指标计算: 内置MA、RSI、MACD等多种技术指标
- 📈 多数据源支持: 支持Yahoo Finance、Tushare、Akshare等数据源
- 🧪 完整测试覆盖: 145+个Python文件,完善的测试体系
- 🖥️ 现代CLI工具: 功能完备的命令行界面,支持配置管理和数据下载
- 🎯 策略引擎: 支持自定义交易策略和过滤器
🔧 环境要求
- Python: 3.8+ (推荐 3.10+)
- FutuOpenD: 富途网关程序 (用于实时数据)
- 富途证券账户: 用于交易功能 (可选)
📦 安装方式
方式一:从源码安装(推荐)
# 1. 克隆项目
git clone https://github.com/rtxIII/decidra.git
cd decidra
# 2. 安装项目(包含所有依赖)
pip install -e .
# 3. 安装开发依赖(可选)
pip install -e ".[dev]"
方式二:传统方式
# 1. 克隆项目
git clone https://github.com/rtxIII/decidra.git
cd decidra
# 2. 安装依赖
pip install -r requirements.txt
验证安装
# 验证CLI工具
decidra --help
# 或使用传统方式
python src/cli.py --help
🚀 快速开始
1. 启动监控界面
# 启动股票监控界面
decidra monitor start
2. 配置富途API
# 配置富途API连接
decidra futu config --host 127.0.0.1 --port 11111
# 测试连接
decidra futu test-connection
🖥️ 监控界面
基于Textual框架的现代化终端界面:
# 启动完整监控界面
decidra monitor start
# 快捷键:
# - q: 退出程序
# - r: 手动刷新数据
# - a: 添加股票
# - d: 删除股票
# - Enter/Space: 进入分析界面
# - Tab: 切换标签页
🏗️ 项目架构
Decidra/
├── 📁 src/ # 源代码目录
│ ├── 📁 api/ # API接口层
│ │ └── futu.py # 富途API封装
│ ├── 📁 monitor/ # 监控界面模块
│ │ ├── 📁 analysis/ # 分析功能
│ │ ├── 📁 main/ # 核心业务逻辑
│ │ ├── 📁 manager/ # 管理器组件
│ │ ├── 📁 widgets/ # UI组件库
│ │ └── ui.py # 主界面入口
│ ├── 📁 modules/ # 功能模块
│ │ ├── 📁 ai/ # AI分析模块
│ │ └── yahoo_data.py # Yahoo Finance接口
│ ├── 📁 filters/ # 交易过滤器
│ ├── 📁 strategies/ # 交易策略
│ ├── 📁 utils/ # 工具函数
│ ├── 📁 tests/ # 测试用例 (145+ 文件)
│ └── cli.py # 命令行入口
├── 📄 pyproject.toml # 现代Python项目配置
├── 📄 requirements.txt # 依赖清单
├── 📄 .pre-commit-config.yaml # 代码质量控制
└── 📄 README.md # 项目文档
🔧 开发配置
开发环境设置
# 安装开发依赖
pip install -e ".[dev]"
# 安装pre-commit钩子
pre-commit install
# 运行代码格式化
black src/
isort src/
# 类型检查
mypy src/
# 运行所有测试
pytest src/tests/ -v
代码质量工具
项目使用现代化的Python开发工具链:
- Black: 代码格式化
- isort: 导入排序
- MyPy: 类型检查
- Pytest: 测试框架
- Ruff: 快速代码检查
- Pre-commit: 提交前代码检查
构建和发布
# 构建项目
python -m build
# 验证构建结果
twine check dist/*
# 本地安装测试
pip install dist/decidra-1.0.0-py3-none-any.whl
📊 使用示例
API使用示例
from src.api.futu import FutuClient
# 创建客户端
client = FutuClient()
client.connect()
# 获取实时报价
quotes = client.quote.get_stock_quote(["HK.00700", "US.AAPL"])
# 获取K线数据
klines = client.quote.get_current_kline("HK.00700", "K_DAY", 30)
# 订阅实时数据
def callback(data):
print(f"价格更新: {data}")
client.quote.subscribe_quote(["HK.00700"], callback=callback)
client.disconnect()
监控界面编程
from src.monitor_app import MonitorApp
# 创建监控应用
app = MonitorApp()
app.monitored_stocks = ["HK.00700", "HK.09988", "US.AAPL"]
# 运行界面
app.run()
⚙️ 配置管理
环境变量配置
# 富途API配置
export FUTU_HOST=127.0.0.1
export FUTU_PORT=11111
export FUTU_TRD_ENV=SIMULATE
# 监控界面配置
export MONITOR_REFRESH_INTERVAL=10
export MONITOR_REFRESH_MODE=auto
# 启用测试模式
export FUTU_TEST_ENABLED=true
配置文件
支持多种配置文件格式:
src/.runtime/config/config.ini: 主配置文件src/stock_strategy_map.yml: 策略映射配置pyproject.toml: 项目构建配置
🤝 参与贡献
我们欢迎所有形式的贡献!
- Fork 项目
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启 Pull Request
🐛 问题排查
常见问题
1. 富途API连接失败
# 检查FutuOpenD是否运行
decidra futu test-connection
# 检查配置
decidra futu info
2. 监控界面启动失败
# 检查依赖是否完整
pip install textual
# 使用调试模式启动
DEBUG=true decidra monitor start
日志和调试
# 启用详细输出
decidra --verbose monitor start
# 查看错误日志
tail -f src/.runtime/logs/decidra.log
📄 许可证
本项目基于 MIT License 开源。
🙏 致谢
📞 联系方式
- 作者: rtx3
- 邮箱: r@rtx3.com
- GitHub: https://github.com/rtxIII/decidra
⭐ 如果这个项目对您有帮助,请给我们一个 Star!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file decidra-1.0.1.tar.gz.
File metadata
- Download URL: decidra-1.0.1.tar.gz
- Upload date:
- Size: 241.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56ca6ca9a044739d50ff0421d2d2e13367c841832a442e58eab1b8805241f237
|
|
| MD5 |
8bf606ccfa063982ac6635a2eb86fdcd
|
|
| BLAKE2b-256 |
d5207b72117cedfa108cbc7cfd4d5c5be4c78db55e169a4eecac24a49b62e631
|
File details
Details for the file decidra-1.0.1-py3-none-any.whl.
File metadata
- Download URL: decidra-1.0.1-py3-none-any.whl
- Upload date:
- Size: 264.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0dc7ece7e1e261f4333d81190dd79198c4b2dc251432e940876c12d8405c23cc
|
|
| MD5 |
5cb3287daae2e4491d78fc52ce845238
|
|
| BLAKE2b-256 |
79ba566feaf9c78d2cc5e4ddca2aaa5b5417398974eef7e515470f9bd5513b58
|