-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathpystocktrader.py
1526 lines (1376 loc) · 75.3 KB
/
pystocktrader.py
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
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import sys
import psutil
import logging
import subprocess
from PyQt5.QtTest import QTest
from multiprocessing import Process, Queue
from coin.receiver_upbit import WebsTicker, WebsOrderbook
from coin.collector_upbit import CollectorUpbit
from coin.strategy_coin import StrategyCoin
from coin.trader_upbit import TraderUpbit
from stock.receiver_kiwoom import ReceiverKiwoom
from stock.collector_kiwoom import CollectorKiwoom
from stock.strategy_stock import StrategyStock
from stock.trader_kiwoom import TraderKiwoom
from utility.setui import *
from utility.sound import Sound
from utility.query import Query
from utility.query_tick import QueryTick
from utility.telegram_msg import TelegramMsg
from utility.static import now, strf_time, strp_time, changeFormat, thread_decorator, comma2int, comma2float
class Window(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.log1 = logging.getLogger('Stock')
self.log1.setLevel(logging.INFO)
filehandler = logging.FileHandler(filename=f"{SYSTEM_PATH}/log/S{strf_time('%Y%m%d')}.txt", encoding='utf-8')
self.log1.addHandler(filehandler)
self.log2 = logging.getLogger('Coin')
self.log2.setLevel(logging.INFO)
filehandler = logging.FileHandler(filename=f"{SYSTEM_PATH}/log/C{strf_time('%Y%m%d')}.txt", encoding='utf-8')
self.log2.addHandler(filehandler)
SetUI(self)
if int(strf_time('%H%M%S')) < 80000 or 160000 < int(strf_time('%H%M%S')):
self.main_tabWidget.setCurrentWidget(self.ct_tab)
self.counter = 0
self.cpu_per = 0
self.int_time = int(strf_time('%H%M%S'))
self.dict_name = {}
self.dict_code = {}
self.writer = Writer()
self.writer.data1.connect(self.UpdateTexedit)
self.writer.data2.connect(self.UpdateTablewidget)
self.writer.data3.connect(self.UpdateGaonsimJongmok)
self.writer.start()
self.qtimer1 = QtCore.QTimer()
self.qtimer1.setInterval(1000)
self.qtimer1.timeout.connect(self.ProcessStarter)
self.qtimer1.start()
self.qtimer2 = QtCore.QTimer()
self.qtimer2.setInterval(500)
self.qtimer2.timeout.connect(self.UpdateProgressBar)
self.qtimer2.start()
self.qtimer3 = QtCore.QTimer()
self.qtimer3.setInterval(500)
self.qtimer3.timeout.connect(self.UpdateCpuper)
self.qtimer3.start()
self.showqsize = False
self.backtester_proc = None
self.receiver_coin_thread1 = WebsTicker(qlist)
self.receiver_coin_thread2 = WebsOrderbook(qlist)
self.collector_coin_proc = Process(target=CollectorUpbit, args=(qlist,), daemon=True)
self.strategy_coin_proc = Process(target=StrategyCoin, args=(qlist,), daemon=True)
self.trader_coin_proc = Process(target=TraderUpbit, args=(qlist,), daemon=True)
self.receiver_stock_proc = Process(target=ReceiverKiwoom, args=(qlist,), daemon=True)
self.collector_stock_proc1 = Process(target=CollectorKiwoom, args=(1, qlist), daemon=True)
self.collector_stock_proc2 = Process(target=CollectorKiwoom, args=(2, qlist), daemon=True)
self.collector_stock_proc3 = Process(target=CollectorKiwoom, args=(3, qlist), daemon=True)
self.collector_stock_proc4 = Process(target=CollectorKiwoom, args=(4, qlist), daemon=True)
self.strategy_stock_proc = Process(target=StrategyStock, args=(qlist,), daemon=True)
self.trader_stock_proc = Process(target=TraderKiwoom, args=(qlist,), daemon=True)
def ProcessStarter(self):
if now().weekday() not in [6, 7]:
if DICT_SET['키움콜렉터'] and self.int_time < DICT_SET['콜렉터'] <= int(strf_time('%H%M%S')):
self.KiwoomCollectorStart()
if DICT_SET['키움트레이더'] and self.int_time < DICT_SET['트레이더'] <= int(strf_time('%H%M%S')):
self.KiwoomTraderStart()
if DICT_SET['업비트콜렉터']:
self.UpbitCollectorStart()
if DICT_SET['업비트트레이더']:
self.UpbitTraderStart()
if DICT_SET['주식최적화백테스터'] and self.int_time < DICT_SET['주식백테시작시간'] <= int(strf_time('%H%M%S')):
self.StockBacktestStart()
if DICT_SET['코인최적화백테스터'] and self.int_time < DICT_SET['코인백테시작시간'] <= int(strf_time('%H%M%S')):
self.CoinBacktestStart()
if self.int_time < 100 <= int(strf_time('%H%M%S')):
self.ClearTextEdit()
self.UpdateWindowTitle()
self.int_time = int(strf_time('%H%M%S'))
# noinspection PyArgumentList
def KiwoomCollectorStart(self):
self.backtester_proc = None
if DICT_SET['아이디2'] is not None:
os.system(f'python {LOGIN_PATH}/versionupdater.py')
os.system(f'python {LOGIN_PATH}/autologin2.py')
if not self.collector_stock_proc1.is_alive():
self.collector_stock_proc1.start()
if not self.collector_stock_proc2.is_alive():
self.collector_stock_proc2.start()
if not self.collector_stock_proc3.is_alive():
self.collector_stock_proc3.start()
if not self.collector_stock_proc4.is_alive():
self.collector_stock_proc4.start()
if not self.receiver_stock_proc.is_alive():
self.receiver_stock_proc.start()
text = '주식 리시버 및 콜렉터를 시작하였습니다.'
soundQ.put(text)
teleQ.put(text)
else:
QtWidgets.QMessageBox.critical(
self, '오류 알림', '키움 두번째 계정이 설정되지 않아\n콜렉터를 시작할 수 없습니다.\n계정 설정 후 다시 시작하십시오.\n')
def KiwoomTraderStart(self):
if DICT_SET['아이디1'] is not None:
os.system(f'python {LOGIN_PATH}/autologin1.py')
if not self.strategy_stock_proc.is_alive():
self.strategy_stock_proc.start()
if not self.trader_stock_proc.is_alive():
self.trader_stock_proc.start()
text = '주식 트레이더를 시작하였습니다.'
soundQ.put(text)
teleQ.put(text)
else:
QtWidgets.QMessageBox.critical(
self, '오류 알림', '키움 첫번째 계정이 설정되지 않아\n트레이더를 시작할 수 없습니다.\n계정 설정 후 다시 시작하십시오.\n')
def UpbitCollectorStart(self):
if not self.receiver_coin_thread1.isRunning():
self.receiver_coin_thread1.start()
if not self.receiver_coin_thread2.isRunning():
self.receiver_coin_thread2.start()
if not self.collector_coin_proc.is_alive():
self.collector_coin_proc.start()
text = '코인 리시버 및 콜렉터를 시작하였습니다.'
soundQ.put(text)
teleQ.put(text)
def UpbitTraderStart(self):
if DICT_SET['Access_key'] is not None:
if not self.strategy_coin_proc.is_alive():
self.strategy_coin_proc.start()
if not self.trader_coin_proc.is_alive():
self.trader_coin_proc.start()
text = '코인 트레이더를 시작하였습니다.'
soundQ.put(text)
teleQ.put(text)
else:
QtWidgets.QMessageBox.critical(
self, '오류 알림', '업비트 계정이 설정되지 않아\n트레이더를 시작할 수 없습니다.\n계정 설정 후 다시 시작하십시오.\n')
def StockBacktestStart(self):
if self.backtester_proc is not None and self.backtester_proc.poll() != 0:
QtWidgets.QMessageBox.critical(self, '오류 알림', '현재 백테스터가 실행중입니다.\n중복 실행할 수 없습니다.\n')
return
else:
self.backtester_proc = subprocess.Popen(f'python {SYSTEM_PATH}/backtester/backtester_stock_vc.py')
def CoinBacktestStart(self):
if self.backtester_proc is not None and self.backtester_proc.poll() != 0:
QtWidgets.QMessageBox.critical(self, '오류 알림', '현재 백테스터가 실행중입니다.\n중복 실행할 수 없습니다.\n')
return
else:
self.backtester_proc = subprocess.Popen(f'python {SYSTEM_PATH}/backtester/backtester_coin_vc.py')
def ClearTextEdit(self):
self.st_textEdit.clear()
self.ct_textEdit.clear()
self.sc_textEdit.clear()
self.cc_textEdit.clear()
def UpdateWindowTitle(self):
if self.showqsize:
queryQ_size = query1Q.qsize() + query2Q.qsize()
stocktickQ_size = tick1Q.qsize() + tick2Q.qsize() + tick3Q.qsize() + tick4Q.qsize()
text = f'PyStockTrader ' \
f'windowQ[{windowQ.qsize()}] | soundQ[{soundQ.qsize()}] | ' \
f'queryQ[{queryQ_size}] | teleQ[{teleQ.qsize()}] | receivQ[{sreceivQ.qsize()}] | ' \
f'stockQ[{stockQ.qsize()}] | coinQ[{coinQ.qsize()}] | sstgQ[{sstgQ.qsize()}] | ' \
f'cstgQ[{cstgQ.qsize()}] | stocktickQ[{stocktickQ_size}] | cointickQ[{tick5Q.qsize()}]'
self.setWindowTitle(text)
elif self.windowTitle() != 'PyStockTrader':
self.setWindowTitle('PyStockTrader')
def UpdateProgressBar(self):
if self.counter > 9:
self.counter = 0
self.counter += 1
self.progressBar.setValue(int(self.cpu_per))
if self.backtester_proc is not None and self.backtester_proc.poll() != 0:
if self.counter % 2 == 0:
self.sb_pushButton_01.setStyleSheet(style_bc_st)
self.sb_pushButton_02.setStyleSheet(style_bc_bt)
self.cb_pushButton_01.setStyleSheet(style_bc_st)
self.cb_pushButton_02.setStyleSheet(style_bc_bt)
else:
self.sb_pushButton_01.setStyleSheet(style_bc_bt)
self.sb_pushButton_02.setStyleSheet(style_bc_st)
self.cb_pushButton_01.setStyleSheet(style_bc_bt)
self.cb_pushButton_02.setStyleSheet(style_bc_st)
else:
self.sb_pushButton_01.setStyleSheet(style_bc_st)
self.sb_pushButton_02.setStyleSheet(style_bc_st)
self.cb_pushButton_01.setStyleSheet(style_bc_st)
self.cb_pushButton_02.setStyleSheet(style_bc_st)
@thread_decorator
def UpdateCpuper(self):
self.cpu_per = psutil.cpu_percent(interval=1)
def ShowQsize(self):
self.showqsize = True if not self.showqsize else False
def CheckboxChanged_01(self, state):
if state == Qt.Checked:
con = sqlite3.connect(DB_SETTING)
df = pd.read_sql('SELECT * FROM kiwoom', con).set_index('index')
con.close()
if len(df) == 0 or df['아이디2'][0] == '':
self.sj_main_checkBox_01.nextCheckState()
QtWidgets.QMessageBox.critical(
self, '오류 알림', '키움 두번째 계정이 설정되지 않아\n콜렉터를 선택할 수 없습니다.\n계정 설정 후 다시 선택하십시오.\n')
def CheckboxChanged_02(self, state):
if state == Qt.Checked:
con = sqlite3.connect(DB_SETTING)
df = pd.read_sql('SELECT * FROM kiwoom', con).set_index('index')
con.close()
if len(df) == 0 or df['아이디1'][0] == '':
self.sj_main_checkBox_02.nextCheckState()
QtWidgets.QMessageBox.critical(
self, '오류 알림', '키움 첫번째 계정이 설정되지 않아\n트레이더를 선택할 수 없습니다.\n계정 설정 후 다시 선택하십시오.\n')
def CheckboxChanged_03(self, state):
if state == Qt.Checked:
con = sqlite3.connect(DB_SETTING)
df = pd.read_sql('SELECT * FROM upbit', con).set_index('index')
con.close()
if len(df) == 0 or df['Access_key'][0] == '':
self.sj_main_checkBox_04.nextCheckState()
QtWidgets.QMessageBox.critical(
self, '오류 알림', '업비트 계정이 설정되지 않아\n트레이더를 선택할 수 없습니다.\n계정 설정 후 다시 선택하십시오.\n')
@QtCore.pyqtSlot(int)
def CellClicked_01(self, row):
item = self.sjg_tableWidget.item(row, 0)
if item is None:
return
name = item.text()
oc = comma2int(self.sjg_tableWidget.item(row, columns_jg.index('보유수량')).text())
c = comma2int(self.sjg_tableWidget.item(row, columns_jg.index('현재가')).text())
buttonReply = QtWidgets.QMessageBox.question(
self, '주식 시장가 매도', f'{name} {oc}주를 시장가매도합니다.\n계속하시겠습니까?\n',
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No
)
if buttonReply == QtWidgets.QMessageBox.Yes:
stockQ.put(['매도', self.dict_code[name], name, c, oc])
@QtCore.pyqtSlot(int)
def CellClicked_02(self, row):
item = self.cjg_tableWidget.item(row, 0)
if item is None:
return
code = item.text()
oc = comma2float(self.cjg_tableWidget.item(row, columns_jg.index('보유수량')).text())
c = comma2float(self.cjg_tableWidget.item(row, columns_jg.index('현재가')).text())
buttonReply = QtWidgets.QMessageBox.question(
self, '코인 시장가 매도', f'{code} {oc}개를 시장가매도합니다.\n계속하시겠습니까?\n',
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No
)
if buttonReply == QtWidgets.QMessageBox.Yes:
coinQ.put(['매도', code, c, oc])
def ButtonClicked_01(self):
if self.main_tabWidget.currentWidget() == self.st_tab:
if not self.s_calendarWidget.isVisible():
boolean1 = False
boolean2 = True
self.tt_pushButton.setStyleSheet(style_bc_dk)
else:
boolean1 = True
boolean2 = False
self.tt_pushButton.setStyleSheet(style_bc_bt)
self.stt_tableWidget.setVisible(boolean1)
self.std_tableWidget.setVisible(boolean1)
self.stj_tableWidget.setVisible(boolean1)
self.sjg_tableWidget.setVisible(boolean1)
self.sgj_tableWidget.setVisible(boolean1)
self.scj_tableWidget.setVisible(boolean1)
self.s_calendarWidget.setVisible(boolean2)
self.sdt_tableWidget.setVisible(boolean2)
self.sds_tableWidget.setVisible(boolean2)
self.snt_pushButton_01.setVisible(boolean2)
self.snt_pushButton_02.setVisible(boolean2)
self.snt_pushButton_03.setVisible(boolean2)
self.snt_tableWidget.setVisible(boolean2)
self.sns_tableWidget.setVisible(boolean2)
elif self.main_tabWidget.currentWidget() == self.ct_tab:
if not self.c_calendarWidget.isVisible():
boolean1 = False
boolean2 = True
self.tt_pushButton.setStyleSheet(style_bc_dk)
else:
boolean1 = True
boolean2 = False
self.tt_pushButton.setStyleSheet(style_bc_bt)
self.ctt_tableWidget.setVisible(boolean1)
self.ctd_tableWidget.setVisible(boolean1)
self.ctj_tableWidget.setVisible(boolean1)
self.cjg_tableWidget.setVisible(boolean1)
self.cgj_tableWidget.setVisible(boolean1)
self.ccj_tableWidget.setVisible(boolean1)
self.c_calendarWidget.setVisible(boolean2)
self.cdt_tableWidget.setVisible(boolean2)
self.cds_tableWidget.setVisible(boolean2)
self.cnt_pushButton_01.setVisible(boolean2)
self.cnt_pushButton_02.setVisible(boolean2)
self.cnt_pushButton_03.setVisible(boolean2)
self.cnt_tableWidget.setVisible(boolean2)
self.cns_tableWidget.setVisible(boolean2)
else:
QtWidgets.QMessageBox.warning(self, '오류 알림', '해당 버튼은 트레이더탭에서만 작동합니다.\n')
# noinspection PyArgumentList
def ButtonClicked_02(self):
buttonReply = QtWidgets.QMessageBox.question(
self, '주식 수동 시작', '주식 콜렉터 또는 트레이더를 시작합니다.\n계속하시겠습니까?\n',
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No
)
if buttonReply == QtWidgets.QMessageBox.Yes:
if DICT_SET['아이디2'] is None:
QtWidgets.QMessageBox.critical(
self, '오류 알림', '키움 두번째 계정이 설정되지 않아\n콜렉터를 시작할 수 없습니다.\n계정 설정 후 다시 시작하십시오.\n')
else:
self.KiwoomCollectorStart()
QTest.qWait(20000)
if DICT_SET['아이디1'] is None:
QtWidgets.QMessageBox.critical(
self, '오류 알림', '키움 첫번째 계정이 설정되지 않아\n트레이더를 시작할 수 없습니다.\n계정 설정 후 다시 시작하십시오.\n')
else:
self.KiwoomTraderStart()
def ButtonClicked_03(self):
if self.geometry().width() > 1000:
self.setFixedSize(722, 383)
self.zo_pushButton.setStyleSheet(style_bc_dk)
else:
self.setFixedSize(1403, 763)
self.zo_pushButton.setStyleSheet(style_bc_bt)
def ButtonClicked_04(self):
buttonReply = QtWidgets.QMessageBox.warning(
self, '데이터베이스 초기화', '체결목록, 잔고목록, 거래목록, 일별목록이 모두 초기화됩니다.\n계속하시겠습니까?\n',
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No
)
if buttonReply == QtWidgets.QMessageBox.Yes:
query1Q.put([2, 'DELETE FROM s_jangolist'])
query1Q.put([2, 'DELETE FROM s_tradelist'])
query1Q.put([2, 'DELETE FROM s_chegeollist'])
query1Q.put([2, 'DELETE FROM s_totaltradelist'])
query1Q.put([2, 'DELETE FROM c_jangolist'])
query1Q.put([2, 'DELETE FROM c_tradelist'])
query1Q.put([2, 'DELETE FROM c_chegeollist'])
query1Q.put([2, 'DELETE FROM c_totaltradelist'])
self.dd_pushButton.setStyleSheet(style_bc_dk)
def ButtonClicked_05(self):
buttonReply = QtWidgets.QMessageBox.warning(
self, '계정 설정 초기화', '계정 설정 항목이 모두 초기화됩니다.\n계속하시겠습니까?\n',
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No
)
if buttonReply == QtWidgets.QMessageBox.Yes:
query1Q.put([1, 'DELETE FROM kiwoom'])
query1Q.put([1, 'DELETE FROM upbit'])
query1Q.put([1, 'DELETE FROM telegram'])
self.sd_pushButton.setStyleSheet(style_bc_dk)
def ButtonClicked_06(self, cmd):
if '집계' in cmd:
if 'S' in cmd:
gubun = 'S'
table = 's_totaltradelist'
else:
gubun = 'C'
table = 'c_totaltradelist'
con = sqlite3.connect(DB_TRADELIST)
df = pd.read_sql(f'SELECT * FROM {table}', con)
con.close()
df = df[::-1]
if len(df) > 0:
sd = strp_time('%Y%m%d', df['index'][df.index[0]])
ld = strp_time('%Y%m%d', df['index'][df.index[-1]])
pr = str((sd - ld).days + 1) + '일'
nbg, nsg = df['총매수금액'].sum(), df['총매도금액'].sum()
sp = round((nsg / nbg - 1) * 100, 2)
npg, nmg = df['총수익금액'].sum(), df['총손실금액'].sum()
nsig = df['수익금합계'].sum()
df2 = pd.DataFrame(columns=columns_nt)
df2.at[0] = pr, nbg, nsg, npg, nmg, sp, nsig
self.UpdateTablewidget([ui_num[f'{gubun}누적합계'], df2])
else:
QtWidgets.QMessageBox.critical(self, '오류 알림', '거래목록이 존재하지 않습니다.\n')
return
if cmd == '일별집계':
df = df.rename(columns={'index': '일자'})
self.UpdateTablewidget([ui_num[f'{gubun}누적상세'], df])
elif cmd == '월별집계':
df['일자'] = df['index'].apply(lambda x: x[:6])
df2 = pd.DataFrame(columns=columns_nd)
lastmonth = df['일자'][df.index[-1]]
month = strf_time('%Y%m')
while int(month) >= int(lastmonth):
df3 = df[df['일자'] == month]
if len(df3) > 0:
tbg, tsg = df3['총매수금액'].sum(), df3['총매도금액'].sum()
sp = round((tsg / tbg - 1) * 100, 2)
tpg, tmg = df3['총수익금액'].sum(), df3['총손실금액'].sum()
ttsg = df3['수익금합계'].sum()
df2.at[month] = month, tbg, tsg, tpg, tmg, sp, ttsg
month = str(int(month) - 89) if int(month[4:]) == 1 else str(int(month) - 1)
self.UpdateTablewidget([ui_num[f'{gubun}누적상세'], df2])
elif cmd == '연도별집계':
df['일자'] = df['index'].apply(lambda x: x[:4])
df2 = pd.DataFrame(columns=columns_nd)
lastyear = df['일자'][df.index[-1]]
year = strf_time('%Y')
while int(year) >= int(lastyear):
df3 = df[df['일자'] == year]
if len(df3) > 0:
tbg, tsg = df3['총매수금액'].sum(), df3['총매도금액'].sum()
sp = round((tsg / tbg - 1) * 100, 2)
tpg, tmg = df3['총수익금액'].sum(), df3['총손실금액'].sum()
ttsg = df3['수익금합계'].sum()
df2.at[year] = year, tbg, tsg, tpg, tmg, sp, ttsg
year = str(int(year) - 1)
self.UpdateTablewidget([ui_num[f'{gubun}누적상세'], df2])
def Activated_01(self):
strategy_name = self.ssi_comboBox.currentText()
if strategy_name != '':
con = sqlite3.connect(DB_STOCK_STRETEGY)
df = pd.read_sql(f"SELECT * FROM init WHERE `index` = '{strategy_name}'", con).set_index('index')
con.close()
self.ss_textEdit_01.clear()
self.ss_textEdit_01.append(df['전략코드'][strategy_name])
def Activated_02(self):
strategy_name = self.ssb_comboBox.currentText()
if strategy_name != '':
con = sqlite3.connect(DB_STOCK_STRETEGY)
df = pd.read_sql(f"SELECT * FROM buy WHERE `index` = '{strategy_name}'", con).set_index('index')
con.close()
self.ss_textEdit_02.clear()
self.ss_textEdit_02.append(df['전략코드'][strategy_name])
def Activated_03(self):
strategy_name = self.sss_comboBox.currentText()
if strategy_name != '':
con = sqlite3.connect(DB_STOCK_STRETEGY)
df = pd.read_sql(f"SELECT * FROM sell WHERE `index` = '{strategy_name}'", con).set_index('index')
con.close()
self.ss_textEdit_03.clear()
self.ss_textEdit_03.append(df['전략코드'][strategy_name])
def Activated_04(self):
strategy_name = self.csi_comboBox.currentText()
if strategy_name != '':
con = sqlite3.connect(DB_COIN_STRETEGY)
df = pd.read_sql(f"SELECT * FROM init WHERE `index` = '{strategy_name}'", con).set_index('index')
con.close()
self.cs_textEdit_01.clear()
self.cs_textEdit_01.append(df['전략코드'][strategy_name])
def Activated_05(self):
strategy_name = self.csb_comboBox.currentText()
if strategy_name != '':
con = sqlite3.connect(DB_COIN_STRETEGY)
df = pd.read_sql(f"SELECT * FROM buy WHERE `index` = '{strategy_name}'", con).set_index('index')
con.close()
self.cs_textEdit_02.clear()
self.cs_textEdit_02.append(df['전략코드'][strategy_name])
def Activated_06(self):
strategy_name = self.css_comboBox.currentText()
if strategy_name != '':
con = sqlite3.connect(DB_COIN_STRETEGY)
df = pd.read_sql(f"SELECT * FROM sell WHERE `index` = '{strategy_name}'", con).set_index('index')
con.close()
self.cs_textEdit_03.clear()
self.cs_textEdit_03.append(df['전략코드'][strategy_name])
def ButtonClicked_11(self):
con = sqlite3.connect(DB_STOCK_STRETEGY)
df = pd.read_sql('SELECT * FROM init', con).set_index('index')
con.close()
if len(df) > 0:
self.ssi_comboBox.clear()
for index in df.index:
self.ssi_comboBox.addItem(index)
windowQ.put([ui_num['S전략텍스트'], '시작전략 불러오기 완료'])
self.ssi_pushButton_04.setStyleSheet(style_bc_st)
else:
windowQ.put([ui_num['S전략텍스트'], '시작전략 없음'])
def ButtonClicked_12(self):
strategy_name = self.ssi_lineEdit.text()
strategy = self.ss_textEdit_01.toPlainText()
if strategy_name == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '시작전략의 이름이 공백 상태입니다.\n이름을 입력하십시오.\n')
elif strategy == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '시작전략의 코드가 공백 상태입니다.\n코드를 작성하십시오.\n')
else:
query1Q.put([3, f"DELETE FROM init WHERE `index` = '{strategy_name}'"])
df = pd.DataFrame({'전략코드': [strategy]}, index=[strategy_name])
query1Q.put([3, df, 'init', 'append'])
windowQ.put([ui_num['S전략텍스트'], '시작전략 저장하기 완료'])
self.ssi_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_13(self):
self.ss_textEdit_01.clear()
self.ss_textEdit_01.append(init_var)
windowQ.put([ui_num['S전략텍스트'], '시작변수 불러오기 완료'])
self.ssi_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_14(self):
strategy = self.ss_textEdit_01.toPlainText()
if strategy == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '시작전략의 코드가 공백 상태입니다.\n')
else:
query1Q.put([3, "DELETE FROM init WHERE `index` = '현재전략'"])
df = pd.DataFrame({'전략코드': [strategy]}, index=['현재전략'])
query1Q.put([3, df, 'init', 'append'])
sstgQ.put(['시작전략', strategy])
windowQ.put([ui_num['S전략텍스트'], '시작전략 설정하기 완료'])
QtWidgets.QMessageBox.warning(self, '적용 알림', '시작전략은 프로그램을 재시작해야 적용됩니다.\n')
self.ssi_pushButton_04.setStyleSheet(style_bc_dk)
def ButtonClicked_15(self):
con = sqlite3.connect(DB_STOCK_STRETEGY)
df = pd.read_sql('SELECT * FROM buy', con).set_index('index')
con.close()
if len(df) > 0:
self.ssb_comboBox.clear()
for index in df.index:
self.ssb_comboBox.addItem(index)
windowQ.put([ui_num['S전략텍스트'], '매수전략 불러오기 완료'])
self.ssb_pushButton_04.setStyleSheet(style_bc_st)
else:
windowQ.put([ui_num['S전략텍스트'], '매수전략 없음'])
def ButtonClicked_16(self):
strategy_name = self.ssb_lineEdit.text()
strategy = self.ss_textEdit_02.toPlainText()
if strategy_name == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '매수전략의 이름이 공백 상태입니다.\n이름을 입력하십시오.\n')
elif strategy == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '매수전략의 코드가 공백 상태입니다.\n코드를 작성하십시오.\n')
else:
query1Q.put([3, f"DELETE FROM buy WHERE `index` = '{strategy_name}'"])
df = pd.DataFrame({'전략코드': [strategy]}, index=[strategy_name])
query1Q.put([3, df, 'buy', 'append'])
windowQ.put([ui_num['S전략텍스트'], '매수전략 저장하기 완료'])
self.ssb_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_17(self):
self.ss_textEdit_02.clear()
self.ss_textEdit_02.append(stock_buy_var)
windowQ.put([ui_num['S전략텍스트'], '매수변수 불러오기 완료'])
self.ssb_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_18(self):
strategy = self.ss_textEdit_02.toPlainText()
if strategy == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '매수전략의 코드가 공백 상태입니다.\n')
else:
query1Q.put([3, "DELETE FROM buy WHERE `index` = '현재전략'"])
df = pd.DataFrame({'전략코드': [strategy]}, index=['현재전략'])
query1Q.put([3, df, 'buy', 'append'])
sstgQ.put(['매수전략', strategy])
windowQ.put([ui_num['S전략텍스트'], '매수전략 시작하기 완료'])
self.ssb_pushButton_04.setStyleSheet(style_bc_dk)
self.ssb_pushButton_12.setStyleSheet(style_bc_st)
def ButtonClicked_19(self):
self.ss_textEdit_02.append(stock_buy1)
windowQ.put([ui_num['S전략텍스트'], '매수전략 모듈추가 완료'])
def ButtonClicked_20(self):
self.ss_textEdit_02.append(stock_buy2)
windowQ.put([ui_num['S전략텍스트'], '매수전략 모듈추가 완료'])
def ButtonClicked_21(self):
self.ss_textEdit_02.append(stock_buy3)
windowQ.put([ui_num['S전략텍스트'], '매수전략 모듈추가 완료'])
def ButtonClicked_22(self):
self.ss_textEdit_02.append(stock_buy4)
windowQ.put([ui_num['S전략텍스트'], '매수전략 모듈추가 완료'])
def ButtonClicked_23(self):
self.ss_textEdit_02.append(stock_buy5)
windowQ.put([ui_num['S전략텍스트'], '매수전략 모듈추가 완료'])
def ButtonClicked_24(self):
self.ss_textEdit_02.append(stock_buy6)
windowQ.put([ui_num['S전략텍스트'], '매수전략 모듈추가 완료'])
def ButtonClicked_25(self):
self.ss_textEdit_02.append(stock_buy_signal)
windowQ.put([ui_num['S전략텍스트'], '매수전략 모듈추가 완료'])
# noinspection PyMethodMayBeStatic
def ButtonClicked_26(self):
sstgQ.put(['매수전략중지', ''])
self.ssb_pushButton_12.setStyleSheet(style_bc_dk)
self.ssb_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_27(self):
if self.backtester_proc is not None and self.backtester_proc.poll() != 0:
QtWidgets.QMessageBox.critical(self, '오류 알림', '현재 백테스터가 실행중입니다.\n중복 실행할 수 없습니다.\n')
return
else:
testperiod = self.ssb_lineEdit_01.text()
totaltime = self.ssb_lineEdit_02.text()
avgtime = self.ssb_lineEdit_03.text()
starttime = self.ssb_lineEdit_04.text()
endtime = self.ssb_lineEdit_05.text()
multi = self.ssb_lineEdit_06.text()
buystg = self.ssb_comboBox.currentText()
sellstg = self.sss_comboBox.currentText()
if buystg == '' or sellstg == '' or testperiod == '' or totaltime == '' or avgtime == '' or \
starttime == '' or endtime == '' or multi == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '일부 설정값이 공백 상태입니다.\n')
return
self.backtester_proc = subprocess.Popen(
f'python {SYSTEM_PATH}/backtester/backtester_stock_stg.py '
f'{testperiod} {totaltime} {avgtime} {starttime} {endtime} {multi} {buystg} {sellstg}'
)
def ButtonClicked_28(self):
if self.backtester_proc is None or self.backtester_proc.poll() == 0:
buttonReply = QtWidgets.QMessageBox.question(
self, '최적화 백테스터',
'backtester/backtester_stock_vc.py 파일을\n본인의 전략에 맞게 수정 후 사용해야합니다.\n계속하시겠습니까?\n',
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No
)
if buttonReply == QtWidgets.QMessageBox.Yes:
self.backtester_proc = subprocess.Popen(f'python {SYSTEM_PATH}/backtester/backtester_stock_vc.py')
def ButtonClicked_83(self):
if self.backtester_proc is not None and self.backtester_proc.poll() != 0:
self.backtester_proc.kill()
else:
QtWidgets.QMessageBox.critical(self, '알림', '현재 백테스터는 농땡이 중입니다.\n')
def ButtonClicked_29(self):
con = sqlite3.connect(DB_STOCK_STRETEGY)
df = pd.read_sql('SELECT * FROM sell', con).set_index('index')
con.close()
if len(df) > 0:
self.sss_comboBox.clear()
for index in df.index:
self.sss_comboBox.addItem(index)
windowQ.put([ui_num['S전략텍스트'], '매도전략 불러오기 완료'])
self.sss_pushButton_04.setStyleSheet(style_bc_st)
else:
windowQ.put([ui_num['S전략텍스트'], '매도전략 없음'])
def ButtonClicked_30(self):
strategy_name = self.sss_lineEdit.text()
strategy = self.ss_textEdit_03.toPlainText()
if strategy_name == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '매도전략의 이름이 공백 상태입니다.\n이름을 입력하십시오.\n')
elif strategy == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '매도전략의 코드가 공백 상태입니다.\n코드를 작성하십시오.\n')
else:
query1Q.put([3, f"DELETE FROM sell WHERE `index` = '{strategy_name}'"])
df = pd.DataFrame({'전략코드': [strategy]}, index=[strategy_name])
query1Q.put([3, df, 'sell', 'append'])
windowQ.put([ui_num['S전략텍스트'], '매도전략 저장하기 완료'])
self.sss_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_31(self):
self.ss_textEdit_03.clear()
self.ss_textEdit_03.append(stock_sell_var)
windowQ.put([ui_num['S전략텍스트'], '매도전략 불러오기 완료'])
self.sss_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_32(self):
strategy = self.ss_textEdit_03.toPlainText()
if strategy == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '매도전략의 코드가 공백 상태입니다.\n')
else:
query1Q.put([3, "DELETE FROM sell WHERE `index` = '현재전략'"])
df = pd.DataFrame({'전략코드': [strategy]}, index=['현재전략'])
query1Q.put([3, df, 'sell', 'append'])
sstgQ.put(['매도전략', strategy])
windowQ.put([ui_num['S전략텍스트'], '매도전략 시작하기 완료'])
self.sss_pushButton_04.setStyleSheet(style_bc_dk)
self.sss_pushButton_12.setStyleSheet(style_bc_st)
def ButtonClicked_33(self):
self.ss_textEdit_03.append(stock_sell1)
windowQ.put([ui_num['S전략텍스트'], '매도전략 모듈추가 완료'])
def ButtonClicked_34(self):
self.ss_textEdit_03.append(stock_sell2)
windowQ.put([ui_num['S전략텍스트'], '매도전략 모듈추가 완료'])
def ButtonClicked_35(self):
self.ss_textEdit_03.append(stock_sell3)
windowQ.put([ui_num['S전략텍스트'], '매도전략 모듈추가 완료'])
def ButtonClicked_36(self):
self.ss_textEdit_03.append(stock_sell4)
windowQ.put([ui_num['S전략텍스트'], '매도전략 모듈추가 완료'])
def ButtonClicked_37(self):
self.ss_textEdit_03.append(stock_sell5)
windowQ.put([ui_num['S전략텍스트'], '매도전략 모듈추가 완료'])
def ButtonClicked_38(self):
self.ss_textEdit_03.append(stock_sell6)
windowQ.put([ui_num['S전략텍스트'], '매도전략 모듈추가 완료'])
def ButtonClicked_39(self):
self.ss_textEdit_03.append(stock_sell_signal)
windowQ.put([ui_num['S전략텍스트'], '매도전략 모듈추가 완료'])
# noinspection PyMethodMayBeStatic
def ButtonClicked_40(self):
sstgQ.put(['매도전략중지', ''])
self.sss_pushButton_12.setStyleSheet(style_bc_dk)
self.sss_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_41(self):
con = sqlite3.connect(DB_COIN_STRETEGY)
df = pd.read_sql('SELECT * FROM init', con).set_index('index')
con.close()
if len(df) > 0:
self.csi_comboBox.clear()
for index in df.index:
self.csi_comboBox.addItem(index)
windowQ.put([ui_num['C전략텍스트'], '시작전략 불러오기 완료'])
self.csi_pushButton_04.setStyleSheet(style_bc_st)
else:
windowQ.put([ui_num['C전략텍스트'], '시작전략 없음'])
def ButtonClicked_42(self):
strategy_name = self.csi_lineEdit.text()
strategy = self.cs_textEdit_01.toPlainText()
if strategy_name == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '시작전략의 이름이 공백 상태입니다.\n이름을 입력하십시오.\n')
elif strategy == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '시작전략의 코드가 공백 상태입니다.\n코드를 작성하십시오.\n')
else:
query1Q.put([4, f"DELETE FROM init WHERE `index` = '{strategy_name}'"])
df = pd.DataFrame({'전략코드': [strategy]}, index=[strategy_name])
query1Q.put([4, df, 'init', 'append'])
windowQ.put([ui_num['C전략텍스트'], '시작전략 저장하기 완료'])
self.csi_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_43(self):
self.cs_textEdit_01.clear()
self.cs_textEdit_01.append(init_var)
windowQ.put([ui_num['C전략텍스트'], '시작변수 불러오기 완료'])
self.csi_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_44(self):
strategy = self.cs_textEdit_01.toPlainText()
if strategy == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '시작전략의 코드가 공백 상태입니다.\n')
else:
query1Q.put([4, "DELETE FROM init WHERE `index` = '현재전략'"])
df = pd.DataFrame({'전략코드': [strategy]}, index=['현재전략'])
query1Q.put([4, df, 'init', 'append'])
cstgQ.put(['시작전략', strategy])
windowQ.put([ui_num['C전략텍스트'], '시작전략 설정하기 완료'])
QtWidgets.QMessageBox.warning(self, '적용 알림', '시작전략은 프로그램을 재시작해야 적용됩니다.\n')
self.csi_pushButton_04.setStyleSheet(style_bc_dk)
def ButtonClicked_45(self):
con = sqlite3.connect(DB_COIN_STRETEGY)
df = pd.read_sql('SELECT * FROM buy', con).set_index('index')
con.close()
if len(df) > 0:
self.csb_comboBox.clear()
for index in df.index:
self.csb_comboBox.addItem(index)
windowQ.put([ui_num['C전략텍스트'], '매수전략 불러오기 완료'])
self.csb_pushButton_04.setStyleSheet(style_bc_st)
else:
windowQ.put([ui_num['C전략텍스트'], '매수전략 없음'])
def ButtonClicked_46(self):
strategy_name = self.csb_lineEdit.text()
strategy = self.cs_textEdit_02.toPlainText()
if strategy_name == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '매수전략의 이름이 공백 상태입니다.\n이름을 입력하십시오.\n')
elif strategy == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '매수전략의 코드가 공백 상태입니다.\n코드를 작성하십시오.\n')
else:
query1Q.put([4, f"DELETE FROM buy WHERE `index` = '{strategy_name}'"])
df = pd.DataFrame({'전략코드': [strategy]}, index=[strategy_name])
query1Q.put([4, df, 'buy', 'append'])
windowQ.put([ui_num['C전략텍스트'], '매수전략 저장하기 완료'])
self.csb_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_47(self):
self.cs_textEdit_02.clear()
self.cs_textEdit_02.append(coin_buy_var)
windowQ.put([ui_num['C전략텍스트'], '매수변수 불러오기 완료'])
self.csb_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_48(self):
strategy = self.cs_textEdit_02.toPlainText()
if strategy == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '매수전략의 코드가 공백 상태입니다.\n')
else:
query1Q.put([4, "DELETE FROM buy WHERE `index` = '현재전략'"])
df = pd.DataFrame({'전략코드': [strategy]}, index=['현재전략'])
query1Q.put([4, df, 'buy', 'append'])
cstgQ.put(['매수전략', strategy])
windowQ.put([ui_num['C전략텍스트'], '매수전략 시작하기 완료'])
self.csb_pushButton_04.setStyleSheet(style_bc_dk)
self.csb_pushButton_12.setStyleSheet(style_bc_st)
def ButtonClicked_49(self):
self.cs_textEdit_02.append(coin_buy1)
windowQ.put([ui_num['C전략텍스트'], '매수전략 모듈추가 완료'])
def ButtonClicked_50(self):
self.cs_textEdit_02.append(coin_buy2)
windowQ.put([ui_num['C전략텍스트'], '매수전략 모듈추가 완료'])
def ButtonClicked_51(self):
self.cs_textEdit_02.append(coin_buy3)
windowQ.put([ui_num['C전략텍스트'], '매수전략 모듈추가 완료'])
def ButtonClicked_52(self):
self.cs_textEdit_02.append(coin_buy4)
windowQ.put([ui_num['C전략텍스트'], '매수전략 모듈추가 완료'])
def ButtonClicked_53(self):
self.cs_textEdit_02.append(coin_buy5)
windowQ.put([ui_num['C전략텍스트'], '매수전략 모듈추가 완료'])
def ButtonClicked_54(self):
self.cs_textEdit_02.append(coin_buy6)
windowQ.put([ui_num['S전략텍스트'], '매수전략 모듈추가 완료'])
def ButtonClicked_55(self):
self.cs_textEdit_02.append(coin_buy_signal)
windowQ.put([ui_num['C전략텍스트'], '매수전략 모듈추가 완료'])
# noinspection PyMethodMayBeStatic
def ButtonClicked_56(self):
cstgQ.put(['매수전략중지', ''])
self.csb_pushButton_12.setStyleSheet(style_bc_dk)
self.csb_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_57(self):
if self.backtester_proc is not None and self.backtester_proc.poll() != 0:
QtWidgets.QMessageBox.critical(self, '오류 알림', '현재 백테스터가 실행중입니다.\n중복 실행할 수 없습니다.\n')
return
else:
testperiod = self.csb_lineEdit_01.text()
totaltime = self.csb_lineEdit_02.text()
avgtime = self.csb_lineEdit_03.text()
starttime = self.csb_lineEdit_04.text()
endtime = self.csb_lineEdit_05.text()
multi = self.csb_lineEdit_06.text()
buystg = self.csb_comboBox.currentText()
sellstg = self.css_comboBox.currentText()
if buystg == '' or sellstg == '' or testperiod == '' or totaltime == '' or avgtime == '' or \
starttime == '' or endtime == '' or multi == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '일부 설정값이 공백 상태입니다.\n')
return
self.backtester_proc = subprocess.Popen(
f'python {SYSTEM_PATH}/backtester/backtester_coin_stg.py '
f'{testperiod} {totaltime} {avgtime} {starttime} {endtime} {multi} {buystg} {sellstg}'
)
def ButtonClicked_58(self):
if self.backtester_proc is None or self.backtester_proc.poll() == 0:
buttonReply = QtWidgets.QMessageBox.question(
self, '최적화 백테스터',
'backtester/backtester_coin_vc.py 파일을\n본인의 전략에 맞게 수정 후 사용해야합니다.\n계속하시겠습니까?\n',
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No
)
if buttonReply == QtWidgets.QMessageBox.Yes:
self.backtester_proc = subprocess.Popen(f'python {SYSTEM_PATH}/backtester/backtester_coin_vc.py')
def ButtonClicked_84(self):
if self.backtester_proc is not None and self.backtester_proc.poll() != 0:
self.backtester_proc.kill()
else:
QtWidgets.QMessageBox.critical(self, '알림', '현재 백테스터는 농땡이 중입니다.\n')
def ButtonClicked_59(self):
con = sqlite3.connect(DB_COIN_STRETEGY)
df = pd.read_sql('SELECT * FROM sell', con).set_index('index')
con.close()
if len(df) > 0:
self.css_comboBox.clear()
for index in df.index:
self.css_comboBox.addItem(index)
windowQ.put([ui_num['C전략텍스트'], '매도전략 불러오기 완료'])
self.css_pushButton_04.setStyleSheet(style_bc_st)
else:
windowQ.put([ui_num['C전략텍스트'], '매도전략 없음'])
def ButtonClicked_60(self):
strategy_name = self.css_lineEdit.text()
strategy = self.cs_textEdit_03.toPlainText()
if strategy_name == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '매도전략의 이름이 공백 상태입니다.\n이름을 입력하십시오.\n')
elif strategy == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '매도전략의 코드가 공백 상태입니다.\n코드를 작성하십시오.\n')
else:
query1Q.put([4, f"DELETE FROM sell WHERE `index` = '{strategy_name}'"])
df = pd.DataFrame({'전략코드': [strategy]}, index=[strategy_name])
query1Q.put([4, df, 'sell', 'append'])
windowQ.put([ui_num['C전략텍스트'], '매도전략 저장하기 완료'])
self.css_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_61(self):
self.cs_textEdit_03.clear()
self.cs_textEdit_03.append(coin_sell_var)
windowQ.put([ui_num['C전략텍스트'], '매도변수 불러오기 완료'])
self.css_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_62(self):
strategy = self.cs_textEdit_03.toPlainText()
if strategy == '':
QtWidgets.QMessageBox.critical(self, '오류 알림', '매도전략의 코드가 공백 상태입니다.\n')
else:
query1Q.put([4, "DELETE FROM sell WHERE `index` = '현재전략'"])
df = pd.DataFrame({'전략코드': [strategy]}, index=['현재전략'])
query1Q.put([4, df, 'sell', 'append'])
cstgQ.put(['매도전략', strategy])
windowQ.put([ui_num['C전략텍스트'], '매도전략 시작하기 완료'])
self.css_pushButton_04.setStyleSheet(style_bc_dk)
self.css_pushButton_12.setStyleSheet(style_bc_st)
def ButtonClicked_63(self):
self.cs_textEdit_03.append(coin_sell1)
windowQ.put([ui_num['C전략텍스트'], '매도전략 모듈추가 완료'])
def ButtonClicked_64(self):
self.cs_textEdit_03.append(coin_sell2)
windowQ.put([ui_num['C전략텍스트'], '매도전략 모듈추가 완료'])
def ButtonClicked_65(self):
self.cs_textEdit_03.append(coin_sell3)
windowQ.put([ui_num['C전략텍스트'], '매도전략 모듈추가 완료'])
def ButtonClicked_66(self):
self.cs_textEdit_03.append(coin_sell4)
windowQ.put([ui_num['C전략텍스트'], '매도전략 모듈추가 완료'])
def ButtonClicked_67(self):
self.cs_textEdit_03.append(coin_sell5)
windowQ.put([ui_num['C전략텍스트'], '매도전략 모듈추가 완료'])
def ButtonClicked_68(self):
self.cs_textEdit_03.append(coin_sell6)
windowQ.put([ui_num['C전략텍스트'], '매도전략 모듈추가 완료'])
def ButtonClicked_69(self):
self.cs_textEdit_03.append(coin_sell_signal)
windowQ.put([ui_num['C전략텍스트'], '매도전략 모듈추가 완료'])
# noinspection PyMethodMayBeStatic
def ButtonClicked_70(self):
cstgQ.put(['매도전략중지', ''])
self.css_pushButton_12.setStyleSheet(style_bc_dk)
self.css_pushButton_04.setStyleSheet(style_bc_st)
def ButtonClicked_71(self):
con = sqlite3.connect(DB_SETTING)
df = pd.read_sql('SELECT * FROM main', con)
df = df.set_index('index')
con.close()
if len(df) > 0: