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
初始化配置
安装后需要运行初始化命令创建配置文件:
# 运行初始化(创建配置目录和模板文件)
decidra-init
# 编辑配置文件(根据提示进行配置)
nano ~/.decidra/config.ini
验证安装
# 验证CLI工具
decidra --help
# 验证配置
decidra config validate
🚀 快速开始
1. 初次使用必须先初始化
# 运行初始化命令
decidra-init
# 按照提示编辑配置文件
nano ~/.decidra/config.ini
2. 启动监控界面
# 启动股票监控界面
decidra monitor start
3. 配置富途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!
Metadata
Release files for decidra 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| decidra-1.1.0.tar.gz | 435.7 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| decidra-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 928.2 kB
Release files / decidra-1.1.0.tar.gz
| Download URL | decidra-1.1.0.tar.gz |
|---|---|
| Size | 435.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19e4a5a488af85080c814904a4f00c969de3c46e64ddcfad53f6629f22882d87
|
|
BLAKE2b-256 checksum How to use checksums |
c50f912ebf4c523d0ca41f8d828e49a8abf8cd274993ce4f3dac4417b8e1b12b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.
Transparency logRelease files / decidra-1.1.0-py3-none-any.whl
| Download URL | decidra-1.1.0-py3-none-any.whl |
|---|---|
| Size | 492.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a67c3e5de74f9c24302e7a8f37ea43a21b8de7ab3ae677b6f59ff46b52d6582d
|
|
BLAKE2b-256 checksum How to use checksums |
4a7e52831daaa710afb69dc8eb5dc536a82445fc24739c0d9fb5cedd16a99edc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.
Transparency logSecurity for decidra 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for decidra-1.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.