Skip to content
This repository was archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1 from innes213/addGetQuote
Browse files Browse the repository at this point in the history
Adding get_quote and building a new release
  • Loading branch information
innes213 committed Feb 6, 2015
2 parents 853d7b9 + 8984c00 commit f26cb96
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 39 deletions.
10 changes: 8 additions & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
v0.1.0, 20140715 -- Initial release.
v0.1.2 20150205 —- Adding tests and ‘get_quote()’ function

* Added basic unit tests which use pyrest
* Added get_quote for querying for data for a single function
* Updated documentation

v0.1.1, 20140717 —- Modules now available at package level, bug fix

* updated __init__.py to import submodules
* fixed bug when acquiring data for more than 199 symbols
* fixed bug when acquiring data for more than 199 symbols

v0.1.0, 20140715 -- Initial release.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ To get current stock data, use the function get_quotes() in quotedata.py
| | |
get_quotes(symbolList,dataList,raw)

To query for data for a single symbol, the function get_quote() in quotedata.py
can be used although it simply creates a single item list and calls get_quotes.

To get current stock data, use the function get_quotes() in quotedata.py

—————————Single symbol. For ‘example YHOO'
|
| ---------List of requested data (like [VOLUME_STR,
| | LAST_TRADE_PRICE_ONLY_STR]
| | or some predefined list like MINIQUOTE. Default is
| | STANDARDQUOTE
| |
| | -----Raw/untyped (string) data? Default is false
| | | (typedef'd data)
| | |
get_quote(symbol,dataList,raw)

## Getting Historic Data

Yahoo's historic stock data API is a little different. There is no way to grab
Expand Down
2 changes: 1 addition & 1 deletion bin/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# pyhoofinance - bin/example.py
#
# Copyright (c) 2014, Rob Innes Hislop
# Copyright (c) 2014-2015, Rob Innes Hislop
# email:robinneshislop__AT__gmail.com
#
# This library is distributed under the terms of the
Expand Down
4 changes: 2 additions & 2 deletions bin/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# pyhoofinance - example1.py
#
# Copyright (c) 2014, Rob Innes Hislop
# email:robinneshislop@gmail.com
# Copyright (c) 2014-2015, Rob Innes Hislop
# email:robinneshislop__AT__gmail.com
#
# This library is distributed under the terms of the
# GNU General Public License (or the Lesser GPL)
Expand Down
2 changes: 1 addition & 1 deletion pyhoofinance/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# pyhoofinance - defs.py
#
# Copyright (c) 2014, Rob Innes Hislop
# Copyright (c) 2014-2015, Rob Innes Hislop
# email:robinneshislop__AT__gmail.com
#
# This library is distributed under the terms of the
Expand Down
2 changes: 1 addition & 1 deletion pyhoofinance/historicdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# pyhoofinance - historicdata.py
#
# Copyright (c) 2014, Rob Innes Hislop
# Copyright (c) 2014-2015, Rob Innes Hislop
# email:robinneshislop__AT__gmail.com
#
# This library is distributed under the terms of the
Expand Down
24 changes: 14 additions & 10 deletions pyhoofinance/quotedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# pyhoofinance - quotedata.py
#
# Copyright (c) 2014, Rob Innes Hislop
# Copyright (c) 2014-2015, Rob Innes Hislop
# email:robinneshislop__AT__gmail.com
#
# This library is distributed under the terms of the
Expand Down Expand Up @@ -177,19 +177,23 @@ def get_quotes(symbols, quoteData = STANDARDQUOTE, raw = False):
if (quoteList != []) and (not raw):
quoteList = _format_quote_data(quoteList)
return quoteList



def get_quote(symbol, quoteData = STANDARDQUOTE, raw = False):
"""
Returns requested quote data (quoteData) for a single valid symbol
If raw is true, the raw text values are returned, otherwise values are properly
typecast.
"""
symbolList = []
symbolList.append(symbol)
return get_quotes(symbolList,quoteData, raw)[0]

if (__name__ == '__main__'):

try:
print(get_quote('YHOO'))
print(get_quotes(['YHOO']))
print(get_quotes(['YHOO'],MINIQUOTE,True))
except:
print('BALLS!')
exit(1)
"""
try:
print(get_quotes(['YHOO'],[SYMBOL_STR,FLOAT_SHARES_STR,SHARES_OUTSTANDING_STR,NAME_STR]))
print(get_quotes(['YHOO','GOOGL','AAPL'],[SYMBOL_STR,FLOAT_SHARES_STR,SHARES_OUTSTANDING_STR,NAME_STR]))
except:
exit(1)
"""
47 changes: 25 additions & 22 deletions test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# pyhoofinance - tests.py
#
# Copyright (c) 2014, Rob Innes Hislop
# Copyright (c) 2014-2015, Rob Innes Hislop
# email:robinneshislop__AT__gmail.com
#
# This library is distributed under the terms of the
Expand All @@ -19,32 +19,35 @@
from pyhoofinance import defs

def test_query_yahoo():
result = q._query_yahoo(['YHOO'], 'n')
assert ''.join(result).find('Yahoo') != -1
result = q._query_yahoo(['YHOO'], 'n')
assert ''.join(result).find('Yahoo') != -1

def test_get_range_of_historical_quotes():
startDate = date(2015,1,23) # Friday
endDate = date(2015,1,26) # Monday
assert len(get_range_of_historical_quotes('YHOO',startDate,endDate)) == 2
startDate = date(2015,1,23) # Friday
endDate = date(2015,1,26) # Monday
assert len(get_range_of_historical_quotes('YHOO',startDate,endDate)) == 2

def test_get_number_of_historical_quotes():
endDate = date(2015,1,26) # Monday
quotes = get_number_of_historical_quotes('YHOO',5,endDate)
assert len(quotes) == 5
endDate = date(2015,1,26) # Monday
quotes = get_number_of_historical_quotes('YHOO',5,endDate)
assert len(quotes) == 5

def test_get_quote_block():
quotes = q._get_quote_block(['YHOO'], [q.SYMBOL_STR], q.YAHOO_FINANCE_KEYS_DICT[q.SYMBOL_STR], [])
assert len(quotes) == 1
quotes = q._get_quote_block(['YHOO'], [q.SYMBOL_STR], q.YAHOO_FINANCE_KEYS_DICT[q.SYMBOL_STR], [])
assert len(quotes) == 1

def test_format_quote_data():
quote = [{q.DAY_LOW_STR: '43.875', q.MARKET_CAPITALIZATION_STR : '33B', q.NAME_STR: 'Yahoo! Inc.', q.AVERAGE_DAILY_VOLUME_STR: '21070800', q.SYMBOL_STR: 'YHOO', q.VOLUME_STR: '16281358', q.LAST_TRADE_PRICE_ONLY_STR: '44.045', q.DAY_HIGH_STR: '44.975', q.OPEN_STR: '44.81', q.CHANGE_STR: '-0.655'}]
result = q._format_quote_data(quote)
assert result[0][q.DAY_LOW_STR] == 43.875
assert result[0][q.MARKET_CAPITALIZATION_STR] == 33000000000


quote = [{q.DAY_LOW_STR: '43.875', q.MARKET_CAPITALIZATION_STR : '33B', q.NAME_STR: 'Yahoo! Inc.', q.AVERAGE_DAILY_VOLUME_STR: '21070800', q.SYMBOL_STR: 'YHOO', q.VOLUME_STR: '16281358', q.LAST_TRADE_PRICE_ONLY_STR: '44.045', q.DAY_HIGH_STR: '44.975', q.OPEN_STR: '44.81', q.CHANGE_STR: '-0.655'}]
result = q._format_quote_data(quote)
assert result[0][q.DAY_LOW_STR] == 43.875
assert result[0][q.MARKET_CAPITALIZATION_STR] == 33000000000

def test_get_quotes():
quoteList = ['YHOO' for i in range(201)]
result = q.get_quotes(quoteList)
assert len(result) == 201
quoteList = ['YHOO' for i in range(201)]
result = q.get_quotes(quoteList)
assert len(result) == 201

def test_get_quote():
#This test may fail if run doing trading hours
result = q.get_quote('YHOO')
assert result == q.get_quotes(['YHOO'])[0]

0 comments on commit f26cb96

Please sign in to comment.