Alpaca Trading Skill
Trade and manage portfolios via Alpaca's REST API using scripts/alpaca.sh.
Setup
Required env vars
| Variable |
Purpose |
APCA_API_KEY_ID |
Alpaca API key |
APCA_API_SECRET_KEY |
Alpaca API secret |
Optional env vars
| Variable |
Default |
Purpose |
APCA_API_BASE_URL |
https://paper-api.alpaca.markets |
Trading endpoint. Set to https://api.alpaca.markets for live |
APCA_DATA_API_BASE_URL |
https://data.alpaca.markets |
Market data endpoint |
Paper trading is the default. Always confirm with the user before switching to live.
Helper script
Source scripts/alpaca.sh from this skill directory. Usage:
alpaca METHOD PATH [JSON_BODY]
# Market data:
ALPACA_DATA=1 alpaca METHOD PATH
Quick Reference
Account & portfolio
alpaca GET /v2/account # balance, equity, buying power
alpaca GET /v2/account/configurations # trading config
alpaca GET '/v2/account/portfolio/history?period=1M&timeframe=1D' # portfolio chart
alpaca GET '/v2/account/activities?activity_types=FILL,DIV' # trade/dividend history
alpaca GET /v2/clock # market open/closed
alpaca GET '/v2/calendar?start=2026-03-01&end=2026-03-31' # trading days
Orders — Equities & Crypto
# Market buy (by qty or dollar amount)
alpaca POST /v2/orders '{"symbol":"AAPL","qty":"10","side":"buy","type":"market","time_in_force":"day"}'
alpaca POST /v2/orders '{"symbol":"AAPL","notional":"1000","side":"buy","type":"market","time_in_force":"day"}'
# Crypto (24/7)
alpaca POST /v2/orders '{"symbol":"BTC/USD","qty":"0.001","side":"buy","type":"market","time_in_force":"gtc"}'
# Limit / stop / stop-limit / trailing stop / bracket / OTO / OCO — see references/api.md
# List / get / replace / cancel
alpaca GET /v2/orders
alpaca GET /v2/orders/ORDER_ID
alpaca PATCH /v2/orders/ORDER_ID '{"qty":"20","limit_price":"190.00"}'
alpaca DELETE /v2/orders/ORDER_ID
alpaca DELETE /v2/orders # cancel ALL
Orders — Options
# Buy call (Level 2+)
alpaca POST /v2/orders '{"symbol":"AAPL260418C00260000","qty":"1","side":"buy","type":"market","time_in_force":"day"}'
# Sell covered call (Level 1+, must own 100 shares per contract)
alpaca POST /v2/orders '{"symbol":"AAPL260418C00270000","qty":"1","side":"sell","type":"limit","limit_price":"2.00","time_in_force":"day"}'
# Buy/sell puts, cash-secured puts, spreads (Level 3) — see references/api.md
# Exercise option
alpaca POST /v2/positions/AAPL260418C00260000/exercise
# Look up contracts
alpaca GET '/v2/options/contracts?underlying_symbols=AAPL&expiration_date_gte=2026-04-01&type=call&limit=10'
alpaca GET /v2/options/contracts/AAPL260418C00260000
Positions
alpaca GET /v2/positions # all open
alpaca GET '/v2/positions?asset_class=us_option' # options only
alpaca GET /v2/positions/AAPL # single equity
alpaca GET /v2/positions/NVDA260417C00220000 # single option
alpaca DELETE /v2/positions/AAPL # close
alpaca DELETE '/v2/positions/AAPL?qty=5' # close partial
alpaca DELETE '/v2/positions?cancel_orders=true' # close ALL
Market data — Stocks
ALPACA_DATA=1 alpaca GET /v2/stocks/AAPL/snapshot # quote + trade + bar
ALPACA_DATA=1 alpaca GET '/v2/stocks/snapshots?symbols=AAPL,MSFT,GOOGL' # multi-snapshot
ALPACA_DATA=1 alpaca GET '/v2/stocks/AAPL/bars?timeframe=1Day&start=2026-03-01&limit=30'
ALPACA_DATA=1 alpaca GET /v1beta1/screener/stocks/most-actives
ALPACA_DATA=1 alpaca GET '/v1beta1/screener/stocks/movers?top=10'
ALPACA_DATA=1 alpaca GET '/v1beta1/news?symbols=AAPL&limit=5'
Market data — Options
ALPACA_DATA=1 alpaca GET '/v1beta1/options/snapshots/AAPL?feed=indicative&limit=10' # option chain
ALPACA_DATA=1 alpaca GET '/v1beta1/options/bars?symbols=NVDA260417C00220000&timeframe=1Day&limit=10'
ALPACA_DATA=1 alpaca GET '/v1beta1/options/quotes/latest?symbols=NVDA260417C00220000'
ALPACA_DATA=1 alpaca GET '/v1beta1/options/trades/latest?symbols=NVDA260417C00220000'
# feed: indicative (free/delayed) or opra (subscription required)
Market data — Crypto
ALPACA_DATA=1 alpaca GET '/v1beta3/crypto/us/latest/quotes?symbols=BTC/USD'
ALPACA_DATA=1 alpaca GET '/v1beta3/crypto/us/bars?symbols=BTC/USD&timeframe=1Day&limit=30'
ALPACA_DATA=1 alpaca GET '/v1beta3/crypto/us/snapshots?symbols=BTC/USD,ETH/USD'
Corporate Actions
ALPACA_DATA=1 alpaca GET '/v1/corporate-actions?symbols=AAPL&types=cash_dividend'
# Types: forward_split, reverse_split, cash_dividend, stock_dividend, spin_off, etc.
Assets & Watchlists
alpaca GET /v2/assets/AAPL # asset info
alpaca GET '/v2/assets?status=active&attributes=has_options' # options-enabled stocks
alpaca GET /v2/watchlists # list watchlists
alpaca POST /v2/watchlists '{"name":"Tech","symbols":["AAPL","MSFT","GOOGL"]}'
Full API reference
Read references/api.md for complete endpoint documentation including:
- All order types (limit, stop, stop-limit, trailing stop, bracket, OCO, OTO)
- Order field reference (side, type, time_in_force, order_class)
- Watchlist CRUD
- Options contracts
- Historical bars/trades/quotes with all query params
- Crypto endpoints
- Market calendar
Safety Rules
- Default to paper trading. Never set
APCA_API_BASE_URL to live without explicit user confirmation.
- Show the order JSON before submitting. Let the user confirm symbol, qty, side, and type.
- Check market clock before placing orders — stocks only trade during market hours (9:30-16:00 ET) unless
extended_hours: true on limit orders.
- Verify buying power via
GET /v2/account before large orders.
- Never provide financial advice. Present data; let the user decide.
- Warn about irreversible actions — closing all positions, canceling all orders.
Troubleshooting
| Symptom |
Fix |
HTTP 401 |
Check APCA_API_KEY_ID / APCA_API_SECRET_KEY are set and valid |
HTTP 403 |
Paper keys on live URL or vice versa; check APCA_API_BASE_URL |
HTTP 422 (insufficient qty) |
Check buying power, fractional support, or symbol validity |
HTTP 429 |
Rate limited — wait and retry; Alpaca allows 200 req/min |
| Order rejected outside hours |
Add "extended_hours":true (limit orders only) or wait for market open |
jq: command not found |
Script falls back to python3 -m json.tool; install jq for better output |
1---2name: alpaca-trading3description: Trade stocks, ETFs, options, and crypto via Alpaca's REST API using curl. Full options support (buy/sell calls & puts, covered calls, cash-secured puts, spreads, exercise, contract lookup, option chain data). Manage orders, positions, watchlists, account activities, and portfolio history. Access real-time and historical market data for stocks, options, and crypto including quotes, bars, snapshots, news, screener (most active, top movers), and corporate actions. Use when the user mentions "buy," "sell," "trade," "options," "call," "put," "market data," "stock price," "stock quote," "portfolio," "account balance," "positions," "orders," "alpaca," "market clock," "watchlist," "top movers," "most active," or any stock/crypto/options trading task. No external CLI binary required — uses curl + jq directly.4---56# Alpaca Trading Skill78Trade and manage portfolios via Alpaca's REST API using `scripts/alpaca.sh`.910## Setup1112### Required env vars1314| Variable | Purpose |15|----------|---------|16| `APCA_API_KEY_ID` | Alpaca API key |17| `APCA_API_SECRET_KEY` | Alpaca API secret |1819### Optional env vars2021| Variable | Default | Purpose |22|----------|---------|---------|23| `APCA_API_BASE_URL` | `https://paper-api.alpaca.markets` | Trading endpoint. Set to `https://api.alpaca.markets` for live |24| `APCA_DATA_API_BASE_URL` | `https://data.alpaca.markets` | Market data endpoint |2526**Paper trading is the default.** Always confirm with the user before switching to live.2728### Helper script2930Source `scripts/alpaca.sh` from this skill directory. Usage:3132```bash33alpaca METHOD PATH [JSON_BODY]34# Market data:35ALPACA_DATA=1 alpaca METHOD PATH36```3738## Quick Reference3940### Account & portfolio4142```bash43alpaca GET /v2/account # balance, equity, buying power44alpaca GET /v2/account/configurations # trading config45alpaca GET '/v2/account/portfolio/history?period=1M&timeframe=1D' # portfolio chart46alpaca GET '/v2/account/activities?activity_types=FILL,DIV' # trade/dividend history47alpaca GET /v2/clock # market open/closed48alpaca GET '/v2/calendar?start=2026-03-01&end=2026-03-31' # trading days49```5051### Orders — Equities & Crypto5253```bash54# Market buy (by qty or dollar amount)55alpaca POST /v2/orders '{"symbol":"AAPL","qty":"10","side":"buy","type":"market","time_in_force":"day"}'56alpaca POST /v2/orders '{"symbol":"AAPL","notional":"1000","side":"buy","type":"market","time_in_force":"day"}'5758# Crypto (24/7)59alpaca POST /v2/orders '{"symbol":"BTC/USD","qty":"0.001","side":"buy","type":"market","time_in_force":"gtc"}'6061# Limit / stop / stop-limit / trailing stop / bracket / OTO / OCO — see references/api.md6263# List / get / replace / cancel64alpaca GET /v2/orders65alpaca GET /v2/orders/ORDER_ID66alpaca PATCH /v2/orders/ORDER_ID '{"qty":"20","limit_price":"190.00"}'67alpaca DELETE /v2/orders/ORDER_ID68alpaca DELETE /v2/orders # cancel ALL69```7071### Orders — Options7273```bash74# Buy call (Level 2+)75alpaca POST /v2/orders '{"symbol":"AAPL260418C00260000","qty":"1","side":"buy","type":"market","time_in_force":"day"}'7677# Sell covered call (Level 1+, must own 100 shares per contract)78alpaca POST /v2/orders '{"symbol":"AAPL260418C00270000","qty":"1","side":"sell","type":"limit","limit_price":"2.00","time_in_force":"day"}'7980# Buy/sell puts, cash-secured puts, spreads (Level 3) — see references/api.md8182# Exercise option83alpaca POST /v2/positions/AAPL260418C00260000/exercise8485# Look up contracts86alpaca GET '/v2/options/contracts?underlying_symbols=AAPL&expiration_date_gte=2026-04-01&type=call&limit=10'87alpaca GET /v2/options/contracts/AAPL260418C0026000088```8990### Positions9192```bash93alpaca GET /v2/positions # all open94alpaca GET '/v2/positions?asset_class=us_option' # options only95alpaca GET /v2/positions/AAPL # single equity96alpaca GET /v2/positions/NVDA260417C00220000 # single option97alpaca DELETE /v2/positions/AAPL # close98alpaca DELETE '/v2/positions/AAPL?qty=5' # close partial99alpaca DELETE '/v2/positions?cancel_orders=true' # close ALL100```101102### Market data — Stocks103104```bash105ALPACA_DATA=1 alpaca GET /v2/stocks/AAPL/snapshot # quote + trade + bar106ALPACA_DATA=1 alpaca GET '/v2/stocks/snapshots?symbols=AAPL,MSFT,GOOGL' # multi-snapshot107ALPACA_DATA=1 alpaca GET '/v2/stocks/AAPL/bars?timeframe=1Day&start=2026-03-01&limit=30'108ALPACA_DATA=1 alpaca GET /v1beta1/screener/stocks/most-actives109ALPACA_DATA=1 alpaca GET '/v1beta1/screener/stocks/movers?top=10'110ALPACA_DATA=1 alpaca GET '/v1beta1/news?symbols=AAPL&limit=5'111```112113### Market data — Options114115```bash116ALPACA_DATA=1 alpaca GET '/v1beta1/options/snapshots/AAPL?feed=indicative&limit=10' # option chain117ALPACA_DATA=1 alpaca GET '/v1beta1/options/bars?symbols=NVDA260417C00220000&timeframe=1Day&limit=10'118ALPACA_DATA=1 alpaca GET '/v1beta1/options/quotes/latest?symbols=NVDA260417C00220000'119ALPACA_DATA=1 alpaca GET '/v1beta1/options/trades/latest?symbols=NVDA260417C00220000'120# feed: indicative (free/delayed) or opra (subscription required)121```122123### Market data — Crypto124125```bash126ALPACA_DATA=1 alpaca GET '/v1beta3/crypto/us/latest/quotes?symbols=BTC/USD'127ALPACA_DATA=1 alpaca GET '/v1beta3/crypto/us/bars?symbols=BTC/USD&timeframe=1Day&limit=30'128ALPACA_DATA=1 alpaca GET '/v1beta3/crypto/us/snapshots?symbols=BTC/USD,ETH/USD'129```130131### Corporate Actions132133```bash134ALPACA_DATA=1 alpaca GET '/v1/corporate-actions?symbols=AAPL&types=cash_dividend'135# Types: forward_split, reverse_split, cash_dividend, stock_dividend, spin_off, etc.136```137138### Assets & Watchlists139140```bash141alpaca GET /v2/assets/AAPL # asset info142alpaca GET '/v2/assets?status=active&attributes=has_options' # options-enabled stocks143alpaca GET /v2/watchlists # list watchlists144alpaca POST /v2/watchlists '{"name":"Tech","symbols":["AAPL","MSFT","GOOGL"]}'145```146147## Full API reference148149Read `references/api.md` for complete endpoint documentation including:150- All order types (limit, stop, stop-limit, trailing stop, bracket, OCO, OTO)151- Order field reference (side, type, time_in_force, order_class)152- Watchlist CRUD153- Options contracts154- Historical bars/trades/quotes with all query params155- Crypto endpoints156- Market calendar157158## Safety Rules1591601. **Default to paper trading.** Never set `APCA_API_BASE_URL` to live without explicit user confirmation.1612. **Show the order JSON before submitting.** Let the user confirm symbol, qty, side, and type.1623. **Check market clock** before placing orders — stocks only trade during market hours (9:30-16:00 ET) unless `extended_hours: true` on limit orders.1634. **Verify buying power** via `GET /v2/account` before large orders.1645. **Never provide financial advice.** Present data; let the user decide.1656. **Warn about irreversible actions** — closing all positions, canceling all orders.166167## Troubleshooting168169| Symptom | Fix |170|---------|-----|171| `HTTP 401` | Check `APCA_API_KEY_ID` / `APCA_API_SECRET_KEY` are set and valid |172| `HTTP 403` | Paper keys on live URL or vice versa; check `APCA_API_BASE_URL` |173| `HTTP 422` (insufficient qty) | Check buying power, fractional support, or symbol validity |174| `HTTP 429` | Rate limited — wait and retry; Alpaca allows 200 req/min |175| Order rejected outside hours | Add `"extended_hours":true` (limit orders only) or wait for market open |176| `jq: command not found` | Script falls back to `python3 -m json.tool`; install jq for better output |