Alpaca Trade API Python (deprecated)
raw JSON → 3.2.0 verified Tue May 12 auth: no python install: verified quickstart: stale deprecated
DEPRECATED. alpaca-trade-api (3.2.0) is the old Alpaca Python SDK — deprecated in 2022, no new features, no patches. The official replacement is 'alpaca-py' (pip install alpaca-py). LLMs heavily trained on alpaca-trade-api tutorials since it dominated for years. New projects must use alpaca-py. alpaca-trade-api still installs and partially works but uses the old v1/v2 API patterns.
pip install alpaca-py Common errors
error ModuleNotFoundError: No module named 'alpaca_trade_api' ↓
cause The 'alpaca_trade_api' module is not installed or not found in the Python environment.
fix
Install the module using 'pip install alpaca-trade-api'.
error alpaca_trade_api.rest.APIError: endpoint not found ↓
cause Attempting to access an unsupported asset class, such as currency pairs like 'USD/JPY', which are not available on Alpaca.
fix
Ensure that the asset being accessed is supported by Alpaca, such as US stocks, ETFs, or cryptocurrencies.
error alpaca_trade_api.rest.APIError: limit price increment must be > 0.1 ↓
cause Submitting a limit order with a price increment less than the minimum allowed (0.1).
fix
Adjust the limit price to ensure the increment is at least 0.1.
error alpaca_trade_api.rest.APIError: account is not authorized to trade ↓
cause The account is not permitted to submit orders, possibly due to trading being disabled or the account not being in an active trading state.
fix
Verify the account status and ensure it is active and authorized for trading.
error alpaca_trade_api.rest.APIError: account is restricted to liquidation only ↓
cause The account is set to liquidation-only mode, allowing only the closing of existing positions.
fix
Contact Alpaca support to understand the restriction and request the removal of the liquidation-only status if appropriate.
Warnings
breaking alpaca-trade-api deprecated 2022. No new features or bug fixes. Official replacement is 'alpaca-py' (pip install alpaca-py). ↓
fix pip install alpaca-py; from alpaca.trading.client import TradingClient
breaking alpaca-py has completely different import structure. No more tradeapi.REST(). Separate clients for trading, market data, and streaming. ↓
fix TradingClient for orders/account. StockHistoricalDataClient for historical data. StockDataStream for live data.
gotcha Paper trading URL no longer needed explicitly. Pass paper=True to TradingClient instead of base_url='https://paper-api.alpaca.markets'. ↓
fix TradingClient(api_key=..., secret_key=..., paper=True)
gotcha alpaca-py orders require typed request objects (MarketOrderRequest, LimitOrderRequest) — not plain dicts. ↓
fix from alpaca.trading.requests import MarketOrderRequest; trading.submit_order(MarketOrderRequest(...))
gotcha API calls result in 'Unauthorized' (HTTP 401) if API Key ID or Secret Key are incorrect or missing when initializing `TradingClient`. This typically manifests as an `APIError: {"message": "unauthorized."}` exception. ↓
fix Ensure you are using valid API Key ID and Secret Key for your Alpaca account. Double-check environment variables or the `api_key` and `secret_key` parameters passed directly to `TradingClient`.
gotcha The `alpaca-py` library, particularly modules like `alpaca.data`, may implicitly depend on `pytz`, which is not always automatically installed as a direct dependency during `pip install alpaca-py`. ↓
fix pip install pytz
Install
pip install alpaca-trade-api Install compatibility verified last tested: 2026-05-12
python os / libc variant status wheel install import disk
3.10 alpine (musl) alpaca-py - - - 269.1M
3.10 alpine (musl) alpaca-trade-api - - - 183.3M
3.10 slim (glibc) alpaca-py - - - 329M
3.10 slim (glibc) alpaca-trade-api - - - 177M
3.11 alpine (musl) alpaca-py - - - 285.9M
3.11 alpine (musl) alpaca-trade-api - - - 198.3M
3.11 slim (glibc) alpaca-py - - - 345M
3.11 slim (glibc) alpaca-trade-api - - - 192M
3.12 alpine (musl) alpaca-py - - - 268.7M
3.12 alpine (musl) alpaca-trade-api - - - 181.2M
3.12 slim (glibc) alpaca-py - - - 328M
3.12 slim (glibc) alpaca-trade-api - - - 175M
3.13 alpine (musl) alpaca-py - - - 264.4M
3.13 alpine (musl) alpaca-trade-api - - - 177.5M
3.13 slim (glibc) alpaca-py - - - 326M
3.13 slim (glibc) alpaca-trade-api - - - 171M
3.9 alpine (musl) alpaca-py - - - 277.6M
3.9 alpine (musl) alpaca-trade-api - - - 191.8M
3.9 slim (glibc) alpaca-py - - - 341M
3.9 slim (glibc) alpaca-trade-api - - - 188M
Imports
- alpaca-py (replacement — recommended) wrong
# Deprecated — do not use for new projects import alpaca_trade_api as tradeapi api = tradeapi.REST( key_id='YOUR_API_KEY', secret_key='YOUR_SECRET_KEY', base_url='https://paper-api.alpaca.markets' ) account = api.get_account()correct# pip install alpaca-py from alpaca.trading.client import TradingClient from alpaca.trading.requests import MarketOrderRequest from alpaca.trading.enums import OrderSide, TimeInForce client = TradingClient( api_key='YOUR_API_KEY', secret_key='YOUR_SECRET_KEY', paper=True # paper trading ) # Get account account = client.get_account() print(account.portfolio_value) # Place market order order_data = MarketOrderRequest( symbol='AAPL', qty=1, side=OrderSide.BUY, time_in_force=TimeInForce.DAY ) order = client.submit_order(order_data)
Quickstart stale last tested: 2026-04-23
# pip install alpaca-py
from alpaca.trading.client import TradingClient
from alpaca.trading.requests import MarketOrderRequest, GetAssetsRequest
from alpaca.trading.enums import OrderSide, TimeInForce, AssetClass
from alpaca.data.historical import StockHistoricalDataClient
from alpaca.data.requests import StockBarsRequest
from alpaca.data.timeframe import TimeFrame
from datetime import datetime
# Trading client
trading = TradingClient(
api_key='YOUR_KEY',
secret_key='YOUR_SECRET',
paper=True # paper trading account
)
# Account info
account = trading.get_account()
print(f'Portfolio: ${account.portfolio_value}')
# Place order
order = trading.submit_order(MarketOrderRequest(
symbol='TSLA',
qty=1,
side=OrderSide.BUY,
time_in_force=TimeInForce.DAY
))
print(f'Order {order.id}: {order.status}')
# Historical data
data_client = StockHistoricalDataClient('YOUR_KEY', 'YOUR_SECRET')
bars = data_client.get_stock_bars(StockBarsRequest(
symbol_or_symbols='AAPL',
timeframe=TimeFrame.Day,
start=datetime(2024, 1, 1)
))
print(bars['AAPL'][-1].close)