mirror of
https://github.com/hydrosquall/tiingo-python.git
synced 2025-12-17 20:04:19 +01:00
pep8 corrections and changed all object names
This commit is contained in:
@@ -79,6 +79,10 @@ class TestTickerPrices(TestCase):
|
|||||||
assert len(tickers) > 1
|
assert len(tickers) > 1
|
||||||
assert all(ticker['assetType'] == 'Stock' for ticker in tickers)
|
assert all(ticker['assetType'] == 'Stock' for ticker in tickers)
|
||||||
|
|
||||||
|
def test_ticker_metadata_for_object(self):
|
||||||
|
data = self._client.get_ticker_metadata("GOOGL", fmt='object')
|
||||||
|
assert len(data.name) > 1
|
||||||
|
|
||||||
|
|
||||||
# tiingo/news
|
# tiingo/news
|
||||||
class TestNews(TestCase):
|
class TestNews(TestCase):
|
||||||
|
|||||||
@@ -90,11 +90,13 @@ class TiingoClient(RestClient):
|
|||||||
"""
|
"""
|
||||||
url = "tiingo/daily/{}".format(ticker)
|
url = "tiingo/daily/{}".format(ticker)
|
||||||
response = self._request('GET', url)
|
response = self._request('GET', url)
|
||||||
|
data = response.json()
|
||||||
if fmt == 'json':
|
if fmt == 'json':
|
||||||
return response.json()
|
return data
|
||||||
elif fmt == 'object':
|
elif fmt == 'object':
|
||||||
# inspired by https://stackoverflow.com/a/15882054
|
# inspired by https://stackoverflow.com/a/15882054
|
||||||
return json.loads(json.dumps(response.json()), object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
|
return json.loads(json.dumps(data),
|
||||||
|
object_hook=lambda d: namedtuple('Ticker', d.keys())(*d.values()))
|
||||||
|
|
||||||
def get_ticker_price(self, ticker,
|
def get_ticker_price(self, ticker,
|
||||||
startDate=None, endDate=None,
|
startDate=None, endDate=None,
|
||||||
@@ -134,7 +136,8 @@ class TiingoClient(RestClient):
|
|||||||
# NEWS FEEDS
|
# NEWS FEEDS
|
||||||
# tiingo/news
|
# tiingo/news
|
||||||
def get_news(self, tickers=[], tags=[], sources=[], startDate=None,
|
def get_news(self, tickers=[], tags=[], sources=[], startDate=None,
|
||||||
endDate=None, limit=100, offset=0, sortBy="publishedDate",fmt='json'):
|
endDate=None, limit=100, offset=0, sortBy="publishedDate",
|
||||||
|
fmt='json'):
|
||||||
"""Return list of news articles matching given search terms
|
"""Return list of news articles matching given search terms
|
||||||
https://api.tiingo.com/docs/tiingo/news
|
https://api.tiingo.com/docs/tiingo/news
|
||||||
|
|
||||||
@@ -161,10 +164,12 @@ class TiingoClient(RestClient):
|
|||||||
'endDate': endDate
|
'endDate': endDate
|
||||||
}
|
}
|
||||||
response = self._request('GET', url, params=params)
|
response = self._request('GET', url, params=params)
|
||||||
|
data = response.json()
|
||||||
if fmt == 'json':
|
if fmt == 'json':
|
||||||
return response.json()
|
return data
|
||||||
elif fmt == 'object':
|
elif fmt == 'object':
|
||||||
return json.loads(json.dumps(response.json()), object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
|
return json.loads(json.dumps(data),
|
||||||
|
object_hook=lambda d: namedtuple('NewsArticle', d.keys())(*d.values()))
|
||||||
|
|
||||||
def get_bulk_news(self, file_id=None, fmt='json'):
|
def get_bulk_news(self, file_id=None, fmt='json'):
|
||||||
"""Only available to institutional clients.
|
"""Only available to institutional clients.
|
||||||
@@ -178,7 +183,9 @@ class TiingoClient(RestClient):
|
|||||||
url = "tiingo/news/bulk_download"
|
url = "tiingo/news/bulk_download"
|
||||||
|
|
||||||
response = self._request('GET', url)
|
response = self._request('GET', url)
|
||||||
|
data = response.json()
|
||||||
if fmt == 'json':
|
if fmt == 'json':
|
||||||
return response.json()
|
return data
|
||||||
elif fmt == 'object':
|
elif fmt == 'object':
|
||||||
return json.loads(json.dumps(response.json()), object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))
|
return json.loads(json.dumps(data),
|
||||||
|
object_hook=lambda d: namedtuple('BulkDownload', d.keys())(*d.values()))
|
||||||
|
|||||||
Reference in New Issue
Block a user