Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
xtquantai: MCP server bridging AI with xtquant for quant trading, enabling AI access to trading data and functionalities.
xtquantai is a Model Context Protocol (MCP) server that integrates the xtquant quantitative trading platform with AI assistants, enabling AI to directly access and manipulate quantitative trading data and functions.
XTQuantAI provides the following core functions (continuously being updated, and everyone is welcome to submit new ideas):
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
) - 创建自定义的图表布局,可以指定指标名称、参数名和参数值⚠️ 注意
uv 是后续用来启动包的工具,因此我们需要在开始安装一下,注意你需要在你要运行 xtquantai 的环境里面安装这个包,这是第一个可能出问题的地方,不确定就都安装一下。
pip install uv
第二个注意点,uv 是有缓存的,因此我才会有 clear_cache_and_run.py
的文件,你一旦中间有错误的运行,不删缓存就会一直不更新,记得运行一下删除。
git clone https://github.com/dfkai/xtquantai.git
或者直接下载 压缩包。你可以下载到任意文件夹,只要最后能够找到 xtquantai 的具体地址即可,最好去文件夹里直接去复制地址。
在 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
需要安装 node 环境。
npx @modelcontextprotocol/inspector uv run xtquantai
准备发布包:
uv sync
uv build
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 文件。
欢迎贡献!请随时提交问题或拉取请求。