mirror of
https://github.com/hydrosquall/tiingo-python.git
synced 2026-02-18 08:34:19 +01:00
Requested changes
This commit is contained in:
@@ -13,3 +13,4 @@ Contributors
|
|||||||
* Dmitry Budaev <condemil@gmail.com>
|
* Dmitry Budaev <condemil@gmail.com>
|
||||||
* Bharat Kalluri
|
* Bharat Kalluri
|
||||||
* Stephen Clark <steveclarkcode@gmail.com>
|
* Stephen Clark <steveclarkcode@gmail.com>
|
||||||
|
* Davis Thames
|
||||||
|
|||||||
@@ -88,11 +88,14 @@ class TiingoClient(RestClient):
|
|||||||
'User-Agent': 'tiingo-python-client {}'.format(VERSION)
|
'User-Agent': 'tiingo-python-client {}'.format(VERSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
self._frequency_pattern = re.compile('^[0-9]+(min)$|(hour)$', re.IGNORECASE)
|
self._frequency_pattern = re.compile('^[0-9]+(min|hour)$', re.IGNORECASE)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<TiingoClient(url="{}")>'.format(self._base_url)
|
return '<TiingoClient(url="{}")>'.format(self._base_url)
|
||||||
|
|
||||||
|
def _is_eod_frequency(self,frequency):
|
||||||
|
return frequency.lower() in ['daily', 'weekly', 'monthly', 'annually']
|
||||||
|
|
||||||
# TICKER PRICE ENDPOINTS
|
# TICKER PRICE ENDPOINTS
|
||||||
# https://api.tiingo.com/docs/tiingo/daily
|
# https://api.tiingo.com/docs/tiingo/daily
|
||||||
def list_tickers(self, assetType):
|
def list_tickers(self, assetType):
|
||||||
@@ -142,17 +145,14 @@ class TiingoClient(RestClient):
|
|||||||
:param frequency (string): frequency string
|
:param frequency (string): frequency string
|
||||||
:return (boolean):
|
:return (boolean):
|
||||||
"""
|
"""
|
||||||
daily_freqs = ['daily', 'weekly', 'monthly', 'annually']
|
is_valid = self._is_eod_frequency(frequency) or re.match(self._frequency_pattern, frequency)
|
||||||
|
return not is_valid
|
||||||
|
|
||||||
if frequency.lower() in daily_freqs or re.match(self._frequency_pattern, frequency):
|
def _get_url(self, ticker, frequency):
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _get_url(self, frequency):
|
|
||||||
"""
|
"""
|
||||||
Return url based on frequency. Daily, weekly, or yearly use Tiingo
|
Return url based on frequency. Daily, weekly, or yearly use Tiingo
|
||||||
EOD api; anything less than daily uses the iex intraday api.
|
EOD api; anything less than daily uses the iex intraday api.
|
||||||
|
:param ticker (string): ticker to be embedded in the url
|
||||||
:param frequency (string): valid frequency per Tiingo api
|
:param frequency (string): valid frequency per Tiingo api
|
||||||
:return (string): url
|
:return (string): url
|
||||||
"""
|
"""
|
||||||
@@ -161,10 +161,10 @@ class TiingoClient(RestClient):
|
|||||||
"for valid EOD or intraday frequency format.")
|
"for valid EOD or intraday frequency format.")
|
||||||
raise InvalidFrequencyError(etext.format(frequency))
|
raise InvalidFrequencyError(etext.format(frequency))
|
||||||
else:
|
else:
|
||||||
if frequency.lower() in ['daily', 'weekly', 'monthly', 'annually']:
|
if self._is_eod_frequency(frequency):
|
||||||
return "tiingo/daily/{}/prices"
|
return "tiingo/daily/{}/prices".format(ticker)
|
||||||
else:
|
else:
|
||||||
return "iex/{}/prices"
|
return "iex/{}/prices".format(ticker)
|
||||||
|
|
||||||
def get_ticker_price(self, ticker,
|
def get_ticker_price(self, ticker,
|
||||||
startDate=None, endDate=None,
|
startDate=None, endDate=None,
|
||||||
@@ -182,7 +182,7 @@ class TiingoClient(RestClient):
|
|||||||
fmt (string): 'csv' or 'json'
|
fmt (string): 'csv' or 'json'
|
||||||
frequency (string): Resample frequency
|
frequency (string): Resample frequency
|
||||||
"""
|
"""
|
||||||
url = self._get_url(frequency).format(ticker)
|
url = self._get_url(ticker, frequency)
|
||||||
params = {
|
params = {
|
||||||
'format': fmt if fmt != "object" else 'json', # conversion local
|
'format': fmt if fmt != "object" else 'json', # conversion local
|
||||||
'resampleFreq': frequency
|
'resampleFreq': frequency
|
||||||
@@ -245,7 +245,7 @@ class TiingoClient(RestClient):
|
|||||||
if pandas_is_installed:
|
if pandas_is_installed:
|
||||||
if type(tickers) is str:
|
if type(tickers) is str:
|
||||||
stock = tickers
|
stock = tickers
|
||||||
url = self._get_url(frequency).format(stock)
|
url = self._get_url(stock, frequency)
|
||||||
response = self._request('GET', url, params=params)
|
response = self._request('GET', url, params=params)
|
||||||
df = pd.DataFrame(response.json())
|
df = pd.DataFrame(response.json())
|
||||||
if metric_name is not None:
|
if metric_name is not None:
|
||||||
@@ -258,7 +258,7 @@ class TiingoClient(RestClient):
|
|||||||
else:
|
else:
|
||||||
prices = pd.DataFrame()
|
prices = pd.DataFrame()
|
||||||
for stock in tickers:
|
for stock in tickers:
|
||||||
url = self._get_url(frequency).format(stock)
|
url = self._get_url(stock, frequency)
|
||||||
response = self._request('GET', url, params=params)
|
response = self._request('GET', url, params=params)
|
||||||
df = pd.DataFrame(response.json())
|
df = pd.DataFrame(response.json())
|
||||||
df.index = df['date']
|
df.index = df['date']
|
||||||
|
|||||||
Reference in New Issue
Block a user