forked from Viandoks/python-crypto-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbotcandlestick.py
70 lines (55 loc) · 2.04 KB
/
botcandlestick.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
from botlog import BotLog
import shared
import sys, getopt
import time
import utils
class BotCandlestick(object):
def __init__(self,date=None,open=None,high=None,low=None,close=None,volume=None):
self.close = close
self.currentPrice = close
self.date = date
self.high = high
self.low = low
self.open = open
self.output = BotLog()
self.priceAverage = False
self.startTime = time.time()
self.volume = volume
if self.close:
self.currentPrice = self.close
def __setitem__(self, key, value):
setattr(self, key, value)
def __getitem__(self, key):
return getattr(self, key)
def toDict(self):
return {
'close': self.close,
'currentPrice': self.currentPrice,
'date': self.date,
'high': self.high,
'low': self.low,
'open' : self.open,
'priceAverage': self.priceAverage,
'startTime': self.startTime,
'volume': self.volume
}
def tick(self, price):
self.currentPrice = float(price)
if self.date is None:
self.date = time.time()
if (self.open is None):
self.open = self.currentPrice
if (self.high is None) or (self.currentPrice > self.high):
self.high = self.currentPrice
if (self.low is None) or (self.currentPrice < self.low):
self.low = self.currentPrice
timedelta = utils.parseTimedelta(shared.strategy['timeframe'])
if time.time() >= ( self.startTime + timedelta):
self.close = self.currentPrice
self.priceAverage = ( self.high + self.low + self.close ) / float(3)
self.output.log("Start time: "+str(self.startTime)+", Open: "+str(self.open)+" Close: "+str(self.close)+" High: "+str(self.high)+" Low: "+str(self.low)+" currentPrice: "+str(self.currentPrice))
def isClosed(self):
if (self.close is not None):
return True
else:
return False