Financial (Stock) Market Data

Introduction

Alpha Vantage provides realtime and historical financial market data through a set of powerful and developer-friendly data APIs.

Project #0

Become familiar with Alpha Vantage, the data available, and the Python API. Get a free (student) API key and use it in your code.

Pick a company or two and get their stock market ticker names. (What is a stock market ticker name?)

Project #1

Use the url (from the web site)

url = 'https://www.alphavantage.co/query' +\ '?function=SYMBOL_SEARCH&keywords=tesco&apikey=demo' r = requests.get(url) data = r.json()

What data is available?

Pretty print the resulting JSON data.

Project #2

Pick a stock/company and use the following URL

url = 'https://www.alphavantage.co/query' +\ '?function=OVERVIEW&symbol={}&apikey={}'

What data is available?

Pretty print the resulting JSON data.

Project #3

Query hourly, daily, or weekly stock price and/or volume for a month or more. Source should be a company, the Dow Jones Industrial Average, or S&P 500. (More than one company?)

Plot the data using a Python plot package.

I suggest you use the pyplot or related modules.
matplotlib.pyplot (documentation and examples)

Links

www.alphavantage.co (home)
www.alphavantage.co (documentation / code examples)
www.alphavantage.co (see demo code)
www.alphavantage.co (claim your Free API Key - student)

Intro to async Python | Writing a Web Crawler (YouTube)
Python Asyncio, Requests, Aiohttp | Make faster API Calls (YouTube)

Demo

#!/usr/bin/python3 # ========================================================= # a synchronous loop though financial (stock) market data # (do the first one, then the next, then the next, ...) # # Try doing it using asyncio? # ========================================================= import requests # ---- my free API key api_key = <my API key - get your own> # ---- stock market ticker symbols # ---- AAPL apple # ---- GOOGL google # ---- TSLA tesla # ---- MSFT microsoft #symbols = [ 'AAPL', 'GOOGL', 'TSLA', 'MSFT' ] symbols = [ 'AAPL' ] results = [] url = 'https://www.alphavantage.co/query' +\ '?function=OVERVIEW&symbol={}&apikey={}' for symbol in symbols: print(f'processing symbol {symbol}') response = requests.get(url.format(symbol, api_key)) results.append(response.json()) print(results[0]) <-- this is not pretty print