Supports environment variable configuration via .env file for storing QMT client settings, trading parameters, and risk control values
Provides project hosting, issue tracking, and documentation through GitHub repositories and wiki
Supports testing the MCP server implementation and its components
Built on Python 3.8+ and provides Python-based trading strategy generation and execution
Integrates with Shields.io for displaying version, Python requirements, and license badges
国金QMT-MCP - 模块化量化交易助手
一个基于FastMCP和XTQuant的模块化量化交易系统,提供智能策略生成、实时交易执行和回测分析功能。
🌟 项目特色
- 🔗 MCP协议集成: 基于Model Context Protocol,与AI助手无缝连接
- 📈 智能策略生成: 自动生成和优化量化交易策略
- ⚡ 实时交易执行: 支持XTQuant/QMT实盘和模拟交易
- 🧠 模块化架构: 清晰的代码结构,易于扩展和维护
- 📊 回测分析: 完整的策略回测和绩效评估
- 🛡️ 风险控制: 内置多层风险控制机制
🎬 演示视频
📺 点击封面图或链接即可在 Bilibili 观看完整演示
https://www.bilibili.com/video/BV1SFGjz6EKN/?vd_source=26053b834f0ddd4f57b22169d74b6f78
🏗️ 系统架构
🚀 快速开始
环境要求
- Python 3.8+
- XTQuant/QMT客户端 (国金/迅投量化交易客户端)
- Windows系统 (XTQuant仅支持Windows)
安装步骤
- 克隆项目
- 安装依赖
- 配置环境
创建 .env
文件并配置以下参数:
- 启动XTQuant客户端
- 打开国金QMT或迅投量化客户端
- 确保客户端已登录并连接
- 启动国金QMT-MCP服务
服务启动后将在 http://127.0.0.1:8000
提供MCP服务。
🔧 功能介绍
交易工具
下单功能
撤单功能
策略生成
双均线策略
自定义策略
📊 策略回测
系统提供完整的策略回测功能,包括:
- 收益指标: 总收益率、年化收益率、夏普比率
- 风险指标: 最大回撤、波动率、VaR
- 交易统计: 交易次数、胜率、平均盈亏
- 绩效评估: 策略评级和优化建议
回测报告示例
🛡️ 风险控制
系统内置多层风险控制机制:
交易层面
- 单笔订单最大金额限制
- 单标的最大持仓限制
- 最小下单数量控制
- 市价单价差保护
策略层面
- 最大回撤限制
- 最小夏普比率要求
- 杠杆率控制
- 止损比例设置
系统层面
- 交易状态控制
- 连接状态监控
- 异常处理机制
- 日志记录追踪
🔌 MCP集成
国金QMT-MCP完全兼容Model Context Protocol,可以与支持MCP的AI助手集成:
首选:SSE 直连配置(推荐)
如果你只需要直接连接到已经启动的国金QMT-MCP服务器,最简洁可靠的方式就是使用 SSE(Server-Sent Events) 直连。
📌 为何推荐 SSE?
- 🛠️ 零依赖:客户端无需再执行 Python/Node 等命令。
- ⚡ 即开即用:服务器启动后即可被任何支持MCP的应用发现。
- 🪶 配置最少:仅需
type
与url
两个关键字段。- 🌐 远程友好:修改
url
即可在局域网/云服务器访问。
下面展示不同工具 (Claude Desktop / VS Code Cline / Cursor) 的完整配置示例,如果需要自动拉起服务器也可使用 command/args
模式。
Claude Desktop集成
在Claude Desktop的配置文件中添加:
可用工具
place_order
: 执行股票交易cancel_order
: 撤销订单save_qmt_strategy
: 保存自定义策略generate_ma_strategy
: 生成双均线策略
📋 配置说明
核心配置项
配置项 | 说明 | 默认值 |
---|---|---|
QMT_PATH | QMT客户端安装路径 | 你的QMT安装路径\userdata_mini |
QMT_SESSION_ID | QMT会话ID | 你的会话ID |
QMT_ACCOUNT_ID | 交易账户ID | 你的交易账户ID |
MAX_ORDER_VALUE | 单笔订单最大金额 | 100000.0 |
MAX_POSITION_VALUE | 单标的最大持仓 | 500000.0 |
策略配置项
配置项 | 说明 | 默认值 |
---|---|---|
DEFAULT_SYMBOL | 默认股票代码 | 000001.SZ |
DEFAULT_SHORT_PERIOD | 默认短期均线 | 5 |
DEFAULT_LONG_PERIOD | 默认长期均线 | 20 |
🧪 开发指南
添加新策略
- 在
src/strategies/
目录下创建策略模块 - 实现策略类,包含信号计算和回测方法
- 在
strategy_generator.py
中注册新策略 - 更新配置文件添加策略参数
添加新工具
- 在
src/tools/
目录下创建工具模块 - 实现工具类和相关方法
- 在
main.py
中使用@mcp.tool()
装饰器注册 - 更新
__init__.py
文件导出新工具
测试
📚 API文档
place_order(symbol, quantity, price, direction)
执行股票交易订单
参数:
symbol
(str): 股票代码,如 "000001.SZ"quantity
(int): 交易数量,必须是100的整数倍price
(float): 下单价格direction
(str): 交易方向,"BUY" 或 "SELL"
返回:
str
: 下单结果信息
generate_ma_strategy(symbol, short_period, long_period, strategy_name)
生成双均线策略
参数:
symbol
(str): 目标股票代码short_period
(int): 短期均线周期long_period
(int): 长期均线周期strategy_name
(str, optional): 策略名称
返回:
str
: 策略生成和回测结果
🔍 常见问题
Q: XTQuant连接失败怎么办?
A: 确保QMT客户端已启动并登录,检查 QMT_PATH
配置是否正确。
Q: 如何修改风险控制参数?
A: 在 .env
文件中修改 MAX_ORDER_VALUE
、MAX_POSITION_VALUE
等参数。
Q: 策略回测数据不准确?
A: 检查数据日期范围,确保XTQuant有相应的历史数据权限。
Q: 如何添加新的技术指标?
A: 在 src/strategies/
目录下创建新的策略模块,参考 ma_strategy.py
的实现。
📄 许可证
本项目采用 MIT 许可证 - 详见 LICENSE 文件
🤝 贡献
欢迎提交Issue和Pull Request来改进项目!
📞 联系方式
- 项目地址: https://github.com/guangxiangdebizi/QMT-MCP
- 问题反馈: https://github.com/guangxiangdebizi/QMT-MCP/issues
- 文档: https://github.com/guangxiangdebizi/QMT-MCP/wiki
- 邮箱: guangxiangdebizi@gmail.com
- LinkedIn: https://www.linkedin.com/in/æå®-é-b5b3b0313/
🌟 如果这个项目对你有帮助,请给个Star支持一下! 🌟
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
A modular quantitative trading assistant that integrates with XTQuant/QMT trading platform, enabling AI-assisted trading strategy generation, real-time trade execution, and performance backtesting.
Related MCP Servers
- AsecurityFlicenseAqualityA server that provides advanced mathematical and financial calculation capabilities for AI code assistants, enabling them to perform complex calculations like symbolic calculus, numerical methods, and financial analysis without implementing algorithms directly.Last updated -181JavaScript
- AsecurityFlicenseAqualityA Model Context Protocol server that enables AI assistants to interact with the Deriv trading API, providing access to active trading symbols and account balance information.Last updated -2Python
- AsecurityAlicenseAqualityAn MCP server that integrates the XTQuant quantitative trading platform with AI assistants, allowing AI to directly access and operate on trading data and functionality.Last updated -830PythonMIT License
- -securityFlicense-qualityA server application that enables large language models to execute stock trading operations through QMT trading system, providing functionality for account queries, position management, and order placement.Last updated -Python