Broker API
Alpaca trading API
US stock, ETF, options and crypto broker, not CFDs or FX: REST Trading API and Market Data API with WebSocket streams, paper trading on its own host.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
Quickstart: key to first call25 endpoints9 messages26 error codes
Alpaca API rate limits and allowances
One record per limit. The scope is part of the limit: a figure without its scope is not a figure you can pace against.
| Limit | Value | Scope | Source |
|---|---|---|---|
| client_order_id length | 128 | POST /v2/orders and PATCH /v2/orders/{order_id} | docs.alpaca.marketschecked |
| Crypto order size | 200,000 | Crypto spot orders, buy or sell | docs.alpaca.marketschecked |
| Market data historical API, Basic plan | 200 | Market Data API historical calls, Basic (free) plan | docs.alpaca.marketschecked |
| Market data points per page | 10,000 | Market Data API historical bars, trades and quotes, counted across all symbols | docs.alpaca.marketschecked |
| Market data historical API, Algo Trader Plus | 10,000 | Market Data API historical calls, Algo Trader Plus plan (99 US dollars a month) | docs.alpaca.marketschecked |
| GTC order age | 90 | Orders with time in force gtc | docs.alpaca.marketschecked |
| Trading API request rate | HTTP 429 above the limit, with X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset headers on replies; no figure on the pages opened | Trading API, per account | docs.alpaca.marketschecked |
| Market data WebSocket authentication timeout | 10 | Market data WebSocket, from connecting to the auth message | docs.alpaca.marketschecked |
| Market data WebSocket connections | Depends on the subscription; 1 for many subscriptions and with none. A second connection is answered with error 406 connection limit exceeded | Market data WebSocket, per account | docs.alpaca.marketschecked |
| Market data WebSocket symbols, Basic plan | 30 | Market data WebSocket, US equities, Basic (free) plan; Algo Trader Plus is unlimited | docs.alpaca.marketschecked |
Alpaca API rate limits in full, with pacing advice and the related error codes.
Access, authentication and streaming
API types listed in the record: REST (Trading API v2), REST (Market Data API), WebSocket streaming.
- How you get a key
Sign up on Alpaca's site with an email address for a Paper Only Account, which gives API access and a dashboard. A paper account has its own API keys, separate from any live account, and the dashboard shows the paper base address. Alpaca's pages do not print the menu steps that generate a key.
Alpaca docs: Paper Tradingchecked Alpaca docs: About Trading APIchecked
- Who can use it
Paper Only Account: anyone, anywhere, with an email address. Live brokerage accounts: individual taxable accounts and business accounts (corporations, LLCs and partnerships, with a 30,000 US dollar minimum deposit), for people and entities from around the world; retirement accounts are not supported. Live accounts are opened as margin accounts; margin trading and short selling need 2,000 US dollars or more of equity. Crypto trading is open in select international and some US jurisdictions.
Alpaca docs: Trading Accountchecked Alpaca docs: Crypto Spot Tradingchecked
- Demo
Yes: paper trading, a real time simulation on its own host, https://paper-api.alpaca.markets, with its own API keys. New paper accounts start with 100,000 US dollars by default; the dashboard can open and delete paper accounts. Fills are simulated from real time quotes against the NBBO; market impact, slippage from latency, queue position, regulatory fees and dividends are not modelled, and about one order in ten gets a partial fill of random size. A Paper Only Account gets IEX data only.
Alpaca docs: Paper Tradingchecked
- Authentication
Two headers on every request, APCA-API-KEY-ID and APCA-API-SECRET-KEY, or HTTP Basic with the key id as the user name and the secret as the password. Live and paper credentials are separate and neither works on the other host. OAuth 2.0 client credentials are documented for the Broker API and marked not yet available for the Trading API.
Alpaca docs: Authenticationchecked
- Streaming
Two WebSocket streams. Account events: wss://paper-api.alpaca.markets/stream and wss://api.alpaca.markets/stream, where a client sends an auth message, then a listen message for the trade_updates stream, and receives one message per order event (new, fill, partial_fill, canceled, expired, replaced and the rest). Market data: wss://stream.data.alpaca.markets/{version}/{feed}, with feeds v2/iex, v2/sip, v2/delayed_sip, v1beta1/boats and v1beta1/overnight for stocks, v1beta3/crypto/{loc} for crypto and v2/test outside market hours, where a client authenticates within 10 seconds, then subscribes by channel (trades, quotes, bars and others) and symbol. Messages are JSON arrays, or MessagePack where the client asks. The connection limit depends on the subscription and is 1 for many; a second connection gets error 406.
Alpaca docs: Websocket Streamingchecked Alpaca docs: WebSocket Stream (market data)checked Alpaca docs: Real-time Stock Datachecked Alpaca docs: Real-time Crypto Datachecked
- Rate limits, as worded
The Trading API OpenAPI document gives HTTP 429 for too many requests, with X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset headers on replies, and no figure on the pages opened. The Market Data API pages give figures by plan: the historical API allows 200 calls a minute on the free Basic plan and 10,000 calls a minute on Algo Trader Plus (99 US dollars a month). Basic allows up to 30 WebSocket symbol subscriptions for equities and 200 quote subscriptions for options; Algo Trader Plus has unlimited equity subscriptions and 1,000 option quote subscriptions.
Alpaca Trading API OpenAPI documentchecked Alpaca docs: About Market Data APIchecked
- History depth
Stock history since 2016 on both market data plans; the Basic plan is limited to data at least 15 minutes old for SIP, so a query for recent SIP trades or quotes needs Algo Trader Plus. Historical requests page at up to 10,000 data points per page, 1,000 by default, counted across all symbols. The market calendar covers 1970 to 2029.
Alpaca docs: About Market Data APIchecked Alpaca docs: Market Data FAQchecked Alpaca Market Data API OpenAPI documentchecked Alpaca reference: Get US Market Calendarchecked
- own_api
Alpaca publishes its own REST Trading API (v2, with paper and live hosts), its own Market Data API on data.alpaca.markets and WebSocket streams for both, with OpenAPI documents for each. The Broker API is a separate business to business product and is outside this site's scope.
Alpaca docs: About Trading APIchecked Alpaca docs: SDKs and Toolschecked Alpaca docs: Authenticationchecked
Alpaca API endpoints
25 documented endpoints. Grouped by what they do
- GET/v1beta3/crypto/{loc}/barsHistorical bars for a list of crypto pairs at one location, paged. The one market data call the FAQ says needs no authentication for history.
- GET/v2/accountThe account behind the keys: status, cash, equity, buying power and margin figures. Start here to prove the keys work.
- GET/v2/account/activitiesThe account's activity log: fills (FILL) and non trade activities such as dividends, fees and journals, paged.
- GET/v2/account/portfolio/historyThe account's equity and profit or loss over time, as parallel arrays of timestamps and values.
- GET/v2/assetsLists assets Alpaca knows: symbol, exchange, class and whether each is tradable, marginable, shortable and fractionable.
- GET/v2/assets/{symbol_or_asset_id}One asset by symbol or asset id, with its dealing flags. 404 where it is not found.
- GET/v2/calendarThe US market calendar: each trading day with its open and close times and settlement date, from 1970 to 2029.
- GET/v2/clockThe US market clock: the current time, whether the market is open, and the next open and close.
- DELETE/v2/ordersCancels every open order on the account. Replies 207 with one status per order.
- GET/v2/ordersLists orders: open ones by default, or closed or all, newest first, with paging by time or by order id.
- POST/v2/ordersPlaces an order: market, limit, stop, stop limit or trailing stop, alone or as a bracket, OCO, OTO or multi leg order. The reply is the Order with its id.
- GET/v2/orders:by_client_order_idOne order by the client_order_id you gave it.
- DELETE/v2/orders/{order_id}Cancels one open order. 204 with no body on success; 422 where the order can no longer be cancelled.
- GET/v2/orders/{order_id}One order by its id, whatever its state: status, filled quantity and average fill price.
- PATCH/v2/orders/{order_id}Replaces an open order with new quantity, prices, time in force or trail. The reply is a new Order with a new id.
- GET/v2/positionsEvery open position on the account: symbol, quantity, side, average entry, market value and unrealised profit or loss.
- DELETE/v2/positions/{symbol_or_asset_id}Closes one open position, in full or in part, by placing the closing order. The reply is that order.
- GET/v2/positions/{symbol_or_asset_id}One open position, by symbol or by asset id.
- GET/v2/stocks/barsHistorical bars (OHLC with volume, trade count and VWAP) for a list of stock symbols, sorted by symbol then time, paged.
- GET/v2/stocks/quotes/latestThe latest best bid and ask for a list of stock symbols: one quote per symbol.
- GET/v2/stocks/snapshotsFor each symbol, the latest trade, latest quote, current minute bar, current daily bar and previous daily bar in one reply.
- GET/v2/stocks/tradesHistorical trades (prints) for a list of stock symbols, sorted by symbol then time, paged.
- POST/v2/watchlistsCreates a watchlist with a name and, optionally, a first set of symbols.
- GET/v2/watchlistsEvery watchlist on the account, without their assets.
- GET/v2/watchlists/{watchlist_id}One watchlist by id, with its assets.
Alpaca messages
9 documented messages and subscriptions of the Alpaca WebSocket streams. They are not HTTP endpoints: none has a method or a path, and each travels over a connection that stays open. Grouped by what they do, each with its summary
Alpaca API error codes
26 decoded error codes. All Alpaca errors
400The market data stream's error 400, invalid syntax: the message sent could not be parsed.401The market data stream's error 401, not authenticated: a message other than auth arrived before the connection was authenticated.402The market data stream's error 402, auth failed: the key id and secret were not accepted, or the feed is not in your subscription.403The market data stream's error 403, already authenticated: a second auth message on a connection that was already authenticated.404The market data stream's error 404, auth timeout: no auth message arrived within the 10 seconds the page allows after connecting.405The market data stream's error 405, symbol limit exceeded: the subscribe message would take the connection past the number of symbols the plan allows.406The market data stream's error 406, connection limit exceeded: a second connection where the plan allows one.407The market data stream's error 407, slow client: the client is not reading messages as fast as the server sends them.409The market data stream's error 409, insufficient subscription: the feed or channel asked for is not in the plan.410The market data stream's error 410: the subscribe action named a channel the connected feed does not serve.42210000The code in the body of a 422 reply.500The market data stream's error 500, internal error, on Alpaca's side.HTTP 400One of the request's parameters is invalid.HTTP 401 (market data)The Market Data API's shared reply where the authentication headers are missing or invalid.HTTP 403Forbidden.HTTP 404Not found: an asset by symbol or id, a watchlist by id, or on the market data host a feed that does not exist.HTTP 422Unprocessable.HTTP 429Too many requests: the rate limit was hit.HTTP 500Internal server error on Alpaca's side.HTTP 504Gateway timeout, listed among the replies of GET /v2/account/portfolio/history.internal server errorThe error_message of an error action on the account stream, which the page says the server sends before closing the connection.order_An event on the trade_updates stream: a request to cancel the order was rejected.cancel_ rejected order_An event on the trade_updates stream: a request to replace the order was rejected.replace_ rejected rejectedAn event on the trade_updates stream: the order was rejected.unable to open new notional orders while having open closing position ordersThe message the Placing Orders page gives when a notional order is rejected because a closing order on the same position is still open, in the sequences outside market hours that Alpaca stopped accepting from 27 October 2021.unauthorizedThe status in an authorization message on the account stream: the auth message failed, or a listen message was sent before the connection was authorised (then the message carries action listen).
Alpaca API SDKs and wrappers
| Library | Language | Official | Note | Source |
|---|---|---|---|---|
| alpaca-py | Python | Official | Listed on Alpaca's SDK page as its Python SDK. | docs.alpaca.marketschecked |
| alpaca-trade-api-js | JavaScript (Node) | Official | Not recorded | docs.alpaca.marketschecked |
| alpaca-trade-api-csharp | C# (.NET) | Official | Not recorded | docs.alpaca.marketschecked |
| alpaca-trade-api-go | Go | Official | Not recorded | docs.alpaca.marketschecked |
| alpaca-java | Java | Official | Not recorded | docs.alpaca.marketschecked |
Alpaca API: questions and answers
Each answer is read from the record on this page, not written separately. Where the record is unverified, the answer says so.
Does Alpaca have an API?
Unverified. Yes. This register records Alpaca as having its own API (REST (Trading API v2), REST (Market Data API) and WebSocket streaming), with availability marked as active. US stock, ETF, options and crypto broker, not CFDs or FX: REST Trading API and Market Data API with WebSocket streams, paper trading on its own host. No source is recorded against this entry.
Unverifiedno source opened
Alpaca API key: how do I get one?
Sign up on Alpaca's site with an email address for a Paper Only Account, which gives API access and a dashboard. A paper account has its own API keys, separate from any live account, and the dashboard shows the paper base address.
Alpaca docs: Paper Tradingchecked Alpaca docs: About Trading APIchecked
Who can use the Alpaca API?
Paper Only Account: anyone, anywhere, with an email address.
Alpaca docs: Trading Accountchecked Alpaca docs: Crypto Spot Tradingchecked
Alpaca API demo: is there a demo or sandbox?
Yes: paper trading, a real time simulation on its own host, https://paper-api.alpaca.markets, with its own API keys. New paper accounts start with 100,000 US dollars by default; the dashboard can open and delete paper accounts.
Alpaca docs: Paper Tradingchecked
What are the Alpaca API rate limits?
client_order_id length: 128 characters. Scope: POST /v2/orders and PATCH /v2/orders/{order_id}. Crypto order size: 200,000 US dollars notional per order. Scope: Crypto spot orders, buy or sell. Market data historical API, Basic plan: 200 requests per minute. Scope: Market Data API historical calls, Basic (free) plan. Market data points per page: 10,000 data points per page. Scope: Market Data API historical bars, trades and quotes, counted across all symbols. Market data historical API, Algo Trader Plus: 10,000 requests per minute. Scope: Market Data API historical calls, Algo Trader Plus plan (99 US dollars a month). GTC order age: 90 days. Scope: Orders with time in force gtc. Trading API request rate: HTTP 429 above the limit, with X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset headers on replies; no figure on the pages opened. Scope: Trading API, per account. Market data WebSocket authentication timeout: 10 seconds. Scope: Market data WebSocket, from connecting to the auth message. Market data WebSocket connections: Depends on the subscription; 1 for many subscriptions and with none. A second connection is answered with error 406 connection limit exceeded. Scope: Market data WebSocket, per account. Market data WebSocket symbols, Basic plan: 30 symbol subscriptions. Scope: Market data WebSocket, US equities, Basic (free) plan; Algo Trader Plus is unlimited. As the record words it: The Trading API OpenAPI document gives HTTP 429 for too many requests, with X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset headers on replies, and no figure on the pages opened.
docs.alpaca.marketschecked docs.alpaca.marketschecked docs.alpaca.marketschecked docs.alpaca.marketschecked docs.alpaca.marketschecked docs.alpaca.marketschecked
How does Alpaca API authentication work?
Two headers on every request, APCA-API-KEY-ID and APCA-API-SECRET-KEY, or HTTP Basic with the key id as the user name and the secret as the password. Live and paper credentials are separate and neither works on the other host.
Alpaca docs: Authenticationchecked
Does the Alpaca API support streaming?
Two WebSocket streams.
Alpaca docs: Websocket Streamingchecked Alpaca docs: WebSocket Stream (market data)checked Alpaca docs: Real-time Stock Datachecked Alpaca docs: Real-time Crypto Datachecked
How much history does the Alpaca API return?
Stock history since 2016 on both market data plans; the Basic plan is limited to data at least 15 minutes old for SIP, so a query for recent SIP trades or quotes needs Algo Trader Plus.
Alpaca docs: About Market Data APIchecked Alpaca docs: Market Data FAQchecked Alpaca Market Data API OpenAPI documentchecked Alpaca reference: Get US Market Calendarchecked
Is there a Python library for the Alpaca API?
This register lists one Python library for the Alpaca API. alpaca-py (official, Python): Listed on Alpaca's SDK page as its Python SDK.
alpaca-pychecked
Alpaca API questions, each answered in a sentence or two.
The capability tables read one feature at a time across every broker and platform record, Alpaca included.
Everything this site records for Alpaca, as one JSON file. Each section of the file states its own licence. About the files. This page as Markdown.
Alpaca API guides and reference
How to cite this
Alpaca trading API. Broker API Hub, https://openbrokerapi.com/brokers/alpaca, newest check .
Where you rely on a single figure, cite the source and the checked date printed beside it as well.