Skip to content

Instantly share code, notes, and snippets.

@databyjp
Last active March 19, 2021 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save databyjp/2596aec234a1e2ac19987364c7bf9f8f to your computer and use it in GitHub Desktop.
Save databyjp/2596aec234a1e2ac19987364c7bf9f8f to your computer and use it in GitHub Desktop.
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