-
Notifications
You must be signed in to change notification settings - Fork 15
/
candle.py
40 lines (31 loc) · 1.11 KB
/
candle.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
import pandas as pd
class Candle:
def __init__(self, open_time, open, high, low, close, volume, close_time):
self.open_time = open_time
self.open = open
self.high = high
self.low = low
self.close = close
self.volume = volume
self.close_time = close_time
def __repr__(self):
return "open_time:" + str(self.open_time) + \
", open:" + str(self.open) + \
", high:" + str(self.high) + \
", low:" + str(self.low) + \
", close:" + str(self.close) + \
", volume:" + str(self.volume) + \
", close_time:" + str(self.close_time)
def to_tuple(self):
return (self.open_time, self.open, self.high, self.low, self.close)
@staticmethod
def candles_list_to_tuples_list(candles_list):
tuples_list = [candle.to_tuple() for candle in candles_list]
return tuples_list
@staticmethod
def candles_list_to_pandas_dataframe(candles_list):
tuples_list = Candle.candles_list_to_tuples_list(candles_list)
df = pd.DataFrame(tuples_list, columns=["Date", "Open", "High", "Low", "Close"])
df.index = pd.DatetimeIndex(df['Date'])
# df.index.name = "Date"
return df