Rebasing api.py

This commit is contained in:
GenusGeoff
2021-03-17 06:32:36 -04:00
parent d114a4b7b3
commit 969cbca412

View File

@@ -311,149 +311,6 @@ class TiingoClient(RestClient):
"Alternatively, just install pandas: pip install pandas.")
raise InstallPandasException(error_message)
####################### BEGIN Modifications (GenusGeoff)
### Add get_daily_data and get_iex_data
###
### The suffix _data is more appropriate in this case because if a metric_name is passed then the method returns a
### pandas.Series not a pandas.DataFrame.
###
# Get Daily Data
def get_daily_data(self, tickers,
startDate=None, endDate=None, metric_name=None,
frequency='daily', fmt='csv'):
""" Returns historical prices for one or more ticker symbols.
By default, return latest EOD Composite Adjusted Closing Price for a list of stock tickers.
On average, each feed contains 3 data sources.
Supported tickers + Available Day Ranges are here:
https://apimedia.tiingo.com/docs/tiingo/daily/supported_tickers.zip
or from the TiingoClient.list_tickers() method.
Args:
tickers (string/list): One or more unique identifiers for a stock ticker.
startDate (string): Start of ticker range in YYYY-MM-DD format.
endDate (string): End of ticker range in YYYY-MM-DD format.
metric_name (string): Optional parameter specifying metric to be returned for each
ticker. In the event of a single ticker, this is optional and if not specified
all of the available data will be returned. In the event of a list of tickers,
this parameter is required.
frequency (string): Resample frequency (defaults to daily).
fmt (string): 'csv' or 'json'
"""
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': fmt,
'resampleFreq': frequency
}
if startDate:
params['startDate'] = startDate
if endDate:
params['endDate'] = endDate
if pandas_is_installed:
if type(tickers) is str:
prices = self._request_pandas(
ticker=tickers, params=params, metric_name=metric_name)
else:
prices = pd.DataFrame()
for stock in tickers:
ticker_series = self._request_pandas(
ticker=stock, params=params, metric_name=metric_name)
ticker_series = ticker_series.rename(stock)
prices = pd.concat([prices, ticker_series], axis=1, sort=True)
return prices
else:
error_message = ("Pandas is not installed, but .get_ticker_price() was "
"called with fmt=pandas. In order to install tiingo with "
"pandas, reinstall with pandas as an optional dependency. \n"
"Install tiingo with pandas dependency: \'pip install tiingo[pandas]\'\n"
"Alternatively, just install pandas: pip install pandas.")
raise InstallPandasException(error_message)
## Get IEX Data
def get_iex_data(self, tickers,
startDate=None, endDate=None, metric_name=None,
frequency='1hour', fmt='csv'):
""" Return a pandas.DataFrame of historical prices for one or more ticker symbols.
By default, return latest EOD Composite Price for a list of stock tickers.
On average, each feed contains 3 data sources.
Supported tickers + Available Day Ranges are here:
https://apimedia.tiingo.com/docs/tiingo/daily/supported_tickers.zip
or from the TiingoClient.list_tickers() method.
Args:
tickers (string/list): One or more unique identifiers for a stock ticker.
startDate (string): Start of ticker range in YYYY-MM-DD format.
endDate (string): End of ticker range in YYYY-MM-DD format.
metric_name (string): Optional parameter specifying metric to be returned for each
ticker. In the event of a single ticker, this is optional and if not specified
all of the available data will be returned. In the event of a list of tickers,
this parameter is required.
frequency (string): Resample frequency (defaults to daily).
fmt (string): 'csv' or 'json'
"""
valid_columns = {'open', 'high', 'low', 'close', 'volume'}
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': fmt,
'resampleFreq': frequency
}
if startDate:
params['startDate'] = startDate
if endDate:
params['endDate'] = endDate
if pandas_is_installed:
if type(tickers) is str:
prices = self._request_pandas(
ticker=tickers, params=params, metric_name=metric_name)
else:
prices = pd.DataFrame()
for stock in tickers:
ticker_series = self._request_pandas(
ticker=stock, params=params, metric_name=metric_name)
ticker_series = ticker_series.rename(stock)
prices = pd.concat([prices, ticker_series], axis=1, sort=True)
return prices
else:
error_message = ("Pandas is not installed, but .get_ticker_price() was "
"called with fmt=pandas. In order to install tiingo with "
"pandas, reinstall with pandas as an optional dependency. \n"
"Install tiingo with pandas dependency: \'pip install tiingo[pandas]\'\n"
"Alternatively, just install pandas: pip install pandas.")
raise InstallPandasException(error_message)
### End of Modifications (GenusGeoff)
# NEWS FEEDS
# tiingo/news
def get_news(self, tickers=[], tags=[], sources=[], startDate=None,