Skip to content

Commit e3ecf2b

Browse files
rgkimballbashtage
authored andcommitted
Reduces import footprint of IEX, adds docstrings, fixes DEEP API test after market hours
1 parent 5a00fc5 commit e3ecf2b

File tree

3 files changed

+123
-28
lines changed

3 files changed

+123
-28
lines changed

pandas_datareader/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
from .data import (get_components_yahoo, get_data_famafrench, get_data_google,
44
get_data_yahoo, get_data_enigma, get_data_yahoo_actions,
55
get_quote_google, get_quote_yahoo, get_tops_iex,
6-
get_last_iex, get_markets_iex, get_data_iex,
7-
get_summary_iex, get_records_iex, get_recent_iex,
8-
get_iex_symbols, get_iex_book,
9-
DataReader, Options)
6+
get_last_iex, get_markets_iex, get_summary_iex,
7+
get_records_iex, get_recent_iex, get_iex_symbols,
8+
get_iex_book, DataReader, Options)
109

1110
__version__ = get_versions()['version']
1211
del get_versions
1312

1413
__all__ = ['__version__', 'get_components_yahoo', 'get_data_enigma',
1514
'get_data_famafrench', 'get_data_google', 'get_data_yahoo',
1615
'get_data_yahoo_actions', 'get_quote_google', 'get_quote_yahoo',
17-
'get_data_iex', 'get_iex_book', 'get_iex_symbols', 'get_last_iex',
16+
'get_iex_book', 'get_iex_symbols', 'get_last_iex',
1817
'get_markets_iex', 'get_recent_iex', 'get_records_iex',
1918
'get_summary_iex', 'get_tops_iex',
2019
'DataReader', 'Options']

pandas_datareader/data.py

Lines changed: 112 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313
from pandas_datareader.google.daily import GoogleDailyReader
1414
from pandas_datareader.google.options import Options as GoogleOptions
1515
from pandas_datareader.google.quotes import GoogleQuotesReader
16-
from pandas_datareader.iex.market import MarketReader as IEXMarkets
17-
from pandas_datareader.iex.ref import SymbolsReader as IEXSymbols
18-
from pandas_datareader.iex.stats import DailySummaryReader as IEXHistorical
19-
from pandas_datareader.iex.stats import MonthlySummaryReader as IEXMonthSummary
2016
from pandas_datareader.iex.deep import Deep as IEXDeep
21-
from pandas_datareader.iex.stats import RecentReader as IEXRecents
22-
from pandas_datareader.iex.stats import RecordsReader as IEXRecords
2317
from pandas_datareader.iex.tops import LastReader as IEXLasts
2418
from pandas_datareader.iex.tops import TopsReader as IEXTops
2519
from pandas_datareader.moex import MoexReader
@@ -38,6 +32,9 @@
3832
'get_data_fred', 'get_data_google', 'get_data_moex',
3933
'get_data_quandl', 'get_data_yahoo', 'get_data_yahoo_actions',
4034
'get_nasdaq_symbols', 'get_quote_google', 'get_quote_yahoo',
35+
'get_tops_iex', 'get_summary_iex', 'get_records_iex',
36+
'get_recent_iex', 'get_markets_iex', 'get_last_iex',
37+
'get_iex_symbols', 'get_iex_book', 'get_dailysummary_iex',
4138
'get_data_stooq', 'DataReader']
4239

4340

@@ -80,9 +77,11 @@ def get_data_quandl(*args, **kwargs):
8077
def get_data_moex(*args, **kwargs):
8178
return MoexReader(*args, **kwargs).read()
8279

80+
8381
def get_data_stooq(*args, **kwargs):
8482
return StooqDailyReader(*args, **kwargs).read()
8583

84+
8685
def get_tops_iex(*args, **kwargs):
8786
return IEXTops(*args, **kwargs).read()
8887

@@ -92,31 +91,118 @@ def get_last_iex(*args, **kwargs):
9291

9392

9493
def get_markets_iex(*args, **kwargs):
95-
return IEXMarkets(*args, **kwargs).read()
94+
"""
95+
Returns near-real time volume data across markets segregated by tape
96+
and including a percentage of overall volume during the session
97+
98+
This endpoint does not accept any parameters.
99+
100+
Reference: https://www.iextrading.com/developer/docs/#markets
101+
102+
:return: DataFrame
103+
"""
104+
from pandas_datareader.iex.market import MarketReader
105+
return MarketReader(*args, **kwargs).read()
96106

97107

98-
def get_data_iex(*args, **kwargs):
99-
return IEXHistorical(*args, **kwargs).read()
108+
def get_dailysummary_iex(*args, **kwargs):
109+
"""
110+
Returns a summary of daily market volume statistics. Without parameters,
111+
this will return the most recent trading session by default.
112+
113+
:param start:
114+
A datetime object - the beginning of the date range.
115+
:param end:
116+
A datetime object - the end of the date range.
117+
118+
Reference: https://www.iextrading.com/developer/docs/#historical-daily
119+
120+
:return: DataFrame
121+
"""
122+
from pandas_datareader.iex.stats import DailySummaryReader
123+
return DailySummaryReader(*args, **kwargs).read()
100124

101125

102126
def get_summary_iex(*args, **kwargs):
103-
return IEXMonthSummary(*args, **kwargs).read()
127+
"""
128+
Returns an aggregated monthly summary of market volume and a variety of
129+
related metrics for trades by lot size, security market cap, and venue.
130+
In the absence of parameters, this will return month-to-date statistics.
131+
For ranges spanning multiple months, this will return one row per month.
132+
133+
:param start:
134+
A datetime object - the beginning of the date range.
135+
:param end:
136+
A datetime object - the end of the date range.
137+
138+
:return: DataFrame
139+
"""
140+
from pandas_datareader.iex.stats import MonthlySummaryReader
141+
return MonthlySummaryReader(*args, **kwargs).read()
104142

105143

106144
def get_records_iex(*args, **kwargs):
107-
return IEXRecords(*args, **kwargs).read()
145+
"""
146+
Returns the record value, record date, recent value, and 30-day average for
147+
market volume, # of symbols traded, # of routed trades and notional value.
148+
This function accepts no additional parameters.
149+
150+
Reference: https://www.iextrading.com/developer/docs/#records
151+
152+
:return: DataFrame
153+
"""
154+
from pandas_datareader.iex.stats import RecordsReader
155+
return RecordsReader(*args, **kwargs).read()
108156

109157

110158
def get_recent_iex(*args, **kwargs):
111-
return IEXRecents(*args, **kwargs).read()
159+
"""
160+
Returns market volume and trade routing statistics for recent sessions.
161+
Also reports IEX's relative market share, lit share volume and a boolean
162+
halfday indicator.
163+
164+
Reference: https://www.iextrading.com/developer/docs/#recent
165+
166+
:return: DataFrame
167+
"""
168+
from pandas_datareader.iex.stats import RecentReader
169+
return RecentReader(*args, **kwargs).read()
112170

113171

114172
def get_iex_symbols(*args, **kwargs):
115-
return IEXSymbols(*args, **kwargs).read()
173+
"""
174+
Returns a list of all equity symbols available for trading on IEX. Accepts
175+
no additional parameters.
176+
177+
Reference: https://www.iextrading.com/developer/docs/#symbols
178+
179+
:return: DataFrame
180+
"""
181+
from pandas_datareader.iex.ref import SymbolsReader
182+
return SymbolsReader(*args, **kwargs).read()
116183

117184

118185
def get_iex_book(*args, **kwargs):
119-
return IEXDeep(*args, **kwargs).read()
186+
"""
187+
Returns an array of dictionaries with depth of book data from IEX for up to
188+
10 securities at a time. Returns a dictionary of the bid and ask books.
189+
190+
:param symbols:
191+
A string or list of strings of valid tickers
192+
:param service:
193+
'book': Live depth of book data
194+
'op-halt-status': Checks to see if the exchange has instituted a halt
195+
'security-event': Denotes individual security related event
196+
'ssr-status': Short Sale Price Test restrictions, per reg 201 of SHO
197+
'system-event': Relays current feed status (i.e. market open)
198+
'trades': Retrieves recent executions, trade size/price and flags
199+
'trade-breaks': Lists execution breaks for the current trading session
200+
'trading-status': Returns status and cause codes for securities
201+
202+
:return: Object
203+
"""
204+
from pandas_datareader.iex.deep import Deep
205+
return Deep(*args, **kwargs).read()
120206

121207

122208
def DataReader(name, data_source=None, start=None, end=None,
@@ -146,7 +232,9 @@ def DataReader(name, data_source=None, start=None, end=None,
146232
single value given for symbol, represents the pause between retries.
147233
session : Session, default None
148234
requests.sessions.Session instance to be used
149-
235+
access_key : (str, None)
236+
Optional parameter to specify an API key for certain data sources.
237+
150238
Examples
151239
----------
152240
@@ -159,7 +247,14 @@ def DataReader(name, data_source=None, start=None, end=None,
159247
160248
# Data from Google Finance
161249
aapl = DataReader("AAPL", "google")
162-
250+
251+
# Price and volume data from IEX
252+
tops = DataReader(["GS", "AAPL"], "iex-tops")
253+
# Top of book executions from IEX
254+
gs = DataReader("GS", "iex-last")
255+
# Real-time depth of book data from IEX
256+
gs = DataReader("GS", "iex-book")
257+
163258
# Data from FRED
164259
vix = DataReader("VIXCLS", "fred")
165260
@@ -183,6 +278,7 @@ def DataReader(name, data_source=None, start=None, end=None,
183278
return YahooActionReader(symbols=name, start=start, end=end,
184279
retry_count=retry_count, pause=pause,
185280
session=session).read()
281+
186282
elif data_source == "yahoo-dividends":
187283
return YahooDivReader(symbols=name, start=start, end=end,
188284
adjust_price=False, chunksize=25,

pandas_datareader/tests/test_iex.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import pandas.util.testing as tm
44

55
from pandas import DataFrame
6-
from datetime import datetime
6+
from datetime import datetime, timedelta
77
from pandas_datareader.data import (DataReader, get_summary_iex, get_last_iex,
8-
get_data_iex, get_iex_symbols)
8+
get_dailysummary_iex, get_iex_symbols,
9+
get_iex_book)
910

1011

1112
class TestIEX(object):
@@ -27,7 +28,7 @@ def test_false_ticker(self):
2728
tm.assert_frame_equal(df, DataFrame())
2829

2930
def test_daily(self):
30-
df = get_data_iex(start=datetime(2017, 5, 5), end=datetime(2017, 5, 6))
31+
df = get_dailysummary_iex(start=datetime(2017, 5, 5), end=datetime(2017, 5, 6)) #noqa
3132
assert df['routedVolume'].iloc[0] == 39974788
3233

3334
def test_symbols(self):
@@ -41,7 +42,6 @@ def test_live_prices(self):
4142
assert df["price"].mean() > 0
4243

4344
def test_deep(self):
44-
dob = DataReader('GS', 'iex-book')
45-
assert 'GS' in dob
46-
assert 'asks' in dob['GS']
47-
assert dob['GS']['bids'][0]['price'] > 0
45+
dob = get_iex_book('GS', service='system-event')
46+
assert len(dob['eventResponse']) > 0
47+
assert dob['timestamp'] > datetime.now() - timedelta(days=1)

0 commit comments

Comments
 (0)