forked from robcarver17/pysystemtrade
-
Notifications
You must be signed in to change notification settings - Fork 1
/
base_data.py
77 lines (52 loc) · 1.83 KB
/
base_data.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
from syslogdiag.log_to_screen import logtoscreen
class baseData(object):
"""
Core data object - Base class
simData objects are used to get data from a particular source, and give certain information about it
The baseData class is highly generic
Normally we'd inherit from this for specific implementations (eg simulation, production for different data types),
specific asset classes (eg carry data for futures), and then for a
specific source of data (eg csv files, databases, ...)
The inheritance is:
Base generic class: simData
-> implementation specific eg simData for simulation
-> asset class specific eg futuresdata.FuturesData
-> source specific eg legacy.csvFuturesSimData
"""
def __init__(self, log=logtoscreen("baseData")):
"""
simData socket base class
>>> data = baseData()
>>> data
simData object
"""
self._log = log
def __repr__(self):
return "baseData object"
@property
def log(self):
return self._log
def __getitem__(self, keyname):
"""
convenience method to get the price, make it look like a dict
:param keyname: instrument to get prices for
:type keyname: str
:returns: pd.DataFrame
"""
raise Exception(
"__getitem__ not defined for baseData class: use a class where it has been overriden"
)
def keys(self):
"""
list of things in this data set (futures contracts, instruments...)
:returns: list of str
>>> data=simData()
>>> data.keys()
[]
"""
raise Exception(
"keys() not defined for baseData class: use a class where it has been overriden"
)
if __name__ == "__main__":
import doctest
doctest.testmod()