npx skills add ...
npx skills add lacymorrow/openclaw-alpaca-trading-skill --skill alpaca-trading
Execute trades, analyze markets, and manage portfolios using apcacli command-line tool for Alpaca's Trading API. Use when the user wants to trade stocks, ETFs, options, crypto, check market data, view positions, manage orders, or analyze their portfolio. Also use when they mention "buy," "sell," "trade," "market data," "stock price," "portfolio," "account balance," or "alpaca trading.
npx skills add lacymorrow/openclaw-alpaca-trading-skill --skill alpaca-trading
Execute trades and manage portfolios through the apcacli command-line tool for Alpaca's Trading API.
apcacli is a Rust CLI. Install it cross-platform:
cargo install apcacliYou are an expert in using apcacli for command-line stock trading. Your goal is to help users trade stocks, ETFs, options, and crypto efficiently through Alpaca's API while emphasizing safety and best practices.
When helping users with trading tasks:
apcacli is a Rust-based CLI for interacting with Alpaca's trading platform. It provides:
Use this skill when the user wants to:
Common trigger phrases:
When NOT to use this skill:
Requirements:
For Paper Trading (Recommended for testing):
For Live Trading:
Get API Credentials:
View account details:
Shows account status, cash balance, buying power, equity, and margin information.
View account activity:
Displays recent account activity including trades, dividends, and transfers.
Update account configuration:
Modify account settings (use --help for available options).
Submit a market order:
Submit a limit order:
Submit advanced orders:
List all orders:
Shows all orders with their status (open, filled, cancelled, etc.).
Get specific order details:
Displays comprehensive order information including timestamps, pricing, and status.
Cancel an order:
Cancels a pending order by its ID.
Cancel all orders:
Cancels all open orders.
List all open positions:
Shows all open positions with:
Get specific position:
Displays detailed information for a specific position.
Close a position:
Close all positions:
Closes all open positions.
List available assets:
Shows all tradeable assets.
Get asset details:
Displays asset information including exchange, class, and tradability status.
Search for assets:
Searches for assets matching the query.
Check market clock:
Shows current market status (open/closed), next open time, and next close time.
Stream account updates:
Monitors real-time account events including order updates and fills.
Stream trade updates:
Monitors real-time trade events for your positions.
apcacli order get to verify order detailsapcacli position listapcacli <command> --help for detailed optionsapcacli market clock before placing ordersSimple stock purchase:
Limit order with monitoring:
Portfolio review:
Close position with stop loss:
| Task | Command |
|---|---|
| View account | apcacli account get |
| Account activity | apcacli account activity |
| Buy stock (market) | apcacli order submit buy SYMBOL --value AMOUNT |
| Buy stock (limit) | apcacli order submit buy SYMBOL --quantity N --limit-price PRICE |
| Sell stock | apcacli order submit sell SYMBOL --quantity N |
| List all orders | apcacli order list |
| Get order details | apcacli order get ORDER_ID |
| Cancel order | apcacli order cancel ORDER_ID |
| Cancel all orders | apcacli order cancel-all |
| List positions | apcacli position list |
| Get position | apcacli position get SYMBOL |
| Close position | apcacli position close SYMBOL |
| Close all positions | apcacli position close-all |
| List assets | apcacli asset list |
| Get asset info | apcacli asset get SYMBOL |
| Check market status | apcacli market clock |
| Stream account events | apcacli stream account |
| Stream trades | apcacli stream trades |
--quantity N - Number of shares to trade--value AMOUNT - Dollar amount to invest (for market orders)--limit-price PRICE - Limit price for limit orders--stop-price PRICE - Stop price for stop orders--trail-percent N - Trailing stop percentage--trail-amount AMOUNT - Trailing stop dollar amountMarket Order - Executes immediately at current market price
Limit Order - Executes only at specified price or better
Stop Order - Converts to market order when stop price is reached
Stop-Limit Order - Converts to limit order when stop price is reached
Trailing Stop - Stop price follows market by specified percentage or amount
cargo install apcacliAPCA_API_KEY_ID and APCA_API_SECRET_KEY are requiredAPCA_API_BASE_URL for live tradingGenerate shell completion for faster command entry:
Use streaming commands to monitor account activity in real-time:
Combine apcacli with shell scripts for automated strategies:
⚠️ IMPORTANT:
apcacli created by d-e-s-o
Built on the apca Rust crate for Alpaca API interactions.
export APCA_API_KEY_ID='your-key-id'
export APCA_API_SECRET_KEY='your-secret-key'
# For live trading (default is paper):
# export APCA_API_BASE_URL='https://api.alpaca.markets'# Using Cargo (Rust package manager)
cargo install apcacli
# Verify installation
apcacli --helpexport APCA_API_KEY_ID='your_paper_key_id'
export APCA_API_SECRET_KEY='your_paper_secret_key'
# Paper trading is the default, no need to set APCA_API_BASE_URLexport APCA_API_BASE_URL='https://api.alpaca.markets'
export APCA_API_KEY_ID='your_live_key_id'
export APCA_API_SECRET_KEY='your_live_secret_key'apcacli account getapcacli account activityapcacli account config <options># Buy with dollar amount
apcacli order submit buy AAPL --value 1000
# Buy specific quantity
apcacli order submit buy AAPL --quantity 10
# Sell shares
apcacli order submit sell TSLA --quantity 5# Buy at specific price
apcacli order submit buy MSFT --quantity 10 --limit-price 420
# Sell at specific price
apcacli order submit sell NVDA --quantity 20 --limit-price 850# Stop order
apcacli order submit sell AAPL --quantity 10 --stop-price 180
# Stop-limit order
apcacli order submit sell TSLA --quantity 5 --stop-price 800 --limit-price 795
# Trailing stop order (percentage)
apcacli order submit sell NVDA --quantity 10 --trail-percent 5apcacli order listapcacli order get <ORDER_ID>apcacli order cancel <ORDER_ID>apcacli order cancel-allapcacli position listapcacli position get <SYMBOL># Close entire position
apcacli position close <SYMBOL>
# Close partial position
apcacli position close <SYMBOL> --quantity 5apcacli position close-allapcacli asset listapcacli asset get <SYMBOL>apcacli asset search <QUERY>apcacli market clockapcacli stream accountapcacli stream trades# 1. Check account balance
apcacli account get
# 2. Verify asset is tradeable
apcacli asset get AAPL
# 3. Check market is open
apcacli market clock
# 4. Submit market order
apcacli order submit buy AAPL --value 1000
# 5. Verify position
apcacli position list# 1. Submit limit order
apcacli order submit buy MSFT --quantity 10 --limit-price 420
# 2. Save the returned ORDER_ID
# 3. Check order status
apcacli order get <ORDER_ID>
# 4. If needed, cancel
apcacli order cancel <ORDER_ID># 1. View all positions
apcacli position list
# 2. Check account summary
apcacli account get
# 3. Review recent activity
apcacli account activity# 1. Check current position
apcacli position get AAPL
# 2. Set trailing stop to protect profits
apcacli order submit sell AAPL --quantity 10 --trail-percent 5
# 3. Monitor the order
apcacli order listapcacli order submit buy AAPL --quantity 10apcacli order submit buy AAPL --quantity 10 --limit-price 185apcacli order submit sell AAPL --quantity 10 --stop-price 180apcacli order submit sell AAPL --quantity 10 --stop-price 180 --limit-price 179# Percentage-based
apcacli order submit sell AAPL --quantity 10 --trail-percent 5
# Dollar-based
apcacli order submit sell AAPL --quantity 10 --trail-amount 10# Error: "Missing APCA_API_KEY_ID"
# Solution: Export required environment variables
export APCA_API_KEY_ID='your_key'
export APCA_API_SECRET_KEY='your_secret'# Error: "apcacli: command not found"
# Solution: Install apcacli
cargo install apcacli
# Verify installation
which apcacli# Install completion script
cargo run --bin=shell-complete > apcacli.bash
source apcacli.bash
# Now you can use tab completion
apcacli order <TAB># Terminal 1: Monitor account events
apcacli stream account
# Terminal 2: Execute trades
apcacli order submit buy AAPL --value 1000
# Watch the fill notification appear in Terminal 1#!/bin/bash
# Example: Daily portfolio check script
echo "=== Daily Portfolio Report ==="
echo ""
echo "Account Status:"
apcacli account get
echo ""
echo "Open Positions:"
apcacli position list
echo ""
echo "Recent Activity:"
apcacli account activity