Historical Data

Alpaca Data API v2 provides three types of historical data: trades, quotes and bars.

Alpaca Data API v2 is currently in public beta. Please keep in mind that the public beta version may be less stable.

Public beta status

Last update: Apr 1, 2021

We finished backfilling all trades, quotes and bars for the 2016-2020 period, these are now available through the APIs.

2021 2020 2019 2018 2017 2016
Trades Done Done Done Done Done Done
Quotes Done Done Done Done Done Done
Bars Done Done Done Done Done Done

Common behavior

Base URL

Alpaca Data API v2 provides historical data through multiple endpoints. These endpoints have the same URL prefix (omitted from now on):

https://data.alpaca.markets/v2

This URL is the same for both subscription plans but users with Free subscription will receive an error when trying to access data that is too recent.

Authentication The authentication is done the same way as with the Trading API, simply set the following HTTP headers:

  • APCA-API-KEY-ID
  • APCA-API-SECRET-KEY

Limiting

Use the limit query parameter. The value should be in the range 1 - 10000 (endpoints included) with 1000 being the default if unspecified.

Paging

To support querying long timespans continuously we support paging in our API. If the result you have received contains a next_page_token that is not null there may be more data available in the timeframe you have chosen. Include the token you have received as the page_token query parameter for the next request you make while leaving the other parameters unchanged to continue where the previous response left off.

Ordering

The results are ordered in ascending order by time.

Trades

The Trades API provides historcial trade data for a given ticker symbol on a specified date.

[GET] Returns trades for the queried stock symbol

GET/v2/stocks/{symbol}/trades
This endpoint returns trade historical data for the requested security.

Parameters

Path Parameters

symbol
string
The symbol to query for

Query Parameters

start
stringRequired
Filter data equal to or after this time in RFC-3339 format. Fractions of a second are not accepted.
end
stringRequired
Filter data equal to or before this time in RFC-3339 format. Fractions of a second are not accepted.
limit
int
Number of data points to return. Must be in range 1-10000, defaults to 1000.
page_token
string
Pagination token to continue from.

Response

A trades response object.

Errors

400 Bad request
Invalid value for query parameter
403 Forbidden
Unauthorized
422 Unprocessable
Invalid query parameter
429 Too many requests
Rate limit exceeded

Example of one trade

{
  "t": "2021-02-06T13:04:56.334320128Z",
  "x": "C",
  "p": 387.62,
  "s": 100,
  "c": [
    " ",
    "T"
  ],
  "i": 52983525029461,
  "z": "B"
}

Properties

t
stringRequired
Timestamp in RFC-3339 format with nanosecond precision.
x
stringRequired
Exchange where the trade happened.
p
numberRequired
Trade price.
s
intRequired
Trade size.
c
array<string>Required
Trade conditions.
i
intRequired
Trade ID.
z
stringRequired
Tape.

Example of multiple trades

{
  "trades": [
      {
          "t": "2021-02-06T13:04:56.334320128Z",
          "x": "C",
          "p": 387.62,
          "s": 100,
          "c": [
              " ",
              "T"
          ],
          "i": 52983525029461,
          "z": "B"
      },
      {
          "t": "2021-02-06T13:09:42.325484032Z",
          "x": "C",
          "p": 387.69,
          "s": 100,
          "c": [
              " ",
              "T"
          ],
          "i": 52983525033813,
          "z": "B"
      }
  ],
  "symbol": "SPY",
  "next_page_token": "MjAyMS0wMi0wNlQxMzowOTo0Mlo7MQ=="
}

Properties

trades
array<trade>Required
Array of trades.
symbol
stringRequired
Symbol that was queried.
next_page_token
string (Nullable)Required
Token that can be used to query the next page.

Quotes

The Quotes API provides NBBO quotes for a given ticker symbol at a specified date.

[GET] Returns quotes (NBBOs) for the queried stock symbol

GET/v2/stocks/{symbol}/quotes
This endpoint returns quote (NBBO) historical data for the requested security.

Parameters

Path Parameters

symbol
string
The symbol to query for

Query Parameters

start
stringRequired
Filter data equal to or after this time in RFC-3339 format. Fractions of a second are not accepted.
end
stringRequired
Filter data equal to or before this time in RFC-3339 format. Fractions of a second are not accepted.
limit
int
Number of data points to return. Must be in range 1-10000, defaults to 1000.
page_token
string
Pagination token to continue from.

Response

A quotes response object.

Errors

400 Bad request
Invalid value for query parameter
403 Forbidden
Unauthorized
422 Unprocessable
Invalid query parameter
429 Too many requests
Rate limit exceeded

Example of one quote

{
  "t": "2021-02-06T13:35:08.946977536Z",
  "ax": "C",
  "ap": 387.7,
  "as": 1,
  "bx": "N",
  "bp": 387.67,
  "bs": 1,
  "c": [
    "R"
  ]
}

Properties

t
stringRequired
Timestamp in RFC-3339 format with nanosecond precision.
ax
stringRequired
Ask exchange.
ap
numberRequired
Ask price.
as
intRequired
Ask size.
bx
stringRequired
Bid exchange.
bp
numberRequired
Bid price.
bs
intRequired
Bid size.
c
array<string>Required
Quote conditions.

Example of multiple quotes

{
  "quotes": [
      {
          "t": "2021-02-06T13:35:08.946977536Z",
          "ax": "C",
          "ap": 387.7,
          "as": 1,
          "bx": "N",
          "bp": 387.67,
          "bs": 1,
          "c": [
              "R"
          ]
      },
      {
          "t": "2021-02-06T13:35:09.327977984Z",
          "ax": "C",
          "ap": 387.7,
          "as": 1,
          "bx": "C",
          "bp": 387.58,
          "bs": 1,
          "c": [
              "R"
          ]
      }
  ],
  "symbol": "SPY",
  "next_page_token": "MjAyMS0wMi0wNlQxMzozNTowOVo7MQ=="
}

Properties

quotes
array<quote>Required
Array of quotes.
symbol
stringRequired
Symbol that was queried.
next_page_token
string (Nullable)Required
Token that can be used to query the next page.

Bars

The bars API returns aggregate historical data for the requested securities.

[GET] Returns bars for the queried stock symbol

GET/v2/stocks/{symbol}/bars
This endpoint returns aggregate historical data for the requested security.

Parameters

Path Parameters

symbol
string
The symbol to query for

Query Parameters

start
stringRequired
Filter data equal to or after this time in RFC-3339 format. Fractions of a second are not accepted.
end
stringRequired
Filter data equal to or before this time in RFC-3339 format. Fractions of a second are not accepted.
limit
int
Number of data points to return. Must be in range 1-10000, defaults to 1000.
page_token
string
Pagination token to continue from.
timeframe
stringRequired
Timeframe for the aggregation. Available values are: 1Min, 1Hour, 1Day.

Response

A bars response object.

Errors

400 Bad request
Invalid value for query parameter
403 Forbidden
Unauthorized
422 Unprocessable
Invalid query parameter
429 Too many requests
Rate limit exceeded

Example of one bar

{
  "t": "2021-02-01T16:01:00Z",
  "o": 133.32,
  "h": 133.74,
  "l": 133.31,
  "c": 133.5,
  "v": 9876
}

Properties

t
stringRequired
Timestamp in RFC-3339 format with nanosecond precision.
o
numberRequired
Open price.
h
numberRequired
High price.
l
numberRequired
Low price.
c
numberRequired
Close price.
v
intRequired
Volume.

Example of multiple bars

{
  "bars": [
    {
      "t": "2021-02-01T16:01:00Z",
      "o": 133.32,
      "h": 133.74,
      "l": 133.31,
      "c": 133.5,
      "v": 9876
    },
    {
      "t": "2021-02-01T16:02:00Z",
      "o": 133.5,
      "h": 133.58,
      "l": 133.44,
      "c": 133.58,
      "v": 3567
    }
  ],
  "symbol": "AAPL",
  "next_page_token": "MjAyMS0wMi0wMVQxNDowMjowMFo7MQ=="
}

Properties

bars
array<bar>Required
Array of bars.
symbol
stringRequired
Symbol that was queried.
next_page_token
string (Nullable)Required
Token that can be used to query the next page.

Suggestions or questions?
We're always happy to hear from you. You can contribute to these docs on GitHub, or you can join our Community Forum or Community Slack to get help from other community members and the Alpaca team.