Skip to main content
Glama

取引rypto Data


これは何?

alpaka-mcp は、AIアシスタント(Claude Desktop、Cursor、VS Code Copilot)とターミナルをAlpaca Trading APIに直接接続する、本番環境対応のMCPサーバー+CLIです。自然言語またはコマンドラインから株式、ETF、暗号通貨を取引できます。

alpaca-pyMCP Python SDK をベースに構築されています。

デフォルトはペーパートレーディング — 実際の市場データ、シミュレーション資金、実際の資金をリスクにさらしません。


Related MCP server: FinClaw

クイックスタート

1. Alpaca APIキーを取得(無料)

alpaca.markets でサインアップ → ペーパートレーディング → APIキー

2. インストール

git clone https://github.com/vikrambtech2025-png/alpaka-mcp.git
cd alpaka-mcp
uv sync

3. 設定

cp .env.example .env
# Add your API keys to .env

4. 実行

uv run alpaka-mcp          # MCP server (stdio for Claude/Cursor)
uv run alpaka account      # CLI — check account
uv run mcp dev src/alpaka_mcp/server.py  # MCP Inspector

AIアシスタントへの接続

%AppData%\Claude\claude_desktop_config.json に追加:

{
  "mcpServers": {
    "alpaka": {
      "command": "uv",
      "args": ["--directory", "C:\\path\\to\\alpaka-mcp", "run", "alpaka-mcp"],
      "env": {
        "ALPACA_API_KEY": "your_key",
        "ALPACA_SECRET_KEY": "your_secret",
        "ALPACA_PAPER": "true"
      }
    }
  }
}

プロジェクトルートの .cursor/mcp.json に追加:

{
  "mcpServers": {
    "alpaka": {
      "command": "uv",
      "args": ["--directory", "/path/to/alpaka-mcp", "run", "alpaka-mcp"],
      "env": {
        "ALPACA_API_KEY": "your_key",
        "ALPACA_SECRET_KEY": "your_secret",
        "ALPACA_PAPER": "true"
      }
    }
  }
}

.vscode/mcp.json に追加:

{
  "servers": {
    "alpaka": {
      "command": "uv",
      "args": ["--directory", "/path/to/alpaka-mcp", "run", "alpaka-mcp"],
      "env": {
        "ALPACA_API_KEY": "your_key",
        "ALPACA_SECRET_KEY": "your_secret",
        "ALPACA_PAPER": "true"
      }
    }
  }
}

MCPツール(16)

ツール

説明

get_account

残高、純資産、買付余力、デイトレード

get_portfolio

P&Lを含むすべてのオープンポジション

ツール

説明

buy

買い注文を出す(成行/指値/逆指値/ストップリミット)

sell

売り注文を出す(成行/指値)

get_orders

ステータスとシンボルで注文を一覧表示

cancel_order

特定の注文をキャンセル

cancel_all_orders

すべてのオープン注文をキャンセル

ツール

説明

get_position

単一ポジションの詳細

close_position

清算(全額または一部)

ツール

説明

get_stock_quote

最新のビッド/アスク相場

get_stock_bars

過去のOHLCVバー

get_stock_snapshot

完全なスナップショット(取引、相場、日足、1分足)

ツール

説明

get_crypto_quote

最新の暗号通貨ビッド/アスク

get_crypto_bars

過去の暗号通貨OHLCVバー

ツール

説明

search_assets

名前またはシンボルで株式/ETF/暗号通貨を検索

get_market_clock

市場の開場/閉場ステータス


CLIコマンド(12)

alpaka account                    # Account balance & buying power
alpaka portfolio                  # Open positions with color-coded P&L
alpaka quote AAPL                 # Bid/ask quote (stocks or crypto)
alpaka buy AAPL --qty 10          # Buy 10 shares
alpaka buy BTC/USD -n 500         # Buy $500 of Bitcoin
alpaka sell AAPL --qty 5          # Sell 5 shares
alpaka orders                     # List open orders
alpaka orders --status closed     # List filled orders
alpaka cancel <order-id>          # Cancel specific order
alpaka cancel-all                 # Cancel everything open
alpaka bars AAPL --tf 1Day        # Historical bars
alpaka clock                      # Is the market open?
alpaka search apple               # Find tradeable assets

すべてのコマンドは --json による機械可読な出力をサポートしています:

$ uv run alpaka account --json
{
  "status": "ACTIVE",
  "equity": "100000.00",
  "buying_power": "200000.00",
  "cash": "100000.00",
  "portfolio_value": "100000.00",
  "daytrade_count": 0,
  "pattern_day_trader": false,
  "mode": "paper"
}

本番環境向け機能

機能

仕組み

堅牢なクライアント

透過プロキシがすべてのAPI呼び出しをレート制限+リトライでラップ

レート制限

3つの独立したトークンバケット(各200リクエスト/分)— 取引、株式データ、暗号通貨

リトライ+バックオフ

429、500、接続エラー時に1秒/2秒/4秒の指数バックオフで3回試行

ノンブロッキング非同期

MCPツールは asyncio.to_thread() を使用 — イベントループはブロックされません

構造化ロギング

JSON監査証跡:logs/trades.jsonl + logs/errors.jsonl

入力検証

シンボル、数量、価格、注文タイプをAPI呼び出し前に検証

ライブ取引ガード

実際の資金には ALPACA_LIVE_CONFIRM=true + 5秒のカウントダウンが必要

設定検証

プレースホルダーのAPIキーを明確なセットアップ手順とともに拒否

スレッドセーフ

lru_cache によるクライアント初期化、可変なグローバル状態なし

CLIエラーハンドリング

すべてのコマンドをラップ — クリーンなエラー、トレースバックなし


アーキテクチャ

src/alpaka_mcp/
├── server.py          # MCP server entry point (stdio)
├── cli.py             # 12 Typer commands + JSON output
├── config.py          # pydantic-settings + credential validation
├── clients.py         # ResilientClient proxy (rate limit + retry + async)
├── utils.py           # Response formatting
├── logging.py         # Structured JSON logging
├── rate_limiter.py    # Token bucket rate limiters (sync + async)
├── retry.py           # Exponential backoff (sync + async)
├── validation.py      # Input validation
└── tools/             # 16 MCP tools
    ├── account.py     # get_account, get_portfolio
    ├── trading.py     # buy, sell, get_orders, cancel_order, cancel_all
    ├── positions.py   # get_position, close_position
    ├── stock_data.py  # get_stock_quote, get_stock_bars, get_stock_snapshot
    ├── crypto_data.py # get_crypto_quote, get_crypto_bars
    └── discovery.py   # search_assets, get_market_clock

Docker

# MCP server
docker compose up alpaka-mcp

# CLI via docker
docker compose run --rm alpaka-cli account
docker compose run --rm alpaka-cli portfolio

ログはDockerボリュームの /app/logs に永続化されます。


環境変数

変数

デフォルト

説明

ALPACA_API_KEY

(必須)

あなたのAlpaca APIキー

ALPACA_SECRET_KEY

(必須)

あなたのAlpacaシークレットキー

ALPACA_PAPER

true

ペーパートレーディングモード

ALPACA_LIVE_CONFIRM

false

ライブ取引には true が必要

ALPACA_LOG_DIR

logs

ログファイルディレクトリ

ALPACA_LOG_LEVEL

INFO

ロギングの詳細度


テスト

# Unit tests (no API keys needed)
uv run pytest tests/ --ignore=tests/test_integration.py -v

# Integration tests (needs real paper API keys)
ALPACA_API_KEY=pk_xxx ALPACA_SECRET_KEY=sk_xxx uv run pytest tests/test_integration.py -v

安全性

  • デフォルトでペーパートレーディング — 実際の資金には明示的なオプトインが必要

  • ライブ取引には ALPACA_PAPER=falseALPACA_LIVE_CONFIRM=true の両方が必要

  • ライブ取引の起動時に5秒のカウントダウン

  • すべてのエラーはクリーンにフォーマット — LLMにトレースバックは送信されません

  • レート制限により意図しないAPIの過剰使用を防止

  • すべての取引に対する構造化された監査証跡


ライセンス

MIT


F
license - not found
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    D
    quality
    D
    maintenance
    MCP server that exposes Alpaca Market Data & Broker API as tools, enabling access to financial data like stock bars, assets, market days, and news through the Message Control Protocol.
    4
    54
    2
    ISC
  • A
    license
    Not graded
    quality
    D
    maintenance
    MCP server that provides AI agents with financial tools including real-time quotes, backtesting, technical analysis, and multi-exchange data via a simple CLI interface.
    1
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    An MCP server implementation for Alpaca's Trading API that enables LLMs to interact with Alpaca's trading infrastructure using natural language, supporting stock, options, and crypto trading, portfolio management, watchlists, and market data.
    4
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    This MCP server connects AI assistants to a Public.com brokerage account, enabling natural language trading of stocks, options, and crypto, along with portfolio management, quotes, and orders.
    37
    65
    Apache 2.0

View all related MCP servers

Related MCP Connectors

  • MCP server for Gainium — manage trading bots, deals, and balances via AI assistants

  • MCP server exposing the Backtest360 engine API as tools for AI agents.

  • Alpaca MCP — real-time US stock market data via the Alpaca Market Data API

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vikrambtech2025-png/alpaka-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server