Futu MCP
About
A quantitative analysis platform for Futu Securities, offering intelligent caching, technical analysis, and pattern recognition.
Details
- Author
- superkonka
- Categories
- Developer Tools, Finance, Other
Jump to
Setup
Install Futu MCP in your MCP client (Claude Desktop, Cursor, Windsurf, and others).
Repository: https://github.com/superkonka/mcp_futu
Follow the installation instructions in the repository README, then restart your MCP client.
基于 FastAPI 和 Model Context Protocol (MCP) 的富途证券专业量化分析平台,集成智能缓存、技术分析、形态识别等功能,将简单的API代理升级为企业级金融数据服务。
- Python 3.10+ 已安装
- 富途OpenD已启动并登录
- 富途账号有相应行情权限
# 1. 克隆项目 git clone <your-repo-url> cd mcp_futu # 2. 创建并激活虚拟环境(推荐) python -m venv venv source venv/bin/activate # Linux/Mac # 或 venv\Scripts\activate # Windows # 3. 安装依赖 pip install -r requirements_enhanced.txt # 4. 启动服务(四种方式) # 🌟 智能统一入口(推荐)- 菜单式操作,提供建议和响应 python futu_assistant.py # 🚀 智能重启 - 自动停止旧服务并启动新服务 python restart.py # 🔥 手动启动增强版MCP服务 - 端口8001 python main_enhanced.py # 🎯 简化版HTTP服务(稳定)- 端口8002 python main_enhanced_simple_alternative.py # 5. (可选) 启动独立 MCP 包装服务 - 端口9001 # Web 服务和 MCP 工具彻底解耦,MCP 只负责转发到 Web API WEB_API_BASE_URL=http://localhost:8001 MCP_PORT=9001 python mcp_service/main.py
# 启动智能助手 python futu_assistant.py # 功能菜单: # 1️⃣ 启动服务 - 智能重启富途服务 # 2️⃣ 健康检查 - 检查服务状态和连接 # 3️⃣ 测试功能 - 完整功能测试 # 4️⃣ 股票报价 - 获取实时股票报价 # 5️⃣ 技术分析 - 计算技术指标 # 6️⃣ 缓存状态 - 查看缓存系统状态 # 7️⃣ API文档 - 打开API文档 # 8️⃣ 查看日志 - 检查服务运行日志 # 9️⃣ 故障诊断 - 智能故障诊断 # 0️⃣ 退出 - 退出助手 # 特点: # 🧠 智能建议和自动响应 # 🔧 故障自动诊断和解决方案 # 📊 实时状态监控 # 🎯 一键解决各种问题
如果遇到端口占用问题(Address already in use),使用智能重启脚本:
# 一键重启 - 自动检测并停止已有服务 python restart.py # 功能特点: # ✅ 自动检测端口占用 # ✅ 安全停止已有进程 # ✅ 重新启动增强版服务 # ✅ 验证启动成功 # ✅ 显示服务地址和文档链接
# 健康检查 curl http://localhost:8001/health # 预期输出: # {"status":"healthy","futu_connected":true,"cache_available":true}
- Web API(行情、Dashboard、/api/)仍然由main_enhanced.py提供,端口保持 8001。
- MCP 工具改由mcp_service/main.py独立运行:
WEB_API_BASE_URL=http://localhost:8001 MCP_PORT=9001 python mcp_service/main.py
- .env会读取EXTERNAL_MCP_ENDPOINT(默认http://localhost:9001/mcp)。若你修改 MCP 端口或部署方式,请同步更新该变量,以便 Web 服务在/mcp/status或重定向时提供正确地址。
- 访问http://localhost:8001/mcp时会收到 307 重定向到外部 MCP,方便老配置顺滑迁移;建议尽快在 MCP 客户端里把地址改成新的端口。
- 三层缓存架构: 内存 + Redis + SQLite 多级缓存
- 性能提升99%+: 缓存命中时响应速度提升99.86%
- 智能过期策略: 不同数据类型的差异化缓存管理
- 自动容错: Redis故障时自动降级到本地缓存
- 15+技术指标: MACD、RSI、布林带、KDJ、移动平均线等
- 智能信号识别: 自动识别金叉死叉、超买超卖等交易信号
- 纯Python实现: 支持TA-Lib和纯Python两种计算方式
- 缓存优化: 指标计算结果智能缓存,避免重复计算
- 数据传输减少99%+: K线和基本信息数据智能压缩
- 响应时间优化: 平均响应时间提升3-5倍
- 内存管理: 智能内存分配和垃圾回收
- 连接复用: 富途API连接池优化
- 健康监控: 完整的服务和缓存状态监控
- 错误恢复: 自动重试和优雅降级机制
- 扩展性: 模块化设计,便于功能扩展
- 向下兼容: 完全兼容原有API接口
# 单个股票查询 curl -X POST http://localhost:8001/api/quote/stock_quote \ -H "Content-Type: application/json" \ -d '{"code_list": ["HK.00700"]}' # 批量股票查询(推荐) curl -X POST http://localhost:8001/api/quote/stock_quote \ -H "Content-Type: application/json" \ -d '{ "code_list": ["HK.00700", "HK.09660", "HK.00005"], "optimization": {"only_essential_fields": true} }'
{ "ret_code": 0, "ret_msg": "获取股票报价成功", "data": { "quotes": [{ "code": "HK.00700", "last_price": 325.4, "change_val": 2.8, "change_rate": 0.87, "volume": 12345678, "turnover": 4.01e9 }] } }
# 获取日K线数据 curl -X POST http://localhost:8001/api/quote/history_kline \ -H "Content-Type: application/json" \ -d '{ "code": "HK.00700", "ktype": "K_DAY", "start": "2024-01-01", "end": "2024-12-31", "max_count": 100 }' # 获取分钟级K线数据 curl -X POST http://localhost:8001/api/quote/history_kline \ -H "Content-Type: application/json" \ -d '{ "code": "HK.00700", "ktype": "K_30M", "max_count": 48 }'
- K_1M,K_3M,K_5M,K_15M,K_30M,K_60M(分钟线)
- K_DAY(日线),K_WEEK(周线),K_MON(月线)
# 计算单个指标 curl -X POST http://localhost:8001/api/analysis/technical_indicators \ -H "Content-Type: application/json" \ -d '{ "code": "HK.00700", "indicators": ["rsi"], "ktype": "K_DAY", "period": 30 }' # 计算多个指标 curl -X POST http://localhost:8001/api/analysis/technical_indicators \ -H "Content-Type: application/json" \ -d '{ "code": "HK.00700", "indicators": ["macd", "rsi", "bollinger_bands"], "ktype": "K_DAY" }' # 计算所有指标(完整分析) curl -X POST http://localhost:8001/api/analysis/technical_indicators \ -H "Content-Type: application/json" \ -d '{ "code": "HK.00700", "indicators": ["all"], "ktype": "K_DAY" }'
- 趋势指标:macd,moving_averages,ema
- 动量指标:rsi,kdj
- 波动性指标:bollinger_bands,atr
- 成交量指标:obv,vwap
- 强度指标:adx
curl -X POST http://localhost:8001/api/analysis/snapshot \ -H "Content-Type: application/json" \ -d '{ "code": "HK.00700", "include_history": true, "include_technicals": true, "technical_period": 120 }' | jq '.'
- 一次请求即可拿到行情、技术面、资金面、最新策略、基本面信号、持仓概览
- insights字段自动给出多维统计(如利好/利空数量、策略条数、最新价格)
- 可通过参数裁剪历史K线、资金流、技术指标等模块
- MCP 工具get_analysis_snapshot直接复用该接口,免去多接口串联
# 查看缓存状态 curl http://localhost:8001/api/cache/status # 预加载热门股票数据 curl -X POST http://localhost:8001/api/cache/preload \ -H "Content-Type: application/json" \ -d '{ "symbols": ["HK.00700", "HK.09660", "HK.00005"], "days": 30, "ktypes": ["K_DAY", "K_30M"] }' # 清理缓存 curl -X DELETE http://localhost:8001/api/cache/clear \ -H "Content-Type: application/json" \ -d '{"cache_type": "memory"}'
# 保存一条策略建议 curl -X POST http://localhost:8001/api/recommendations \ -H "Content-Type: application/json" \ -d '{ "code": "HK.00700", "action": "BUY", "rationale": "突破年线并放量,RSI回升至50上方", "confidence": 0.72, "timeframe": "swing", "tags": ["技术面", "突破"], "source": "kimi-k2-thinking-turbo", "evidence": [ {"type": "indicator", "name": "MACD", "value": "金叉"}, {"type": "news", "title": "Q3 财报高于预期"} ] }' # 查询策略建议(可按代码、标签、采纳状态等过滤) curl -X POST http://localhost:8001/api/recommendations/query \ -H "Content-Type: application/json" \ -d '{ "code": "HK.00700", "tag": "技术面", "limit": 20 }'
接口会自动在data/recommendations.db中持久化记录,既能通过 HTTP 使用,也会在 MCP 客户端中以save_recommendation/get_recommendations工具呈现,方便大模型写入与查询策略建议。
当你希望把某只股票的行情、资讯、策略和个人持仓集中展示给同事或终端用户,可以通过新的create_dashboard_session接口为任意标的生成一个可共享的 Web 看板:
# 1) 生成会话,得到 Web URL curl -X POST http://localhost:8001/api/dashboard/session \ -H "Content-Type: application/json" \ -d '{"code": "HK.00700"}' # 响应示例: # { # "session_id": "1Np4dJ6xG6M", # "url": "http://localhost:8001/web/dashboard?session=1Np4dJ6xG6M" # } # 2) 把 url 发给浏览器或 MCP 客户端,页面会自动: # • 订阅 Futu 报价/盘口/逐笔/分时等推送,并实时刷新图表 # • 拉取 Metaso 搜索结果,按“利好/利空”分区展示 # • 展示资金流向 / 资金分布 / 历史K线等关键指标 # • 读取最近的策略建议和(若可用)个人持仓摘要 # • 会话 ID 会落盘到 data/dashboard_sessions.json,重启服务后仍可复用链接 # ⚙️ 如需让 MCP 返回公网地址,可设置 DASHBOARD_BASE_URL 环境变量: # export DASHBOARD_BASE_URL="https://your-domain.com" # 这样 create_dashboard_session 工具会直接返回公网可访问的 URL。 看板页面顶部会展示所有已订阅的股票,并实时显示 Futu 订阅额度使用情况,可一键取消订阅,便于控制配额。 > 另外,服务启动后控制台会输出 http://localhost:8001/web,打开即可查看所有看板的列表总览,并快速进入详情页。
MCP 侧同样会暴露create_dashboard_session工具,LLM 只需给出股票代码即可获得实时大屏的链接,实现“问即得 URL”的工作流。
# 确认Python版本 python --version # 需要 3.10+ # 创建虚拟环境(推荐) python -m venv venv source venv/bin/activate # Linux/Mac # 或 venv\Scripts\activate # Windows # 安装依赖 pip install -r requirements_enhanced.txt
# 1. 下载富途OpenD客户端 # https://www.futunn.com/download/openAPI # 2. 启动OpenD # - 登录富途账号 # - 确保有相应市场的行情权限 # - 默认端口: 11111 # 3. 验证连接 telnet 127.0.0.1 11111
# macOS安装 brew install redis brew services start redis # Ubuntu安装 sudo apt-get install redis-server sudo systemctl start redis # 验证Redis redis-cli ping # 应返回 PONG
# macOS安装 brew install ta-lib pip install TA-Lib # Ubuntu安装 sudo apt-get install libta-lib-dev pip install TA-Lib # 注意: 如果安装失败,系统会自动使用纯Python实现
# 🌟 启动智能助手 - 一站式解决所有需求 python futu_assistant.py # 智能助手提供: # 🎯 菜单式操作界面 # 🧠 智能建议和自动响应 # 🔧 故障自动诊断 # 📊 实时状态监控 # 🚀 一键重启和修复 # 💡 使用指导和帮助
- ✅零编程基础: 菜单式操作,简单易用
- ✅智能诊断: 自动检测问题并提供解决方案
- ✅一键修复: 自动处理端口占用、服务重启等问题
- ✅实时监控: 显示服务状态、缓存情况、连接状态
- ✅交互友好: 提供建议响应,引导用户操作
import httpx import asyncio class FutuAnalysisAPI: def __init__(self, base_url="http://localhost:8001"): self.base_url = base_url self.client = httpx.AsyncClient() async def get_stock_quote(self, codes: list): """获取股票报价""" response = await self.client.post( f"{self.base_url}/api/quote/stock_quote", json={"code_list": codes} ) return response.json() async def get_technical_analysis(self, code: str, indicators: list = ["all"]): """获取技术分析""" response = await self.client.post( f"{self.base_url}/api/analysis/technical_indicators", json={ "code": code, "indicators": indicators, "ktype": "K_DAY" } ) return response.json() # 使用示例 api = FutuAnalysisAPI() quote = await api.get_stock_quote(["HK.00700"]) analysis = await api.get_technical_analysis("HK.00700")
{ "mcpServers": { "futu-enhanced": { "url": "http://127.0.0.1:8001/mcp", "name": "富途量化分析平台" } } }
# 1. 检查OpenD是否运行 netstat -an | grep 11111 # 2. 检查账号登录状态 # 确保OpenD客户端已登录并有行情权限 # 3. 重启服务 python main_enhanced.py
# Redis可选,不影响核心功能 # 如需启用Redis: brew install redis && brew services start redis # macOS # 或 sudo apt-get install redis-server && sudo systemctl start redis # Ubuntu
# 清理缓存,重新获取数据 curl -X DELETE http://localhost:8001/api/cache/clear \ -H "Content-Type: application/json" \ -d '{"cache_type": "sqlite"}' # 预加载数据 curl -X POST http://localhost:8001/api/cache/preload \ -H "Content-Type: application/json" \ -d '{"symbols": ["HK.00700"], "days": 60}'
ERROR: Received request before initialization was complete
# 使用稳定的HTTP API替代MCP curl -X POST http://localhost:8001/api/quote/stock_quote \ -H "Content-Type: application/json" \ -d '{"code_list": ["HK.00700"]}'
# 1. 服务状态检查 curl http://localhost:8001/health # 2. 缓存状态检查 curl http://localhost:8001/api/cache/status # 3. 测试核心功能 curl -X POST http://localhost:8001/api/quote/stock_quote \ -H "Content-Type: application/json" \ -d '{"code_list": ["HK.00700"]}' # 4. 性能测试 time curl -X POST http://localhost:8001/api/analysis/technical_indicators \ -H "Content-Type: application/json" \ -d '{"code": "HK.00700", "indicators": ["rsi"]}'
FROM python:3.10-slim WORKDIR /app COPY requirements_enhanced.txt . RUN pip install -r requirements_enhanced.txt COPY . . EXPOSE 8001 CMD ["uvicorn", "main_enhanced:app", "--host", "0.0.0.0", "--port", "8001"]
# 构建并运行 docker build -t futu-mcp-enhanced . docker run -d -p 8001:8001 \ -v $(pwd)/data:/app/data \ --name futu-mcp \ futu-mcp-enhanced
# /etc/systemd/system/futu-mcp.service [Unit] Description=富途MCP增强服务 After=network.target [Service] Type=simple User=ubuntu WorkingDirectory=/opt/mcp_futu Environment=PATH=/opt/mcp_futu/venv/bin ExecStart=/opt/mcp_futu/venv/bin/python main_enhanced.py Restart=always RestartSec=3 [Install] WantedBy=multi-user.target
# 启用服务 sudo systemctl enable futu-mcp sudo systemctl start futu-mcp sudo systemctl status futu-mcp
- 🔥生产环境:main_enhanced_simple_alternative.py(端口8002)
- 🤖AI集成:main_enhanced.py(端口8001) + HTTP API备选
- ⚡轻量场景:main_simple.py(端口8000)
- 📖API文档:http://localhost:8001/docs
- 🔍健康检查:http://localhost:8001/health
- 📊缓存状态:http://localhost:8001/api/cache/status
- GitHub Issues:报告问题
- 讨论**:GitHub Discussions
# 1. 系统信息 python --version pip list | grep -E "(fastapi|futu|redis|pandas)" # 2. 服务状态 curl http://localhost:8001/health # 3. 错误日志 tail -n 50 logs/futu_mcp.log # 如果有日志文件
This is a web browser that enables your coding agent, such as Claude Code, to visit websites on your behalf and assist you in identifying bugs or creating UI test cases.
Managed MCP server for Bybit perpetual futures trading. Isolated sub-accounts, built-in risk management, 12 trading tools.
Deterministic macro regime engine for AI trading agents — RISK_ON / NEUTRAL / RISK_OFF / STRESS with transparent scoring rules.
A high-performance MCP server for comprehensive options order flow analysis.
Complete MCP server for MT5: Through the MCP protocol, it allows [Trades, Orders, History, Graphic Objects, Terminal Logs, Compilation, etc.]
Access real-time and historical token, wallet, and trading data from the Solana ecosystem via the Solana Tracker API.
Access financial data like stock prices, currency info, and insider trading data using the Synth Finance API.
A modular trading automation project using the Zerodha Kite Connect API for tool-based and resource-based automation.
Integrates the xtquant quantitative trading platform with an AI assistant, enabling AI to access and operate quantitative trading data and functions.
Provides stock market data and trading capabilities using the yfinance library.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.





