Skip to main content

xtquantai

xtquantai 是一个基于 Model Context Protocol (MCP) 的服务器,它将迅投 (xtquant) 量化交易平台的功能与人工智能助手集成,使 AI 能够直接访问和操作量化交易数据和功能。

Python Version License

功能特点

XTQuantAI 提供以下核心功能(陆续更新中,欢迎大家提交新创意):

基础数据查询

  • 获取交易日期 (get_trading_dates) - 获取指定市场的交易日期
  • 获取板块股票列表 (get_stock_list) - 获取特定板块的股票列表
  • 获取股票详情 (get_instrument_detail) - 获取股票的详细信息

行情数据

  • 获取历史行情数据 (get_history_market_data) - 获取股票的历史行情数据
  • 获取最新行情数据 (get_latest_market_data) - 获取股票的最新行情数据
  • 获取完整行情数据 (get_full_market_data) - 获取股票的完整行情数据

图表和可视化

  • 创建图表面板 (create_chart_panel) - 创建股票图表面板,支持各种技术指标
  • 创建自定义布局 (create_custom_layout) - 创建自定义的图表布局,可以指定指标名称、参数名和参数值

安装

⚠️ 注意

  1. QMT 生态系统目前仅支持 Windows,因此以下均在 Windows 环境实现
  2. Windows 环境目前在实现 MCP 过程中有不少细节,需要注意

前提条件

  • Python 3.11 或更高版本
  • 迅投 QMT 或投研终端
  • uv 包管理工具 (推荐)

uv 的安装及注意事项

uv 是后续用来启动包的工具,因此我们需要在开始安装一下,注意你需要在你要运行 xtquantai 的环境里面安装这个包,这是第一个可能出问题的地方,不确定就都安装一下。

pip install uv

第二个注意点,uv 是有缓存的,因此我才会有 clear_cache_and_run.py 的文件,你一旦中间有错误的运行,不删缓存就会一直不更新,记得运行一下删除。

下载即可

git clone https://github.com/dfkai/xtquantai.git

或者直接下载 压缩包。你可以下载到任意文件夹,只要最后能够找到 xtquantai 的具体地址即可,最好去文件夹里直接去复制地址。

使用方法

与 Cursor 的集成

Windows(QMT/投研端目前仅支持 Windows,需在 Windows 环境)

在 Cursor 中配置 MCP 服务器:

方法一:

在当前项目建立 .cursor 文件夹,在该文件夹下建立 mcp.json 文件,则 Cursor 编辑器会自动添加该 mcp 工具

{
  "mcpServers": {
    "xtquantai": {
      "command": "cmd /c uvx",
      "args": [
        "path:\\to\\xtquantai"
      ]
    }
  }
}

⚠️ 注意:在 windows 中,命令务必加上 cmd /c,否则会导致命令窗口执行完立即关闭。

方法二:

直接在 设置-MCP-添加新的 MCP Server,名字叫 xtquantai,命令(command)是:cmd /c uvx path:\to\xtquantai,调整为Enabled。

这里注意 path to 意思是你自己本地的地址,同时注意你手动填写进去是单斜杠,仅仅在json文件中需要两个斜杠防止转义。

工具使用示例

获取交易日期

# 获取上海市场的交易日期
dates = get_trading_dates(market="SH")

获取股票列表

# 获取沪深A股板块的股票列表
stocks = get_stock_list(sector="沪深A股")

创建图表面板

# 创建包含MA指标的图表面板
result = create_chart_panel(
    codes="000001.SZ,600519.SH",
    period="1d",
    indicator_name="MA",
    param_names="period",
    param_values="5"
)

开发

直接启动服务器

# 使用 Python 直接运行
python -m xtquantai

# 或使用安装的命令行工具
xtquantai

使用 MCP Inspector 进行调试(仅在开发的的时候使用)

需要安装 node 环境。

npx @modelcontextprotocol/inspector uv run xtquantai

构建和发布

准备发布包:

  1. 同步依赖并更新锁文件:
uv sync
  1. 构建包分发:
uv build
  1. 发布到 PyPI:
uv publish

调试

由于 MCP 服务器通过标准输入/输出运行,调试可能具有挑战性。我们强烈建议使用 MCP Inspector 进行调试。

项目结构

xtquantai/
├── src/
│   └── xtquantai/
│       ├── __init__.py    # 包初始化文件
│       └── server.py      # MCP 服务器实现
├── main.py                # 启动脚本
├── server_direct.py       # 直接 HTTP 服务器实现
├── pyproject.toml         # 项目配置
└── README.md              # 项目文档

许可证

本项目采用 MIT 许可证 - 详见 LICENSE 文件。

贡献

欢迎贡献!请随时提交问题或拉取请求。

致谢

Metadata

Release files for xtquantai 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xtquantai 0.1.0
File Size Uploaded Provenance Actions
xtquantai-0.1.0.tar.gz 17.4 kB Without provenance Details for xtquantai-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xtquantai 0.1.0
File Interpreter ABI Platform Actions
xtquantai-0.1.0-py3-none-any.whl Python 3 none any Details for xtquantai-0.1.0-py3-none-any.whl

Total release size: 31.2 kB

Release files / xtquantai-0.1.0.tar.gz

Download URL xtquantai-0.1.0.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4c4f5cdd76062bdd965a31d86bc4739f9ca8756c737e17480a52b705187b5f35
BLAKE2b-256 checksum
How to use checksums
f080c538b32cff1ac16d278d0bdff3387f8d5d2d6c4350e27816b7adf19a802d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Release files / xtquantai-0.1.0-py3-none-any.whl

Download URL xtquantai-0.1.0-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0100f7e428887d96237d8d078fef86a535e2fce9ddad4e3b3fb4970f1b2da636
BLAKE2b-256 checksum
How to use checksums
f6e0aea31bc352eebfe9583a8127bc72b8380f1cb5167947a594c0cb253e023a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Security for xtquantai 0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page