# Market Data FAQ Frequently Asked Questions # General ## Why am I getting HTTP 403 (Forbidden)? The market data endpoints return HTTP 403 if any of the following conditions are true: * the request was not authenticated * the provided credentials were incorrect * the authenticated user has insufficient permissions To fix these issues, there are two checklists, one for regular users and one for broker partners. If you're unsure which refers to you, check this [FAQ](https://docs.alpaca.markets/docs/broker-api-faq#what-is-the-difference-between-trading-api-and-broker-api). If you're still unsure, then check your access key. If it starts with the letter `C`, then you're a broker partner, otherwise you're a regular user. If you don't have an access key yet, generate it on the right-hand side of the Alpaca [dashboard](https://app.alpaca.markets/brokerage/dashboard/overview). ### Checklist for regular users * make sure you provide your credentials in the following HTTP headers: * `APCA-API-KEY-ID` * `APCA-API-SECRET-KEY` * make sure your credentials are valid: * check the key on the[ web UI](https://app.alpaca.markets/brokerage/dashboard/overview) * when you reset your paper account, you need to regenerate your credentials * make sure the host is `data.alpaca.markets` [for historical](https://docs.alpaca.markets/docs/historical-api#base-url) or `stream.data.alpaca.markets` [for live](https://docs.alpaca.markets/docs/streaming-market-data#connection) * if you get a message like `subscription does not permit querying recent SIP data` in the HTTP response body, make sure you have the proper [subscription](https://docs.alpaca.markets/docs/about-market-data-api#subscription-plans) * for example to query any SIP trades or quotes in the last 15 minutes, you need the Algo Trader Plus subscription ### Checklist for broker partners * make sure you provide your credentials in [HTTP basic authentication](https://docs.alpaca.markets/docs/about-market-data-api#subscription-plans) * make sure your credentials are valid * make sure you're using the right host based on your environment: * the production host is `data.alpaca.markets` [for historical](https://docs.alpaca.markets/docs/historical-api#base-url) and `stream.data.alpaca.markets` [for live](https://docs.alpaca.markets/docs/streaming-market-data#connection) * the sandbox host (for testing) is `data.sandbox.alpaca.markets` [for historical](https://docs.alpaca.markets/docs/historical-api#base-url) and `stream.data.sandbox.alpaca.markets` [for live](https://docs.alpaca.markets/docs/streaming-market-data#connection) * if you get a message like `subscription does not permit querying recent SIP data` in the HTTP response body, make sure you have the proper [subscription](https://docs.alpaca.markets/docs/about-market-data-api#broker-partners) * for example, to query any SIP trades or quotes in the last 15 minutes, you need a special subscription ## How do I subscribe to AlgoTrader Plus? You can subscribe to AlgoTrader Plus on the [Alpaca UI](https://app.alpaca.markets/account/plans-and-features): on the left sidebar of the main page click on "Plans & Features" and on that page click on "Upgrade to AlgoTrader Plus" inside the Market Data box. # Stocks ## What's the difference between IEX and SIP data? SIP is short for [Securities Information Processor](https://en.wikipedia.org/wiki/Securities_information_processor). All US exchanges are mandated by the regulators to report their activities (trades and quotes) to the consolidated tape. This is what we call SIP data. IEX ([Investors Exchange](https://en.wikipedia.org/wiki/IEX)) is a single stock exchange. #### [Websocket stream](https://docs.alpaca.markets/us/docs/real-time-stock-pricing-data) Our free market data offering includes live data only from the IEX exchange: ``` wss://stream.data.alpaca.markets/v2/iex ``` The Algo Trader Plus subscription on the other hand offers SIP data: ``` wss://stream.data.alpaca.markets/v2/sip ``` #### [Historical data](https://docs.alpaca.markets/reference/stockbars) On the historical endpoints, use the `feed` parameter to switch between the two data feeds: ```json $ curl -s -H "APCA-API-KEY-ID: ${APCA_API_KEY_ID}" -H "APCA-API-SECRET-KEY: ${APCA_API_SECRET_KEY}" \ "https://data.alpaca.markets/v2/stocks/AAPL/bars?feed=sip&timeframe=1Day&start=2023-09-29&limit=1" | jq . { "bars": [ { "t": "2023-09-29T04:00:00Z", "o": 172.02, "h": 173.07, "l": 170.341, "c": 171.21, "v": 51861083, "n": 535134, "vw": 171.599691 } ], "symbol": "AAPL", "next_page_token": "QUFQTHxEfDIwMjMtMDktMjlUMDQ6MDA6MDAuMDAwMDAwMDAwWg==" } $ curl -s -H "APCA-API-KEY-ID: ${APCA_API_KEY_ID}" -H "APCA-API-SECRET-KEY: ${APCA_API_SECRET_KEY}" \ "https://data.alpaca.markets/v2/stocks/AAPL/bars?feed=iex&timeframe=1Day&start=2023-09-29&limit=1" | jq . { "bars": [ { "t": "2023-09-29T04:00:00Z", "o": 172.015, "h": 173.06, "l": 170.36, "c": 171.29, "v": 923134, "n": 12630, "vw": 171.716432 } ], "symbol": "AAPL", "next_page_token": null } ``` In this example (2023-09-29 Apple daily bar), you can clearly see the difference between the two feeds: there were **12 630** eligible trades on the IEX exchange that day and more than **535 136** trades in total across all exchanges (naturally including IEX). Similar differences can be seen between their volumes. All the latest endpoints (including the [snapshot](https://docs.alpaca.markets/reference/stocksnapshotsingle) endpoint), require a subscription to be used with the SIP feed. For historical queries, the `end` parameter must be at least 15 minutes old to query SIP data without a subscription. The default value for `feed` is always the "best" available feed based on the user's subscription. ```json $ curl -s -H "APCA-API-KEY-ID: ${APCA_API_KEY_ID}" -H "APCA-API-SECRET-KEY: ${APCA_API_SECRET_KEY}" \ "https://data.alpaca.markets/v2/stocks/AAPL/trades/latest" | jq . { "symbol": "AAPL", "trade": { "t": "2023-09-29T19:59:59.246196362Z", "x": "V", // << IEX exchange code "p": 171.29, "s": 172, "c": [ "@" ], "i": 12727, "z": "C" } } $ curl -H "APCA-API-KEY-ID: ${APCA_API_KEY_ID}" -H "APCA-API-SECRET-KEY: ${APCA_API_SECRET_KEY}" \ "https://data.alpaca.markets/v2/stocks/AAPL/trades/latest?feed=sip" {"code":42210000,"message":"subscription does not permit querying recent SIP data"} ``` In this example, we're querying the latest AAPL trade without a subscription. The default `feed` in this case is `iex`. If we were to try to query the SIP feed, we would get an error. To fix that error, we need to subscribe to [Algo Trader Plus](https://docs.alpaca.markets/docs/about-market-data-api#subscription-plans). ## Why can't I find market data for a particular symbol (e.g. CGRNQ)? ### OTC Make sure the symbol is not traded in OTC using the [assets endpoint](https://docs.alpaca.markets/reference/get-v2-assets-symbol_or_asset_id). `https://api.alpaca.markets/v2/assets/CGRNQ` returns ```json { "id": "dc2d8be9-33b5-4a32-8f57-5b7d209d2c82", "class": "us_equity", "exchange": "OTC", // << This symbol is traded in OTC "symbol": "CGRNQ", "name": "CAPSTONE GREEN ENERGY CORP COM PAR $.001", "status": "active", "tradable": false, "marginable": false, "maintenance_margin_requirement": 100, "shortable": true, "easy_to_borrow": true, "fractionable": true, "attributes": [] } ``` Market data for OTC symbols can only be queried with a special subscription currently available only for broker partners. If you do have the subscription, you can use `feed=otc` to query the data. ### Inactive Make sure the asset is active. Check the `status` field of the [same endpoint](https://docs.alpaca.markets/reference/get-v2-assets-symbol_or_asset_id). ### Halt Make sure the symbol isn't or wasn't halted at the time you're querying. You can check the [current halts](https://www.nasdaqtrader.com/trader.aspx?id=TradeHalts) or the [historical halts](https://www.nasdaqtrader.com/Trader.aspx?id=TradingHaltSearch) on the Nasdaq website. For example, the symbol SVA has been halted since 2019-02-22. ## What happens when a ticker symbol of a company changes? Perhaps the most famous example for this was when Facebook decided to [rename itself ](https://about.fb.com/news/2021/10/facebook-company-is-now-meta/)to Meta and to change its ticker symbol from FB to META. This transition happened on 2022-06-09. ### Latest endpoints On the latest endpoints ([latest trades](https://docs.alpaca.markets/reference/stocklatesttrades-1), [latest quotes](https://docs.alpaca.markets/reference/stocklatestquotes-1), [latest bars](https://docs.alpaca.markets/reference/stocklatestbars-1) and [snapshots](https://docs.alpaca.markets/reference/stocksnapshots-1)), the data is never manipulated in any way. These endpoints always return the data as it was received at the time (this is also why there is no `adjustment` parameter on the [latest bars](https://docs.alpaca.markets/reference/stocklatestbars-1)). So, in this case, the latest FB trade returns the last trade when the company was still called FB: ```json $ curl -s -H "APCA-API-KEY-ID: ${APCA_API_KEY_ID}" -H "APCA-API-SECRET-KEY: ${APCA_API_SECRET_KEY}" "${APCA_API_DATA_URL}/v2/stocks/trades/latest?symbols=FB" | jq . { "trades": { "FB": { "c": [ "@", "T" ], "i": 31118, "p": 196.29, "s": 121, "t": "2022-06-08T23:59:55.103033856Z", "x": "P", "z": "C" } } } ``` Note the timestamp in the response is 2022-06-08, the night before the name change. ### Stream endpoints The symbols always reflect the ones used by the companies at the time of the transmission on the [streaming endpoints](https://docs.alpaca.markets/edit/real-time-stock-pricing-data) as well. In practice this means that a stream client must resubscribe to the new symbol after a name change to continue receiving data. The resubscribe requires no reconnection, in the Facebook example you could simply send a [subscribe message](https://docs.alpaca.markets/docs/streaming-market-data#subscription) to META. ### Historical endpoints On the historical endpoints we introduced the `asof` parameter to link together the data before and after the rename. By default, this parameter is "enabled", so even if you don't specify it, you will get the data for both the old and new symbol when querying the new symbol after the rename. For the example of the FB - META rename, we can simply query the daily bars for META for the whole week (the rename happened on Thursday), yet we see the bars for Monday, Tuesday and Wednesday as well, even though on those days, the company was still called FB. ```shell $ curl -s -H "APCA-API-KEY-ID: ${APCA_API_KEY_ID}" -H "APCA-API-SECRET-KEY: ${APCA_API_SECRET_KEY}" \ "${APCA_API_DATA_URL}/v2/stocks/bars?timeframe=1Day&symbols=META&start=2022-06-06&end=2022-06-11" | \ jq -r '.bars.META[] | [.t, .o, .h, .l, .c] | @tsv' 2022-06-06T04:00:00Z 193.99 196.92 188.4 194.25 2022-06-07T04:00:00Z 191.93 196.53 191.49 195.65 2022-06-08T04:00:00Z 194.67 202.03 194.41 196.64 2022-06-09T04:00:00Z 194.28 199.45 183.68 184 2022-06-10T04:00:00Z 183.04 183.1 175.02 175.57 ``` If you disable the `asof` parameter, you won't get the FB bars: ```shell $ curl -s -H "APCA-API-KEY-ID: ${APCA_API_KEY_ID}" -H "APCA-API-SECRET-KEY: ${APCA_API_SECRET_KEY}" \ "${APCA_API_DATA_URL}/v2/stocks/bars?timeframe=1Day&symbols=META&start=2022-06-06&end=2022-06-11&asof=-" | \ jq -r '.bars.META[] | [.t, .o, .h, .l, .c] | @tsv' 2022-06-09T04:00:00Z 194.28 199.45 183.68 184 2022-06-10T04:00:00Z 183.04 183.1 175.02 175.57 ``` If you set `asof` to a date before the rename, you can query by the old ticker: ```shell $ curl -s -H "APCA-API-KEY-ID: ${APCA_API_KEY_ID}" -H "APCA-API-SECRET-KEY: ${APCA_API_SECRET_KEY}" \ "${APCA_API_DATA_URL}/v2/stocks/bars?timeframe=1Day&symbols=FB&start=2022-06-06&end=2022-06-11&asof=2022-06-06" | \ jq -r '.bars.FB[] | [.t, .o, .h, .l, .c] | @tsv' 2022-06-06T04:00:00Z 193.99 196.92 188.4 194.25 2022-06-07T04:00:00Z 191.93 196.53 191.49 195.65 2022-06-08T04:00:00Z 194.67 202.03 194.41 196.64 2022-06-09T04:00:00Z 194.28 199.45 183.68 184 2022-06-10T04:00:00Z 183.04 183.1 175.02 175.57 ``` Unfortunately, the `asof` mapping is only available on our historical endpoints the day after the rename. In the FB-META example, it was available since 2022-06-10, so running the same queries on the day of the rename (2022-06-09) didn't return the FB bars. This is because of a limitation of one of our data sources. We're actively working on improving this and doing the mapping before the market opens with the new symbol. ## How are bars aggregated? Minute and daily bars are aggregated from trades. The (SIP) timestamp of the trade is truncated to the minute for minute bars and to the day (in New York) for daily bars. For example, a trade at 14:52:28 belongs to the 14:52:00 minute bar, which contains all the trades between 14:52:00 (inclusive) and 14:53:00 (exclusive). The timestamp of the bar is the left side of the interval (14:52:00 in this example). There are three parts of the bar that a trade can potentially update: * open / close price * high / low price * volume The rules of these updates depend on * the tape of the trade (`A`, `B`: NYSE, `C`: Nasdaq, `O`: OTC) * the conditions of the trade * the type of the bar (`M`: minute, `D`: daily) * Some rules are different for minute and daily bars. For example `P` (Prior Reference Price) relates to an obligation to trade at an earlier point in the trading day. This will update the high / low price of a daily bar but will not update the high / low price of a minute bar, because that price possibly happened in another minute. The rules are based on the guidelines of the SIPs: * the [CTS specification](https://www.ctaplan.com/publicdocs/ctaplan/CTS_Pillar_Output_Specification.pdf) for NYSE (tape `A` and `B`) * the [UTP specification](https://utpplan.com/DOC/UtpBinaryOutputSpec.pdf) for Nasdaq (tape `C`) * the [TDDS specification](https://www.finra.org/sites/default/files/2022-05/TDDS-2.1-MOLD.pdf) for OTC (tape `O`) The following table contains all the updating rules:
| Condition code | Condition description | Tape | Bar type | Update open / close | Update high / low | Update volume |
|---|---|---|---|---|---|---|
| ` ` | Regular Sale | AB | MD | :green\_circle: | :green\_circle: | :green\_circle: |
| `@` | Regular Sale | CO | MD | :green\_circle: | :green\_circle: | :green\_circle: |
| `A` | Acquisition | C | MD | 🟢 | 🟢 | 🟢 |
| `B` | Average Price Trade | AB | MD | :red\_circle: | :red\_circle: | :green\_circle: |
| `B` | Bunched Trade | C | MD | :green\_circle: | :green\_circle: | :green\_circle: |
| `C` | Cash Sale | ABCO | MD | :red\_circle: | :red\_circle: | :green\_circle: |
| `D` | Distribution | C | MD | 🟢 | 🟢 | 🟢 |
| `E` | Automatic Execution | AB | MD | :green\_circle: | :green\_circle: | :green\_circle: |
| `F` | Intermarket Sweep | ABC | MD | :green\_circle: | :green\_circle: | :green\_circle: |
| `G` | Bunched Sold Trade | C | M | :red\_circle: | 🔴 | :green\_circle: |
| `G` | Bunched Sold Trade | C | D | :yellow\_circle: | 🟢 | 🟢 |
| `H` | Price Variation Trade | ABC | MD | :red\_circle: | :red\_circle: | :green\_circle: |
| `I` | Odd Lot Trade | ABCO | MD | :red\_circle: | :red\_circle: | :green\_circle: |
| `K` | Rule 127 or Rule 155 | ABC | MD | :green\_circle: | :green\_circle: | :green\_circle: |
| `L` | Sold Last | ABC | MD | :green\_circle: | :green\_circle: | :green\_circle: |
| `M` | Market Center Official Close | ABC | MD | :red\_circle: | :red\_circle: | :red\_circle: |
| `N` | Next Day | ABCO | MD | :red\_circle: | :red\_circle: | :green\_circle: |
| `O` | Market Center Opening Trade | ABC | MD | :green\_circle: | :green\_circle: | :green\_circle: |
| `P` | Prior Reference Price | ABCO | M | :red\_circle: | :red\_circle: | :green\_circle: |
| `P` | Prior Reference Price | ABCO | D | :yellow\_circle: | :green\_circle: | :green\_circle: |
| `Q` | Market Center Official Open | ABC | MD | :red\_circle: | :red\_circle: | :red\_circle: |
| `R` | Seller | ABCO | MD | :red\_circle: | :red\_circle: | :green\_circle: |
| `T` | Extended Hours Trade | ABCO | M | 🟢 | 🟢 | :green\_circle: |
| `T` | Extended Hours Trade | ABCO | D | :red\_circle: | :red\_circle: | 🟢 |
| `U` | Extended Trading Hours | ABCO | MD | :red\_circle: | :red\_circle: | :green\_circle: |
| `V` | Contingent Trade | ABC | MD | :red\_circle: | :red\_circle: | :green\_circle: |
| `W` | Average Price Trade | CO | MD | 🔴 | 🔴 | 🟢 |
| `X` | Cross Trade | ABC | MD | :green\_circle: | :green\_circle: | :green\_circle: |
| `Y` | Yellow Flag Regular Trade | C | MD | 🟢 | 🟢 | 🟢 |
| `Z` | Sold Out Of Sequence | ABC | M | 🔴 | 🔴 | :green\_circle: |
| `Z` | Sold Out Of Sequence | ABC | D | :yellow\_circle: | :green\_circle: | :green\_circle: |
| `4` | Derivatively Priced | ABC | M | :red\_circle: | :red\_circle: | :green\_circle: |
| `4` | Derivatively Priced | ABC | D | :yellow\_circle: | 🟢 | 🟢 |
| `5` | Market Center Reopening Trade | ABC | MD | :green\_circle: | :green\_circle: | :green\_circle: |
| `6` | Market Center Closing Trade | ABC | MD | :green\_circle: | :green\_circle: | :green\_circle: |
| `7` | Qualified Contingent Trade | ABC | MD | :red\_circle: | :red\_circle: | :green\_circle: |
| `9` | Corrected Consolidated Close | ABC | M | :red\_circle: | :red\_circle: | :red\_circle: |
| `9` | Corrected Consolidated Close | ABC | D | :green\_circle: | :green\_circle: | :red\_circle: |