tkp-archive/pyEX

Stale Data using Client's chartDF & intraday-prices methods

Closed this issue · 3 comments

Describe the bug
I've noticed that when making several subsequent calls of either the chartDF or intradayDF methods they return stale data. For example, I will call the method once per minute, expecting to see a new row appended to the dataframe upon each iteration. However, the data is stale and is up to date as of the minute I initiated the script.

To Reproduce
Run a script similar to the following:

import pyEX
from time import sleep

TOKEN = "sk_xxxxxxxxxxxxxxxxxxxx"

client = pyEX.Client(api_token=TOKEN)

while True:
    print(client.chartDF("MU", "dynamic").iloc[-1])
    sleep(60)

Expected behavior
If I tailed the df and fetched the last row and minute (label), I would expect to see the following: (this was fetched directly from the IEX Cloud API bypassing the pyEX library):
Screen Shot 2021-11-19 at 1 33 01 PM

However, I tend to see the following (using pyEX):

Screen Shot 2021-11-19 at 1 26 16 PM

ENV

  • Tested on Ubuntu 18.04, MacOS Big Sur
  • Tested on Python 3.9 and Python 3.8
  • intradayDF and chartDF methods (using both 1d and dynamic intervals)
  • Tested Tickers: AAPL, MU, MSFT (all stocks that should have enough volume to have minute price changes)
  • This is all running v0.5.0 (latest as of writing)

chart by default caches your data locally to avoid excess charges, by default it expires at 4am EST daily: https://github.com/iexcloud/pyEX/blob/main/pyEX/stocks/chart.py#L26

intraday does not cache: https://github.com/iexcloud/pyEX/blob/main/pyEX/stocks/intraday.py#L22

First step in debugging would be to set the env var PYEX_NOCACHE and try your test again to see

Ah that's a handy library. Tested again with PYEX_NOCACHE and everything worked as I originally excepted. I will close this issue now but it would be ideal if this was made more apparent. Thanks!

Chart and intraday are a little clunky, but intraday should get you what you need and for all other queries (like historical intraday queries) the caching will make sure you don't even spend the extra credits for cloud cache/api usage.