Install
openclaw skills install alpaca-py-cliClawHub Security found sensitive or high-impact capabilities. Review the scan results before using.
AI agent skill for Alpaca Markets trading. Intelligent setup wizard (alpaca init) guides users through registration. Trade stocks/crypto, manage portfolios, execute orders via natural language. Token-efficient design with runtime guidance. Paper trading by default ($100k virtual money). IMPORTANT - Setup requires user interaction to configure API keys in shell environment.
openclaw skills install alpaca-py-cliTrade stocks and crypto programmatically via Alpaca's API using a Python-based CLI tool.
IMPORTANT - READ BEFORE USE:
This skill stores API keys as environment variables in your shell config file.
What happens during setup:
alpaca init displays registration steps for agent automationalpaca auth saves API keys to shell startup files (~/.zshrc, ~/.bashrc, or ~/.profile)Security considerations:
Recommended practices:
For agents:
alpaca auth (saves keys to shell config)alpaca init is safe to run - it only displays instructionsalpaca auth to save themLinks:
Trade stocks and crypto programmatically via Alpaca's API using a Python-based CLI tool.
Links:
Manage your Alpaca Markets trading account using the alpaca CLI tool and Python SDK. Supports both paper trading (simulated) and live trading.
# Install Homebrew Python 3.11+
brew install python@3.11
# Install alpaca-py
/opt/homebrew/bin/pip3.11 install alpaca-py pytz
pip3 install alpaca-py pytz
Note: System Python may show urllib3 warnings on macOS due to LibreSSL compatibility. Use Homebrew Python for a cleaner experience.
alpaca auth
This will interactively prompt you for:
The command automatically saves your credentials to your shell config file (~/.zshrc, ~/.bashrc, or ~/.profile).
Alternatively, set these in your shell profile manually:
export ALPACA_API_KEY="your_api_key"
export ALPACA_SECRET_KEY="your_secret_key"
export ALPACA_PAPER="true" # Use "false" for live trading
Get your API keys from https://alpaca.markets (Dashboard → API Keys)
Paper Trading (recommended for testing):
Live Trading (real money):
alpaca auth
Interactive setup wizard that guides you through:
alpaca account
Shows:
alpaca clock
Shows:
# Show next 30 trading days (default)
alpaca calendar
# Show next 7 trading days
alpaca calendar --days 7
Shows trading days with open/close times (Eastern Time).
# Default: 1 month, daily bars
alpaca history
# Last week
alpaca history --period 1W
# Last 3 months with hourly bars
alpaca history --period 3M --timeframe 1H
Periods: 1D, 1W, 1M, 3M, 1Y, all
Timeframes: 1Min, 5Min, 15Min, 1H, 1D
Shows:
alpaca positions
Shows all current holdings with:
# Single symbol
alpaca quote AAPL
# Multiple symbols
alpaca quote AAPL,TSLA,MSFT
Shows:
Note: Quotes may show incomplete data when market is closed. Best used during market hours (9:30 AM - 4:00 PM ET).
# Show open orders (default)
alpaca orders
# Show all recent orders
alpaca orders --status all
# Show last 20 closed orders
alpaca orders --status closed --limit 20
Shows:
# Buy shares
alpaca buy AAPL 10
# Sell shares
alpaca sell AAPL 5
Places a market order that executes at market price when market is open.
# Cancel specific order
alpaca cancel <order_id>
# Cancel all open orders
alpaca cancel-all
# Close specific position
alpaca close AAPL
# Close all positions (requires confirmation)
alpaca close-all
Note: close-all will prompt for confirmation before closing all positions.
# Configure credentials
alpaca auth
# Check account
alpaca account
# Check if market is open
alpaca clock
# Check current price
alpaca quote TSLA
# Check account balance
alpaca account
# Buy some shares
alpaca buy TSLA 5
# Check pending orders
alpaca orders
# View positions (after order fills)
alpaca positions
# Get updated quote
alpaca quote TSLA
# Sell some shares
alpaca sell TSLA 2
# Check order history
alpaca orders --status all
# View current positions
alpaca positions
# View portfolio history
alpaca history --period 1M
# Check market calendar
alpaca calendar --days 7
# Check all open orders
alpaca orders
# Cancel specific order
alpaca cancel <order_id>
# Cancel all orders
alpaca cancel-all
# Close specific position
alpaca close AAPL
# Close all positions
alpaca close-all
When a user wants to start trading but hasn't configured Alpaca yet, agents can automate the entire setup process using browser automation.
alpaca init - Displays clear registration stepsalpaca auth - Save the extracted keys to shell configUser: "I want to start trading stocks"
Agent:
1. Runs: alpaca init (gets registration steps)
2. Uses browser skill to:
- Open https://alpaca.markets
- Fill registration form with user info
- Verify email automatically
- Navigate to API Keys page
- Generate and extract keys
3. Runs: alpaca auth (with extracted keys)
4. Confirms: "✓ Setup complete! You have $100k in paper money."
alpaca init is non-interactive - just displays stepsalpaca auth requires user consent (modifies shell config)alpaca clock or alpaca accountWhen the user asks about their portfolio or wants to trade:
alpaca auth for first-time setupalpaca clock to see if market is openalpaca account to see current balance and buying poweralpaca positions to list current holdingsalpaca orders to see pending/recent ordersalpaca quote <symbols> to check current pricesalpaca buy/sell to execute tradesalpaca cancel/close commands as neededALPACA_PAPER=true)alpaca auth to safely configure credentials (secret key is hidden)alpaca clock before trading to see if market is openaccount.buying_power before placing ordersTimeInForce.DAY to auto-cancel unfilled orders at market closealpaca positionsalpaca ordersalpaca historyalpaca cancel-all to quickly cancel all pending ordersalpaca close-all with caution (requires confirmation)US stock market hours (Eastern Time):
Orders placed outside market hours will be queued and executed when market opens.
Quotes may show incomplete or stale data when market is closed.
Use alpaca clock to check current market status.
If you see:
NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently using LibreSSL
Solution: Install and use Homebrew Python 3.11+ which uses OpenSSL:
brew install python@3.11
/opt/homebrew/bin/pip3.11 install alpaca-py pytz
Then update the script shebang to use Homebrew Python:
sed -i '' '1s|#!/usr/bin/env python3|#!/opt/homebrew/bin/python3.11|' ~/.openclaw/workspace/skills/alpaca-py-cli/scripts/alpaca
If you see:
ModuleNotFoundError: No module named 'pytz'
Solution:
pip3 install pytz
# or
/opt/homebrew/bin/pip3.11 install pytz
If alpaca command is not found, use the full path:
~/.openclaw/workspace/skills/alpaca-py-cli/scripts/alpaca
Or add to PATH in your shell config:
export PATH="$HOME/.openclaw/workspace/skills/alpaca-py-cli/scripts:$PATH"
~/.openclaw/workspace/skills/alpaca-py-cli/scripts/alpaca~/.zshrc (or ~/.bashrc, ~/.profile)See the "Automated Setup for Agents" section above for the complete workflow.
Quick summary:
alpaca init to see registration stepsalpaca auth to save keys (with user consent)alpaca clock or alpaca accountThe new alpaca init command is non-interactive and agent-friendly - it simply displays clear steps that an agent can follow using browser automation.