-
Notifications
You must be signed in to change notification settings - Fork 136
/
base.py
77 lines (58 loc) · 2.02 KB
/
base.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import datetime
import pandas as pd
from iexfinance.base import _IEXBase
class ReferenceData(_IEXBase):
@property
def url(self):
return "ref-data/%s" % self.endpoint
@property
def endpoint(self):
raise NotImplementedError
class TradingDatesReader(ReferenceData):
"""
Base class to retrieve trading holiday information
"""
def __init__(self, type_, direction=None, last=1, startDate=None, **kwargs):
if isinstance(startDate, datetime.date) or isinstance(
startDate, datetime.datetime
):
self.startDate = startDate.strftime("%Y%m%d")
else:
self.startDate = startDate
self.type = type_
if direction not in ("next", "last"):
raise ValueError("direction must be either next or last")
self.direction = direction
self.last = last
super(TradingDatesReader, self).__init__(**kwargs)
@property
def endpoint(self):
ret = "us/dates/%s/%s/%s" % (self.type, self.direction, self.last)
if self.startDate:
ret += "/%s" % self.startDate
return ret
def _format_output(self, out, format=None):
out = [{k: pd.to_datetime(v) for k, v in day.items()} for day in out]
return super(TradingDatesReader, self)._format_output(out)
class Symbols(ReferenceData):
@property
def endpoint(self):
return "symbols"
class IEXSymbols(ReferenceData):
@property
def endpoint(self):
return "iex/symbols"
class IntlRegionSymbols(ReferenceData):
def __init__(self, region, **kwargs):
self.region = region
super(IntlRegionSymbols, self).__init__(**kwargs)
@property
def endpoint(self):
return "region/%s/symbols" % self.region
class IntlExchangeSymbols(ReferenceData):
def __init__(self, exchange, **kwargs):
self.exchange = exchange
super(IntlExchangeSymbols, self).__init__(**kwargs)
@property
def endpoint(self):
return "exchange/%s/symbols" % self.exchange