Skip to content

Instantly share code, notes, and snippets.

@vvksh
Created August 4, 2020 15:45
Show Gist options
  • Save vvksh/2f6f8861855e934b7f77ec97bb05ea07 to your computer and use it in GitHub Desktop.
Save vvksh/2f6f8861855e934b7f77ec97bb05ea07 to your computer and use it in GitHub Desktop.
Yahoo finance get last 20 mins of stock data
import requests
import time
def getUrl(symbol):
now = int(time.time())
return "https://query1.finance.yahoo.com/v8/finance/chart/{}?symbol={}&period1={}&period2={}&interval=1m&includePrePost=true&lang=en-US&region=US&corsDomain=finance.yahoo.com".format(symbol, symbol, now-20*60, now)
def main():
print(getUrl("UBER"))
r = requests.get(getUrl("UBER"))
response = r.json()
print(response['chart']['result'][0]['indicators']['quote'][0]['close'])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment