
Alpaca 交易 API 的模型上下文协议(MCP)服务器
概览
这是一个Alpaca模型上下文协议(MCP)服务器,允许像Claude这样的大型语言模型与Alpaca交易API交互。它支持股票交易、头寸检查、获取市场数据和管理账户——所有这些都通过自然语言实现。 - 📊 - 获取实时股票报价和历史价格数据 - 💵 - 检查你的余额、购买力和状态 - 📈 - 查看当前头寸及其表现 - 🛒 - 通过自然语言下单和限价单 - 📋 - 挂牌、跟踪和取消订单 - Python 3.10+ - Alpaca API 密钥 - Claude 桌面版或其他 MCP 客户端 3. 创建一个包含你的Alpaca API凭证的.env文件: 1. 打开桌面版 2.进入设置 3.点击“开发者”,然后选择“编辑配置” 4.将服务器配置添加到claude_desktop_config。
概述(AI 翻译)
这是一个Alpaca模型上下文协议(MCP)服务器,允许像Claude这样的大型语言模型与Alpaca交易API交互。它支持股票交易、头寸检查、获取市场数据和管理账户——所有这些都通过自然语言实现。
特色
- 📊 市场数据 - 获取实时股票报价和历史价格数据
- 💵 账户信息 - 检查您的余额、购买力和状态
- 📈 职位管理 - 查看当前职位及其绩效
- 🛒 下单 - 通过自然语言下市价和限价单
- 📋 订单管理 - 列出、跟踪和取消订单
先修条件
- Python 3.10+
- 羊驼 API 密钥
- Claude桌面版或其他MCP客户端
安装
-
克隆此仓库:
-
安装所需的软件包:
-
创建一个包含你的羊驼 API 凭证的
.env文件:
用途
运行服务器
启动服务器时运行:
配置Claude桌面版
-
打开桌面版Claude
-
进入设置
-
点击“开发者”,然后选择“编辑配置”
-
将服务器配置添加到
claude_desktop_config.json: -
保存并重启桌面版Claude
可用工具
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Alpaca MCP Server
This is a Model Context Protocol (MCP) server for Alpaca, allowing LLMs like Claude to interact with the Alpaca trading API. It enables trading stocks, checking positions, fetching market data, and managing your account - all through natural language.
Features
- 📊 Market Data - Get real-time stock quotes and historical price data
- 💵 Account Information - Check your balances, buying power, and status
- 📈 Position Management - View current positions and their performance
- 🛒 Order Placement - Place market and limit orders through natural language
- 📋 Order Management - List, track, and cancel orders
Prerequisites
- Python 3.10+
- Alpaca API keys
- Claude for Desktop or another MCP client
Installation
-
Clone this repository:
git clone https://github.com/YOUR_USERNAME/alpaca-mcp.git cd alpaca-mcp -
Install the required packages:
pip install mcp alpaca-py python-dotenv -
Create a
.envfile with your Alpaca API credentials:API_KEY_ID=your_alpaca_api_key API_SECRET_KEY=your_alpaca_secret_key
Usage
Running the server
Start the server by running:
python alpaca_mcp_server.py
Configuring Claude for Desktop
- Open Claude for Desktop
- Go to Settings
- Click on “Developer” and then “Edit Config”
- Add the server configuration to
claude_desktop_config.json:
{
"mcpServers": {
"alpaca": {
"command": "python",
"args": [
"/path/to/alpaca_mcp_server.py"
],
"env": {
"API_KEY_ID": "your_alpaca_api_key",
"API_SECRET_KEY": "your_alpaca_secret_key"
}
}
}
}
- Save and restart Claude for Desktop
Available Tools
The server exposes the following tools:
get_account_info()- Get account balances and statusget_positions()- List all current positions in the portfolioget_stock_quote(symbol)- Get the latest quote for a stockget_stock_bars(symbol, days)- Get historical price bars for a stockget_orders(status, limit)- List orders with specified statusplace_market_order(symbol, side, quantity)- Place a market orderplace_limit_order(symbol, side, quantity, limit_price)- Place a limit ordercancel_all_orders()- Cancel all open ordersclose_all_positions(cancel_orders)- Close all open positions
Example Queries
Once the server is connected to Claude, you can ask questions like:
- “What’s my current account balance and buying power?”
- “Show me my current positions”
- “Get the latest quote for AAPL”
- “Show me the price history for TSLA over the last 10 days”
- “Buy 5 shares of MSFT at market price”
- “Sell 10 shares of AMZN with a limit price of $130”
- “Cancel all my open orders”
Note
This server uses Alpaca’s paper trading by default. To use real money trading, change paper=True to paper=False in the TradingClient initialization.
Security Notice
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →配置
{
"mcpServers": {
"alpaca": {
"command": "python",
"args": [
"/path/to/alpaca_mcp_server.py"
],
"env": {
"API_KEY_ID": "your_alpaca_api_key",
"API_SECRET_KEY": "your_alpaca_secret_key"
}
}
}
}