# Recieving incorrect stock price data from the API

**URL:** <https://forum.alpaca.markets/t/recieving-incorrect-stock-price-data-from-the-api/4112>\
**Category:** Alpaca Market Data\
**Created:** [January 28, 2021, 10:22am UTC](https://forum.alpaca.markets/t/recieving-incorrect-stock-price-data-from-the-api/4112 "2021-01-28T10:22:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan953](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@dan953](https://forum.alpaca.markets/u/dan953)\
**Post date:** [January 28, 2021, 10:22am UTC](https://forum.alpaca.markets/t/recieving-incorrect-stock-price-data-from-the-api/4112/1 "2021-01-28T10:22:00Z")

</div>

Hello, I have been having some trouble using the Alpaca API as it is giving me incorrect data, such that the API is useless to me. I am still practising with the paper API as i’m not sure whether to use this API for live trading yet.  
I have attached the sample code below,

LASTQUOTE\_URL = “[https://data.alpaca.markets/v1/last\_quote/stocks](https://data.alpaca.markets/v1/last_quote/stocks)”

def new\_price():  
last\_quote\_url = LASTQUOTE\_URL + ‘/AAPL’  
r = requests.get(last\_quote\_url, headers=HEADERS)

```
last_price_json = json.loads((json.dumps(r.json(), indent=4)))
print(last_price_json)

```

new\_price()

I greatly appreciate any help!

---

<div class="post-metadata">

**Author:** ![melgazar9](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/melgazar9/32/1082_2.png) [@melgazar9](https://forum.alpaca.markets/u/melgazar9)\
**Post date:** [January 29, 2021, 1:03am UTC](https://forum.alpaca.markets/t/recieving-incorrect-stock-price-data-from-the-api/4112/2 "2021-01-29T01:03:11Z")

</div>

I have this same experience. The data from alpaca is not reliable.

> <https://github.com/alpacahq/alpaca-trade-api-python/issues/361>
>
> NIO released its IPO on September 12, 2018, yet somehow data is returned since 2003-10-01. What concerns me more is there...

---

<div class="post-metadata">

**Author:** ![melgazar9](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/melgazar9/32/1082_2.png) [@melgazar9](https://forum.alpaca.markets/u/melgazar9)\
**Post date:** [January 29, 2021, 1:08am UTC](https://forum.alpaca.markets/t/recieving-incorrect-stock-price-data-from-the-api/4112/3 "2021-01-29T01:08:45Z")

</div>

I can prove that alpaca returns unreliable data. NIO released its IPO on September 12, 2018, yet somehow data is returned since 2003-10-01. What concerns me more is there is no missing data in any of these rows, so how is this data being populated? How many other stocks is this the case for? Please see the NIO example below.

```auto
import alpaca_trade_api as alpaca_api
nio = alpaca_api.REST(**ALPACA_HEADERS).polygon.historic_agg_v2('AAPL', 1, 'day', _from='1900-01-01', to='2099-12-31').df # returns data since 2003

nio.index.min()
Out[8]: Timestamp('2003-10-01 00:00:00-0400', tz='America/New_York')

nio.index.to_series().diff().max()
Out[23]: Timedelta('887 days 00:00:00')

```

---

<div class="post-metadata">

**Author:** ![Nahe](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/nahe/32/1962_2.png) [@Nahe](https://forum.alpaca.markets/u/Nahe)\
**Post date:** [February 1, 2021, 3:06am UTC](https://forum.alpaca.markets/t/recieving-incorrect-stock-price-data-from-the-api/4112/4 "2021-02-01T03:06:38Z")

</div>

Agree with @melgazar9 I suggest not to use Alpaca data as your source; it is not reliable (In addition, I experienced the unreliability of Alpaca paper trading)

I checked their historical data, and there is a **significant** discrepancy between data in yahoo finance and alpaca data.  
Please, check this example.

```auto
# alpaca data
NY = 'America/New_York'
start_iso = pd.Timestamp('2016-07-21 09:30:00', tz=NY).isoformat()
end_iso = pd.Timestamp('2016-07-21 16:00:00', tz=NY).isoformat()
api.get_barset(['FNF'], 'day', start=start_iso, end=end_iso).df

                             FNF
                            open high low close volume
time
2016-07-21 00:00:00-04:00 37.06 37.73 36.8 37.52 2652549

```

and

```auto
# yahoo finance data
import yfinance as yf
yf.download(tickers='FNF',start='2016-07-21',end='2016-07-22')
[*********************100%***********************] 1 of 1 completed
                 Open High Low Close Adj Close Volume
Date
2016-07-20 26.678699 26.693142 26.555958 26.592058 23.105539 4056804
2016-07-21 26.758123 27.241877 26.570396 27.083033 23.532139 4427291

```

---

<div class="post-metadata">

**Author:** ![Dan\_Whitnable\_Alpaca](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.alpaca.markets/dan_whitnable_alpaca/32/1658_2.png) [@Dan\_Whitnable\_Alpaca](https://forum.alpaca.markets/u/Dan_Whitnable_Alpaca)\
**Post date:** [February 1, 2021, 5:26pm UTC](https://forum.alpaca.markets/t/recieving-incorrect-stock-price-data-from-the-api/4112/5 "2021-02-01T17:26:52Z")

</div>

The data returned by the `get_barset` method is not adjusted for splits or dividends. Furthermore, it’s only data reported from several major exchanges and not the broader market. It is provided free for all users with the intended use case to be debugging algorithms in paper trading.

The [Polygon.io](http://Polygon.io) data is provided is by default adjusted for splits but not dividends. It is generally very reliable. It can be fetched as split or non-split adjusted.

---

<div class="post-metadata">

**Author:** ![darrenzou](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@darrenzou](https://forum.alpaca.markets/u/darrenzou)\
**Post date:** [November 9, 2021, 2:05am UTC](https://forum.alpaca.markets/t/recieving-incorrect-stock-price-data-from-the-api/4112/6 "2021-11-09T02:05:23Z")

</div>

Ok, the alpaca devs uses Polygon api for their stock data so they cant really do anything about the prices being incorrect, but

**BARSET have been depreciated so use get\_bars instead**

```auto
alpaca_api = tradeapi.REST(key["PUBLIC_KEY"],key["SECRET_KEY"],key["END_POINT"])
 barset = alpaca_api.get_bars([ticker], "5Day", start =trade_Date, end= "2020-08-05", adjustment="all" 
  ,limit=507)
#adjustment = "all" is the most important thing here, it will count all stock splits, dividends, and what ever, making the data accurate. 

```

However there still are times when the API gives back pre IPO price for no reason like seen below:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/alp/original/2X/b/bf9a95ced5b15f26446e13b04a3427350b378df8.png)

I have a dumb fix for this:

```auto
def removeExtraFromBarset(self,barset):
        if len(barset)==0:
            return []
        removeindex = -1
        for i in range(len(barset)):
            if barset[i].v ==0:
                removeindex = i
            if(removeindex!=-1 and barset[i].v!=0):
                return barset[removeindex+2:]

```
