Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[documentation][clarification] get_dataframe function for multiple tickers with intraday prices #468

Open
MrHarBear opened this issue Jun 4, 2020 · 1 comment

Comments

@MrHarBear
Copy link

I am a new user trying to get some intraday stock data. In the documentation, it says we could use get "any intraday frequency for both the get_ticker_price and get_dataframe methods", but I couldn't get it to work.

Please see the code I've used below. The objective is trying to pull multiple tickers with say 5min timeframe.

ticker_history = client.get_dataframe(['GOOGL', 'AAPL'],
                                      frequency='30Min',
                                      metric_name='adjClose',
                                      startDate='2017-01-01',
                                      endDate='2018-05-31')

Error I am getting

Traceback (most recent call last):

  File "C:\Users\chenh\anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2646, in get_loc
    return self._engine.get_loc(key)

  File "pandas\_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\hashtable_class_helper.pxi", line 1619, in pandas._libs.hashtable.PyObjectHashTable.get_item

  File "pandas\_libs\hashtable_class_helper.pxi", line 1627, in pandas._libs.hashtable.PyObjectHashTable.get_item

KeyError: 'GOOGL'


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "<ipython-input-12-42944e325660>", line 5, in <module>
    endDate='2018-05-31')

  File "C:\Users\chenh\anaconda3\lib\site-packages\tiingo\api.py", line 270, in get_dataframe
    prices = pd.concat([prices, df[stock]], axis=1)

  File "C:\Users\chenh\anaconda3\lib\site-packages\pandas\core\frame.py", line 2800, in __getitem__
    indexer = self.columns.get_loc(key)

  File "C:\Users\chenh\anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 2648, in get_loc
    return self._engine.get_loc(self._maybe_cast_indexer(key))

  File "pandas\_libs\index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\hashtable_class_helper.pxi", line 1619, in pandas._libs.hashtable.PyObjectHashTable.get_item

  File "pandas\_libs\hashtable_class_helper.pxi", line 1627, in pandas._libs.hashtable.PyObjectHashTable.get_item

KeyError: 'GOOGL'
@hydrosquall
Copy link
Owner

Hi @MrHarBear,

Thanks for writing in. We should look into clarifying the documentation, the first priority has been on making sure get_ticker_price should expose all the core functionality for both end of day and intraday datasets. The pandas helper is a convenience helper method, but it was written primarily with the EOD endpoint in mind. We could do more to validate what metric names can be passed in for each frequency type. I'm not sure if adjClose is available for intraday frequencies, but close might be (see section 2.5.3 here: https://api.tiingo.com/documentation/iex )

In the meantime, would you be able to get the information you need using get_ticker_price to get data for 1 ticker at a time? If you end up with a code sample that you're willing to share and is generalizable, we could explore pushing back into the core library.

It might look something like this:

import pandas as pd
tickers = ['GOOGL', 'APPL']
prices = [client.get_ticker_price(ticker,
                                            fmt='json',
                                            startDate='2017-08-01',
                                            endDate='2017-08-31',
                                            frequency='5min') for ticker in tickers]
price_dataframes = [pd.DataFrame(price_json) for price_json in prices]
# price_dataframes[0].head() # inspect dataframe/modify response further from here

Thanks for taking the time to share your experience with tiingo-python !

@hydrosquall hydrosquall changed the title get_dataframe function for multiple tickers with intraday prices [documentation][clarification] get_dataframe function for multiple tickers with intraday prices Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants