import webbrowser
from pandas import Series
from pyecharts import options as opts
from pyecharts.commons.utils import JsCode
from calculate import calculate_ma, calcu_rate
from pyecharts.charts import Kline, Line, Bar, Grid, Page
import requests
from bs4 import BeautifulSoup
from pyecharts.globals import ThemeType
from formula import *
from name_opera import stock_name_transfer
from price_opera import data_from_database, transferToWeekLine
def ren_ming_wang():
webbrowser.open("http://www.people.com.cn/")
def dong_fang_cai_fu():
webbrowser.open("https://www.eastmoney.com/")
def tushare_help():
webbrowser.open("https://tushare.pro/document/2")
def jukuan_help():
webbrowser.open("https://www.joinquant.com/help/api/help?name=JQData")
def boke():
webbrowser.open("https://linqingfeng.blog.csdn.net")
def hx_news():
webbrowser.open("http://www.hexun.com/")
def xinlang_news():
webbrowser.open("https://finance.sina.com.cn/")
def toutiao_quick():
url="https://cj.sina.com.cn/k/article/column_article/3"
text=requests.get(url)
text.encoding=text.apparent_encoding
soup=BeautifulSoup(text.text,"lxml")
res=soup.find_all("li",{"class":""})
i=[]
for li in res:
i.append(str(li.a.text))
url="https:"+str(li.a['href'])
i.append(url)
return i
def yield_k_xian(stockindex,start,end):
stockname=stock_name_transfer(stockindex)
def get_data():
stock_index=stockindex
data1=data_from_database(stock_index,start,end)
data2=calcu_rate(data1)
return split_data(data=data2)
def split_data(data):
category_data = []
values = []
volumes = []
for i in range(len(data)):
category_data.append(data[i][0])
values.append(data[i])
volumes.append([i, data[i][6], 1 if data[i][1] > data[i][2] else -1])
return {"categoryData": category_data, "values": values, "volumes": volumes}
def draw_charts():
kline_data = [data[1:-1] for data in chart_data["values"]]
# print(kline_data)
kline = (
Kline()
.add_xaxis(xaxis_data=chart_data["categoryData"])
.add_yaxis(
series_name=stockname,
y_axis=kline_data,
itemstyle_opts=opts.ItemStyleOpts(color="#ec0000", color0="#00da3c"),
)
.set_global_opts(
title_opts=opts.TitleOpts(title=stockname+" 日线图", pos_left="10",pos_top="10"),
legend_opts=opts.LegendOpts(
is_show=True, pos_top=10, pos_left="center"
),
datazoom_opts=[
opts.DataZoomOpts(
is_show=False,
type_="inside",
xaxis_index=[0, 1],
range_start=98,
range_end=100,
),
opts.DataZoomOpts(
is_show=True,
xaxis_index=[0, 1],
type_="slider",
pos_top="95%",
range_start=98,
range_end=100,
),
],
yaxis_opts=opts.AxisOpts(
is_scale=True,
splitarea_opts=opts.SplitAreaOpts(
is_show=False, areastyle_opts=opts.AreaStyleOpts(opacity=1)
),
),
tooltip_opts=opts.TooltipOpts(
trigger="axis",
axis_pointer_type="cross",
background_color="rgba(245, 245, 245, 0.8)",
border_width=1,
border_color="#ccc",
textstyle_opts=opts.TextStyleOpts(color="#000"),
# formatter="股票代码:{}".format(kline_data)
formatter=JsCode(
"""function (params) {
return params[1].value[0]+'<br>'+'open: '+params[0].value[1]+'<br>'+'close: '+params[0].value[2]+'<br>'+'low: '+params[0].value[3]+'<br>'+'high: '+params[0].value[4]+'<br>'+'volume: '+params[5].value[1]+'<br>'+'rate: '+params[0].value[5];
}"""
)
),
visualmap_opts=opts.VisualMapOpts(
is_show=False,
dimension=2,
series_index=5,
is_piecewise=True,
pieces=[
{"value": 1, "color": "#00da3c"},
{"value": -1, "color": "#ec0000"},
],
),
axispointer_opts=opts.AxisPointerOpts(
is_show=True,
link=[{"xAxisIndex": "all"}],
label=opts.LabelOpts(background_color="#777"),
),
brush_opts=opts.BrushOpts(
x_axis_index="all",
brush_link="all",
out_of_brush={"colorAlpha": 0.1},
brush_type="lineX",
),
)
)
line = (
Line()
.add_xaxis(xaxis_data=chart_data["categoryData"])
.add_yaxis(
series_name="MA5",
y_axis=calculate_ma(day_count=5, data=chart_data),
is_smooth=True,
# is_hover_animation=False,
linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
label_opts=opts.LabelOpts(is_show=False),
)
.add_yaxis(
series_name="MA10",
y_axis=calculate_ma(day_count=10, data=chart_data),
is_smooth=True,
# is_hover_animation=False,
linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
label_opts=opts.LabelOpts(is_show=False),
)
.add_yaxis(
series_name="MA20",
y_axis=calculate_ma(day_count=20, data=chart_data),
is_smooth=True,
# is_hover_animation=False,
linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
label_opts=opts.LabelOpts(is_show=False),
)
.add_yaxis(
series_name="MA30",
y_axis=calculate_ma(day_count=30, data=chart_data),
is_smooth=True,
# is_hover_animation=False,
linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
label_opts=opts.LabelOpts(is_show=False),
)
.set_global_opts(xaxis_opts=opts.AxisOpts(type_="category"))
)
bar = (
Bar()
.add_xaxis(xaxis_data=chart_data["categoryData"])
.add_yaxis(
series_name="Volume",
y_axis=chart_data["volumes"],
xaxis_index=1,
yaxis_index=1,
label_opts=opts.LabelOpts(is_show=False),
)
.set_global_opts(
xaxis_opts=opts.AxisOpts(
type_="category",
is_scale=True,
grid_index=1,
boundary_gap=False,
axisline_opts=opts.AxisLineOpts(is_on_zero=False),
axistick_opts=opts.AxisTickOpts(is_show=False),
splitline_opts=opts.SplitLineOpts(is_show=False),
axislabel_opts=opts.LabelOpts(is_show=False),
split_number=20,
min_="dataMin",
评论1