-
Notifications
You must be signed in to change notification settings - Fork 14
/
prices_visualization_server.py
98 lines (77 loc) · 2.15 KB
/
prices_visualization_server.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
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import flask
import pandas as pd
import time
import os
from lib import tuilib, visualization_lib
rpc_connection = tuilib.def_credentials("REKT0")
server = flask.Flask('app')
server.secret_key = os.environ.get('secret_key', 'secret')
visualization_lib.make_csv_for_stack(rpc_connection, ["BTC_USD", "KMD_BTC", "*", 1], "BTC_USD*KMD_BTC", "435")
df = pd.read_csv('BTC_USD*KMD_BTC.csv')
app = dash.Dash('app', server=server)
app.scripts.config.serve_locally = False
pair_names = ["BTC_USD*KMD_BTC"]
options_arg = []
for pair in pair_names:
pair_arg = {}
pair_arg['label'] = pair
pair_arg['value'] = pair
options_arg.append(pair_arg)
app.layout = html.Div([
html.H1('Prices provided by Komodo PricesCC trustless oracle'),
dcc.Dropdown(
id='my-dropdown',
options=options_arg,
value='BTC_USD*KMD_BTC'
),
dcc.Graph(id='my-graph')
], className="container")
@app.callback(Output('my-graph', 'figure'),
[Input('my-dropdown', 'value')])
def update_graph(selected_dropdown_value):
visualization_lib.make_csv_for_stack(rpc_connection, ["BTC_USD", "KMD_BTC", "*", 1], "BTC_USD*KMD_BTC", "435")
df = pd.read_csv('BTC_USD*KMD_BTC.csv')
dff = df[df['pair'] == selected_dropdown_value]
return {
'data': [
{
'x': dff.date,
'y': dff.price1,
'line': {
'width': 3,
'shape': 'spline'
}
},
{
'x': dff.date,
'y': dff.price2,
'line': {
'width': 3,
'shape': 'spline'
}
},
{
'x': dff.date,
'y': dff.price3,
'line': {
'width': 3,
'shape': 'spline'
}
},
],
'layout': {
'margin': {
'l': 30,
'r': 20,
'b': 30,
't': 20
}
}
}
if __name__ == '__main__':
app.run_server(host = '0.0.0.0')