-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsite.py
More file actions
303 lines (273 loc) · 7.66 KB
/
site.py
File metadata and controls
303 lines (273 loc) · 7.66 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import os, sys, time, datetime, collections
from decimal import Decimal as D
import numpy as np
from timeit import default_timer as timer
import pandas as pd
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import colorlover as cl # fucking really????
import ag.bittensor.utils.options as options
from ag.bittensor.ai.make_data import MakeData
import ag.bittensor.utils.talib as talib
import flask
# ////////////// Build Globals
config = options.Options('config/access_codes.yaml')
datasmith = MakeData(config)
TA = talib.TALib(config)
# PRE-SETUP DATA INIT
# make dropdown data:
dropdownelements = []
for i in datasmith.all_pairs:
if 'USDT' in i:
coin = i[:-9]
else:
coin = i[:-8]
pair = i[:-4]
item = {
'label': '{} - {}'.format(coin, pair),
'value': i
}
dropdownelements.append(item)
# get all available TA conditions
taelements = []
for i, e in enumerate(TA.available):
taelements.append({
'label': e,
'value': e
})
# ////////////// START SETUP
colorscale = cl.scales['9']['qual']['Paired']
colors = {
'background': '#111316',
'text': '#7FDBFF'
}
banner = html.H1(
children = 'AlphaGriffin Technical Analysis',
style = {
'textAlign': 'center',
'color': colors['text']
}
)
banner2 = html.Div(
children='''{}'''.format(datetime.datetime.now()),
style = {
'textAlign': 'center',
'color': colors['text']
}
)
# ////////////// MAKE BUTTONS
dropbox = dcc.Dropdown(
id='top-dropdown',
options=[
x for x in dropdownelements
],
value='BTC_USDT.csv'
)
checkboxes = dcc.Checklist(
id='ta-checks',
options=[
x for x in taelements
],
values=['Moving Average'],
style={
'color': '#ffffff'
}
)
buttons = html.Div(
children = [
html.Label('Available Pairs', style={'color': '#ffffff'}),
dropbox,
html.Label('Available TA Indicators', style={'color': '#ffffff'}),
checkboxes
],
style={'backgroundColor': '#333333'}
)
# ////////////// /Buttons
# ////////////// MAKE GRAPH STARTING GRAPH
FIG = {
'data': [],
'layout': {
'title': 'LoadingScreen'
}
}
randomfile = datasmith.random_filename
datasmith.dataframe = randomfile
datasmith.candles = '15T'
start_df = datasmith.candles
MASTERDF = start_df
FIG['data'].append({
'x': start_df.index,
'y': start_df['Volume'],
'type': 'bar',
'name': 'Volume'
})
graph = dcc.Graph(
id='main-graph',
figure = FIG
)
graphdiv = html.Div(id='graphs', children=[graph])
subgraphdiv = html.Div(id='subgraphs', children=[graph])
# ////////////// /graph
mainwindow = html.Div([buttons, graphdiv, subgraphdiv])
# ////////////// START APP
app = dash.Dash()
app.css.append_css({'external_url': 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'})
app.layout = html.Div(
style={
"backgroundColor": colors['background'],
},
children=[
banner,
banner2,
mainwindow,
]
)
@app.callback(Output('subgraphs', 'children'), [Input('top-dropdown', 'value'), Input('ta-checks', 'values')])
def subupdate(pair, tachecks):
graphs = []
df = MASTERDF
for x in tachecks:
if 'Realitive Strength Index' in x:
indicator = TA.available[x](df)
# start a new graph
data = {
'x': df.index,
'y': indicator,
'type': 'scatter',
'name': x
}
topline = {
'x': df.index,
'y': np.repeat(70, len(df)),
'type': 'line',
'name': 'overbought'
}
botline = {
'x': df.index,
'y': np.repeat(30, len(df)),
'type': 'line',
'name': 'oversold'
}
rsi = dcc.Graph(id=x, figure={
'data': [data, topline, botline],
'layout': {
# 'title': '{}'.format(x),
'margin': {
'l': 100,
'r': 100,
't': 20,
'b': 10
},
'legend': {'x': 0}
}
})
graphs.append(rsi)
if 'Commodity Channel Index' in x:
indicator = TA.available[x](df)
# start a new graph
data = {
'x': df.index,
'y': indicator,
'type': 'scatter',
'name': x
}
topline = {
'x': df.index,
'y': np.repeat(100, len(df)),
'type': 'line',
'name': 'overbought'
}
botline = {
'x': df.index,
'y': np.repeat(-100, len(df)),
'type': 'line',
'name': 'oversold'
}
rsi = dcc.Graph(id=x, figure={
'data': [data, topline, botline],
'layout': {
# 'title': '{}'.format(x),
'margin': {
'l': 100,
'r': 100,
't': 10,
'b': 10
},
'legend': {'x': 0}
}
})
graphs.append(rsi)
"""
z = dcc.Graph(
id='stuff'+str(x),
figure={
'data': [{'x': list(range(5)), 'y':[2,4,1,5,3], 'type': 'line'}],
'layout': {
'margin': {'b': 15, 'r': 100, 'l': 60, 't': 10},
'legend': {'x': 0}
}
}
)
graphs.append(z)
"""
return graphs
@app.callback(Output('graphs', 'children'), [Input('top-dropdown', 'value'), Input('ta-checks', 'values')])
def mainupdate(pair, tachecks):
timeframe = '1H'
datasmith.dataframe = pair
datasmith.candles = timeframe
MASTERDF = df = datasmith.candles
# setup main graph
candlestick = {
'x': df.index,
'open': df['Open'],
'high': df['High'],
'low': df['Low'],
'close': df['Close'],
'volume': df['Volume'],
'type': 'candlestick',
'name': pair[:-4],
'legendgroup': pair[:-4],
'increasing': {'line': {'color': colorscale[0]}},
'decreasing': {'line': {'color': colorscale[1]}}
}
FIG = {
'data': [],
'layout': {
'title': '{}'.format(pair[:-4]),
'margin': {
'l': 100,
'r': 100,
't': 40,
'b': 10
},
'legend': {'x': 0}
}
}
FIG['data'].append(candlestick)
for i in tachecks:
if 'Exp Moving Average' in i or 'Moving Average' in i or 'Average True Range' in i:
indicator = TA.available[i](df)
data = {
'x': df.index,
'y': indicator,
'type': 'line',
'name': i
}
FIG['data'].append(data)
if 'Bollinger Bands' in i:
indicator = TA.available[i](df)
for index, j in enumerate(indicator):
# print(j.values)
data = {
'x': df.index,
'y': j.values,
'type': 'scatter',
'name': '{} {}'.format(i, index)
}
FIG['data'].append(data)
return dcc.Graph(id=pair[:-4], figure=FIG)
if __name__ == '__main__':
app.run_server(debug=True)