Free stock api for trading and research

finnhub stock api

Financial data nowadays, is surprisingly hard to get. Thanks to the new kid in the block Finnhub, we now have access to a free stock api with super high quality data. You can build trading strategy using their free data and backtest it in live market for free. In this example, we will try to pull the price of Apple and calculate a simple moving average.

You can get your Free API key first to access 60 calls/minute. In this tutorial I will use the API without a API key, which will limit me to 2 calls per mintue. Here is an example:

Get 2000 Daily candles for AAPL

https://finnhub.io/api/v1/stock/candle?symbol=AAPL&resolution=D&count=500



import requests
import json
import pandas as pd
r = requests.get('https://finnhub.io/api/v1/stock/candle?symbol=AAPL&resolution=D&count=500')
j = json.loads(r.text)
closes = j['c'].
N = 20
print(pd.Series(x).rolling(window=N).mean().iloc[N-1:].values)




To learn more about Finnhub stock API , read the docs here
Featured as the best option on Medium stock market API guide