pyEX Chart Batch Request (IEX Cloud API)

Viewed 174

I am trying to use pyEX to get the closing prices of a list of tickers and then convert that into a pandas data frame. I want the range of prices to be a year in length. Based on the documentation I should assign a value of '1y' to the range_ parameter. However when I do this only get two weeks of data. The following code returns a data frame of 50 rows (10 for each stock) meaning 10 unique days of prices.

import pandas as pd
import pyEX as p

tickers = ['AAPL', 'FB', 'AMZN', 'GOOGL', 'NFLX']
c = p.Client(api_token='YOUR_TOKEN_HERE', version='sandbox')
pd.DataFrame(c.batchDF(symbols=tickers, fields='chart', range_='1y')['chart'])

I have tried changing the range variable to a value below 2 weeks, like 5 days ('5d') and that works however it seems not return anything longer than two weeks even if range_ is greater than two weeks. I'm wondering if anybody else has run into this problem or figured out a workaround?

Here is a link to the documentation: https://pyex.readthedocs.io/en/latest/_modules/pyEX/stocks/batch.html?highlight=batch

1 Answers

As per the pyEX documentation, the batchDF call defaults the parameter 'last' to 10.

Provide the 'last' parameter, as shown here, to get the full year of data:

c.batchDF(symbols=tickers, fields='chart', last=365, range_='1y')

The full example looks like this:

import pandas as pd
import pyEX as p

tickers = ['AAPL', 'FB', 'AMZN', 'GOOGL', 'NFLX']
c = p.Client(api_token='YOUR_TOKEN_HERE', version='sandbox')
pd.DataFrame(c.batchDF(symbols=tickers, fields='chart', last=365, range_='1y')['chart'])
Related