addisonlynch / iexfinance

Python SDK for IEX Cloud
https://addisonlynch.github.io/iexfinance
Apache License 2.0
648 stars 136 forks source link

Message allocation #240

Closed burrittresearch closed 3 years ago

burrittresearch commented 3 years ago

Summary (include Python version)

Python 3.8.6, iexfinance 0.4.3

Hello: I'm trying to figure out data weights for historical_prices endpoint. It looks like they come in packets of 2520, but I'm not sure about how they are calculated.

For example, using the get_historical_prices endpoint, here is sample message usage to the current date:

1 symbol, from 1-1-18 to present: 12,590 1 symbol, from 1-1-19 to present: 5,040 1 symbol, from 1-1-20 to present: 2,520 1 symbol, from 12-1-20 to present: 2,520

I reached out to IEX Cloud and there response was:

I saw your response on the other ticket but I can provide a little more clarity here.

It looks like the code library you are using is rounding up your requests to '1y' and then cutting down the returned response to give you only the dates requested. That's why requesting data for different time periods within 1 year are charged the same amount of 2,520.

The same is done for 1-1-19, as they are likely making a 'range=2y' call.

This is likely just a feature of the library you're using. Client libraries are maintained by 3rd-party developers. I suggest reaching out to the developer of that library for assistance.

Date/time of issue

Current

Expected behavior

Message count corresponds correctly with dates.

Actual behavior

Message count does not correspond correctly with dates,.

addisonlynch commented 3 years ago

That is correct. iexfinance pulls the minimum amount of data needed and then slices it to the date range you need.

For 1/1/2019, a date that is almost 2 years ago, range=2y must be used.

Here's what I'm seeing

1 symbol, from 1-1-18 to present: 12,590

Call: get_historical_data("AAPL", start="1-1-2018", end="12-14-2020") Query: https://sandbox.iexapis.com/stable/stock/market/batch?symbols=AAPL&types=chart&range=5y&chartByDay=False&chartCloseOnly=False Messages Used: 12580

1 symbol, from 1-1-19 to present: 5,040 Call: get_historical_data("AAPL", start="1-1-2019", end="12-14-2020") Query: https://sandbox.iexapis.com/stable/stock/market/batch?symbols=AAPL&types=chart&range=2y&chartByDay=False&chartCloseOnly=False Messages Used: 5030

1 symbol, from 1-1-20 to present: 2,520 Call: get_historical_data("AAPL", start="1-1-2020", end="12-14-2020") Query: https://sandbox.iexapis.com/stable/stock/market/batch?symbols=AAPL&types=chart&range=1y&chartByDay=False&chartCloseOnly=False Messages Used: 2510

1 symbol, from 12-1-20 to present: 2,520 Call: get_historical_data("AAPL", start="12-1-2020", end="12-14-2020") Query: https://sandbox.iexapis.com/stable/stock/market/batch?symbols=AAPL&types=chart&range=1m&chartByDay=False&chartCloseOnly=False Messages Used: 190

iexfinance correctly uses 1m for the call with the most recent range and only 190 messages are used, not 1y.

EDIT You are using an outdated version of iexfinance which is not optimized for new range parameters from IEX Cloud. Please upgrade to 0.5.0 and re-open if the issue persists!

dcwtx commented 3 years ago

If I understand this correctly

Data Weighting

Adjusted + Unadjusted 10 per symbol per time interval returned (Excluding 1d) Example: If you query for AAPL 5 day, it will return 5 days of prices for AAPL for a total of 50.

Adjusted close only 2 per symbol per time interval returned (Excluding 1d) use chartCloseOnly param

If you changed _closeonly below to True as the default, you'd use 1/5 of the message count (but at the cost of the other data). Design decision as to what to default, but my bet is most people use this endpoint only for the historical data and they toss the rest.

class HistoricalReader(Stock):
    """
    Base class to download historical data from the chart endpoint
    Reference: https://iextrading.com/developer/docs/#chart
    """

    def __init__(self, symbols, start, end=None, close_only=False, **kwargs):
burrittresearch commented 3 years ago

Thank you!

addisonlynch commented 3 years ago

@dcwtx that's a great point. It may be a good idea to add to the iexfinance documentation that chartCloseOnly greatly reduces message counts.

dcwtx commented 3 years ago

Well, you actually already have it in the docs, I just don't think most people read that stuff.

So one suggestion is to make _closeonly=True and to either a) create a new flag to get detailed historical data, or b) just enter _closeonly=False to get the detailed data. This is under the presumption that most people prefer lower message count and only want closing price and volume.