Alpaca

Alpaca Trading + Market Data API

Paper-trade US stocks and crypto: account, clock and calendar, orders, positions, and bars, quotes and trades from Market Data.

Finance & bankingGuided#trading#stocks#crypto#paper-trading#market-data#brokerage

Fork copies the collection into your workspace, without the publisher's secrets, so you can add your own key and send requests. Star saves it to your starred APIs (Account › Marketplace) and helps others find it.

Overview

Alpaca offers commission-free trading of US stocks, ETFs, options and crypto through a REST Trading API, plus a Market Data API with historical and latest bars, quotes and trades. Every account comes with a paper trading account that runs against simulated money with the same API, which makes it ideal for building and testing bots. This guided collection is set up for paper trading.

Getting API keys

  1. Create a free account at https://app.alpaca.markets/signup (paper trading is available without funding a live account).
  2. In the dashboard switch to your Paper account, open the API Keys panel on the home page and choose Generate New Keys (or Regenerate).
  3. Copy the Key ID into apiKeyId and the Secret Key into apiSecretKey. The secret is shown only once. Paper and live accounts have different keys.

Guides: https://docs.alpaca.markets/us/docs/getting-started-with-trading-api and https://docs.alpaca.markets/us/docs/authentication

Authentication

Send two headers on every request: APCA-API-KEY-ID and APCA-API-SECRET-KEY. They are added to each request in this collection from the variables. Apps acting for other users use OAuth 2.0 (https://docs.alpaca.markets/us/docs/using-oauth2-and-trading-api) and send a Bearer token instead.

Base URLs

PurposeURL
Trading, paper (this collection)https://paper-api.alpaca.markets
Trading, live moneyhttps://api.alpaca.markets
Market datahttps://data.alpaca.markets (sandbox for Broker API: https://data.sandbox.alpaca.markets)

Switch tradingUrl to the live host only on purpose, with live keys.

Variables and run order

Fill apiKeyId and apiSecretKey. Run 1. Start here (account, market clock and calendar), then 2. Assets to check a symbol is tradable, 3. Orders (places a small limit order far from the market so it rests, then replaces and cancels it; saves orderId), 4. Positions and 5. Market data. Note that orders submitted while the market is closed wait for the next session unless they are extended-hours limit orders.

Data feeds and limits

Stock data comes from a feed: iex (single exchange, included with the free plan), sip (all US exchanges, real time with a paid subscription; free plans see SIP history only up to about 15 minutes ago) and others. Crypto data needs no subscription. The Trading API and Market Data API each enforce per-minute request limits that depend on your plan; a 429 means slow down. See https://docs.alpaca.markets/us/docs/about-market-data-api and the plan comparison on https://alpaca.markets/data.

Common errors

StatusMeaningFix
401 / 40110000Missing or wrong key headersCheck both headers; paper keys only work on the paper host.
403Insufficient buying power or shares, or a feed your plan lacksReduce size, or use feed=iex.
404Unknown order, position or symbolCheck orderId / symbol.
422Invalid order parameters, or order no longer cancelableRead message; e.g. notional only works with market day orders.
429Rate limitBack off and retry.

Links

  • Trading API reference: https://docs.alpaca.markets/us/reference/getaccount-1
  • Orders guide: https://docs.alpaca.markets/us/docs/orders-at-alpaca
  • Market Data reference: https://docs.alpaca.markets/us/reference/stockbars

Endpoints 22

1. Start here

  • GETGet account{{tradingUrl}}/v2/accountReturns the paper (or live) account the keys belong to: status (should be ACTIVE), cash, buying_power, equity, portfolio_value, pattern_day_trader, and flags…
  • GETGet US market clock (v2){{tradingUrl}}/v2/clockTells you whether the US equity market is open right now (is_open) and when it next opens and closes. Check it before sending market orders from a bot. For…
  • GETGet market clock (v3, multiple markets){{tradingUrl}}/v3/clockThe newer clock endpoint. Pass markets as a comma-separated list of market codes (NYSE, NASDAQ, BOATS for overnight, OPRA for options, and non-US markets).…
  • GETGet market calendar (v3){{tradingUrl}}/v3/calendar/NYSELists trading days for one market between start and end (dates, default today to one week later), with pre-market, core and after-hours session times and the…

2. Assets

  • GETGet an asset{{tradingUrl}}/v2/assets/{{symbol}}Reads one asset by symbol (or asset ID) in symbol. Check tradable before ordering, fractionable before sending fractional qty or notional, and shortable /…
  • GETList assets{{tradingUrl}}/v2/assetsReturns the master list of assets, filtered by status (active), asset_class (us_equity, us_option, crypto) and exchange. The list is large; cache it daily…

3. Orders

  • POSTPlace a limit order{{tradingUrl}}/v2/ordersSubmits an order. Required: symbol, side (buy/sell), type (market, limit, stop, stop_limit, trailing_stop) and time_in_force (day, gtc, opg, cls, ioc, fok),…
  • POSTPlace a bracket order{{tradingUrl}}/v2/ordersSubmits an entry order with an attached take-profit and stop-loss (order_class: bracket). When the entry fills, the two exit legs become active and one…
  • GETList orders{{tradingUrl}}/v2/ordersLists orders filtered by status (open by default, closed or all), symbols, side, and time window after / until. limit defaults to 50 (max 500). Set…
  • GETGet an order{{tradingUrl}}/v2/orders/{{orderId}}Reads the order in orderId to follow its status (new, accepted, partially_filled, filled, canceled, rejected, expired ...), filled_qty and filled_avg_price.…
  • PATCHReplace an order{{tradingUrl}}/v2/orders/{{orderId}}Changes an open order: send only what changes among qty, limit_price, stop_price, trail, time_in_force and client_order_id. Alpaca creates a new order that…
  • DELETECancel an order{{tradingUrl}}/v2/orders/{{orderId}}Requests cancellation of the order in orderId. Returns 204 when the request is accepted; the order then moves to pending_cancel and canceled. Returns 422 if…
  • DELETECancel all open orders{{tradingUrl}}/v2/ordersAttempts to cancel every open order. Returns 207 Multi-Status with one entry per order, each with the order id and an HTTP status for that cancellation.…

4. Positions and portfolio

  • GETList open positions{{tradingUrl}}/v2/positionsLists every open position with quantity, side, avg_entry_price, market_value, unrealized_pl and today's change. Empty array when you hold nothing (place and…
  • GETGet a position{{tradingUrl}}/v2/positions/{{symbol}}Reads your position in symbol (or asset ID). Returns 404 when you hold no position in it. qty_available excludes shares tied up in open sell orders.
  • DELETEClose a position{{tradingUrl}}/v2/positions/{{symbol}}Liquidates the position in symbol with a market order. Pass qty (shares) or percentage (0 to 100) to close only part of it; omit both to close everything.…
  • GETGet portfolio history{{tradingUrl}}/v2/account/portfolio/historyReturns equity and profit/loss time series for the account. period is a number plus unit (D, W, M, A) and timeframe is 1Min, 5Min, 15Min, 1H or 1D; long…

5. Market data

  • GETStock bars (historical){{dataUrl}}/v2/stocks/barsReturns OHLCV bars for one or more symbols. timeframe takes forms like 1Min, 15Min, 1Hour, 1Day, 1Week, 1Month. start and end accept RFC 3339 or YYYY-MM-DD.…
  • GETLatest stock quotes{{dataUrl}}/v2/stocks/quotes/latestReturns the latest best bid and ask for each symbol: bp/bs (bid price/size), ap/as (ask), exchange codes bx/ax, and time t. With feed=iex the quote is from…
  • GETLatest stock trades{{dataUrl}}/v2/stocks/trades/latestReturns the most recent trade per symbol: price p, size s, exchange x, conditions c and time t. Trades with conditions that should not update the last price…
  • GETStock snapshots{{dataUrl}}/v2/stocks/snapshotsOne call that returns, per symbol, the latest trade, latest quote, current minute bar, today's daily bar and the previous daily bar. Good for watchlists and…
  • GETCrypto bars (historical){{dataUrl}}/v1beta3/crypto/us/barsReturns OHLCV bars for crypto pairs such as BTC/USD. loc in the path is us for Alpaca's own venue. Crypto market data does not need a paid subscription; the…

API details

Base URL
https://paper-api.alpaca.markets
https://api.alpaca.markets
https://data.alpaca.markets
Authentication
An API key in the APCA-API-KEY-ID header
An API key in the APCA-API-SECRET-KEY header
Operations
22 operations on 22 pathsGET 16DELETE 3POST 2PATCH 1
Main resources
1. Start here 42. Assets 23. Orders 74. Positions and portfolio 45. Market data 5
Description format
Swastik Codes guided collection, API version checked against the docs on 2026-11-18

How to test the Alpaca Trading + Market Data API in Swastik Codes

  1. Open the APISelect “Fork & run in Swastik Codes” on this page. Sign in or create a free account if asked.
  2. Fork it into your workspaceChoose a workspace. You get your own copy of the Alpaca Trading + Market Data API collection, without the publisher's secrets.
  3. Add your credentialsThis API uses an API key in the APCA-API-KEY-ID header. Add yours in the collection's variables or an environment; the requests already reference it.
  4. Send a requestPick an endpoint, for example “Get account” (GET {{tradingUrl}}/v2/account), and press Send. Check the response, add tests and run the whole collection with the runner.

Frequently asked questions

What is the Alpaca Trading + Market Data API?

Paper-trade US stocks and crypto: account, clock and calendar, orders, positions, and bars, quotes and trades from Market Data. It is listed under Finance & banking and has 22 endpoints.

Who publishes the Alpaca Trading + Market Data API?

It is listed from Alpaca's public API description (an OpenAPI document), not published by Alpaca on Swastik Codes. Anyone who controls alpaca.markets can claim the profile by adding a DNS TXT record.

What is the base URL of the Alpaca Trading + Market Data API?

Its description lists 3 base URLs: https://paper-api.alpaca.markets, https://api.alpaca.markets, https://data.alpaca.markets. The first is the usual one; the others are typically sandbox or regional servers.

How do I authenticate with the Alpaca Trading + Market Data API?

It accepts 2 methods: an API key in the APCA-API-KEY-ID header; an API key in the APCA-API-SECRET-KEY header.

How many endpoints does the Alpaca Trading + Market Data API have?

22 operations on 22 paths (16 GET, 3 DELETE, 2 POST, 1 PATCH). The largest groups are 1. Start here, 2. Assets, 3. Orders, 4. Positions and portfolio.

Is forking the Alpaca Trading + Market Data API free?

Yes. Forking copies the collection into your workspace for free. It has been starred 0 times and forked 0 times.

Suggest an API

Tell us which public API is missing. We check it, then add it here with its endpoints when it has an OpenAPI (Swagger) description.