Search code examples
pythonjsonregexgoogle-financestockquotes

google finance python package not working for some stocks


This is functional code for retrieving stock prices.

from googlefinance import getQuotes
import json
import re


def get_last_trade_price(TICKER):
    Asset = json.dumps(getQuotes(TICKER))
    raw = (json.loads(Asset)[0]["LastTradePrice"])
    raw = re.sub(',','',raw)        
    return float(raw)

This function retrieves the last traded price of the stock.

get_last_trade_price('AAPL')

But it does not work for some of the stocks listed in other exchanges outside the US.

get_last_trade_price('C52')

This link shows the details of the company. How can I get this code to work?


Solution

  • try using the ticker with the index specified first SGX:C52

    get_last_trade_price('SGX:C52')