Stock Price API Finnhub

How to fetch current Stock Prices or the historical dividend of companies for free? Finnhub code examples in python.

Stock Price

Finnhub is a API where you can request for example stock prices:

https://finnhub.io/docs/api#quote

With the quote command you get the open / high / low / current and previous close price.

Historical Dividend

https://finnhub.io/docs/api#stock-dividends

Here it is possible to define a start and end date for a specified stock symbol.

Code

You have to replace your own API token.

import requests
from pprint import pprint
import json

stockSymbol = "APC.F"
stockPriceRequest = requests.get('https://finnhub.io/api/v1/quote?symbol=%s&token=XXXXXXX' % stockSymbol)
stockPriceJson = stockPriceRequest.json()

print(stockPriceJson)
print(stockPriceJson['c'])

dividendRequest = requests.get('https://finnhub.io/api/v1/stock/dividend?symbol=%s&from=2000-01-01&to=2021-01-01&token=XXXXXX' % stockSymbol)
dividendJson = dividendRequest.json()

pprint(dividendJson)

for i in dividendJson:
    print(i['amount'])

Result

Stock Price API Finnhub

And yeah, Apple paid 3 dollars. 2014 was a 7 for 1 stock split as you can see on the Apple website:

https://investor.apple.com/dividend-history/default.aspx

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Nach oben scrollen