Last active
March 19, 2021 09:14
-
-
Save databyjp/2596aec234a1e2ac19987364c7bf9f8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_prices(symbol, key, date_param='5d'): | |
url_prefix = "https://cloud.iexapis.com/stable/" | |
path = f'stock/{symbol}/chart/{date_param}?chartCloseOnly=True&&token={key}' | |
print(f"Fetching {date_param} data for {symbol}") | |
full_url = requests.compat.urljoin(url_prefix, path) | |
try: | |
resp = requests.get(full_url) | |
except Exception as e: | |
print(f"Exception {e} occurred!") | |
return None | |
if resp.status_code != 200: | |
print(f"Uh oh, something's wrong! Response code {resp.status_code} received.") | |
return resp | |
else: | |
print(f"Got the data") | |
return resp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment