Has Yahoo finance web service disappeared? API changed? Down temporarily?

后端 未结 9 1437
礼貌的吻别
礼貌的吻别 2020-11-27 13:12

For quite some time I\'ve been using the following REST API to query Yahoo finance for current prices. It is documented in several Stack Overflow posts, e.g. Yahoo finance

相关标签:
9条回答
  • 2020-11-27 13:49

    The Python Yahoo Finance API seems to have a problem too. If you use it to look up, for example, Amazon stock prices it just shows the same two values over and over.

    from yahoo_finance import Share import time f = open('/tmp/amazon/amzn.csv', 'w') while True:
        amzn=Share("AMZN")
        s = amzn.get_price() + "," + amzn.get_trade_datetime() + '\n'
        print (s)
        f.write (s)
        f.flush()
        time.sleep(5)
        del amzn
    
    0 讨论(0)
  • 2020-11-27 13:51

    I found a way to use the csv API.

    link

    where you need to write the symbol, the parameters and columns.

    Use this website to find the parameters needed: http://www.jarloo.com/yahoo_finance/

    example:

    If you need to know the symbol's volume replace the string sl1d1t1c1ohgv with v

    and replace the columns symbol%2Cprice%2Cdate%2Ctime%2Cchange%2Ccol1%2Chigh%2Clow%2Cvolume with volume

    The only issue is that data is kinda random and not real time like it was in webservice API

    0 讨论(0)
  • 2020-11-27 13:53

    It is redirecting to the same page, but adding the parameter "bypass=true", which gives an error.

    EDIT: The answer given by https://stackoverflow.com/users/6593038/hemant-prasad is working for me. When changing the user agent to a mobile device, the API works fine, and doesn't redirect so far.

    This is the code I'm using in Java (it's for the XML version, but it can be use for JSON as well):

    URL url = new URL ("https://finance.yahoo.com/webservice/v1/symbols/" + stocks + "/quote");
    HttpURLConnection urlc = (HttpURLConnection) url.openConnection ();
    urlc.setRequestProperty ("User-Agent", "Mozilla/5.0 (Linux; Android 6.0; MotoE2(4G-LTE) Build/MPI24.65-39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.81 Mobile Safari/537.36");
    Document xml = DocumentBuilderFactory.newInstance ().newDocumentBuilder ().parse (urlc.getInputStream ());
    
    0 讨论(0)
提交回复
热议问题