Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Retrieve Stock Market Data from the AlphaVantage API
from urllib.request import urlopen
import yaml
def retrieve(symbol=None):
with open('config.yml') as f:
config = yaml.load(f)
params = {
'function': 'TIME_SERIES_DAILY',
'symbol': symbol,
'outputsize': 'full',
'apikey': config['alphavantage']['apikey']
param_str = '&'.join(['{}={}'.format(key, value) for key, value in params.items()])
url = "{}".format(param_str)
print('Retrieving {}'.format(url))
csv_data = urlopen(url).read().decode('utf-8')
print('Saving to {}.csv'.format(symbol))
with open('{}.csv'.format(symbol), 'w') as f:
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description="Data Retriever")
parser.add_argument('--symbol', help="The symbol to retrieve", default='GOOGL')
args = parser.parse_args()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.