forked from EodHistoricalData/python-eodhistoricaldata
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_data.py
More file actions
82 lines (65 loc) · 2.42 KB
/
Copy pathtest_data.py
File metadata and controls
82 lines (65 loc) · 2.42 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
72
73
74
75
76
77
78
79
80
81
82
from unittest.mock import sentinel
import pandas as pd
from eod_historical_data import (set_envar,
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 = set_envar()
# api_key = "YOURAPI"
def test_get_eod_data_no_date():
df = get_eod_data("AAPL", "US", api_key=api_key, session=session)
print(df)
# Note if df is Sentinel it means that the request was sent through but the response
# was forbidden indicating that the APi Key may not have been authorized to perform the
# Operation
if df is not sentinel:
assert df.index.name == "Date"
def test_get_eod_data_with_date():
df = get_eod_data("AAPL", "US", start="2020-02-01", end="2020-02-10",
api_key=api_key, session=session)
print(df)
if df is not sentinel:
assert df.index.name == "Date"
assert df.index[0] != ""
def test_get_dividends():
df = get_dividends("AAPL", "US", start="2020-02-01", end="2020-02-10",
api_key=api_key, session=session)
print(df)
if df is not sentinel:
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)
if df is not sentinel:
assert df.index.name == "Code"
assert "AAPL" in df.index
def test_get_exchanges():
df = get_exchanges()
print(df)
if df is not sentinel:
assert df.index.name == "ID"
assert "US" in df["Exchange Code"].unique()
def test_get_currencies():
df = get_currencies()
print(df)
if df is not sentinel:
assert df.index.name == "ID"
assert "USD" in df["Currency Code"].unique()
def test_get_indexes():
df = get_indexes()
print(df)
if df is not sentinel:
assert df.index.name == "ID"
assert "GSPC" in df["Code"].unique()