How To Download Data From Google Finance

Google Sheets has a built-in function called GOOGLEFINANCE which fetches current or historical securities information from Google Finance to a Google Sheet. In contrast, both Google Finance and Yahoo Finance sites offer an URL with query string parameters API for specifying what stocks and time period to download data. However, the URL with query string parameters approach allows the downloading of data for just one ticker symbol at a time. If I feed it a start date before the IPO, the output reverts to give me only data from the last year or so. This seems to be a Google Finance interface issue. Not necessarily just an issue with your code. The same thing happens when I try the other Google Finance data grabbers posted on Mathworks. Then you turn on the waterworks, visiting the “Pricing” page of some expensive data feed company; and, in the end, after a long and tiresome day spent searching for quotes, you get desperate. You decide to go to the Google Finance website, and you see the Google stock historical prices data that you are requiring. To transfer your portfolio data from Google Finance to Excel, you can use Google's data export tool. This will take only a few minutes to download and import your stock data.

I am trying to download stock prices from Google Finance, and it kinda work and not in same time. (only 289 stocks out of 505 tickers are downloaded)

it says:

Why am I having this issue, and how can I download rest 200+ data?

Thank you!

Kevin ChoiKevin Choi

1 Answer

Download Data Yahoo Finance

Well, for some reason, Google don't seem to have the day-series price data for Lockheed Martin for 2017 (the ticker symbol your query failed on.)

How To Download Data From Google Finance

Also, Google don't like automated queries on financial data: if I run your code I regularly get a response including the text 'We're sorry... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.'

If you just want the price data, one simple answer is to use Yahoo instead. Here's a test program (based on your code) that I ran on Yahoo, to check for how many of your symbols it could supply price data:

How To Download Data From Google Finance

... and the answer is, all of them:

Hope this may help.

AS MackayAS Mackay
2,0677 gold badges12 silver badges21 bronze badges

How To Download Share Price Data From Google Finance

Not the answer you're looking for? Browse other questions tagged pythonpandasgoogle-finance or ask your own question.

Here is a script that pulls 60 minute data from yahoo. Copy the contents below into python2.x file. Pass the symbol as the variable. You can change the data interval at the line on bottom of the code.

import requests
import pandas as pd
import arrow
from dateutil.parser import parse
from dateutil.tz import gettz
import datetime
from pprint import pprint
import urllib,time,datetime
import sys

Download Stock Data From Google

symbol1 = sys.argv[1]
symbolname = symbol1
symbol1 = symbol1.upper()

How To Download Data From Google Finance Account

def get_quote_data(symbol='iwm', data_range='1d', data_interval='60m'):
res = requests.get('https://query1.finance.yahoo.com/v8/finance/chart/{symbol}?range={data_range}&interval={data_interval}'.format(**locals()))
data = res.json()
body = data['chart']['result'][0]
dt = datetime.datetime
dt = pd.Series(map(lambda x: arrow.get(x).to('EST').datetime.replace(tzinfo=None), body['timestamp']), name='dt')
df = pd.DataFrame(body['indicators']['quote'][0], index=dt)
dg = pd.DataFrame(body['timestamp'])
return df.loc[:, ('open', 'high', 'low', 'close', 'volume')]

How To Download Historical Data From Google Finance To Excel

q = jpy5m = get_quote_data(symbol1, '2d', ' 60m')
print q