mirror of
https://github.com/hydrosquall/tiingo-python.git
synced 2025-12-18 12:24:18 +01:00
Add support for tiingo crypto endpoints to TiingoClient
This commit is contained in:
@@ -144,7 +144,7 @@ class TiingoClient(RestClient):
|
|||||||
is_valid = self._is_eod_frequency(frequency) or re.match(self._frequency_pattern, frequency)
|
is_valid = self._is_eod_frequency(frequency) or re.match(self._frequency_pattern, frequency)
|
||||||
return not is_valid
|
return not is_valid
|
||||||
|
|
||||||
def _get_url(self, ticker, frequency):
|
def _get_price_url(self, ticker, 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.
|
||||||
@@ -178,7 +178,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(ticker, frequency)
|
url = self._get_price_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(stock, frequency)
|
url = self._get_price_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(stock, frequency)
|
url = self._get_price_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']
|
||||||
@@ -331,3 +331,66 @@ class TiingoClient(RestClient):
|
|||||||
return data
|
return data
|
||||||
elif fmt == 'object':
|
elif fmt == 'object':
|
||||||
return dict_to_object(data, "BulkNews")
|
return dict_to_object(data, "BulkNews")
|
||||||
|
|
||||||
|
# Crypto
|
||||||
|
# tiingo/crypto
|
||||||
|
def get_crypto_top_of_book(self, tickers=[],
|
||||||
|
endDate=None, exchanges=[],
|
||||||
|
includeRawExchangeData=False, convertCurrency=None):
|
||||||
|
url = 'https://api.tiingo.com/tiingo/crypto/top'
|
||||||
|
params = {
|
||||||
|
'tickers': ','.join(tickers)
|
||||||
|
}
|
||||||
|
|
||||||
|
if endDate:
|
||||||
|
params['endDate'] = endDate
|
||||||
|
if len(exchanges):
|
||||||
|
params['exchanges'] = ','.join(exchanges)
|
||||||
|
if includeRawExchangeData is True:
|
||||||
|
params['includeRawExchangeData'] = True
|
||||||
|
if convertCurrency:
|
||||||
|
params['convertCurrency'] = convertCurrency
|
||||||
|
|
||||||
|
response = self._request('GET', url, params=params)
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
def get_crypto_price_history(self, tickers=[], baseCurrency=None,
|
||||||
|
startDate=None, endDate=None, exchanges=[],
|
||||||
|
consolidateBaseCurrency=False, includeRawExchangeData=False,
|
||||||
|
resampleFreq=None, convertCurrency=None):
|
||||||
|
url = 'https://api.tiingo.com/tiingo/crypto/prices'
|
||||||
|
params = {
|
||||||
|
'tickers': ','.join(tickers)
|
||||||
|
}
|
||||||
|
|
||||||
|
if startDate:
|
||||||
|
params['startDate'] = startDate
|
||||||
|
if endDate:
|
||||||
|
params['endDate'] = endDate
|
||||||
|
if len(exchanges):
|
||||||
|
params['exchanges'] = ','.join(exchanges)
|
||||||
|
if consolidateBaseCurrency is True:
|
||||||
|
params['consolidateBaseCurrency'] = ','.join(consolidateBaseCurrency)
|
||||||
|
if includeRawExchangeData is True:
|
||||||
|
params['includeRawExchangeData'] = ','.join(includeRawExchangeData)
|
||||||
|
if resampleFreq:
|
||||||
|
params['resampleFreq'] = resampleFreq
|
||||||
|
if convertCurrency:
|
||||||
|
params['convertCurrency'] = convertCurrency
|
||||||
|
|
||||||
|
response = self._request('GET', url, params=params)
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
def get_crypto_meta_data(self, tickers=[], fmt='json'):
|
||||||
|
url = 'https://api.tiingo.com/tiingo/crypto'
|
||||||
|
|
||||||
|
params = {
|
||||||
|
'tickers': ','.join(tickers),
|
||||||
|
'format': fmt,
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self._request('GET', url, params=params)
|
||||||
|
if fmt == 'csv':
|
||||||
|
return response.content.decode("utf-8")
|
||||||
|
else:
|
||||||
|
return response.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user