Actively developed

alpaca-py guide

alpaca-py is the most direct way to script Alpaca, one of the most developer-friendly US brokers.

Last reviewed · Also known as alpaca-trade-api, alpaca python sdk

Quick answer

alpaca-py is Alpaca’s official Python SDK, replacing the older alpaca-trade-api package. It provides typed request models and clients for trading (TradingClient), historical data (StockHistoricalDataClient, CryptoHistoricalDataClient, options) and live WebSocket streams, with paper=True for Alpaca’s free paper account.

alpaca-py at a glance

Category
Broker, exchange & data libraries
Language
Python
License
Apache-2.0
Does
Market data, Order execution, Paper trading
Markets
Stocks, ETFs, Options, Crypto
Best for
US stock, options and crypto automation on Alpaca.
In AlgoGP
Use the exported strategy object from your own code

Pick it if

US stock, options and crypto automation on Alpaca.

Watch out for

Alpaca only.

alpaca-py strengths and limitations

Strengths

  • Official, typed SDK.
  • Free paper trading.
  • Stocks, options and crypto in one API.

Limitations

  • Alpaca only.
  • Free data plan is IEX-only for real-time stocks.

alpaca-py example

pip install alpaca-py
Install
from alpaca.trading.client import TradingClient
from alpaca.trading.requests import MarketOrderRequest
from alpaca.trading.enums import OrderSide, TimeInForce
client = TradingClient("KEY_ID", "SECRET", paper=True)
client.submit_order(MarketOrderRequest(symbol="AAPL", qty=1, side=OrderSide.BUY, time_in_force=TimeInForce.DAY))
Paper market order.

Use alpaca-py with AlgoGP

AlgoGP does not add alpaca-py to projects automatically yet, but nothing stops you using them together. Every AlgoGP project exports plain Python with a framework-neutral strategy object, so you can call it from alpaca-py yourself.

  1. 1

    Design and backtest in AlgoGP

    Describe the idea to the copilot and backtest it on AlgoGP’s normalized history.

  2. 2

    Add any bridge to get the adapter core

    Adding a bridged framework (for example Backtrader) writes frameworks/algogp_bridge.py, whose StrategyBridge.on_bar() returns the orders the strategy wants.

  3. 3

    Call it from alpaca-py

    Feed alpaca-py’s bars to StrategyBridge, place the returned orders with alpaca-py, and report fills back with sync().

alpaca-py connects to Alpaca. Each guide shows how to create the API key, which you can store in the project’s Keys & secrets.

alpaca-py: frequently asked questions

Do I need alpaca-py for AlgoGP?

No. AlgoGP’s exported code has a built-in standard-library Alpaca adapter; alpaca-py is useful for your own extensions.

alpaca-py alternatives

Independent guide. AlgoGP is not affiliated with alpaca-py. Features, licenses and maintenance change; check the official documentation. Nothing here is investment advice.

Build a strategy