Skip to content
SlashClone
Made by@qtrader

Alpaca connector

@qtrader/alpaca-connector

Talk to Alpaca from Claude Code: account, positions, orders (list, place, cancel), latest quote, and historical bars to CSV, using Node's built-in fetch. Paper trading by default. Live orders need ALPACA_LIVE=1 plus your yes in chat for each order. Not financial advice.

SkillTradingv1.0.0 (latest)Tested
Activity
New: be the first to try it
  1. 1# alpaca-connector
  2. 2
  3. 3Check your Alpaca account, positions, and orders, place or cancel orders, get quotes, and download price history to CSV, all by asking Claude. It uses paper trading unless you turn live mode on yourself, and even then every live order waits for your yes in chat.
  4. 4
  5. 5**Who it is for:** people learning to trade systematically, and anyone who wants a quick way to pull Alpaca data into a backtest or a spreadsheet.
  6. 6
  7. 7Not financial advice. This kit runs the orders you ask for; it never picks trades.
  8. 8
  9. 9## Example
  10. 11You: "Download daily bars for SPY since 2021 and save them for a backtest."
  11. 13```bash
  12. 14node scripts/alpaca.mjs bars --symbol SPY --timeframe 1Day --start 2021-01-01 --out data/SPY-1Day.csv
  13. 15```
  14. 17```csv
  15. 18timestamp,open,high,low,close,volume,trade_count,vwap
  16. 192021-01-04T05:00:00Z,...
  17. 20```
  18. 22You: "Buy 10 AAPL on paper."
  19. 24> Paper: BUY 10 shares AAPL, market, day. Placed. Order id 61e6...f47d, status accepted.
  20. 26With `ALPACA_LIVE=1`, the script refuses to send until you confirm:
  21. 28```text
  22. 29LIVE MODE (real money). Not sent: BUY 10 shares AAPL, market, day
  23. 30Ask the user to confirm this exact action in chat. If they say yes, rerun with: --confirm-live LIVE-BUY-10-AAPL-MARKET
  24. 31```
  25. 33The token encodes the side, size, symbol, type, and price, so a yes for one order cannot be reused for a different one.
  26. 35## What it can access
  27. 37- **Network:** `paper-api.alpaca.markets` (paper trading), `api.alpaca.markets` (live trading, only with `ALPACA_LIVE=1`), `data.alpaca.markets` (quotes and bars).
  28. 38- **Env vars (names only):** `ALPACA_API_KEY_ID`, `ALPACA_API_SECRET_KEY`, `ALPACA_LIVE`.
  29. 39- **Files:** writes CSVs and JSON to `data/` and `out/` when you ask it to save.
  30. 40- **Shell:** only `node scripts/alpaca.mjs` and its offline self-test.
  31. 42Keys are read from your environment and sent only as Alpaca's auth headers. `--dry-run` prints the request with the secret redacted.
  32. 44## Setup
  33. 461. Create a free Alpaca account and generate **paper trading** API keys in the dashboard.
  34. 472. Add them to your shell profile (not to the project):
  35. 49 ```bash
  36. 50 export ALPACA_API_KEY_ID=... # your paper key id
  37. 51 export ALPACA_API_SECRET_KEY=... # your paper secret
  38. 52 ```
  39. 543. Node 22 or newer. Try `node scripts/alpaca.mjs account`.
  40. 56Live trading: generate live keys, set them instead, and `export ALPACA_LIVE=1`. Turn it off with `unset ALPACA_LIVE`.
  41. 58Tests (`node scripts/selftest.mjs`) use a fake fetch and never touch the network.
  42. 60This kit is not made or endorsed by Alpaca.