如何在两个数据流PYTHON中连接图表和在线图表的报价?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在两个数据流PYTHON中连接图表和在线图表的报价?相关的知识,希望对你有一定的参考价值。
该代码不起作用。一个线程应该从HUOBI.COM网站获得报价。第二个线程应该进行“回调”,并采用一个price_low值来更新图表!我也无法添加第二个price_high行。请帮助
答案
import dash
from dash.dependencies import Output, Event
import dash_core_components as dcc
import dash_html_components as html
import plotly
import random
import plotly.graph_objs as go
from collections import deque
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from time import sleep
from selenium.webdriver.common.action_chains import ActionChains #движение мыши
import threading
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import re # Латинский регистр
import subprocess # Окрыть файл модуль
import math
import requests
from selenium.webdriver.firefox import options
from selenium.webdriver.firefox import options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
price_low=1
X = deque(maxlen=20)
X.append(1)
Y = deque(maxlen=20)
Y.append(price_low)
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.Graph(id='live-graph', animate=True),
dcc.Interval(
id='graph-update',
interval=1*100
),
]
)
@app.callback(Output('live-graph', 'figure'),
events=[Event('graph-update', 'interval')])
def live_grafic():
X.append(X[-1]+1)
Y.append(price_low)
data = plotly.graph_objs.Scatter(
x=list(X),
y=list(Y),
name='Scatter',
mode= 'lines+markers'
)
return {'data': [data],'layout' : go.Layout(xaxis=dict(range=[min(X),max(X)]),
yaxis=dict(range=[min(Y),max(Y)]),)}
def huobi():
global price_low
global price_high
price_low=0
price_high=0
login ="dtrade66@yandex.ru"
password = "3216732167e"
binary = FirefoxBinary(r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe")
caps = DesiredCapabilities.FIREFOX.copy()
print(caps)
w = webdriver.Firefox(firefox_binary=binary,capabilities=caps, executable_path='C:/geckodriver.exe')
print("Авторизация HUOBI")
w.get("https://www.huobi.com/login/")
sleep(7)
try:
w.find_element_by_css_selector("#__layout > div > div.l-main > div > div.layout_container > div > div.el-dialog__wrapper > div > div.el-dialog__body > em").click()
except:
print("Huobi START")
w.get("https://www.huobi.us/markets")
sleep(6)
tool = "dash"
w.find_element_by_css_selector('#__layout > div > div.l-main > div > div.layout_container > div > div > div:nth-child(1) > div.exchange-left.card-radius > div.exchange-left-table.card-radius > div > div.el-card__header > div > div > div > div > div > input').send_keys(tool)
sleep(1)
w.find_element_by_css_selector('#__layout > div > div.l-main > div > div.layout_container > div > div > div:nth-child(1) > div.exchange-left.card-radius > div.exchange-left-table.card-radius > div > div.el-card__body > div > div > div.el-table.hb-el-table.el-table--fit.el-table--fluid-height.el-table--enable-row-hover.el-table--enable-row-transition.el-table--mini > div.el-table__body-wrapper.is-scroll-left > table > tbody > tr > td.el-table_1_column_2 > div > span').click()
sleep(3)
while True:
price_high = w.find_element_by_css_selector("#__layout > div > div.l-main > div > div.layout_container > div > div > div:nth-child(2) > div.exchange-right > div > div.el-card__body > div > div > div.exchange_style.card-body.exchange_trade_body > div:nth-child(1) > table > tbody > tr:nth-child(16) > td.out.tl.trade-table-price").text
price_low = w.find_element_by_css_selector("#__layout > div > div.l-main > div > div.layout_container > div > div > div:nth-child(2) > div.exchange-right > div > div.el-card__body > div > div > div.exchange_style.card-body.exchange_trade_body > div:nth-child(3) > table > tbody > tr:nth-child(1) > td.in.tl.trade-table-price").text
print("HIGH"," ",price_high," LOW ",price_low)
sleep(0.1)
t = threading.Thread(target=huobi)
t.start()
t = threading.Thread(target=app.run_server(debug=True))
t.start()
以上是关于如何在两个数据流PYTHON中连接图表和在线图表的报价?的主要内容,如果未能解决你的问题,请参考以下文章
Superset环境搭建 01CentOS release 7.5 在线安装数据可视化图表工具 Superset(python虚拟环境使用+问题解决+WEB登录验证+炫酷官方图表)避坑指南