Alpaca

US equities, options, and crypto via Alpaca. Connect with one line.

Alpaca is a commission-free US broker with a clean REST + WebSocket API, a free paper sandbox, and equity / option / crypto coverage. Usable from the core library via hz.connect("alpaca", ...).

Connect

python
import horizon as hz

ex = hz.connect("alpaca",
    paper=True,                    # False for live
    api_key="APCA-...",
    api_secret="...",
)
ex.buy("AAPL", qty=10, limit=180.0)
print(ex.positions())
ex.close()

Kwargs

KwargTypeDefaultNotes
paperboolTruePaper sandbox vs. live. Fail-safe default.
api_keystr \| NoneNoneFalls back to secrets / env (ALPACA_API_KEY).
api_secretstr \| NoneNoneFalls back to secrets / env (ALPACA_SECRET_KEY).
secretsSecrets \| NoneNoneCredential resolver (see Secrets).
http_clientHttpClient \| NoneRate-limited defaultInject for tests or custom retry.
budget_usdfloat0.0Optional hard cap on notional the venue will accept.

Credentials are resolved in order: explicit kwarg → secrets.get("alpaca.api_key") → environment variable. Use whichever fits your deployment.

Install

bash
pip install -e ".[equity]"          # alpaca-py + ib_async + pandas-ta
# add validate for stats inference (scipy + sklearn)
pip install -e ".[equity,validate]"
# add options for the options chain / IV path
pip install -e ".[equity,options,validate]"

Bracket / OCO / OTO order

python
from horizon.types import OrderAction

action = OrderAction.place(
    market_id="AAPL", side="buy", quantity=10, price=180.0,
    order_class="bracket",
    take_profit_price=190.0,
    stop_loss_price=175.0,
)
ex.venue.submit(action)

The venue rejects a bracket / OCO with a missing leg before anything hits Alpaca. Details: Alpaca pro docs.

Options chain

python
chain = ex.venue.options_chain(
    "AAPL", expiry="2026-06-19", option_type="call",
    strike_gte=175.0, strike_lte=200.0,
)
for row in chain:
    print(row["symbol"], row.get("impliedVolatility"))

Pair with horizon.stats.iv_rank / iv_hv_spread for an end-to-end research workflow.

Status

  • REST submit / cancel / amend: shipped.
  • Bracket / OCO / OTO as one ticket: shipped.
  • Options chain snapshot: shipped (Alpaca.options_chain).
  • Polling drain_fills(): shipped.
  • WebSocket order stream + quote feed: see horizon.data.live.alpaca_ws.
  • Rate-limited HTTP, exponential backoff, audit chain integration: shipped.
  • Multi-leg options combos / spreads: follow-up.

Examples

Full integration details, wire formats, error mapping: Alpaca (professionals).