Documentation Index
Fetch the complete documentation index at: https://mathematicalcompany.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Partially verified. As of v0.8.8+, the Alpaca client has been byte-for-byte
audited against
alpaca-py. Several critical bugs were fixed:- Fill polling now uses
/v2/account/activities/FILLinstead of the invalid/v2/orders?status=filledquery (which was silently returning zero fills). Each execution now arrives as its own dedup’d record, so partial fills are no longer lost. client_order_idis generated per submit so retries on network errors are idempotent (no risk of duplicate orders).- Limit-price formatter no longer rounds to 2 decimal places — sub-dollar stocks and crypto pairs trade at their native tick size.
Daytime-in-force is now supported (required for equity options).- Short positions parse with their signed quantity preserved.
Quick Setup
Standalone Equity Trading
Credentials
- Explicit
- Environment variables
Paper vs Live
Alpaca Configuration
| Field | Default | Description |
|---|---|---|
api_key | None | Alpaca API key ID (env: ALPACA_API_KEY or APCA_API_KEY_ID) |
api_secret | None | Alpaca API secret key (env: ALPACA_API_SECRET or APCA_API_SECRET_KEY) |
paper | True | Use paper trading URL |
api_url | Auto | Override API URL (set automatically from paper flag) |
data_source | "iex" | Market data source: "iex" (free) or "sip" (paid, full NBBO) |
Authentication
Alpaca uses header-based auth. No token refresh needed.APCA-API-KEY-ID: {api_key}APCA-API-SECRET-KEY: {api_secret}
Market Data Feed
Stock quotes via WebSocket:wss://stream.data.alpaca.markets/v2/{source} and subscribes to both trades and quotes for each symbol.
Each symbol gets its own snapshot entry keyed by {feed_name}:{SYMBOL} (e.g., tlt:TLT), plus a feed-level entry under the feed name with the last update across all symbols.
| Field | Type | Default | Description |
|---|---|---|---|
symbols | list[str] | required | Stock/ETF tickers to subscribe (e.g., ["TLT", "SPY"]) |
api_key | str | None | Override API key (defaults to env vars) |
api_secret | str | None | Override API secret (defaults to env vars) |
data_source | str | "iex" | "iex" (free, 15-min delayed for some symbols) or "sip" (paid, real-time NBBO) |
Symbol Mapping
Alpaca uses standard stock tickers. No token ID resolution needed:| Horizon Field | Alpaca Field | Notes |
|---|---|---|
OrderRequest.market_id | symbol | Standard ticker (e.g., “AAPL”, “SPY”, “TLT”) |
OrderRequest.order_side | side | "buy" or "sell" |
OrderRequest.price | limit_price | Limit order price |
OrderRequest.size | qty | Supports fractional shares |
Alpaca uses
Side.Long for all positions. Prediction market concepts like Side.Yes / Side.No do not apply to stock orders.Fill Polling
Alpaca fills are polled from theGET /v2/orders?status=filled endpoint. Each cycle:
- Queries recently filled orders
- Deduplicates against previously seen fill IDs (FIFO eviction at 10k)
- Maps Alpaca’s response to Horizon
Fillobjects with exchange-assigned timestamps
Multi-Exchange Hedging
Use Alpaca alongside Polymarket or Kalshi for hedged strategies:market.exchange.
Feature Support Matrix
| Feature | Polymarket | Kalshi | Alpaca |
|---|---|---|---|
| Trading (orders/fills) | Yes | Yes | Yes |
| Orderbook feed | Yes (WS) | Yes (REST) | Yes (WS) |
| Market discovery | Yes | Yes | Yes |
| Hedge pipeline | No | No | Yes |
| Paper trading | No | Yes (demo) | Yes |
| Fractional shares | No | No | Yes |
| LLM forecasting | Yes | Yes | No |
| Resolution analysis | Yes | Yes | No |
Getting API Keys
- Sign up at alpaca.markets
- Go to Paper Trading > API Keys
- Generate a new key pair
- For live trading, switch to Live Trading and generate live keys