-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplotlyTest.py
86 lines (69 loc) · 2.09 KB
/
plotlyTest.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
78
79
80
81
82
83
84
85
86
import plotly.graph_objects as go
import plotly.express as px
import pandas as pd
from datetime import datetime
from plotly.subplots import make_subplots
from indis.hccp import getHCCP
# df = (pd.read_csv('test/testData.csv')).drop('Unnamed: 0',axis=1)
fig = go.Figure()
fig.update_layout(hovermode="x")
fig.update_yaxes(fixedrange=False)
def initSubPlots(r, c):
"""
r - rows
c - columns
"""
global fig
fig = make_subplots(rows=r, cols=c, shared_xaxes=True)
def plotCandles(df, r=1, c=1):
fig.add_trace(go.Candlestick(
x=pd.to_datetime(df['openTime']/1000, unit='s'),
open=df['open'],
high=df['high'],
low=df['low'],
close=df['close']
), row=r, col =c)
def plotLines(data, r=1, c=1):
for column in data :
if column == 'openTime':
continue
else:
fig.add_trace(go.Scatter(
x=pd.to_datetime(data['openTime']/1000, unit='s'),
y=data[column], name=column
), row=r, col =c)
def plotBuy(dates,r=1, c=1):
for date in dates:
fig.add_vline(
x = str(date),
line_color="green"
)
def plotSell(dates,r=1, c=1):
for date in dates:
fig.add_vline(
x = str(date),
line_color="red"
)
def showPlot(file="output/plot.html") :
try:
# fig.write_html(file)
fig.show()
except:
print('its okay')
if __name__ == "__main__":
import getData
candles = getData.getCandles()
df = pd.DataFrame(candles)
df = df.drop([7,8,9,10,11], axis=1)
df.columns = ['openTime', 'open', 'high', 'low', 'close', 'volume', 'closeTime']
for column in df:
if column == 'openTime' or column == 'closeTime' :
continue
df[column] = pd.to_numeric(df[column], downcast="float")
print(df)
hccpData = getHCCP(df)
hccpData = hccpData.drop(['open', 'high', 'low', 'close', 'volume', 'closeTime'], axis=1)
initSubPlots(1,1)
plotCandles(df)
plotLines(hccpData)
showPlot()