Alpaca Setup Guide
Time: 5 minutes | Difficulty: Easy | Market: US Equities Mode: Full automation | API: Trading API v2 (REST + Streaming) | Docs: docs.alpaca.markets
This guide sets up an Alpaca stock trading bot using the botwir3 runtime. Connect to Alpaca's commission-free API, configure a strategy for US equities, and run locally with paper or live trading.
Before you start
Verify that automated operation is permitted under Alpaca's current terms of service before deploying. botwir3 provides tools for building structured automation. The user is responsible for compliance with the platform's terms and all applicable regulations.
Alpaca Terms of Service | Last verified: May 2026
What you need
- An Alpaca account (paper or live — no minimum balance for paper)
- The botwir3 runtime downloaded and unzipped
- A strategy config file from the builder
Step 1: Create API credentials
- Sign up or log in at alpaca.markets
- Open the Dashboard
- On the right panel, locate API Keys
- Click Generate New Key
- Copy the API Key ID and Secret Key
- Note the Base URL:
- Paper trading:
https://paper-api.alpaca.markets - Live trading:
https://api.alpaca.markets
- Paper trading:
Permissions required: Trading access is enabled by default on all Alpaca API keys. Permissions to disable: N/A — Alpaca API keys do not have withdrawal scopes. Transfers require the dashboard.
🔒 Security. Alpaca API keys cannot initiate withdrawals or ACH transfers. Trading-only by design.
Step 2: Configure the adapter
Create adapter.json in the bot directory:
{
"adapter": "alpaca",
"credentials": {
"api_key": "paste-api-key-here",
"api_secret": "paste-api-secret-here",
"base_url": "https://paper-api.alpaca.markets"
},
"trading_pair": "AAPL",
"environment": "paper",
"rate_limit_ms": 300
}
Common symbols: AAPL, TSLA, SPY, QQQ, MSFT, NVDA, AMD.
To switch from paper to live trading, change base_url to https://api.alpaca.markets and set environment to "live".
API keys are stored in a local config file on the machine running the bot. They are not transmitted to botwir3 or any third party. botwir3 never sees, stores, or has access to platform credentials.
Step 3: Test the connection
botwir3 test --adapter alpaca
Expected output:
[botwir3] Adapter: alpaca
[botwir3] Connection: OK
[botwir3] Permissions: trading
[botwir3] Rate limit: 200 requests/minute
Step 4: Start the bot
botwir3 start --config my-strategy.json
The runtime loads the strategy, computes the spec hash, connects to Alpaca via the local API credentials, and begins evaluating signals. The gate function compares proposed actions against the configured spec. The user is responsible for monitoring the bot and verifying execution outcomes.
Rate limits and considerations
| Endpoint | Limit | Notes |
|---|---|---|
| REST API | 200 requests/minute | Per API key. Applies to all endpoints. |
| Order placement | 200 orders/minute | Shared with REST limit. |
| Streaming | 1 connection/key | Real-time quotes and trade updates. |
ℹ Market hours. US equities trade 9:30 AM – 4:00 PM ET, Monday through Friday. The bot holds outside market hours unless extended-hours trading is enabled in the Alpaca dashboard.
T+1 settlement. Trades settle the next business day. This affects available buying power, not bot operation. All actions and decisions are recorded in the local ledger.
Pattern Day Trader rule. Accounts under $25,000 are subject to FINRA's Pattern Day Trader rule. The user is responsible for understanding and configuring strategy constraints accordingly.
Common Alpaca bot configurations include momentum strategies on high-liquidity tickers (SPY, QQQ, AAPL), mean reversion on volatile small-caps, and scheduled DCA into index ETFs. Paper trading mirrors live conditions — strategies can run on paper indefinitely before switching one line in the config to go live.
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
CONNECTION_REFUSED | API key invalid, expired, or wrong base URL | Verify API key and base URL (paper vs live) in adapter config |
RATE_LIMITED | Exceeded 200 requests/minute | Increase rate_limit_ms in adapter config to 300+ |
PERMISSION_DENIED | Account not approved for live trading | Complete Alpaca's account verification process |
INSUFFICIENT_FUNDS | Account balance cannot cover the proposed trade | Reduce position sizing in strategy config |
MANDATE_INTEGRITY_VIOLATION | Config file modified while bot is running | Stop the bot, verify config, restart |
Related guides
- Interactive Brokers Setup Guide — equities, multi-asset, global
- Schwab Setup Guide — US equities, requires developer app approval
- TradingView → Broker Setup Guide — route TradingView alerts to Alpaca
One bot. $129. No subscription. No $749/mo platform. → Build for Alpaca