Here is an article that deals with your question:
Creating an application DASH with graphics updates consisting of consisting and live broadcast WebSocket
As a trader you want to stay in the current state of real -time market data. An effective way to do this is to create a live transmission panel using Dash, the popular Python library to create web applications. A real time chart.
assumptions
Before we start, make sure you have the following installed:
- Dash (
Pip Install Dash
)
- Fences (
pip install plotrly
)
- Python 3.x
Set the environment
Create a new Python file (eg app.py
) and add the following code to the environment configuration:
`Python
Import
Dash Import DCC, HTML
Import the consisting of .graph_objects
Import WebBrowser
Initialize the Dash app
App = Dash.dash (__ Name__)
Configure Plotly Chart
Cap = go.figure (data = [go.scartter (x = [[], y = []))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) ))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Create a component with a plot
plotly_component = dcc.graph (id = ‘live-boasocket-graph’)
`
Create a negotiating bot
Then create a new file (eg “Trading_bot.Py) that contains your logic of business robots. In this example, we will use a simple blockchain knot to search for live data:
Python
Import et_utils
Eth_positia Import Blocknumber
Configure the Blockchain Ethereum knot
node_url = ‘
et_node = ‘http: //’ + node_url
Def Get_block_number ():
BLACK_NUMBER = blonumber.from_string (‘1’)
Return block_number.to_int ()
app.layout = html.div (
HTML.H1 (“Live Transmission Panel Ethereum”),
DCC.Graph (id = ‘live-webesocket-graph’),
Dcc.livesocket (URL = Node_url, ID = ‘Vive-Websocket-Scket’, Stream = TRUE),
))))))
Def Update_graph ():
Look for live data from the Ethereum Blockchain node
block_number = get_block_number ()
block_data = et_utils.get_block (block_number) .Gget_value ()
Update the chart with new data
Fig.Data [0] .x.extend (block_number)
Fig.Data [0] .y.extend ([block_data])
Remember the chart
App.update_graph (id = ‘live-websocket-graph’, layout = fig.layout)
@app.callback (
[html.Button (‘update data’, ID = ‘Refresch-Data-Button’)],
[Dash.dependences.output (‘Live-WebSocket-Stom-S-Stream’, ‘Data’), Dash.Dependences.output (‘Live-Websocket-Stom-Stom’, ‘Figual’)]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] ]]]]
)
Def Refresh_data_Button ():
Find new data from Ethereum Blockchain Node
block_number = get_block_number ()
Update the chart with new data
Fig.Update_layout (x = [block_number], y = [])
Return HTML.P (“successfully updated data!”), Fig.
If __name__ == ‘__main__’:
App.Run_server (debug = TRUE)
`
Start the app
To start the app, run the following command:
`Bash
Python app.py
`
This triggers the Dash server and opens the web browser in the panel.
Live Broadcast Data
Now that you configured Live Broadcast data, click “Update Data”. This updates the plot graph with new data obtained from the Ethereum Blockchain node.
To view this in more detail, you can use the Dash_core_components’ library in the -in library to create a panel with multiple interactive elements:
`Python
Import Dast_core_components as DCC
Dash Import HTML
Create a panel
App = Dash.dash (__ Name__)
Add widencies to the panel
app.layout = html.div (
HTML.H1 (“Live Transmission Panel Ethereum”),
DCC.Graph (id = ‘live-webesocket-graph’),
DCC.LIVESOCKET (ID = ‘Live-Basocket-Scket’, Stream = TRUE),
))))))
@app.callback (
[html.Button (‘update data’, ID = ‘Refresch-Data-Button’)],
[Dash.dependences.output (‘Live-Websocket-Socket-Stream’, ‘Data’), Dash.Dependences.