tiingo-python icon indicating copy to clipboard operation
tiingo-python copied to clipboard

[Feature Request] Add support for fetching intraday volume data in the get_dataframe method

Open whyrv opened this issue 5 years ago • 15 comments

For intraday prices, Tiingo can provide the IEX volume if explicitly requested as "?columns=open,high,low,close,volume" per their docs.

Unfortunately the get_dataframe doesn't expose this, when no metric_name is provided, it passes no value for the column parameter to Tiingo's APIs

                url = self._get_url(stock, frequency)
                response = self._request('GET', url, params=params)
                df = pd.DataFrame(response.json())

I recommend providing a way to request the volume optionally so that the user can get all fields for OHLCV (and choose to discard volume as it may not be complete, or use it with that understanding)

whyrv avatar May 26 '20 02:05 whyrv

Hi @whyrv ,

This is great feedback, thanks for taking a look and providing this idea! When thinking about how to expose this to users, how would you feel if metric_name can be provided as either a list of strings, or as a single string (for the single metric case)? In the case where metric_name was provided as a list, we could thread that through to _get_url as you've suggested.

hydrosquall avatar Jun 03 '20 01:06 hydrosquall

Hi, your suggestion makes sense. I hacked this locally by overriding this method by passing an additional flag includeIntradayVolume as follows

def get_dataframe(self, tickers,
                    startDate=None, endDate=None, metric_name=None, frequency='daily', includeIntradayVolume=True):

#...
# append volume to columns appropriately under the right conditions: intraday and this flag is set.
params['columns'] = 'open,high,low,close,volume'

You could do this and document that volume is IEX only for intraday or flip the boolean.

thanks for looking into this.

whyrv avatar Jun 03 '20 04:06 whyrv

Hi @whyrv, happy to hear that this worked, thanks for sharing your solution. I'd be happy to review a PR if you are interested in making a PR with this adjustment, otherwise I'll leave this open for contributions / add it next time I cut a feature release .

hydrosquall avatar Jun 07 '20 15:06 hydrosquall

Hello @whyrv, could you may detail your solution a little bit more? I am unfortunaltely not able to come across with an workaround. Thanks!

Cheers

maxko37 avatar Mar 01 '21 17:03 maxko37

Hi,

This is the relevant set of changes I had made (search for ### below) in the get_dataframe API I mentioned above.

regards.

valid_columns = {'open', 'high', 'low', 'close', 'volume', 'adjOpen', 'adjHigh', 'adjLow',
                'adjClose', 'adjVolume', 'divCash', 'splitFactor'}


if metric_name is not None and metric_name not in valid_columns:
  raise APIColumnNameError('Valid data items are: ' + str(valid_columns))

if metric_name is None and isinstance(tickers, list):
  raise MissingRequiredArgumentError("""When tickers is provided as a list, metric_name is a required argument.
                                        Please provide a metric_name, or call this method with one ticker at a time.""")

params = {
    'format': 'json',
    'resampleFreq': frequency,
}
### -> this here is key, you need to pass these as columns for getting intraday.
if includeIntradayVolume:
  params['columns'] = 'open,high,low,close,volume'

if startDate:
  params['startDate'] = startDate
if endDate:
  params['endDate'] = endDate

whyrv avatar Mar 02 '21 00:03 whyrv

Hi, thanks for the quick reply. That is really strange. Basically, I did the same but I had the if includeIntradayVolume line below the endDate, which did not seem to work.

maxko37 avatar Mar 02 '21 05:03 maxko37

@hydrosquall I could work on getting a PR later this week.

datatalking avatar Aug 08 '21 22:08 datatalking

That would be very welcome! Thanks @datatalking

hydrosquall avatar Aug 08 '21 23:08 hydrosquall

So I looked for the 'get_dataframe' method, it doesn't look like anybody actually specifically named in which file since it's in three. I'm guessing you are talking about test_tingo_pandas.py? That method is also in api.py and basic-usage-with-pandas.ipynb

datatalking avatar Aug 26 '21 02:08 datatalking

Ok, I think I found it and made the change, not sure if this is the exact place you were thinking so here is a screen shot.

Screen Shot 2021-08-25 at 7 32 33 PM

datatalking avatar Aug 26 '21 02:08 datatalking

The other part of the solution is adding the additional parameter includeIntradayVolume=True in after the fmt=json like this?

Which creates my next question, how do you have it defined? Is it the int64 defined here? Tiingo Docs Section 2.5.3 Historical Intraday Prices Endpoint gave https://api.tiingo.com/iex/<ticker>/prices?startDate=2019-01-02&resampleFreq=5min as an RESTendpoint

Tiingo can also provide the fmt="CSV" so would an additional documentation issue be good to add that? https://api.tiingo.com/documentation/general/overview Section 1.14

Screen Shot 2021-08-25 at 7 59 10 PM

datatalking avatar Aug 26 '21 03:08 datatalking

@datatalking @hydrosquall Any update on this issue? I really need volume data wtih intraday, need to pass volume to the columns params as mentioned in doc,, but not sure how to do with this library?

The number of shares traded on IEX only. This value will only be exposed if explicitly passed to the "columns" request parameter. E.g. ?columns=open,high,low,close,volume

rizclive avatar May 07 '23 12:05 rizclive

Hey @rizclive , the https://github.com/hydrosquall/tiingo-python/pull/673 PR hasn't been worked on in a while.

I think you would be able to get the volume data without further code changes if you request the metric with name "volume" directly:

ticker_history = client.get_dataframe("some-iex-ticker", metric_name='volume')

hydrosquall avatar May 08 '23 22:05 hydrosquall

@rizclive and @hydrosquall I've not worked on this since OP, I could look at it this weekend if this feature still needed or available?

datatalking avatar May 09 '23 22:05 datatalking

@hydrosquall I have tried passing metric_name='volume' but its doesn't seems to be working when I specify lower timeframe then daily. @datatalking would be good to get this feature released.

Thanks! Riz

rizclive avatar May 10 '23 11:05 rizclive