Alpaca MCP Server

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Enables secure storage and loading of Alpaca API credentials through environment variables stored in a .env file.

  • Required for cloning the repository during the installation process.

  • The repository hosting the MCP server code that users need to clone for installation.

羊驼 MCP 服务器

这是 Alpaca 的模型上下文协议 (MCP) 服务器,允许像 Claude 这样的法学硕士 (LLM) 与 Alpaca 交易 API 进行交互。它支持通过自然语言进行股票交易、查看持仓、获取市场数据和管理账户。

特征

  • 📊市场数据- 获取实时股票报价和历史价格数据
  • 💵账户信息- 检查您的余额、购买力和状态
  • 📈职位管理- 查看当前职位及其表现
  • 🛒订单下达- 通过自然语言下达市价单和限价单
  • 📋订单管理——列出、跟踪和取消订单

先决条件

  • Python 3.10+
  • 羊驼 API 密钥
  • Claude 桌面版或其他 MCP 客户端

安装

  1. 克隆此存储库:
    git clone https://github.com/YOUR_USERNAME/alpaca-mcp.git cd alpaca-mcp
  2. 安装所需的软件包:
    pip install mcp alpaca-py python-dotenv
  3. 使用您的 Alpaca API 凭证创建一个.env文件:
    API_KEY_ID=your_alpaca_api_key API_SECRET_KEY=your_alpaca_secret_key

用法

运行服务器

通过运行以下命令启动服务器:

python alpaca_mcp_server.py

为桌面配置 Claude

  1. 打开 Claude 桌面版
  2. 前往“设置”
  3. 点击“开发者”,然后点击“编辑配置”
  4. 将服务器配置添加到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" } } } }
  1. 保存并重新启动 Claude for Desktop

可用工具

该服务器公开以下工具:

  • get_account_info() - 获取账户余额和状态
  • get_positions() - 列出投资组合中的所有当前头寸
  • get_stock_quote(symbol) - 获取股票的最新报价
  • get_stock_bars(symbol, days) - 获取股票的历史价格条
  • get_orders(status, limit) - 列出指定状态的订单
  • place_market_order(symbol, side, quantity) - 下达市价订单
  • place_limit_order(symbol, side, quantity, limit_price) - 下限价单
  • cancel_all_orders() - 取消所有未结订单
  • close_all_positions(cancel_orders) - 关闭所有未平仓头寸

示例查询

一旦服务器连接到 Claude,您就可以询问以下问题:

  • “我目前的账户余额和购买力是多少?”
  • “显示我当前的位置”
  • “获取 AAPL 的最新报价”
  • “显示过去 10 天 TSLA 的价格历史记录”
  • “以市场价格购买 5 股 MSFT 股票”
  • “以 130 美元的限价卖出 10 股 AMZN”
  • “取消我所有未完成的订单”

笔记

此服务器默认使用 Alpaca 的模拟交易。如需使用真实货币交易,请在TradingClient初始化过程中将paper=True更改为paper=False

安全声明

此 MCP 服务器将访问您的 Alpaca 账户并进行真实交易。在批准任何交易之前,请务必查看 Claude 的建议。

执照

麻省理工学院

-
security - not tested
A
license - permissive license
-
quality - not tested

模型上下文协议服务器使像 Claude 这样的 LLM 能够通过自然语言与 Alpaca 交易 API 进行交互,以进行股票交易、检查头寸、获取市场数据和管理您的账户。

  1. Features
    1. Prerequisites
      1. Installation
        1. Usage
          1. Running the server
          2. Configuring Claude for Desktop
          3. Available Tools
        2. Example Queries
          1. Note
            1. Security Notice
              1. License
                ID: x24m37r31n