Alpaca Trading API 2026: The Commission-Free Stock Brokerage API for Algorithmic Trading — Setup Guide
Complete guide to the Alpaca Trading API for commission-free algorithmic trading. Learn setup, order placement, WebSocket streaming, fractional shares, and paper trading with Python code examples.
- ⭐ 1879
- Python
- Apache-2.0
- Updated 2026-08-27
pgvector 2026: Turn PostgreSQL into a High-Performance Vector Database — Setup, Tuning & RAG Integration Guide • Chroma DB 2026: The Developer-Friendly Vector Database for RAG with 50x Faster Embeddings — Python Guide
Introduction #
Algorithmic trading used to be the exclusive domain of hedge funds with millions in infrastructure. The Alpaca Trading API changed that. Alpaca is a commission-free stock brokerage that exposes its entire trading stack — order routing, market data, portfolio management — through a modern REST API and WebSocket streams. It is the on-ramp that turned retail algorithmic trading into a mainstream developer activity.
This guide covers everything: account setup, paper trading, placing orders, streaming market data, fractional shares, and production considerations.
What Is Alpaca? #
Alpaca Securities LLC is a US brokerage that offers commission-free trading of stocks and ETFs. Its flagship product is the Trading API — a fully documented REST API that mirrors a real brokerage backend, backed by Apex Clearing. Because the API is the product, developers get the same order types, execution quality, and market data access as institutional systems.
Key capabilities:
- Commission-free trades: zero commission on US stocks and ETFs
- Paper trading: a free simulated environment with real-time market data
- Fractional shares: trade as little as $1 worth of any stock
- WebSocket streams: real-time quotes, trades, and account updates
- OAuth-based auth: secure API keys scoped per account
- Multi-asset: stocks and crypto (via Alpaca Crypto)
Getting Started #
1. Create Accounts #
Sign up at alpaca.markets. You get two environments:
- Paper account (immediate, free) — simulated $100K balance, real-time data
- Live account (after KYC approval) — real trading
2. Install the Python SDK #
pip install alpaca-py
3. First API Call: Get Account #
from alpaca.trading.client import TradingClient
client = TradingClient("YOUR_API_KEY", "YOUR_SECRET_KEY", paper=True)
account = client.get_account()
print(f"Equity: ${account.equity}")
print(f"Buying power: ${account.buying_power}")
Placing Orders #
Alpaca supports all standard order types:
from alpaca.trading.requests import MarketOrderRequest, LimitOrderRequest
from alpaca.trading.enums import OrderSide, TimeInForce
# Market order
market_order = MarketOrderRequest(
symbol="AAPL",
qty=10,
side=OrderSide.BUY,
time_in_force=TimeInForce.DAY,
)
client.submit_order(market_order)
# Limit order
limit_order = LimitOrderRequest(
symbol="MSFT",
qty=5,
limit_price=420.50,
side=OrderSide.BUY,
time_in_force=TimeInForce.GTC,
)
client.submit_order(limit_order)
Order types supported: market, limit, stop, stop-limit, trailing-stop, and bracket orders (entry + take-profit + stop-loss in one).
Streaming Real-Time Data #
For live quotes and trade updates, use the WebSocket streams:
from alpaca.data.live.stock import StockDataStream
stream = StockDataStream("API_KEY", "SECRET_KEY")
async def quote_handler(data):
print(f"{data.symbol}: bid {data.bid_price} / ask {data.ask_price}")
stream.subscribe_quotes(quote_handler, "AAPL", "MSFT")
stream.run()
Fractional Shares & Dollar-Cost Averaging #
Alpaca supports fractional orders down to $1 notional. This makes systematic DCA strategies practical:
# Buy $50 of AAPL regardless of share price
fractional = MarketOrderRequest(
symbol="AAPL",
notional=50.0, # dollar amount instead of qty
side=OrderSide.BUY,
time_in_force=TimeInForce.DAY,
)
client.submit_order(fractional)
Production Considerations #
- Paper first: always validate strategies in the paper environment before risking capital
- Rate limits: the API has documented rate limits; implement backoff for production bots
- Market hours: equity orders only execute during regular/extended market hours
- Data plans: free tier includes delayed data; IEX real-time data is available free; full SIP feeds are paid
- OAuth tokens: rotate API keys regularly and scope them to the minimum permissions
Conclusion #
The Alpaca Trading API is the most accessible path from idea to automated equity trading. Free paper trading, commission-free execution, fractional shares, and a clean Python SDK make it the default choice for algorithmic stock trading in 2026.
crypto trading platform📌 Affiliate Disclosure: This article contains affiliate links. We may earn a commission if you sign up through our link — at no extra cost to you. Our reviews are independent and based on thorough research.
🚀 Try Minara for AI-Powered Trading: Sign up with Minara — the AI trading platform that helps you build, backtest, and deploy automated strategies with zero coding required.
💬 Discussion