ALPACA_DATA_ENABLED=true. The same API key and secret are used for both; the base URL selects paper vs live.
1. Overview
If Alpaca keys are not set, trading uses
MockTradingAPIService. If ALPACA_DATA_ENABLED is false or Alpaca returns no data, market data falls back to yahooquery (see Stock Prediction Setup).
1.1 Broker API (Multiuser Brokerage)
For multiuser brokerage (one Alpaca customer account per user), use the Alpaca Broker API:
Set
ALPACA_BROKER_* env vars. See Account Opening and Broker API.
2. Configuration
Broker API (multiuser):
ALPACA_BROKER_API_KEY, ALPACA_BROKER_API_SECRET, ALPACA_BROKER_BASE_URL (sandbox: https://broker-api.sandbox.alpaca.markets), ALPACA_BROKER_PAPER.
3. Getting Alpaca Credentials
- Sign up at Alpaca.
- Paper: Paper Dashboard → API Keys.
- Live: Live Dashboard → API Keys. Use with care.
ALPACA_BASE_URL=https://paper-api.alpaca.markets for paper and https://api.alpaca.markets for live.
4. Trading (Place Order, Portfolio, Market Data Tab)
- Place order:
POST /api/trades/orders— usesAlpacaTradingAPIServicewhen keys are set. - Portfolio:
GET /api/trades/portfolio— positions and account info from Alpaca. - Market data:
GET /api/trades/market-data,GET /api/trades/market-data/{symbol}— bid/ask etc. from Alpaca.
MockTradingAPIService is used: orders are simulated, no real broker calls.
5. Historical Data (Stock Prediction and Backtesting)
WhenALPACA_DATA_ENABLED=true and keys are set, MarketDataService.get_historical_data uses alpaca.data.StockHistoricalDataClient for 1D, 1H, 15Min. If Alpaca returns nothing, it falls back to yahooquery.
- Data client: Separate from trading; uses the same
ALPACA_API_KEYandALPACA_API_SECRET. - Timeframes: 1D, 1H, 15Min.
- Used by:
StockPredictionService(daily/hourly/15min) andrun_backtest_from_data_source.
6. Dependencies
alpaca-py is required for both trading and historical data:
modal image used for Chronos already includes alpaca-py; the FastAPI app needs it when ALPACA_DATA_ENABLED=true or when Alpaca is used for trading.