Alpaca Trading API - Technical Reference
Overview
Commission-free trading platform with REST API and WebSocket streaming. Developer-friendly alternative to Java-based platforms like Interactive Brokers. Supports stocks, options, and cryptocurrency trading through HTTP requests.
Configuration
Account Setup
- Minimum Balance: $0 to open account
- Pattern Day Trading: Requires $25,000 minimum equity for unlimited day trading
- Margin Trading: $2,000 minimum equity required
- Verification: 24-48 hours for account approval
- International: Accepted from most countries, US securities only
API Rate Limits
- Free Tier: 200 API calls per minute
- Paid Tier: 10,000 API calls per minute ($99/month)
- Critical Warning: Free tier limit hit in 30 seconds when rebalancing 50-stock portfolio
Authentication
- Separate API key pairs for paper and live trading
- OAuth 2.0 support for third-party applications
- IP restriction capability for API keys
- TLS 1.3 encryption with 2FA support
Market Data Configuration
Data Tiers
Tier | Cost | Coverage | Latency |
---|---|---|---|
IEX (Free) | $0 | 3% trading volume, all symbols | 15-minute delay |
SIP Data | $99/month | All exchanges | Sub-20ms real-time |
WebSocket Streaming
- Connection Reliability: Drops during high volatility when most needed
- Reconnection: Python SDK reconnection logic broken in newer versions
- SSL Issues:
ssl.SSLEOFError
common in Python 3.11+ - Batch Updates: Automatic for high-volume symbol tracking
Critical Failure Modes
API Connection Issues
- WebSocket Disconnections: Every 20 minutes during volatility
- SSL Errors:
ConnectionResetError: [Errno 104]
indicates server issues - Rate Limiting:
403 Forbidden: rate limit exceeded
even at 50 requests/minute - WSL2 Specific: WebSocket drops every 20 minutes due to Microsoft networking
Trading Reality vs Paper Trading
- Performance Gap: 15% backtested → 8% paper → 3% live returns typical
- Slippage Impact: Paper trading fills at midpoint, live gives market scraps
- Spread Costs: 0.05% spread on small-caps destroys returns on $50k positions
- Partial Fills: Not simulated in paper trading
Production Deployment Issues
- Memory Leaks: Common in long-running bots
- Dependency Hell:
pandas >=1.2.0 numpy >=1.20.0
version conflicts - JSON Validation:
KeyError: 'timestamp'
during market open - always validate responses
Resource Requirements
Time Investment
- Setup: 10 minutes (ideal) to 2 hours (typical)
- First Trade: ~1 hour for basic implementation
- Production Ready: Weeks to months for robust system
Expertise Costs
- Basic Trading: HTTP request knowledge sufficient
- Production Systems: Requires error handling, reconnection logic, risk management
- Debugging: Environmental issues (Python versions, SSL, WebSocket) require system administration skills
Financial Costs
- Trading: $0 commissions + regulatory fees (FINRA TAF $0.000166/share max $8.30, SEC $0.0000278/dollar)
- Data: $99/month for real-time consolidated data
- Infrastructure: Self-hosted or cloud deployment costs
Platform Comparison
Feature | Alpaca | Interactive Brokers | Charles Schwab | TD Ameritrade |
---|---|---|---|---|
Setup Complexity | Low | High (Java hell) | Medium | Medium |
API Reliability | Good (volatility issues) | Poor (random disconnects) | Slow responses | Medium |
Rate Limits | 200/min (10k paid) | 50/sec | 120/min | 120/min |
International Markets | No | Yes | No | No |
Crypto Trading | Built-in | No | No | No |
Best Use Case | US retail algo trading | Complex international | Conservative trading | Legacy TD users |
Success Patterns
Effective Strategies
- Timeframe: Minute-to-hour execution (avoid sub-minute scalping)
- Portfolio Size: <50 stocks to avoid rate limits on free tier
- Order Types: Standard market/limit orders most reliable
- Risk Management: Implement custom position limits beyond platform defaults
Working Configurations
- Python SDK: Stable with Python 3.8-3.10, issues with 3.11+
- WebSocket Handling: Build custom reconnection with exponential backoff
- Error Recovery:
docker system prune -a && docker-compose up
for nuclear reset - Dependency Management: Pin specific versions to avoid SSL/numpy conflicts
Critical Warnings
What Documentation Doesn't Tell You
- Scalping Limitation: 1-second strategies get rate-limited immediately
- WebSocket Reliability: Expect disconnections during high volatility
- Paper Trading Deception: Performance gap is significant and predictable
- Spread Impact: Small-cap stocks have spreads that devour algorithmic returns
- SSL Certificate Issues: Newer Python versions break randomly
Breaking Points
- Rate Limits: Hit at 50 requests/minute despite 200/minute limit
- Memory Usage: Long-running bots develop memory leaks
- Network Stability: WSL2 users experience predictable 20-minute disconnections
- Market Volatility: All connection issues worsen during high-volume periods
Risk Controls Reality
- Platform Safeguards: Basic position limits and PDT compliance only
- Custom Implementation Required: Day trading limits, sector concentration, stop-losses
- Margin Calls: Trigger at worst possible timing
- Account Protection: FINRA/SIPC coverage for platform failures, not trading losses
Decision Criteria
Choose Alpaca When:
- Building US-focused retail trading bots
- Need crypto integration
- Want simple HTTP API over Java complexity
- Commission-free structure is priority
- Development speed matters over advanced features
Avoid Alpaca When:
- Requiring international markets
- High-frequency trading (sub-minute)
- Need ultra-reliable connections during volatility
- Complex multi-asset strategies
- Institutional-grade risk management required
Migration Considerations
- From IBKR: Significant simplification but feature reduction
- From Schwab/TD: Similar features, better developer experience
- To Production: Expect 6-month development cycle for robust system
- Cost Analysis: Free tier sufficient for learning, $99/month for serious trading
Troubleshooting Guide
Common SSL/Connection Fixes
# Nuclear option for connection issues
docker system prune -a && docker-compose up
# Dependency reset
rm -rf node_modules && npm install
# Or for Python
pip uninstall alpaca-trade-api && pip install alpaca-trade-api==1.4.1
Error Code Meanings
ssl.SSLEOFError
: Python version compatibility issueConnectionResetError [Errno 104]
: Alpaca server instability403 Forbidden rate limit
: Actual usage exceeds documented limitsKeyError: 'timestamp'
: JSON response validation failureHTTP 404 WebSocket
: Complete environment reset required
Support Resources Quality
- GitHub Issues: Responsive, actual solutions
- Community Forum: Slow but helpful for trading-specific problems
- Discord: 24/7 community support, best for urgent issues
- Documentation: Accurate examples that work when copied
- Status Page: Essential bookmark for production deployments
Useful Links for Further Investigation
Resources That Don't Suck (For Once)
Link | Description |
---|---|
Alpaca Trading API Documentation | Their REST API docs are surprisingly readable - clear examples that actually work when you copy-paste them instead of exploding |
WebSocket Streaming Documentation | Real-time feeds that disconnect less than you'd expect (still crap out during high volatility when you need them most) |
Market Data API Reference | Historical data that doesn't cost $500/month like Bloomberg's highway robbery. Quality varies but it's reasonably priced |
Python SDK - alpaca-trade-api-python | Actually maintained and works with modern Python versions (mostly). Watch out for SSL nonsense in newer Python versions |
JavaScript/Node.js SDK | Does what it promises. Async/await support that doesn't randomly explode in your face |
Go SDK | For when you need speed and enjoy the masochism of writing Go for trading |
Building Your First Trading Bot | Skip the theory sections, go straight to the code examples. The paper trading walkthrough is solid |
Options Trading Tutorial | Multi-leg options if you want to lose money in creative ways |
Alpaca Community Forum | Responses take forever but people actually help. Better than Stack Overflow for trading-specific nonsense |
GitHub Issues | They actually respond to bug reports (shocking for a fintech company, I know) |
System Status Page | Bookmark this immediately - you'll need it when your bot mysteriously stops working during market hours |
Postman Collection | Pre-built requests so you don't have to write curl commands like a caveman |
TradingView Integration | Connect alerts from TradingView. Works better than most webhook implementations |
Interactive Brokers API | More powerful but feels like it was designed by people who despise happiness. Java gateway that breaks constantly and makes you question your life choices |
Charles Schwab Developer Platform | Decent but API responses move like molasses. Their OAuth implementation is a special kind of torture |
Polygon.io Market Data | Better data quality than Alpaca but costs real money. Use when Alpaca's data looks questionable |
Related Tools & Recommendations
Alpaca Trading API Production Deployment Guide
Master Alpaca Trading API production deployment with this comprehensive guide. Learn best practices for monitoring, alerts, disaster recovery, and handling real
Alpaca-py - Python Stock Trading That Doesn't Suck
Explore Alpaca-py, the official Python SDK for Alpaca's trading APIs. Learn installation, API key setup, and how to build powerful stock trading strategies with
Alpaca Trading API Integration - Real Developer's Guide
Master Alpaca Trading API integration with this developer's guide. Learn architecture, avoid common mistakes, manage API keys, understand rate limits, and choos
TWS Will Make You Hate Your Life (Until You Don't)
Look, I've Been Using TWS for 4 Years and It Still Pisses Me Off
IBKR: Powerful But Complicated - Here's Whether It's Worth The Headache
The honest truth about Interactive Brokers from someone who's actually used it for 3 years
ib_insync is Dead, Here's How to Migrate Without Breaking Everything
ibinsync → ibasync: The 2024 API Apocalypse Survival Guide
Interactive Brokers vs Charles Schwab vs Fidelity vs TD Ameritrade vs E*TRADE - Which Actually Works
Stop Overthinking It - Here's Which Broker Actually Works for Your Situation
pandas - The Excel Killer for Python Developers
Data manipulation that doesn't make you want to quit programming
Fixing pandas Performance Disasters - Production Troubleshooting Guide
When your pandas code crashes production at 3AM and you need solutions that actually work
When pandas Crashes: Moving to Dask for Large Datasets
Your 32GB laptop just died trying to read that 50GB CSV. Here's what to do next.
JupyterLab Performance Optimization - Stop Your Kernels From Dying
The brutal truth about why your data science notebooks crash and how to fix it without buying more RAM
JupyterLab Getting Started Guide - From Zero to Productive Data Science
Set up JupyterLab properly, create your first workflow, and avoid the pitfalls that waste beginners' time
JupyterLab Debugging Guide - Fix the Shit That Always Breaks
When your kernels die and your notebooks won't cooperate, here's what actually works
jQuery - The Library That Won't Die
Explore jQuery's enduring legacy, its impact on web development, and the key changes in jQuery 4.0. Understand its relevance for new projects in 2025.
Hoppscotch - Open Source API Development Ecosystem
Fast API testing that won't crash every 20 minutes or eat half your RAM sending a GET request.
Stop Jira from Sucking: Performance Troubleshooting That Works
Frustrated with slow Jira Software? Learn step-by-step performance troubleshooting techniques to identify and fix common issues, optimize your instance, and boo
TradingView - Where Traders Go to Avoid Paying $2,000/Month for Bloomberg
The charting platform that made professional-grade analysis accessible to anyone who isn't JPMorgan
Get Alpaca Market Data Without the Connection Constantly Dying on You
WebSocket Streaming That Actually Works: Stop Polling APIs Like It's 2005
Northflank - Deploy Stuff Without Kubernetes Nightmares
Discover Northflank, the deployment platform designed to simplify app hosting and development. Learn how it streamlines deployments, avoids Kubernetes complexit
LM Studio MCP Integration - Connect Your Local AI to Real Tools
Turn your offline model into an actual assistant that can do shit
Recommendations combine user behavior, content similarity, research intelligence, and SEO optimization