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.
- Activity
- New: be the first to try it
- Installs
- 0 installs
- Likes
- 0 likes
- Clones
- 0 clones
- 1# alpaca-connector
- 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.
- 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.
- 7Not financial advice. This kit runs the orders you ask for; it never picks trades.
- 9## Example
- 11You: "Download daily bars for SPY since 2021 and save them for a backtest."
- 13```bash
- 14node scripts/alpaca.mjs bars --symbol SPY --timeframe 1Day --start 2021-01-01 --out data/SPY-1Day.csv
- 15```
- 17```csv
- 18timestamp,open,high,low,close,volume,trade_count,vwap
- 192021-01-04T05:00:00Z,...
- 20```
- 22You: "Buy 10 AAPL on paper."
- 24> Paper: BUY 10 shares AAPL, market, day. Placed. Order id 61e6...f47d, status accepted.
- 26With `ALPACA_LIVE=1`, the script refuses to send until you confirm:
- 28```text
- 29LIVE MODE (real money). Not sent: BUY 10 shares AAPL, market, day
- 30Ask the user to confirm this exact action in chat. If they say yes, rerun with: --confirm-live LIVE-BUY-10-AAPL-MARKET
- 31```
- 33The token encodes the side, size, symbol, type, and price, so a yes for one order cannot be reused for a different one.
- 35## What it can access
- 37- **Network:** `paper-api.alpaca.markets` (paper trading), `api.alpaca.markets` (live trading, only with `ALPACA_LIVE=1`), `data.alpaca.markets` (quotes and bars).
- 38- **Env vars (names only):** `ALPACA_API_KEY_ID`, `ALPACA_API_SECRET_KEY`, `ALPACA_LIVE`.
- 39- **Files:** writes CSVs and JSON to `data/` and `out/` when you ask it to save.
- 40- **Shell:** only `node scripts/alpaca.mjs` and its offline self-test.
- 42Keys are read from your environment and sent only as Alpaca's auth headers. `--dry-run` prints the request with the secret redacted.
- 44## Setup
- 461. Create a free Alpaca account and generate **paper trading** API keys in the dashboard.
- 472. Add them to your shell profile (not to the project):
- 49 ```bash
- 50 export ALPACA_API_KEY_ID=... # your paper key id
- 51 export ALPACA_API_SECRET_KEY=... # your paper secret
- 52 ```
- 543. Node 22 or newer. Try `node scripts/alpaca.mjs account`.
- 56Live trading: generate live keys, set them instead, and `export ALPACA_LIVE=1`. Turn it off with `unset ALPACA_LIVE`.
- 58Tests (`node scripts/selftest.mjs`) use a fake fetch and never touch the network.
- 60This kit is not made or endorsed by Alpaca.
