diff --git a/README.md b/README.md index c7baa51..21f368e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,62 @@ # googlefinance Python module to get stock data from Google Finance API + +This module provides **no delay**, **real time** stock data in NYSE & NASDAQ. [yahoo-finance](https://github.com/lukaszbanasiak/yahoo-finance)'s data is delayed by 15 min, but it provides apis to fetch historical day-by-day stock data. + +##Install +From PyPI with pip: + + $pip install googlefinance + +From development repo (requires git) + + $git clone https://github.com/hongtaocai/googlefinance.git + $cd googlefinance + $python setup.py install + +##Usage example + + >>> from googlefinance import getQuotes + >>> import json + >>> print json.dumps(getQuotes('AAPL'), indent=2) + [ + { + "Index": "NASDAQ", + "LastTradeWithCurrency": "129.09", + "LastTradeDateTime": "2015-03-02T16:04:29Z", + "LastTradePrice": "129.09", + "Yield": "1.46", + "LastTradeTime": "4:04PM EST", + "LastTradeDateTimeLong": "Mar 2, 4:04PM EST", + "Dividend": "0.47", + "StockSymbol": "AAPL", + "ID": "22144" + } + ] + >>> print json.dumps(getQuotes(['AAPL', 'GOOG']), indent=2) + [ + { + "Index": "NASDAQ", + "LastTradeWithCurrency": "129.09", + "LastTradeDateTime": "2015-03-02T16:04:29Z", + "LastTradePrice": "129.09", + "Yield": "1.46", + "LastTradeTime": "4:04PM EST", + "LastTradeDateTimeLong": "Mar 2, 4:04PM EST", + "Dividend": "0.47", + "StockSymbol": "AAPL", + "ID": "22144" + }, + { + "Index": "NASDAQ", + "LastTradeWithCurrency": "571.34", + "LastTradeDateTime": "2015-03-02T16:04:29Z", + "LastTradePrice": "571.34", + "Yield": "", + "LastTradeTime": "4:04PM EST", + "LastTradeDateTimeLong": "Mar 2, 4:04PM EST", + "Dividend": "", + "StockSymbol": "GOOG", + "ID": "304466804484872" + } + ] diff --git a/googlefinance/__init__.py b/googlefinance/__init__.py index 431fcd5..b2c39b4 100644 --- a/googlefinance/__init__.py +++ b/googlefinance/__init__.py @@ -1,12 +1,8 @@ -''' -MIT License -''' - from urllib2 import Request, urlopen import json import sys -__author__ = 'hongtaocai@gmail.com' +__author__ = 'Hongtao Cai' googleFinanceKeyToFullName = { u'id' : u'ID', @@ -48,12 +44,24 @@ def replaceKeys(quotes): def getQuotes(symbols): ''' - get real-time quotes (index, last trade price, last trade time, etc) for stocks, using google api: - http://finance.google.com/finance/info?client=ig&q=symbols - Unlike python package 'yahoo-finance', There is no delay for NYSE and NASDAQ stocks in googlefinance. - :param symbols: a list of stock symbols - :return: real-time quotes + get real-time quotes (index, last trade price, last trade time, etc) for stocks, using google api: http://finance.google.com/finance/info?client=ig&q=symbols + + Unlike python package 'yahoo-finance' (15 min delay), There is no delay for NYSE and NASDAQ stocks in 'googlefinance' package. + + example: + quotes = getQuotes('AAPL') + return: + [{u'Index': u'NASDAQ', u'LastTradeWithCurrency': u'129.09', u'LastTradeDateTime': u'2015-03-02T16:04:29Z', u'LastTradePrice': u'129.09', u'Yield': u'1.46', u'LastTradeTime': u'4:04PM EST', u'LastTradeDateTimeLong': u'Mar 2, 4:04PM EST', u'Dividend': u'0.47', u'StockSymbol': u'AAPL', u'ID': u'22144'}] + + quotes = getQuotes(['AAPL', 'GOOG']) + return: + [{u'Index': u'NASDAQ', u'LastTradeWithCurrency': u'129.09', u'LastTradeDateTime': u'2015-03-02T16:04:29Z', u'LastTradePrice': u'129.09', u'Yield': u'1.46', u'LastTradeTime': u'4:04PM EST', u'LastTradeDateTimeLong': u'Mar 2, 4:04PM EST', u'Dividend': u'0.47', u'StockSymbol': u'AAPL', u'ID': u'22144'}, {u'Index': u'NASDAQ', u'LastTradeWithCurrency': u'571.34', u'LastTradeDateTime': u'2015-03-02T16:04:29Z', u'LastTradePrice': u'571.34', u'Yield': u'', u'LastTradeTime': u'4:04PM EST', u'LastTradeDateTimeLong': u'Mar 2, 4:04PM EST', u'Dividend': u'', u'StockSymbol': u'GOOG', u'ID': u'304466804484872'}] + + :param symbols: a single symbol or a list of stock symbols + :return: real-time quotes list ''' + if type(symbols) == type('str'): + symbols = [symbols] content = json.loads(request(symbols)) return replaceKeys(content); diff --git a/setup.py b/setup.py index ed6da7b..265ad2a 100644 --- a/setup.py +++ b/setup.py @@ -2,12 +2,12 @@ from distutils.core import setup setup( name = 'googlefinance', packages = ['googlefinance'], # this must be the same as the name above - version = '0.2', + version = '0.3', description = 'Python module to get stock data from Google Finance API', author = 'Hongtao Cai', author_email = 'caiht.ht@gmail.com', url = 'https://github.com/hongtaocai/googlefinance', # use the URL to the github repo - download_url = 'https://github.com/hongtaocai/googlefinance/tarball/0.2', # I'll explain this in a second + download_url = 'https://github.com/hongtaocai/googlefinance/tarball/0.3', # I'll explain this in a second keywords = ['googlefinance', 'stock', 'price' , 'finance', 'google'], # arbitrary keywords classifiers = [], )