Administrator
2022-09-23 21d753614ea7bbe936b8560cbf466c4e438821b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
from random import random
from tkinter import *
from tkinter.messagebox import *
import tkintertable
import socket
import threading
import json
from threading import Lock, Thread
import time, os
 
import win32gui
 
import data_export_util
import multiprocessing
 
 
import redis_manager
import mongo_data
import server
import trade_gui
from l2_code_operate import L2CodeOperate
from l2_trade_factor import L2TradeFactorUtil
 
from server import *
 
 
def createServer(pipe):
    print("create SocketServer")
    # 初始化参数
    global_util.init()
    laddr = "", 9001
    tcpserver = MyThreadingTCPServer(laddr, MyBaseRequestHandle, pipe=pipe)  # 注意:参数是MyBaseRequestHandle
    # tcpserver.handle_request()  # 只接受一个客户端连接
    tcpserver.serve_forever()  # 永久循环执行,可以接受多个客户端连接
 
 
def startJueJin(pipe):
    juejin.JueJinManager(pipe).start()
 
 
class GUI:
    def __init__(self):
        p1, p2 = multiprocessing.Pipe()
 
        self.serverProcess = multiprocessing.Process(target=createServer, args=(p1,))
        self.jueJinProcess = multiprocessing.Process(target=startJueJin, args=(p2,))
        # L2显示
        self.l2_codes = {}
        # 获取l2的客户端列表
        clients = authority.get_l2_clients()
        for client_id in clients:
            self.l2_codes[client_id] = []
            for i in range(0, 8):
                code = gpcode_manager.get_listen_code_by_pos(client_id, i)
                self.l2_codes[client_id].append(code)
 
    def run(self):
        # TODO
        self.jueJinProcess.start()
        self.serverProcess.start()
        L2CodeOperate.get_instance()
        # 客户端队列操作
        process = multiprocessing.Process(target=L2CodeOperate.run())
        process.start()
 
        # 客户端server连接
        t1 = threading.Thread(target=lambda: server.test_client_server())
        # 后台运行
        t1.setDaemon(True)
        t1.start()
 
        self.create_gui()
 
    def _draw_check(self, root):
 
        def _set_error_color(text, line, content):
            for i in range(0, len(content)):
                text.tag_add('error', "{}.{}".format(line, i))
 
        def sync_target_codes():
            server.sync_target_codes_to_ths()
 
        def click():
            text.delete('1.0', END)
 
            # 验证redis
            try:
                redis = redis_manager.RedisManager().getRedis()
                redis.set("test", "1")
                redis.delete("test")
                text.insert(END, "redis连接成功!\n")
            except:
                error = "redis连接失败...\n"
                text.insert(END, error)
                _set_error_color(text, 1, error)
            # 验证mongodb
            try:
                count = mongo_data.count("clients", {})
                if count < 1:
                    raise Exception("")
                text.insert(END, "mongodb连接成功!\n")
            except:
                error = "mongodb连接失败...\n"
                text.insert(END, error)
                _set_error_color(text, 2, error)
                pass
 
            try:
                trade_gui.THSGuiTrade.checkEnv()
                text.insert(END, "交易环境检测通过!\n")
            except Exception as e:
                error = "交易环境异常-{}...\n".format(str(e))
                text.insert(END, error)
                _set_error_color(text, 3, error)
                pass
            jurjin_win = 0
            hWndList = []
            win32gui.EnumWindows(lambda hWnd, param: param.append(hWnd), hWndList)
            for hwnd in hWndList:
                title = win32gui.GetWindowText(hwnd)
                if title.find("掘金") > -1:
                    print(title)
                    jurjin_win = hwnd
                    break
            if jurjin_win > 0:
                text.insert(END, "交易环境-掘金客户端已开启!\n")
            else:
                error = "交易环境异常-掘金客户端未开启\n"
                text.insert(END, error)
                _set_error_color(text, 4, error)
 
            text.tag_config('error', foreground='red')
 
        # 设置掘金信息
        width = 300
        height = 150
        frame = Frame(root, {"height": height, "width": width, "bg": "#DDDDDD"})
 
        text = Text(frame, height=100, undo=True)
        text.place(x=0, y=40)
 
        btn = Button(frame, text="运行环境检测", command=click)
        btn.place(x=5, y=5)
 
        btn = Button(frame, text="同步THS目标标的", command=sync_target_codes)
        btn.place(x=100, y=5)
 
        frame.grid(row=1, column=2)
 
    # 绘制开盘前的数据准备情况
    def __draw_pre_data_check(self, frame):
        def refresh_close_price_data():
            redis = redis_manager.RedisManager(0).getRedis()
            count = len(redis.keys("price-pre-*"))
            sv_num.set("获取到收盘价数量:{}".format(count))
 
        def re_get_close_price():
            juejin.re_set_price_pres(gpcode_manager.get_gp_list())
 
        def get_limit_up_codes_win():
            width = 500
            height = 800
            win = Tk()
            win.title("今日涨停")
            win.resizable(height=False, width=False)
 
            limit_up_datas = {}
            limit_up_datas["row{}".format(0)] = {'代码': '', '首次涨停时间': '', '现价': '','涨幅':'', '涨停封单额': ''}
 
            cl = Label(win, text="更新时间:", bg="#DDDDDD", fg="#666666")
            cl.place(x=10, y=10)
 
            limit_up_datas_time = StringVar(value="未知")
            cl = Label(win, textvariable=limit_up_datas_time, bg="#DDDDDD", fg="#666666")
            cl.place(x=100, y=10)
 
            table_height = height - 100
            table_width = width - 20
 
            table_frame = Frame(win, {"height": table_height, "width": table_width, "bg": "#DDDDDD"})
            table_frame.place(x=10, y=45)
            table_limit_up = tkintertable.TableCanvas(table_frame, data=limit_up_datas, read_only=True,
                                                      width=table_width,
                                                      height=table_height, thefont=('微软雅黑', 10), cellwidth=90,
                                                      rowheaderwidth=20)
            table_limit_up.show()
 
            # 获取数据
            time_str, datas = gpcode_manager.get_limit_up_list();
            limit_up_datas_time.set(time_str)
            # 删除所有的行
            # table_limit_up.model.deleteRows()
            # 增加数据
            index = 0
            for data in datas:
                data = json.loads(data)
                table_limit_up.model.addRow()
                table_limit_up.model.setValueAt(data["code"], index, 0)
                table_limit_up.model.setValueAt(data["time"], index, 1)
                table_limit_up.model.setValueAt(float(data["price"]), index, 2)
                table_limit_up.model.setValueAt(float(data["limitUpPercent"]), index, 3)
                table_limit_up.model.setValueAt(
                    "{}{}".format(float(data["limitMoney"]), ("亿" if data["limitMoneyUnit"] == 0 else "万")), index, 4)
                index += 1
            table_limit_up.redraw()
 
            win.geometry("{}x{}".format(width, height))
            win.mainloop()
 
        btn = Button(frame, text="刷新收盘价", command=refresh_close_price_data)
        btn.place(x=5, y=150)
 
        sv_num = StringVar(value="获取到收盘价数量:未知")
        cl = Label(frame, textvariable=sv_num, bg="#DDDDDD", fg="#666666")
        cl.place(x=5, y=180)
 
        btn = Button(frame, text="重新获取收盘价", command=re_get_close_price)
        btn.place(x=150, y=150)
 
        btn = Button(frame, text="今日涨停", command=get_limit_up_codes_win)
        btn.place(x=300, y=150)
 
    # 绘制l2数据状态
    def __draw_l2_state(self, root):
        def update_data():
            while True:
                # 刷新数据
                try:
                    if auo_refresh.get() > 0:
                        refresh_data()
                except:
                    pass
                time.sleep(1)
 
        def refresh_data():
            for client_id in code_sv_map:
                ip = data_process.getActiveClientIP(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")
                    else:
                        client_state[client_id].configure(text="(在线:{})".format(ip), foreground="#008000")
                else:
                    client_state[client_id].configure(text="(离线:未知IP)", foreground="#999999")
 
                for i in range(0, 8):
                    code = gpcode_manager.get_listen_code_by_pos(client_id, i)
                    data_count = l2_data_manager.get_l2_data_latest_count(code)
                    if code is not None and len(code) > 0:
                        code_sv_map[client_id][i].set(code + "({})".format(data_count))
                    else:
                        code_sv_map[client_id][i].set("")
                    if data_count > 0:
                        code_labels[client_id][i].configure(foreground="#FF0000")
 
                    else:
                        code_labels[client_id][i].configure(foreground="#999999")
 
        def check(event):
            client = (event.widget["command"])
            msg_list = []
            try:
                result = get_client_env_state(client)
                if result["ths_l2_win"]:
                    msg_list.append(("同花顺L2屏正常!", 0))
                else:
                    msg_list.append(("同花顺L2屏未打开...", 1))
                if result["ths_fp_1"]:
                    msg_list.append(("同花顺副屏1正常!", 0))
                else:
                    msg_list.append(("同花顺副屏1未打开...", 1))
 
                if result["ths_fp_2"]:
                    msg_list.append(("同花顺副屏2正常!", 0))
                else:
                    msg_list.append(("同花顺副屏2未打开...", 1))
 
                if result["ths_trade_success"]:
                    msg_list.append(("交易成功页面正常!", 0))
                else:
                    msg_list.append(("交易成功页面未打开...", 1))
 
                if result["l2_channel_invalid_count"] <= 0:
                    msg_list.append(("L2监控线程正常数:{} 异常数:{}...".format(result["l2_channel_valid_count"],
                                                                     result["l2_channel_invalid_count"]), 0))
                else:
                    msg_list.append(("L2监控线程正常数:{} 异常数:{}!".format(result["l2_channel_valid_count"],
                                                                   result["l2_channel_invalid_count"]), 1))
 
                if result["limitUp"]:
                    msg_list.append(("涨停监控线程正常!", 0))
                else:
                    msg_list.append(("涨停监控线程异常...", 1))
 
                if result["tradeSuccess"]:
                    msg_list.append(("当日成交监控线程正常!", 0))
                else:
                    msg_list.append(("当日成交监控线程异常...", 1))
 
            except Exception as e:
                msg_list.append((str(e), 1))
 
            def repair():
                try:
                    server.repair_client_env(client)
                    showinfo("提示", "修复完成")
                except Exception as e:
                    showerror("修复出错", str(e))
 
            # 创建界面
            win = Tk()
            win.title("检测结果")
            win.resizable(height=False, width=False)
            text = Text(win, height=100, undo=True)
            text.place(x=0, y=30)
            btn = Button(win, text="一键修复", command=repair)
            btn.place(x=0, y=0)
 
            line = 0
            for msg in msg_list:
                line += 1
                if msg[1] == 0:
                    text.insert(END, "{}\n".format(msg[0]))
                else:
                    text.insert(END, "{}\n".format(msg[0]))
                    for i in range(0, len(msg[0])):
                        text.tag_add('error', "{}.{}".format(line, i))
 
            text.tag_config('error', foreground='red')
 
            win.geometry("300x300")
            win.mainloop()
 
        width = 800
        height = 290
        frame = Frame(root, {"height": height, "width": width, "bg": "#DDDDDD"})
        cl = Label(frame, text="L2采集状态", bg="#DDDDDD")
        cl.place(x=5, y=5)
 
        btn = Button(frame, text="刷新数据", command=refresh_data)
        btn.place(x=width - 150, y=5)
        auo_refresh = IntVar()
        ch1 = Checkbutton(frame, text='自动刷新', variable=auo_refresh, onvalue=1, offvalue=0, background="#DDDDDD",
                          activebackground="#DDDDDD")
        ch1.place(x=width - 80, y=5)
 
        l2_client_count = 0
        code_sv_map = {}
        code_labels = {}
        client_state = {}
        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)
            btn = Button(frame, text="检测", command=key)
            btn.bind('<Button-1>', check)
            btn.place(x=0, 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[key] = client_state_lb
 
            code_sv_map[key] = []
            code_labels[key] = []
            for i in range(0, 8):
                sv = StringVar(value=self.l2_codes[key][i])
                code_sv_map[key].append(sv)
                cframe = Frame(frame, {"height": 23, "width": 70, "bg": "#FFFFFF"})
                code_label = Label(cframe, textvariable=sv, background="#FFFFFF", foreground="#FF0000")
                code_labels[key].append(code_label)
 
                code_label.place(x=0, y=0)
                cframe.place(x=200 + i * 75, y=40 + l2_client_count * 30)
            l2_client_count += 1
        # 添加更新线程
        t1 = threading.Thread(target=lambda: update_data())
        # 后台运行
        t1.setDaemon(True)
        t1.start()
        refresh_data()
        self.__draw_pre_data_check(frame)
 
        frame.grid(row=0, column=1, padx=5, pady=5, rowspan=2)
 
    # 绘制交易数据
    def __draw_trade_data(self, root):
        def auto_refresh():
            while True:
                if auo_refresh.get() > 0:
                    refresh_data()
                time.sleep(1)
 
        def refresh_data():
            money = trade_manager.get_available_money()
            if money is not None:
                sv_trade_money.set(money)
            else:
                sv_trade_money.set("未知")
 
            # 获取委托数据
            datas, time_str = trade_manager.get_trade_delegate_data()
            # 删除所有的行
            table_delegate.model.deleteRows()
            delegate_datas_time.set(time_str)
 
            # 增加数据
            index = 0
            for data in datas:
                table_delegate.model.addRow()
                table_delegate.model.setValueAt(data["time"], index, 0)
                table_delegate.model.setValueAt(data["code"], index, 1)
                table_delegate.model.setValueAt(data["num"], index, 2)
                table_delegate.model.setValueAt(data.get("price"), index, 3)
                table_delegate.model.setValueAt(data.get("trade_price"), index, 4)
                table_delegate.model.setValueAt(data.get("trade_num"), index, 5)
                if int(data["type"]) > 0:
                    table_delegate.model.setValueAt("卖出", index, 6)
                else:
                    table_delegate.model.setValueAt("买入", index, 6)
                index += 1
            table_delegate.redraw()
 
            # 获取所有的数据
            datas, time_str = trade_manager.get_trade_success_data()
            trade_datas_time.set(time_str)
            # 删除所有的行
            table_trade.model.deleteRows()
            # 增加数据
            index = 0
            for data in datas:
                table_trade.model.addRow()
                table_trade.model.setValueAt(data["code"], index, 0)
                table_trade.model.setValueAt(data["time"], index, 1)
                table_trade.model.setValueAt(data["num"], index, 2)
                table_trade.model.setValueAt(data["price"], index, 3)
                table_trade.model.setValueAt(data["money"], index, 4)
                table_trade.model.setValueAt(data["trade_num"], index, 5)
                if int(data["type"]) > 0:
                    table_trade.model.setValueAt("卖出", index, 6)
                else:
                    table_trade.model.setValueAt("买入", index, 6)
                index += 1
            table_trade.redraw()
 
            pass
 
        def create_table(_frame, data, cell_width=70):
            table = tkintertable.TableCanvas(_frame, data=data, read_only=True, width=table_width,
                                             height=table_height, thefont=('微软雅黑', 10), cellwidth=cell_width,
                                             rowheaderwidth=20)
            return table
 
        # 设置掘金信息
        width = 800
        height = 280
        frame = Frame(root, {"height": height, "width": width, "bg": "#DDDDDD"})
        cl = Label(frame, text="交易数据", bg="#DDDDDD")
        cl.place(x=5, y=5)
 
        # ------表头开始------
        # 获取交易账户可用金额
        cl = Label(frame, text="交易账户可用资金:", bg="#DDDDDD", fg="#666666")
        cl.place(x=80, y=5)
 
        sv_trade_money = StringVar(value="未知")
        cl = Label(frame, textvariable=sv_trade_money, bg="#DDDDDD", fg="#666666")
        cl.place(x=190, y=5)
 
        btn = Button(frame, text="刷新数据", command=refresh_data)
        btn.place(x=width - 150, y=5)
        auo_refresh = IntVar()
        ch1 = Checkbutton(frame, text='自动刷新', variable=auo_refresh, onvalue=1, offvalue=0, background="#DDDDDD",
                          activebackground="#DDDDDD")
        ch1.place(x=width - 80, y=5)
 
        # ------表头结束------
 
        # 委托表格
        cl = Label(frame, text="今日委托:", bg="#DDDDDD", fg="#666666")
        cl.place(x=5, y=30)
        delegate_datas = {}
        delegate_datas["row{}".format(0)] = {'委托时间': '', '代码': '', '委托数量': '', '委托价格': '', '成交均价': '', '成交数量': '',
                                             '操作': ''}
 
        cl = Label(frame, text="更新时间:", bg="#DDDDDD", fg="#666666")
        cl.place(x=width / 2 - 130, y=30)
 
        delegate_datas_time = StringVar(value="未知")
        cl = Label(frame, textvariable=delegate_datas_time, bg="#DDDDDD", fg="#666666")
        cl.place(x=width / 2 - 70, y=30)
 
        table_height = 180
        table_width = width / 2 - 50
 
        table_frame = Frame(frame, {"height": table_height, "width": table_width, "bg": "#DDDDDD"})
        table_frame.place(x=5, y=52)
        table_delegate = create_table(table_frame, data=delegate_datas)
        table_delegate.show()
 
        # 成交表格
        cl = Label(frame, text="今日成交:", bg="#DDDDDD", fg="#666666")
        cl.place(x=width / 2, y=30)
        cl = Label(frame, text="更新时间:", bg="#DDDDDD", fg="#666666")
        cl.place(x=width - 130, y=30)
 
        trade_datas_time = StringVar(value="10:00:00")
        cl = Label(frame, textvariable=trade_datas_time, bg="#DDDDDD", fg="#666666")
        cl.place(x=width - 70, y=30)
 
        trade_datas = {}
        trade_datas["row{}".format(0)] = {'证券代码': '', '成交时间': '', '成交数量': '', '成交均价': '', '成交金额': '',
                                          '合同编号': '', '操作': ''}
 
        table_frame = Frame(frame, {"height": table_height, "width": table_width, "bg": "#DDDDDD"})
        table_frame.place(x=width / 2, y=52)
        table_trade = create_table(table_frame, trade_datas, 90)
        table_trade.show()
 
        frame.grid(row=2, column=1, padx=5, pady=5, rowspan=2)
 
        # 添加更新线程
        t1 = threading.Thread(target=lambda: auto_refresh())
        # 后台运行
        t1.setDaemon(True)
        t1.start()
 
    def __draw_juejin(self, root):
        def click():
            account = account_var.get()
            sid = sid_var.get()
            token = token_var.get()
            if len(account.strip()) < 1 or len(sid.strip()) < 1 or len(token.strip()) < 1:
                showinfo('提示', "数据不完整")
                return
            juejin.setAccountInfo(account, sid, token)
            showinfo('提示', "设置成功")
 
        # 设置掘金信息
        frame = Frame(root, {"height": 150, "width": 300, "bg": "#DDDDDD"})
        left = 10
        top = 10
 
        cl = Label(frame, text="账号ID:", bg="#DDDDDD")
        cl.place(x=left, y=top)
        account_var = StringVar(value="1233")
        entry = Entry(frame, textvariable=account_var, width=30)
        entry.place(x=left + 60, y=top)
 
        cl = Label(frame, text="策略ID:", bg="#DDDDDD")
        cl.place(x=left, y=top + 30)
        sid_var = StringVar(value="1233")
        entry = Entry(frame, textvariable=sid_var, width=30)
        entry.place(x=left + 60, y=top + 30)
 
        token_var = StringVar(value="1233")
        cl = Label(frame, text="Token:", bg="#DDDDDD")
        cl.place(x=left, y=top + 60)
        entry = Entry(frame, textvariable=token_var, width=30)
        entry.place(x=left + 60, y=top + 60)
 
        btn = Button(frame, text="设置掘金参数", command=click)
        btn.place(x=left + 60, y=top + 90)
        # frame.place(x=260,y=10)
        frame.grid(row=0, column=2, pady=5, padx=5)
 
        # 设置参数
        account, sid, token = juejin.getAccountInfo()
        account_var.set(account)
        sid_var.set(sid)
        token_var.set(token)
 
    def __draw_test(self, root):
        def startJueJinGui():
            if self.jueJinProcess.is_alive():
                print("已经启动")
            else:
                self.jueJinProcess.start()
 
        def setGPCode(client, position, gpcode):
            if client is None or len(client) < 1:
                return
            if position is None or len(position) < 1:
                return
            if gpcode is None or len(gpcode) < 6:
                return
            l2_code_operate.L2CodeOperate.setGPCode(client, position, gpcode)
 
        def resub():
            self.p1.send("resub")
 
        def refresh_hwnds():
            try:
                trade_gui.THSGuiTrade.checkEnv()
                trade_gui.THSGuiTrade().refresh_hwnds()
                showinfo('提示', "刷新成功")
            except Exception as e:
                print(e)
                showwarning('警告', e)
 
        def export_l2_data(code):
            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)
            except Exception as 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"]
                    _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)
            except Exception as e1:
                    showerror("导出失败", str(e1))
 
            showinfo("提示", "导出完成")
 
        def compute_m(code):
            m = L2TradeFactorUtil.compute_m_value(code)
            showinfo("提示", "{}".format(m))
 
        frame = Frame(root, {"height": 280, "width": 300, "bg": "#DDDDDD"})
        frame.grid(row=2, column=2, rowspan=2, pady=5)
        btntext = StringVar()
 
        el = Label(frame, text="测试区域", bg="#DDDDDD", fg="#A0A000")
        el.place(x=240, y=10)
 
        el = Label(frame, text="客户端ID:", bg="#DDDDDD")
        el.place(x=10, y=10)
        ep_client = Entry(frame, width=2)
        ep_client.place(x=70, y=10)
 
        el = Label(frame, text="位置:", bg="#DDDDDD")
        el.place(x=10, y=40)
        ep = Entry(frame, width=2)
        ep.place(x=50, y=40)
 
        cl = Label(frame, text="代码:", bg="#DDDDDD")
        cl.place(x=10, y=70)
        code = Entry(frame)
        code.place(x=50, y=70)
 
        btn = Button(frame, text="设置代码", command=lambda: setGPCode(ep_client.get(), ep.get(), code.get()), )
        btn.place(x=10, y=100)
 
        btn = Button(frame, text="修复L2数据", command=lambda: L2CodeOperate.get_instance().repaire_l2_data(code.get()))
        btn.place(x=70
                  , y=100)
 
        btn = Button(frame, text="导出L2数据", command=lambda: export_l2_data(code.get()))
        btn.place(x=145, y=100)
 
        btn = Button(frame, text="导出L2原始数据", command=lambda: export_l2_data_origin(code.get()))
        btn.place(x=220, y=100)
 
        btn = Button(frame, text="获取m值", command=lambda: compute_m(code.get()))
        btn.place(x=10, y=120)
 
        # 交易按钮
        btn = Button(frame, textvariable=btntext, command=startJueJinGui)
        btn.place(x=10, y=150)
        btntext.set("启动掘金")
 
        btn = Button(frame, text="重新订阅行情", command=resub)
        btn.place(x=10, y=190)
 
        btn = Button(frame, text="刷新窗口句柄", command=refresh_hwnds)
        btn.place(x=200, y=190)
 
    def create_gui(self):
 
        root = Tk()
        root.title("自动化交易系统")
        root.resizable(height=False, width=False)
 
        self.__draw_juejin(root)
        self._draw_check(root)
        self.__draw_l2_state(root)
        self.__draw_trade_data(root)
        self.__draw_test(root)
 
        root.geometry("1120x600")
        root.mainloop()
 
 
if __name__ == '__main__':
    listen = gpcode_manager.is_listen("000333")
    print(listen)
    # 启动掘金任务
    GUI().run()