From 985be59c2f1bfc2e08116f694a252d8c2464e482 Mon Sep 17 00:00:00 2001 From: josuebrunel Date: Sat, 27 Jun 2015 15:51:24 +0200 Subject: [PATCH] #1: updating stockscraper module --- docs/stockscraper.md | 124 ++++++++++++++++++ .../finance/stockscraper/stockretriever.py | 2 +- tests/tests.py | 4 +- 3 files changed, 127 insertions(+), 3 deletions(-) diff --git a/docs/stockscraper.md b/docs/stockscraper.md index 8bea0af..a326af0 100644 --- a/docs/stockscraper.md +++ b/docs/stockscraper.md @@ -336,6 +336,130 @@ data = stocks.get_industry_index(112) } ``` +#### *StockRetriever.get_xchange_rate(pairs, items=None)* + +```python +from myql.contrib.finance.stockscraper import StockRetriever +stocks = StockRetriever(format='json') +data = stocks.get_xchange_rate(['EURUSD','GBPUSD']) +``` + +```json +{ + "query": { + "count": 2, + "created": "2015-06-27T13:48:51Z", + "lang": "en-US", + "results": { + "rate": [ + { + "Ask": "1.1174", + "Bid": "1.1162", + "Date": "6/27/2015", + "Name": "EUR/USD", + "Rate": "1.1168", + "Time": "12:53pm", + "id": "EURUSD" + }, + { + "Ask": "1.5756", + "Bid": "1.5738", + "Date": "6/27/2015", + "Name": "GBP/USD", + "Rate": "1.5747", + "Time": "12:53pm", + "id": "GBPUSD" + } + ] + } + } +} + +``` + +#### *StockRetriever.get_dividendhistory(symbol, startDate, endDate)* + +```python +from myql.contrib.finance.stockscraper import StockRetriever +stocks = StockRetriever(format='json') +data = stocks.get_dividendhistory('AAPL',"2008-01-01", "2015-06-15") +``` + +```json +{ + "query": { + "count": 12, + "created": "2015-06-27T13:42:27Z", + "lang": "en-US", + "results": { + "quote": [ + { + "Date": "2015-05-07", + "Dividends": "0.520000", + "Symbol": "AAPL" + }, + { + "Date": "2015-02-05", + "Dividends": "0.470000", + "Symbol": "AAPL" + }, + { + "Date": "2014-11-06", + "Dividends": "0.470000", + "Symbol": "AAPL" + }, + { + "Date": "2014-08-07", + "Dividends": "0.470000", + "Symbol": "AAPL" + }, + { + "Date": "2014-05-08", + "Dividends": "0.470000", + "Symbol": "AAPL" + }, + { + "Date": "2014-02-06", + "Dividends": "0.435710", + "Symbol": "AAPL" + }, + { + "Date": "2013-11-06", + "Dividends": "0.435710", + "Symbol": "AAPL" + }, + { + "Date": "2013-08-08", + "Dividends": "0.435710", + "Symbol": "AAPL" + }, + { + "Date": "2013-05-09", + "Dividends": "0.435710", + "Symbol": "AAPL" + }, + { + "Date": "2013-02-07", + "Dividends": "0.378570", + "Symbol": "AAPL" + }, + { + "Date": "2012-11-07", + "Dividends": "0.378570", + "Symbol": "AAPL" + }, + { + "Date": "2012-08-09", + "Dividends": "0.378570", + "Symbol": "AAPL" + } + ] + } + } +} + +``` + #### *StockRetriever.get_symbols(company_name)*      **Always returns data as JSON** diff --git a/myql/contrib/finance/stockscraper/stockretriever.py b/myql/contrib/finance/stockscraper/stockretriever.py index 222abea..3069a07 100644 --- a/myql/contrib/finance/stockscraper/stockretriever.py +++ b/myql/contrib/finance/stockscraper/stockretriever.py @@ -71,7 +71,7 @@ def get_industry_index(self, index_id,items=None): response = self.select('yahoo.finance.industry',items).where(['id','=',index_id]) return response - def get_xchange(self, pairs, items=None): + def get_xchange_rate(self, pairs, items=None): """Retrieves currency exchange rate data for given pair(s). Accepts both where pair='eurusd, gbpusd' and where pair in ('eurusd', 'gpbusd, usdaud') """ diff --git a/tests/tests.py b/tests/tests.py index a2909a8..ff37c90 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -283,8 +283,8 @@ def test_get_symbols(self,): logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200) - def test_get_xchange(self,): - data = self.stock.get_xchange(['EURUSD','GBPUSD']) + def test_get_xchange_rate(self,): + data = self.stock.get_xchange_rate(['EURUSD','GBPUSD']) logging.debug(pretty_json(data.content)) self.assertEqual(data.status_code, 200)