mirror of
https://github.com/hydrosquall/tiingo-python.git
synced 2025-12-18 04:14:20 +01:00
Add Objects to Prices endpoint, Refactor with List Comprehension
This commit is contained in:
@@ -123,7 +123,7 @@ class TiingoClient(RestClient):
|
|||||||
"""
|
"""
|
||||||
url = "tiingo/daily/{}/prices".format(ticker)
|
url = "tiingo/daily/{}/prices".format(ticker)
|
||||||
params = {
|
params = {
|
||||||
'format': fmt,
|
'format': fmt if fmt != "object" else 'json', # conversion local
|
||||||
'frequency': frequency
|
'frequency': frequency
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +137,9 @@ class TiingoClient(RestClient):
|
|||||||
response = self._request('GET', url, params=params)
|
response = self._request('GET', url, params=params)
|
||||||
if fmt == "json":
|
if fmt == "json":
|
||||||
return response.json()
|
return response.json()
|
||||||
|
elif fmt == "object":
|
||||||
|
data = response.json()
|
||||||
|
return [dict_to_object(item, "TickerPrice") for item in data]
|
||||||
else:
|
else:
|
||||||
return response.content.decode("utf-8")
|
return response.content.decode("utf-8")
|
||||||
|
|
||||||
@@ -175,12 +178,7 @@ class TiingoClient(RestClient):
|
|||||||
if fmt == 'json':
|
if fmt == 'json':
|
||||||
return data
|
return data
|
||||||
elif fmt == 'object':
|
elif fmt == 'object':
|
||||||
obj_arr = []
|
return [dict_to_object(item, "NewsArticle") for item in data]
|
||||||
for el in data:
|
|
||||||
# inspired by https://stackoverflow.com/a/15882054
|
|
||||||
arr_el = dict_to_object(el, "NewsArticle")
|
|
||||||
obj_arr.append(arr_el)
|
|
||||||
return obj_arr
|
|
||||||
|
|
||||||
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user