forked from kbai/python-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraderGUI.py
More file actions
69 lines (50 loc) · 1.86 KB
/
traderGUI.py
File metadata and controls
69 lines (50 loc) · 1.86 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
import json
import os
import dash
import dash_core_components as dcc
import dash_html_components as html
import zmq
from dash.dependencies import Input, Output
from util import *
params = {'ready': 0,
'posUpperLimit': 0,
'posLowerLimit': 0,
'spread': 10.0,
'buysellSkew': 0.0,
'alphaMultiplier': 0.0,
'positionSkew': 0.0}
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
def createZmqPublisher():
context = zmq.Context()
publisher = context.socket(zmq.PUB)
publisher.bind(commandEndPoint)
return publisher
def valueSetter(value, name):
params[name] = value
print(params)
return 'changed'
def createLayout():
page_content = []
for key in params:
page_content.append(
html.Div([html.Div(["{:<20}:".format(key)]), dcc.Input(id=key, type='float', value=params[key]),
html.Div(id=key + "state", children='ready', style={'display': 'none'})]))
page_content.append(html.Button('Submit', id='submit-val', n_clicks=0))
page_content.append(html.Div(id='state'))
return html.Div(page_content)
app = dash.Dash(__name__,external_stylesheets=external_stylesheets)
app.layout = createLayout # dynamic layout creation
@app.callback(Output('state', 'children'),
[Input('submit-val', 'n_clicks')])
def buttonReact(click):
print("ready")
pub.send_string(commandTopic + json.dumps(params))
print(os.getpid())
return str(params)
for key in params:
app.callback(Output(component_id=key + 'state', component_property='children'),
[Input(component_id=key, component_property='value'),
Input(component_id=key, component_property='id')])(valueSetter)
if __name__ == '__main__':
pub = createZmqPublisher()
app.run_server(debug=False, threaded=True, host='0.0.0.0')