Skip to content

Instantly share code, notes, and snippets.

@jordan-chalupka
Created October 4, 2019 18:32
Show Gist options
  • Save jordan-chalupka/c9e055b82950757a00ba6e6cbf1776b0 to your computer and use it in GitHub Desktop.
Save jordan-chalupka/c9e055b82950757a00ba6e6cbf1776b0 to your computer and use it in GitHub Desktop.
Gets a stock quote from AlphaVantage
import os
from botocore.vendored import requests
def get_stock_quote(symbol):
API_KEY = os.environ['API_KEY']
response = requests.get(f'https://www.alphavantage.co/query?apikey={API_KEY}&function=GLOBAL_QUOTE&symbol={symbol}')
return response.json()['Global Quote']
# get_stock_quote('AAPL')
# {
# '01. symbol': 'AAPL',
# '02. open': '225.5400',
# '03. high': '226.1900',
# '04. low': '223.8900',
# '05. price': '225.9700',
# '06. volume': '9226278',
# '07. latest trading day': '2019-10-04',
# '08. previous close': '220.8200',
# '09. change': '5.1500',
# '10. change percent': '2.3322%'
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment