Created
December 23, 2018 16:26
-
-
Save km09/815de013bcdee4596d27b5fb10804bf0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kurt@grafana:~/ticker$ cat sp500.py | |
import requests | |
try: | |
info = requests.get("https://query1.finance.yahoo.com/v8/finance/chart/VUSA.L?region=US&lang=en-US&includePrePost=false&interval=1d&range=1d&corsDomain=finance.yahoo.com&.tsrc=finance").json() | |
lastPrice = round(info['chart']['result'][0]['indicators']['quote'][0]['close'][-1],2) | |
prevClose = info['chart']['result'][0]['meta']['chartPreviousClose'] | |
change = '{0:.2f}'.format(((lastPrice / prevClose -1) * 100)) + "%" | |
print("ticker sp500=\"£" + str(lastPrice)[:5] + " (" + change + ")\"") | |
except: | |
print("ticker sp500=\"API ERROR\"") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment