Skip to main content

全市场金融数据 MCP Server — A股/港股/美股/期货 行情/K线/技术指标/选股/回测 基于 easy-tdx + AKShare + yfinance 三数据源

Project description

mcp-finance

面向 AI 助手的全市场金融数据 MCP Server
A股/港股/美股/期货 — 实时行情、K线、技术指标、条件选股、策略回测、盯盘告警、交互式图表

English · GitHub · Changelog

Python 3.10+ MCP 1.4+ Version 0.7.0 MIT License Dual Data Source CI Status


能力矩阵

类别 工具 覆盖市场
实时行情 get_realtime_quote A股/港股/美股/期货
K线数据 get_kline A股/港股/美股/期货(日/周/月,前/后复权)
财务数据 get_financials A股(营收/净利润/ROE/毛利率等)
大盘指数 get_market_indices A股/港股/美股
板块排行 get_sector_ranking A股行业/概念
资金流向 get_north_flow 北向/南向资金
股票搜索 search_stock A股/港股/美股(纯本地,毫秒级)
批量查询 batch_quotes A股/港股/美股
期货列表 get_futures_list 国内期货主力合约
技术指标 get_technical_indicators MA/MACD/KDJ/RSI/BOLL/WR/BIAS + 信号识别
条件选股 stock_screener 全市场 11 维度筛选(涨跌幅/量比/换手率/PE/PB/市值等)
策略回测 backtest_strategy Backtrader 引擎,5 种策略 + 买入持有基准
参数优化 optimize_strategy 网格扫描(组合数上限 200)
盯盘告警 set_alert 一次性条件检查,支持钉钉/企业微信/Server酱
K线图表 plot_kline Plotly 交互式 HTML(蜡烛图+均线+MACD/KDJ/RSI)
龙虎榜 get_dragon_tiger 每日明细
大宗交易 get_block_trades 逐笔明细
融资融券 get_margin_trading 沪深两市
ML回测 pybroker_backtest 实验性均值比较信号回测
数据诊断 test_data_sources 全数据源可用性测试

快速开始

# 安装
pip install mcp-finance  # or: pip install -e ".[dev]"

核心依赖mcp / pydantic / easy-tdx / akshare / plotly / numpy / pandas / backtrader

配置 Claude Desktop

{
  "mcpServers": {
    "mcp-finance": {
      "command": "python",
      "args": ["-m", "mcp_finance.server"]
    }
  }
}

配置 Codex

codex mcp add mcp-finance -- python -m mcp_finance.server

配置 Cursor / VS Code

{
  "mcpServers": {
    "mcp-finance": {
      "type": "stdio",
      "command": "python",
      "args": ["-m", "mcp_finance.server"]
    }
  }
}

数据源

说明 覆盖范围
easy-tdx 通达信 TCP 协议,毫秒级,无需 API Key A 股实时行情+K线
AKShare (新浪) 开源金融数据接口 港股/美股行情+K线
AKShare (同花顺) 开源金融数据接口 财务数据/板块排行

easy-tdx 直连通达信行情服务器(端口 7709),毫秒级响应,无速率限制。 所有网络调用均有 15 秒超时保护 + asyncio 层 90 秒兜底,防止线程池耗尽。


使用示例

场景 跟 AI 说
A股行情 "查一下茅台(600519)的最新价和涨跌幅"
港股行情 "腾讯(00700)港股现在多少钱?"
美股行情 "AAPL 苹果股价多少?英伟达 NVDA 什么价?"
期货行情 "看看螺纹钢期货行情"
技术分析 "帮我分析比亚迪的技术指标,有没有金叉?RSI 超卖没有?"
选股 "涨超 3%、量比 > 1.5、换手率 > 5%、ROE > 10%"
回测 "双均线(5,20)回测美的集团 2024 年,和买入持有对比"
参数优化 "帮我找找美的集团双均线的最佳参数"
画图 "画一张茅台最近 120 天的 K 线图,带上 MACD 和 RSI"

项目结构

mcp-finance/
  pyproject.toml          # 依赖与元数据
  README.md               # 中文文档
  README.en.md            # English docs
  CHANGELOG.md            # 版本变更记录
  .github/workflows/      # CI 配置
  run_monitor.py          # 独立盯盘进程
  mcp_finance/
    __init__.py            # 版本号
    api.py                 # easy-tdx + AKShare 双数据源
    data.py                # 股票映射 & 行业分类
    indicators.py          # 9 大技术指标 + 信号识别
    screener.py            # 条件筛选(11 维度)
    backtest.py            # Backtrader 回测引擎
    pybroker_strategy.py   # 实验性 ML 策略
    monitor.py             # 告警监控
    chart.py               # Plotly 交互式图表
    server.py              # MCP Server 路由
    cache.py               # TTL 缓存
    validators.py          # Pydantic 参数校验
    errors.py              # 统一错误类型
    logging_config.py      # 结构化日志
  tests/
    test_indicators.py     # 指标测试
    test_screener.py       # 选股器测试

开发

# 安装 dev 依赖
pip install -e ".[dev]"

# 运行测试
pytest tests/ -v

# lint
ruff check mcp_finance/

CI 状态:CI


License

MIT

Read this in English · Changelog

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_markets-0.8.0.tar.gz (68.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_markets-0.8.0-py3-none-any.whl (69.0 kB view details)

Uploaded Python 3

File details

Details for the file mcp_markets-0.8.0.tar.gz.

File metadata

  • Download URL: mcp_markets-0.8.0.tar.gz
  • Upload date:
  • Size: 68.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for mcp_markets-0.8.0.tar.gz
Algorithm Hash digest
SHA256 1bd20170c3f99d421ae160428099cfb8346f5d902839667eae4ba86f7365be81
MD5 cebb2051c6e86117770661a96bb079d2
BLAKE2b-256 d6d8cd32b6160e309f27300e8c2144638710bd5663401543af0007f76c300ded

See more details on using hashes here.

File details

Details for the file mcp_markets-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_markets-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 69.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for mcp_markets-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49fa8ca5e714f9464b20ee8ff7c0a2e977ddab84cab5810ad613e7c2a5a6aa37
MD5 68212f721b2ff3e2e5dec9c61f8cd2de
BLAKE2b-256 435c4fc1c4bc465bcdd3cf3283d04aa7aa4465e66c0a21dd12cdafd5fdc18c24

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page