Equities

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

  1. Sign up or log in at alpaca.markets
  2. Open the Dashboard
  3. On the right panel, locate API Keys
  4. Click Generate New Key
  5. Copy the API Key ID and Secret Key
  6. Note the Base URL:
    • Paper trading: https://paper-api.alpaca.markets
    • Live trading: https://api.alpaca.markets

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

EndpointLimitNotes
REST API200 requests/minutePer API key. Applies to all endpoints.
Order placement200 orders/minuteShared with REST limit.
Streaming1 connection/keyReal-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

ErrorCauseFix
CONNECTION_REFUSEDAPI key invalid, expired, or wrong base URLVerify API key and base URL (paper vs live) in adapter config
RATE_LIMITEDExceeded 200 requests/minuteIncrease rate_limit_ms in adapter config to 300+
PERMISSION_DENIEDAccount not approved for live tradingComplete Alpaca's account verification process
INSUFFICIENT_FUNDSAccount balance cannot cover the proposed tradeReduce position sizing in strategy config
MANDATE_INTEGRITY_VIOLATIONConfig file modified while bot is runningStop the bot, verify config, restart

Related guides


One bot. $129. No subscription. No $749/mo platform. → Build for Alpaca


Build your Alpaca bot

botwir3 compiler

1 Platform

2 Objective