forked from Galts-Gulch/avarice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.py
61 lines (55 loc) · 1.73 KB
/
storage.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
import avarice
import shelve
import genconfig as gc
class indicators:
indshelve = ''
def CreateShelveName():
configurables = ['ShortPeriod', 'LongPeriod', 'Period', 'AlphaConstant',
'SignalPeriod', 'FastKPeriod', 'FullKPeriod', 'FullDPeriod',
'TenkanSenPeriod', 'SenkouSpanPeriod', 'KijunSenPeriod',
'ChikouSpanPeriod', 'Multiplier']
configurable_values = []
for indicator in gc.Trader.TradeIndicators:
if isinstance(indicator, list):
for i in indicator:
for c in configurables:
try:
configurable_values.append(getattr(getattr(gc, i), c))
except AttributeError:
pass
else:
for c in configurables:
try:
configurable_values.append(getattr(getattr(gc, indicator), c))
except AttributeError:
pass
indicators.indshelve = gc.Database.Path + '/' + gc.API.TradePair + \
str(gc.Candles.Size) + ''.join(str(x)
for x in configurable_values) + 'indicators.shelve'
def writelist(ln, key):
if not key == None:
db = shelve.open(indicators.indshelve, writeback=True)
if ln not in db:
db[ln] = [key]
else:
temp = db[ln]
temp.append(key)
if gc.Database.StoreAll:
db[ln] = temp
else:
db[ln] = temp[-avarice.MaxCandleDepends:]
db.close()
def getlist(ln):
db = shelve.open(indicators.indshelve, writeback=True)
if ln not in db:
temp = []
else:
try:
temp = db[ln]
except EOFError:
try:
temp = db[ln]
except EOFError:
temp = []
db.close
return temp