hongtaocai / googlefinance

Python module to get real-time stock data from Google Finance API
MIT License
700 stars 172 forks source link

Google Finance API change? #39

Open edward-dauvergne opened 7 years ago

edward-dauvergne commented 7 years ago

The URLs such as https://finance.google.com/finance/info?client=ig&q=EURUSD now return the response:

httpserver.cc: Response Code 400

Has the Google Finance API changed?

ccampbell commented 7 years ago

Now they are returning 404

arnaudsj commented 7 years ago

Yes, any getQuotes request for me returns 404 since this morning. Anybody else still able to use this library?

lashkapolta commented 7 years ago

me having 404 too with the method below in python 2.7 print json.dumps(getQuotes('AAPL'), indent=2)

leikahing commented 7 years ago

It seems like that endpoint itself has changed or gone away (temporarily? permanently? can't say), which is the unfortunate nature of this system since it has no official API anymore.

I helped someone on StackOverflow with a 'workaround' of basically parsing the full response to get information.

https://stackoverflow.com/a/46081537/297696

Code from answer below:

import json
import requests

rsp = requests.get('https://finance.google.com/finance?q=AAPL&output=json')
if rsp.status_code in (200,):

    # This magic here is to cut out various leading characters from the JSON 
    # response, as well as trailing stuff (a terminating ']\n' sequence), and then
    # we decode the escape sequences in the response
    # This then allows you to load the resulting string
    # with the JSON module.
    fin_data = json.loads(rsp.content[6:-2].decode('unicode_escape'))

    # print out some quote data
    print('Opening Price: {}'.format(fin_data['op']))
    print('Price/Earnings Ratio: {}'.format(fin_data['pe']))
    print('52-week high: {}'.format(fin_data['hi52']))
    print('52-week low: {}'.format(fin_data['lo52']))

A derivative of this could integrated into the library assuming the other endpoint doesn't come back (and a better endpoint isn't found), though there are limitations of the normal endpoint, like it not supporting multiple quotes in the same request.

valenciakarlos commented 7 years ago

Can google be contacted for a solution? this was a pretty useful API.

bkcollection commented 7 years ago

This url will not work if you want to get the quotes for more than one stocks. https://finance.google.com/finance?q=AAPL,MSFT&output=json will not return any of the stock quotes

Also, a few ticker will not work with the above url

  1. currency such as CURRENCY:USDEUR
  2. Last trade time missing
PassHours commented 6 years ago

@bkcollection it's works but asking for a download. Do you know how to use it in javascript. Or how the print the output in browser window instead of download