| | |
| | | import multiprocessing |
| | | |
| | | import global_util |
| | | import log |
| | | import mysql_data |
| | | import redis_manager |
| | | import mongo_data |
| | | import server |
| | | import trade_gui |
| | | from l2_code_operate import L2CodeOperate |
| | |
| | | from server import * |
| | | |
| | | |
| | | def createServer(pipe): |
| | | # 读取server进程的消息 |
| | | def __read_server_pipe(pipe): |
| | | while True: |
| | | value = pipe.recv() |
| | | if value is not None: |
| | | value = json.loads(value) |
| | | if value.get("type") == "clear_l2": |
| | | code = value["data"]["code"] |
| | | print("清除l2数据", code) |
| | | if len(code) != 6: |
| | | continue |
| | | l2_data_manager.clear_l2_data(code) |
| | | # 删除level2的数据 |
| | | if l2_data_manager.local_today_datas and code in l2_data_manager.local_today_datas: |
| | | l2_data_manager.local_today_datas.pop(code) |
| | | if l2_data_manager.local_latest_datas and code in l2_data_manager.local_latest_datas: |
| | | l2_data_manager.local_latest_datas.pop(code) |
| | | |
| | | time.sleep(0.1) |
| | | |
| | | |
| | | def createServer(pipe_juejin, pipe_gui): |
| | | print("create SocketServer") |
| | | # 初始化参数 |
| | | global_util.init() |
| | | |
| | | t1 = threading.Thread(target=lambda: __read_server_pipe(pipe_gui)) |
| | | # 后台运行 |
| | | t1.setDaemon(True) |
| | | t1.start() |
| | | |
| | | laddr = "", 9001 |
| | | tcpserver = MyThreadingTCPServer(laddr, MyBaseRequestHandle, pipe=pipe) # 注意:参数是MyBaseRequestHandle |
| | | tcpserver = MyThreadingTCPServer(laddr, MyBaseRequestHandle, pipe_juejin=pipe_juejin) # 注意:参数是MyBaseRequestHandle |
| | | # tcpserver.handle_request() # 只接受一个客户端连接 |
| | | tcpserver.serve_forever() # 永久循环执行,可以接受多个客户端连接 |
| | | |
| | |
| | | |
| | | |
| | | class GUI: |
| | | |
| | | |
| | | def __init__(self): |
| | | p1, p2 = multiprocessing.Pipe() |
| | | gs_gui_pipe, gs_server_pipe = multiprocessing.Pipe() |
| | | |
| | | self.serverProcess = multiprocessing.Process(target=createServer, args=(p1,)) |
| | | self.serverProcess = multiprocessing.Process(target=createServer, args=(p1, gs_server_pipe,)) |
| | | self.jueJinProcess = multiprocessing.Process(target=startJueJin, args=(p2,)) |
| | | self.p1 = p1 |
| | | self.p2 = p2 |
| | | self.gs_gui_pipe = gs_gui_pipe |
| | | # L2显示 |
| | | self.l2_codes = {} |
| | | # 获取l2的客户端列表 |
| | |
| | | for i in range(0, 8): |
| | | code = gpcode_manager.get_listen_code_by_pos(client_id, i) |
| | | self.l2_codes[client_id].append(code) |
| | | |
| | | # 读取server进程的消息 |
| | | def __read_gui_server_pipe(self,pipe): |
| | | while True: |
| | | value = pipe.recv() |
| | | if value is not None: |
| | | value = json.loads(value) |
| | | if value.get("type") == "l2_data_notify": |
| | | code = value["data"]["code"] |
| | | count =value["data"]["count"] |
| | | print("l2数据通知:{}-{}", code,count) |
| | | |
| | | time.sleep(0.1) |
| | | |
| | | def run(self): |
| | | # TODO |
| | |
| | | |
| | | # 客户端server连接 |
| | | t1 = threading.Thread(target=lambda: server.test_client_server()) |
| | | # 后台运行 |
| | | t1.setDaemon(True) |
| | | t1.start() |
| | | |
| | | t1 = threading.Thread(target=lambda: self.__read_gui_server_pipe(self.gs_gui_pipe)) |
| | | # 后台运行 |
| | | t1.setDaemon(True) |
| | | t1.start() |
| | |
| | | _set_error_color(text, 1, error) |
| | | # 验证mongodb |
| | | try: |
| | | count = mongo_data.count("clients", {}) |
| | | if count < 1: |
| | | counts = mysql_data.Mysqldb().select_one("select count(*) from clients") |
| | | if counts[0] < 1: |
| | | raise Exception("") |
| | | text.insert(END, "mongodb连接成功!\n") |
| | | text.insert(END, "mysql连接成功!\n") |
| | | except: |
| | | error = "mongodb连接失败...\n" |
| | | error = "mysql连接失败...\n" |
| | | text.insert(END, error) |
| | | _set_error_color(text, 2, error) |
| | | pass |
| | |
| | | # 绘制交易状态 |
| | | def __draw_trade_state(self, frame): |
| | | def refresh_data(): |
| | | normal=True |
| | | 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 |
| | | 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") |
| | | cl_win.configure(text="异常:{}".format(str(e)), foreground="#FF7F27") |
| | | # 状态有问题,需要报警 |
| | | if not normal: |
| | | alert_util.alarm() |
| | |
| | | pass |
| | | time.sleep(2) |
| | | |
| | | start_y=230 |
| | | 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", |
| | |
| | | auo_refresh.set(1) |
| | | ch1.place(x=100, y=start_y) |
| | | |
| | | y_=start_y+30 |
| | | y_ = start_y + 30 |
| | | cl = Label(frame, text="操作队列状态:", bg="#DDDDDD") |
| | | cl.place(x=10, y=y_) |
| | | cl_queue = Label(frame, text="未知", bg="#DDDDDD") |
| | |
| | | m = L2TradeFactorUtil.compute_m_value(code) |
| | | showinfo("提示", "{}".format(m)) |
| | | |
| | | def clear_l2(code): |
| | | self.gs_gui_pipe.send(json.dumps({"type": "clear_l2", "data": {"code": code}})) |
| | | pass |
| | | |
| | | frame = Frame(root, {"height": 280, "width": 300, "bg": "#DDDDDD"}) |
| | | frame.grid(row=2, column=2, rowspan=2, pady=5) |
| | | btntext = StringVar() |
| | |
| | | btn.place(x=220, y=100) |
| | | |
| | | btn = Button(frame, text="获取m值", command=lambda: compute_m(code.get())) |
| | | btn.place(x=10, y=120) |
| | | btn.place(x=10, y=130) |
| | | |
| | | btn = Button(frame, text="导出交易日志", command=lambda: log.export_l2_log(code.get())) |
| | | btn.place(x=80, y=130) |
| | | |
| | | btn = Button(frame, text="清空l2数据", command=lambda: clear_l2(code.get())) |
| | | btn.place(x=150, y=130) |
| | | |
| | | # 交易按钮 |
| | | btn = Button(frame, textvariable=btntext, command=startJueJinGui) |
| | | btn.place(x=10, y=150) |
| | | btn.place(x=10, y=160) |
| | | btntext.set("启动掘金") |
| | | |
| | | btn = Button(frame, text="重新订阅行情", command=resub) |