forked from femtotrader/python-eodhistoricaldata
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_data.py
More file actions
71 lines (54 loc) · 1.99 KB
/
Copy pathtest_data.py
File metadata and controls
71 lines (54 loc) · 1.99 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
import pandas as pd
from eod_historical_data import (get_api_key,
get_eod_data,
get_dividends,
get_exchange_symbols,
get_exchanges, get_currencies, get_indexes)
import datetime
import requests_cache
pd.set_option("max_rows", 10)
# Cache session (to avoid too much data consumption)
expire_after = datetime.timedelta(days=1)
session = requests_cache.CachedSession(cache_name='cache', backend='sqlite',
expire_after=expire_after)
# Get API key
# from environment variable
# bash> export EOD_HISTORICAL_API_KEY="YOURAPI"
api_key = get_api_key()
# api_key = "YOURAPI"
def test_get_eod_data_no_date():
df = get_eod_data("AAPL", "US", api_key=api_key, session=session)
print(df)
assert df.index.name == "Date"
def test_get_eod_data_with_date():
df = get_eod_data("AAPL", "US", start="2016-02-01", end="2016-02-10",
api_key=api_key, session=session)
print(df)
assert df.index.name == "Date"
assert df.index[0] == pd.to_datetime("2016-02-01")
def test_get_dividends():
df = get_dividends("AAPL", "US", start="2016-02-01", end="2016-02-10",
api_key=api_key, session=session)
print(df)
assert df.index.name == "Date"
def test_get_exchange_symbols():
df = get_exchange_symbols(exchange_code="US",
api_key=api_key, session=session)
print(df)
assert df.index.name == "Code"
assert "AAPL" in df.index
def test_get_exchanges():
df = get_exchanges()
print(df)
assert df.index.name == "ID"
assert "US" in df["Exchange Code"].unique()
def test_get_currencies():
df = get_currencies()
print(df)
assert df.index.name == "ID"
assert "USD" in df["Currency Code"].unique()
def test_get_indexes():
df = get_indexes()
print(df)
assert df.index.name == "ID"
assert "GSPC" in df["Code"].unique()