Administrator
2022-10-12 be73e2b78857adaf006063275726b69c4c60f0d7
gui.py
@@ -5,13 +5,13 @@
from tkinter.messagebox import *
import tkintertable
import win32gui
import alert_util
import data_export_util
import multiprocessing
import global_util
import redis_manager
import mongo_data
import server
@@ -163,7 +163,7 @@
            win.resizable(height=False, width=False)
            limit_up_datas = {}
            limit_up_datas["row{}".format(0)] = {'代码': '', '首次涨停时间': '', '现价': '','涨幅':'', '涨停封单额': ''}
            limit_up_datas["row{}".format(0)] = {'代码': '', '首次涨停时间': '', '现价': '', '涨幅': '', '涨停封单额': ''}
            cl = Label(win, text="更新时间:", bg="#DDDDDD", fg="#666666")
            cl.place(x=10, y=10)
@@ -218,6 +218,66 @@
        btn = Button(frame, text="今日涨停", command=get_limit_up_codes_win)
        btn.place(x=300, y=150)
    # 绘制交易状态
    def __draw_trade_state(self, frame):
        def refresh_data():
            normal=True
            if l2_code_operate.L2CodeOperate.is_read_queue_valid():
                cl_queue.configure(text="正常", foreground="#008000")
            else:
                cl_queue.configure(text="异常", foreground="#FF7F27")
                normal=False
            try:
                trade_gui.THSGuiTrade.checkEnv()
                cl_win.configure(text="正常", foreground="#008000")
            except Exception as e:
                normal = False
                cl_win.configure(text="异常:{}".format(str(e)),foreground="#FF7F27")
            # 状态有问题,需要报警
            if not normal:
                alert_util.alarm()
        def update_data():
            while True:
                # 刷新数据
                try:
                    if auo_refresh.get() > 0:
                        refresh_data()
                except:
                    pass
                time.sleep(2)
        start_y=230
        btn = Button(frame, text="刷新状态", command=refresh_data)
        btn.place(x=10, y=start_y)
        auo_refresh = IntVar()
        ch1 = Checkbutton(frame, text='自动刷新', variable=auo_refresh, onvalue=1, offvalue=0, background="#DDDDDD",
                          activebackground="#DDDDDD")
        # 默认自动刷新
        auo_refresh.set(1)
        ch1.place(x=100, y=start_y)
        y_=start_y+30
        cl = Label(frame, text="操作队列状态:", bg="#DDDDDD")
        cl.place(x=10, y=y_)
        cl_queue = Label(frame, text="未知", bg="#DDDDDD")
        cl_queue.place(x=100, y=y_)
        cl = Label(frame, text="交易窗口状态:", bg="#DDDDDD")
        cl.place(x=200, y=y_)
        cl_win = Label(frame, text="未知", bg="#DDDDDD")
        cl_win.place(x=300, y=y_)
        refresh_data()
        # 添加更新线程
        t1 = threading.Thread(target=lambda: update_data())
        # 后台运行
        t1.setDaemon(True)
        t1.start()
    # 绘制l2数据状态
    def __draw_l2_state(self, root):
        def update_data():
@@ -233,7 +293,7 @@
        def refresh_data():
            for client_id in code_sv_map:
                ip = data_process.getActiveClientIP(client_id)
                ths_dead=data_process.getTHSState(client_id)
                ths_dead = data_process.getTHSState(client_id)
                if ip is not None and len(ip) > 0:
                    if ths_dead:
                        client_state[client_id].configure(text="(在线:{})".format(ip), foreground="#FF7F27")
@@ -342,6 +402,7 @@
        ch1 = Checkbutton(frame, text='自动刷新', variable=auo_refresh, onvalue=1, offvalue=0, background="#DDDDDD",
                          activebackground="#DDDDDD")
        ch1.place(x=width - 80, y=5)
        auo_refresh.set(1)
        l2_client_count = 0
        code_sv_map = {}
@@ -350,13 +411,13 @@
        for key in self.l2_codes:
            client_lb = Label(frame, text="设备:{}".format(key), background="#DDDDDD")
            client_lb.place(x=30, y=40 + l2_client_count * 30)
            client_lb.place(x=38, y=40 + l2_client_count * 30)
            btn = Button(frame, text="检测", command=key)
            btn.bind('<Button-1>', check)
            btn.place(x=0, y=35 + l2_client_count * 30)
            btn.place(x=5, y=35 + l2_client_count * 30)
            client_state_lb = Label(frame, text="(未知)", background="#DDDDDD", font=('微软雅黑', 8))
            client_state_lb.place(x=75, y=40 + l2_client_count * 30)
            client_state_lb.place(x=80, y=40 + l2_client_count * 30)
            client_state[key] = client_state_lb
            code_sv_map[key] = []
@@ -471,7 +532,7 @@
        ch1 = Checkbutton(frame, text='自动刷新', variable=auo_refresh, onvalue=1, offvalue=0, background="#DDDDDD",
                          activebackground="#DDDDDD")
        ch1.place(x=width - 80, y=5)
        auo_refresh.set(1)
        # ------表头结束------
        # 委托表格
@@ -597,29 +658,28 @@
                showwarning('警告', e)
        def export_l2_data(code):
            if code not in  l2_data_manager.local_today_datas:
            if code not in l2_data_manager.local_today_datas:
                l2_data_manager.load_l2_data(code)
            datas = l2_data_manager.local_today_datas[code]
            try:
                path=data_export_util.export_l2_data(code,datas)
                showinfo("提示","导出成功,路径为:"+path)
                path = data_export_util.export_l2_data(code, datas)
                showinfo("提示", "导出成功,路径为:" + path)
            except Exception as e1:
                showerror("导出失败",str(e1))
                showerror("导出失败", str(e1))
        def export_l2_data_origin(code):
            redis = redis_manager.RedisManager(1).getRedis()
            keys = redis.keys("big_data-{}-*".format(code))
            try:
                for k in keys:
                    datas=redis.get(k)
                    datas=json.loads(datas)
                    datas=datas["data"]["data"]
                    datas = redis.get(k)
                    datas = json.loads(datas)
                    _t = k.split("-")[2]
                    k = time.strftime("%Y_%m_%d_%H_%M_%S_",time.localtime(float(_t)/1000))
                    k = "{}{}".format(k,_t[-3:])
                    data_export_util.export_l2_data_origin(code, datas,k)
                    k = time.strftime("%Y_%m_%d_%H_%M_%S_", time.localtime(float(_t) / 1000))
                    k = "{}{}".format(k, _t[-3:])
                    data_export_util.export_l2_data_origin(code, datas, k)
            except Exception as e1:
                    showerror("导出失败", str(e1))
                showerror("导出失败", str(e1))
            showinfo("提示", "导出完成")
@@ -685,6 +745,7 @@
        self.__draw_juejin(root)
        self._draw_check(root)
        self.__draw_l2_state(root)
        self.__draw_trade_state(root)
        self.__draw_trade_data(root)
        self.__draw_test(root)