Alpaca API GET /v2/stocks/bars
Historical bars (OHLC with volume, trade count and VWAP) for a list of stock symbols, sorted by symbol then time, paged.
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.
Market Data API: the host is https://data.alpaca.markets, not the trading host, so the base address in a generated sample must be changed to it. Authentication is the same two headers as the Trading API. The OpenAPI document gives 200 with X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset headers, and 400, 401, 403, 429 and 500. Bar fields: t, o, h, l, c, v, n, vw. The single symbol form GET /v2/stocks/{symbol}/bars takes the same query and is not recorded separately.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
| symbolsrequired | query | string | Comma separated symbols, such as AAPL,TSLA. |
| timeframerequired | query | string | The width of each bar: 1Min to 59Min, 1Hour to 23Hour, 1Day, 1Week, or 1, 2, 3, 4, 6 or 12 Month. |
| start | query | string | The inclusive start, RFC 3339 or YYYY-MM-DD. Default the start of the current day, or 15 minutes ago without real time access. |
| end | query | string | The inclusive end, RFC 3339 or YYYY-MM-DD. Default now, or 15 minutes ago without real time access. |
| limit | query | integer | How many data points a page holds at most, counted across all symbols. Default 1000, maximum 10000. |
| adjustment | query | string | Comma separated: raw (default), split, dividend, spin-off or all. An unknown value or a repeated key is answered with 400. |
| asof | query | string | The date used to resolve a symbol's past names, YYYY-MM-DD. Default the current day; a hyphen skips the mapping. |
| feed | query | string | iex, otc, sip or boats. Default sip. |
| currency | query | string | The currency of the prices, an ISO 4217 code. Default USD. |
| page_token | query | string | The next_page_token of the previous reply. |
| sort | query | string | asc (default) or desc. |
Authentication headers
| Name | Type | Description |
|---|---|---|
| APCA-API-KEY-IDrequired | string | Your API key id. Placeholder only: never paste a real key into this site. |
| APCA-API-SECRET-KEYrequired | string | The secret key that goes with the key id. Placeholder only: never paste a real secret into this site. |
Request
Written from the method, path and parameters recorded on this page, against the demo host. Not executed against a live or demo account. Credentials are read from environment variables on your own machine and are never entered on this site. The request builder writes these same snippets, from the same record.
Python
# Set ALPACA_API_KEY_ID, ALPACA_API_SECRET_KEY as environment variables first. Never paste real values into code.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Optional and not shown: query parameters start, end, limit, adjustment, asof, feed, currency, page_token, sort.
import os
import requests
BASE_URL = "https://paper-api.alpaca.markets" # the demo host
headers = {
"APCA-API-KEY-ID": os.environ["ALPACA_API_KEY_ID"],
"APCA-API-SECRET-KEY": os.environ["ALPACA_API_SECRET_KEY"],
}
params = {"symbols": "{symbols}", "timeframe": "{timeframe}"}
resp = requests.get(BASE_URL + "/v2/stocks/bars", headers=headers, params=params, timeout=10)
resp.raise_for_status()
print(resp.json())JavaScript
// Set ALPACA_API_KEY_ID, ALPACA_API_SECRET_KEY as environment variables first. Never paste real values into code.
// Replace each {placeholder}, "..." and 0 with a real value before running.
// Optional and not shown: query parameters start, end, limit, adjustment, asof, feed, currency, page_token, sort.
// Run as a module, for example a .mjs file, on a Node version that has fetch built in.
const BASE_URL = "https://paper-api.alpaca.markets"; // the demo host
const res = await fetch(BASE_URL + "/v2/stocks/bars" + "?symbols={symbols}&timeframe={timeframe}", {
method: "GET",
headers: {
"APCA-API-KEY-ID": process.env.ALPACA_API_KEY_ID,
"APCA-API-SECRET-KEY": process.env.ALPACA_API_SECRET_KEY,
},
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());curl
# Set ALPACA_API_KEY_ID, ALPACA_API_SECRET_KEY as environment variables first. Never paste real values into code.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Optional and not shown: query parameters start, end, limit, adjustment, asof, feed, currency, page_token, sort.
curl -X GET "https://paper-api.alpaca.markets/v2/stocks/bars?symbols={symbols}&timeframe={timeframe}" \
-H "APCA-API-KEY-ID: $ALPACA_API_KEY_ID" \
-H "APCA-API-SECRET-KEY: $ALPACA_API_SECRET_KEY"Response
A mock response. The values are invented, so check field names against the official reference.
{
"_mock": true,
"bars": {
"MOCK": [
{
"t": "2026-11-30T14:30:00Z",
"o": 100,
"h": 100.6,
"l": 99.8,
"c": 100.5,
"v": 12000,
"n": 150,
"vw": 100.2
}
]
},
"next_page_token": null,
"currency": "USD"
}Limits that apply at Alpaca
| 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 errors you may meet
- HTTP 400HTTP 400. One of the request's parameters is invalid.
- HTTP 401 (market data)HTTP 401. The Market Data API's shared reply where the authentication headers are missing or invalid.
- HTTP 403HTTP 403. Forbidden.
- HTTP 404HTTP 404. Not found: an asset by symbol or id, a watchlist by id, or on the market data host a feed that does not exist.
- HTTP 422HTTP 422. Unprocessable.
- 42210000The code in the body of a 422 reply.
All Alpaca API error codes, including 20 more not listed here.