91 lines
2.5 KiB
Python
91 lines
2.5 KiB
Python
|
from pyecharts.charts import Bar, Line
|
|||
|
import pyecharts.options as opts
|
|||
|
|
|||
|
from utils.stock_web_api import execute_stock_web_api_method, stock_web_api_money_flow
|
|||
|
from utils.comm import *
|
|||
|
|
|||
|
|
|||
|
class MoneyFlow:
|
|||
|
def __init__(self, trade_date):
|
|||
|
self.trade_date = trade_date.strftime('%Y%m%d')
|
|||
|
self.start_date = return_trading_day(trade_date, -6)
|
|||
|
self.end_date = self.trade_date
|
|||
|
print(self.start_date, "---", self.end_date)
|
|||
|
|
|||
|
def hsgt_top10(self):
|
|||
|
"""
|
|||
|
当日沪深股通十大成交股
|
|||
|
:return:
|
|||
|
"""
|
|||
|
df = xcsc_pro.hsgt_top10(trade_date=self.end_date)
|
|||
|
print(df)
|
|||
|
|
|||
|
def money_flow_chart(self):
|
|||
|
df = execute_stock_web_api_method(
|
|||
|
func=stock_web_api_money_flow,
|
|||
|
start_date=self.start_date, end_date=self.end_date)
|
|||
|
x_data = df['trade_date'].tolist()
|
|||
|
# 沪股通
|
|||
|
y_axis_hgt = (round(df['hgt'] / 100, 2)).tolist()
|
|||
|
# 深股通
|
|||
|
y_axis_sgt = (round(df['sgt'] / 100, 2)).tolist()
|
|||
|
# 北上资金
|
|||
|
y_axis_north_money = (round(df['north_money'] / 100, 2)).tolist()
|
|||
|
bar = (
|
|||
|
Bar(init_opts=opts.InitOpts(width="100%", height="400px"))
|
|||
|
.add_xaxis(xaxis_data=x_data)
|
|||
|
.add_yaxis(
|
|||
|
series_name="沪股通",
|
|||
|
y_axis=y_axis_hgt,
|
|||
|
label_opts=opts.LabelOpts(is_show=False),
|
|||
|
)
|
|||
|
.add_yaxis(
|
|||
|
series_name="深股通",
|
|||
|
y_axis=y_axis_sgt,
|
|||
|
label_opts=opts.LabelOpts(is_show=False),
|
|||
|
)
|
|||
|
.extend_axis(
|
|||
|
yaxis=opts.AxisOpts(
|
|||
|
name="金额",
|
|||
|
type_="value",
|
|||
|
interval=2000,
|
|||
|
axislabel_opts=opts.LabelOpts(formatter="{value} 亿元"),
|
|||
|
)
|
|||
|
)
|
|||
|
.set_global_opts(
|
|||
|
tooltip_opts=opts.TooltipOpts(
|
|||
|
is_show=True, trigger="axis", axis_pointer_type="cross"
|
|||
|
),
|
|||
|
xaxis_opts=opts.AxisOpts(
|
|||
|
type_="category",
|
|||
|
axispointer_opts=opts.AxisPointerOpts(is_show=True, type_="shadow"),
|
|||
|
),
|
|||
|
yaxis_opts=opts.AxisOpts(
|
|||
|
name="金额",
|
|||
|
type_="value",
|
|||
|
interval=3000,
|
|||
|
axislabel_opts=opts.LabelOpts(formatter="{value} 亿元"),
|
|||
|
axistick_opts=opts.AxisTickOpts(is_show=True),
|
|||
|
splitline_opts=opts.SplitLineOpts(is_show=True),
|
|||
|
),
|
|||
|
)
|
|||
|
)
|
|||
|
line = (
|
|||
|
Line()
|
|||
|
.add_xaxis(xaxis_data=x_data)
|
|||
|
.add_yaxis(
|
|||
|
series_name="北上资金",
|
|||
|
# yaxis_index 0:折线图使用柱状图的y轴 1:使用extend_axis中的Y轴
|
|||
|
yaxis_index=0,
|
|||
|
y_axis=y_axis_north_money,
|
|||
|
label_opts=opts.LabelOpts(is_show=False),
|
|||
|
)
|
|||
|
)
|
|||
|
bar.overlap(line).render(f"../复盘指标/html/{self.trade_date}/mixed_bar_and_line.html")
|
|||
|
|
|||
|
|
|||
|
if __name__ == '__main__':
|
|||
|
# money_flow = MoneyFlow(trade_date=datetime.now().strftime('%Y%m%d'))
|
|||
|
money_flow = MoneyFlow(trade_date=datetime.now())
|
|||
|
money_flow.money_flow_chart()
|