-
Notifications
You must be signed in to change notification settings - Fork 679
/
Copy pathtest_iex.py
59 lines (47 loc) · 1.68 KB
/
test_iex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from datetime import datetime
from pandas import DataFrame
import pytest
from pandas_datareader.data import (
DataReader,
get_dailysummary_iex,
get_iex_book,
get_iex_symbols,
get_last_iex,
get_summary_iex,
)
from pandas_datareader.exceptions import UnstableAPIWarning
pytestmark = pytest.mark.xfail(reason="Changes in API need fixes")
class TestIEX:
@classmethod
def setup_class(cls):
pytest.importorskip("lxml")
def test_read_iex(self):
gs = DataReader("GS", "iex-last")
assert isinstance(gs, DataFrame)
def test_historical(self):
df = get_summary_iex(start=datetime(2017, 4, 1), end=datetime(2017, 4, 30))
assert df.T["averageDailyVolume"].iloc[0] == 137650908.9
def test_false_ticker(self):
df = get_last_iex("INVALID TICKER")
assert df.shape[0] == 0
@pytest.mark.xfail(reason="IEX daily history API is returning 500 as of Jan 2018")
def test_daily(self):
with pytest.warns(UnstableAPIWarning, match="Daily statistics"):
df = get_dailysummary_iex(
start=datetime(2017, 5, 5), end=datetime(2017, 5, 6)
)
assert df["routedVolume"].iloc[0] == 39974788
def test_symbols(self):
df = get_iex_symbols()
assert "GS" in df.symbol.values
def test_live_prices(self):
dftickers = get_iex_symbols()
tickers = dftickers[:5].symbol.values
df = get_last_iex(tickers[:5])
assert df["price"].mean() > 0
def test_deep(self):
dob = get_iex_book("GS", service="book")
if dob:
assert "GS" in dob
else:
pytest.xfail(reason="Can only get Book when market open")