Showing
20 changed files
with
291 additions
and
25 deletions
proj/__pycache__/ai_trader.cpython-38.pyc
0 → 100644
No preview for this file type
proj/__pycache__/collector.cpython-38.pyc
0 → 100644
No preview for this file type
proj/__pycache__/graph.cpython-38.pyc
0 → 100644
No preview for this file type
proj/__pycache__/trader.cpython-38.pyc
0 → 100644
No preview for this file type
| ... | @@ -59,7 +59,7 @@ def lstm_algorithm(dataset,ai_setting): | ... | @@ -59,7 +59,7 @@ def lstm_algorithm(dataset,ai_setting): |
| 59 | msg += f' {ratio:.2f}% ⯆ ' | 59 | msg += f' {ratio:.2f}% ⯆ ' |
| 60 | print(msg, end=' ') | 60 | print(msg, end=' ') |
| 61 | 61 | ||
| 62 | - return ai_setting['ratio_cut'] | 62 | + return ai_setting['ratio_cut']>=ratio |
| 63 | 63 | ||
| 64 | 64 | ||
| 65 | def create_training_engine(db_name): | 65 | def create_training_engine(db_name): |
| ... | @@ -78,7 +78,7 @@ def ai_filter(ai_filter_num,engine,until=datetime.datetime.today()): | ... | @@ -78,7 +78,7 @@ def ai_filter(ai_filter_num,engine,until=datetime.datetime.today()): |
| 78 | if ai_filter_num == 1: | 78 | if ai_filter_num == 1: |
| 79 | ai_setting = { | 79 | ai_setting = { |
| 80 | "n_steps": 100, # 시퀀스 데이터를 몇개씩 담을지 설정 | 80 | "n_steps": 100, # 시퀀스 데이터를 몇개씩 담을지 설정 |
| 81 | - "lookup_step": 30, # 단위 : 몇 일(분) 뒤의 종가를 예측 할 것 인지 | 81 | + "lookup_step": 1, # 단위 : 몇 일(분) 뒤의 종가를 예측 할 것 인지 |
| 82 | "test_size": 0.2, # train 범위 | 82 | "test_size": 0.2, # train 범위 |
| 83 | "n_layers": 4, # LSTM layer 개수 | 83 | "n_layers": 4, # LSTM layer 개수 |
| 84 | "units": 50, # LSTM neurons 개수 | 84 | "units": 50, # LSTM neurons 개수 |
| ... | @@ -87,7 +87,7 @@ def ai_filter(ai_filter_num,engine,until=datetime.datetime.today()): | ... | @@ -87,7 +87,7 @@ def ai_filter(ai_filter_num,engine,until=datetime.datetime.today()): |
| 87 | "optimizer": "adam", # optimizer : 최적화 알고리즘 선택 | 87 | "optimizer": "adam", # optimizer : 최적화 알고리즘 선택 |
| 88 | "batch_size": 64, # 각 학습 반복에 사용할 데이터 샘플 수 | 88 | "batch_size": 64, # 각 학습 반복에 사용할 데이터 샘플 수 |
| 89 | "epochs": 400, # 몇 번 테스트 할지 | 89 | "epochs": 400, # 몇 번 테스트 할지 |
| 90 | - "ratio_cut": 3, # 단위:(%) lookup_step 기간 뒤 ratio_cut(%) 만큼 증가 할 것이 예측 된다면 매수 | 90 | + "ratio_cut": 2, # 단위:(%) lookup_step 기간 뒤 ratio_cut(%) 만큼 증가 할 것이 예측 된다면 매수 |
| 91 | "table": "daily_craw", # 분석 시 daily_craw(일별데이터)를 이용 할지 min_craw(분별데이터)를 이용 할지 | 91 | "table": "daily_craw", # 분석 시 daily_craw(일별데이터)를 이용 할지 min_craw(분별데이터)를 이용 할지 |
| 92 | "is_used_predicted_close" : True # ratio(예상 상승률) 계산 시 예측 그래프의 close 값을 이용 할 경우 True, | 92 | "is_used_predicted_close" : True # ratio(예상 상승률) 계산 시 예측 그래프의 close 값을 이용 할 경우 True, |
| 93 | # 실제 close 값을 이용할 시 False | 93 | # 실제 close 값을 이용할 시 False |
| ... | @@ -109,6 +109,7 @@ def ai_filter(ai_filter_num,engine,until=datetime.datetime.today()): | ... | @@ -109,6 +109,7 @@ def ai_filter(ai_filter_num,engine,until=datetime.datetime.today()): |
| 109 | feature_columns = ["close", "volume", "open", "high", "low"] | 109 | feature_columns = ["close", "volume", "open", "high", "low"] |
| 110 | filtered_list = [] | 110 | filtered_list = [] |
| 111 | for code_name in buy_list: | 111 | for code_name in buy_list: |
| 112 | + code_name=code_name[0] | ||
| 112 | sql = """ | 113 | sql = """ |
| 113 | SELECT {} FROM `{}` | 114 | SELECT {} FROM `{}` |
| 114 | WHERE STR_TO_DATE(date, '%Y%m%d%H%i') <= '{}' | 115 | WHERE STR_TO_DATE(date, '%Y%m%d%H%i') <= '{}' | ... | ... |
| 1 | import pymysql | 1 | import pymysql |
| 2 | pymysql.install_as_MySQLdb() | 2 | pymysql.install_as_MySQLdb() |
| 3 | -import sys | ||
| 4 | 3 | ||
| 5 | from library.collector_api import * | 4 | from library.collector_api import * |
| 5 | +import library.cf | ||
| 6 | 6 | ||
| 7 | class Collector: | 7 | class Collector: |
| 8 | - def __init__(self): | 8 | + def __init__(self,num=1): |
| 9 | + self.set_simul_num(num) | ||
| 9 | self.collector_api=collector_api() | 10 | self.collector_api=collector_api() |
| 10 | 11 | ||
| 11 | def collecting(self): | 12 | def collecting(self): |
| 12 | self.collector_api.code_update_check() | 13 | self.collector_api.code_update_check() |
| 13 | 14 | ||
| 15 | + def set_simul_num(self,num): | ||
| 16 | + library.cf.test_num=num | ||
| 17 | + | ||
| 18 | + def set_real_num(self,num=1): | ||
| 19 | + library.cf.real_num=num | ||
| 20 | + | ||
| 14 | if __name__=="__main__": | 21 | if __name__=="__main__": |
| 15 | app=QApplication(sys.argv) | 22 | app=QApplication(sys.argv) |
| 16 | c=Collector() | 23 | c=Collector() | ... | ... |
proj/graph.py
0 → 100644
| 1 | +import sys | ||
| 2 | +from PyQt5.QtWidgets import * | ||
| 3 | +import numpy as np | ||
| 4 | +import matplotlib.pyplot as plt | ||
| 5 | +from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas | ||
| 6 | + | ||
| 7 | +from sqlalchemy import create_engine | ||
| 8 | +from library.cf import * | ||
| 9 | + | ||
| 10 | +class Graph(QDialog): | ||
| 11 | + def __init__(self,num=1): | ||
| 12 | + QDialog.__init__(self,None) | ||
| 13 | + self.setGeometry(200,200,1000,800) | ||
| 14 | + | ||
| 15 | + self.engine1 = create_engine("mysql+pymysql://" + db_id + ":" + db_pw + "@" + | ||
| 16 | + db_ip + ":" + db_port + "/simul1", encoding='utf-8') | ||
| 17 | + self.engine2 = create_engine("mysql+pymysql://" + db_id + ":" + db_pw + "@" + | ||
| 18 | + db_ip + ":" + db_port + "/simul2", encoding='utf-8') | ||
| 19 | + self.engine3 = create_engine("mysql+pymysql://" + db_id + ":" + db_pw + "@" + | ||
| 20 | + db_ip + ":" + db_port + "/simul3", encoding='utf-8') | ||
| 21 | + self.engine4 = create_engine("mysql+pymysql://" + db_id + ":" + db_pw + "@" + | ||
| 22 | + db_ip + ":" + db_port + "/simul4", encoding='utf-8') | ||
| 23 | + | ||
| 24 | + date,data=self.getAlgorithm(num) | ||
| 25 | + | ||
| 26 | + col="" | ||
| 27 | + if num==1: | ||
| 28 | + col="red" | ||
| 29 | + elif num==2: | ||
| 30 | + col="blue" | ||
| 31 | + elif num==3: | ||
| 32 | + col="green" | ||
| 33 | + elif num==4: | ||
| 34 | + col="purple" | ||
| 35 | + | ||
| 36 | + N = len(data) | ||
| 37 | + value = data | ||
| 38 | + ind = np.arange(N) | ||
| 39 | + width = 0.35 | ||
| 40 | + | ||
| 41 | + self.fig = plt.Figure() | ||
| 42 | + ax = self.fig.add_subplot(111) | ||
| 43 | + ax.bar(ind, value, width,color=col) | ||
| 44 | + ax.set_xticks(ind + width / 20) | ||
| 45 | + ax.set_xticklabels(date) | ||
| 46 | + | ||
| 47 | + canvas = FigureCanvas(self.fig) | ||
| 48 | + canvas.draw() | ||
| 49 | + | ||
| 50 | + lay=QVBoxLayout() | ||
| 51 | + self.setLayout(lay) | ||
| 52 | + lay.addWidget(canvas) | ||
| 53 | + canvas.show() | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + def getdata(self,engine): | ||
| 57 | + query="select date, sum_valuation_profit from jango_data order by date" | ||
| 58 | + result=engine.execute(query).fetchall() | ||
| 59 | + date=list() | ||
| 60 | + data=list() | ||
| 61 | + for i in range(len(result)): | ||
| 62 | + date.append(result[i][0]) | ||
| 63 | + data.append(int(result[i][1])) | ||
| 64 | + return date,data | ||
| 65 | + | ||
| 66 | + def getAlgorithm(self,num): | ||
| 67 | + if num==1: | ||
| 68 | + engine=self.engine1 | ||
| 69 | + elif num==2: | ||
| 70 | + engine=self.engine2 | ||
| 71 | + elif num==3: | ||
| 72 | + engine=self.engine3 | ||
| 73 | + elif num==4: | ||
| 74 | + engine=self.engine4 | ||
| 75 | + else: | ||
| 76 | + sys.exit() | ||
| 77 | + date,data=self.getdata(engine) | ||
| 78 | + return date,data | ||
| 79 | + | ||
| 80 | +if __name__=="__main__": | ||
| 81 | + app=QApplication(sys.argv) | ||
| 82 | + main_dialog=Graph() | ||
| 83 | + main_dialog.show() | ||
| 84 | + app.exec_() |
| ... | @@ -75,7 +75,7 @@ def load_data(df,n_steps=100,lookup_step=1,test_size=0.2,shuffle=True): | ... | @@ -75,7 +75,7 @@ def load_data(df,n_steps=100,lookup_step=1,test_size=0.2,shuffle=True): |
| 75 | 75 | ||
| 76 | last_sequence=list(sequences)+list(last_sequence) | 76 | last_sequence=list(sequences)+list(last_sequence) |
| 77 | last_sequence=np.array(pd.DataFrame(last_sequence).shift(-1).dropna()) | 77 | last_sequence=np.array(pd.DataFrame(last_sequence).shift(-1).dropna()) |
| 78 | - | 78 | + result['last_sequence']=last_sequence |
| 79 | X,y=[],[] | 79 | X,y=[],[] |
| 80 | 80 | ||
| 81 | for seq,target in sequence_data: | 81 | for seq,target in sequence_data: | ... | ... |
| ... | @@ -564,28 +564,101 @@ class simulator_api: | ... | @@ -564,28 +564,101 @@ class simulator_api: |
| 564 | 564 | ||
| 565 | # 다음날 매수 할 종목의 리스트를 선정하는 함수 | 565 | # 다음날 매수 할 종목의 리스트를 선정하는 함수 |
| 566 | def db_to_realtime_daily_buy_list(self,date_rows_today,date_rows_yesterday,i): | 566 | def db_to_realtime_daily_buy_list(self,date_rows_today,date_rows_yesterday,i): |
| 567 | - realtime_daily_buy_list=None # 다음날 매수할 종목 리스트를 저장하는 변수 | 567 | + realtime_daily_buy_list=list() # 다음날 매수할 종목 리스트를 저장하는 변수 |
| 568 | + if self.db_to_realtime_daily_buy_list_num in [5,6,7,8]: | ||
| 569 | + self.use_ai=True | ||
| 570 | + | ||
| 568 | # (5,20) 골든크로스 | 571 | # (5,20) 골든크로스 |
| 569 | - if self.db_to_realtime_daily_buy_list_num == 1: | 572 | + if self.db_to_realtime_daily_buy_list_num in [1,5]: |
| 570 | query=f"select * from `{date_rows_yesterday}` " \ | 573 | query=f"select * from `{date_rows_yesterday}` " \ |
| 571 | f"where yes_clo20>yes_clo5 and clo5>clo20 and close<'{self.invest_unit}' group by code" | 574 | f"where yes_clo20>yes_clo5 and clo5>clo20 and close<'{self.invest_unit}' group by code" |
| 572 | realtime_daily_buy_list=self.engine_daily_buy_list.execute(query).fetchall() | 575 | realtime_daily_buy_list=self.engine_daily_buy_list.execute(query).fetchall() |
| 573 | 576 | ||
| 574 | # (20,60) 골든크로스 | 577 | # (20,60) 골든크로스 |
| 575 | - elif self.db_to_realtime_daily_buy_list_num == 2: | 578 | + elif self.db_to_realtime_daily_buy_list_num in [2,6]: |
| 576 | query = f"select * from `{date_rows_yesterday}` " \ | 579 | query = f"select * from `{date_rows_yesterday}` " \ |
| 577 | - f"where yes_clo40 > yes_clo5 and clo5 > clo40 and close < '{self.invest_unit}' group by code" | 580 | + f"where yes_clo60 > yes_clo20 and clo20 > clo60 and close < '{self.invest_unit}' group by code" |
| 578 | realtime_daily_buy_list = self.engine_daily_buy_list.execute(query).fetchall() | 581 | realtime_daily_buy_list = self.engine_daily_buy_list.execute(query).fetchall() |
| 579 | - """ | 582 | + |
| 580 | # RSI | 583 | # RSI |
| 581 | - elif self.db_to_realtime_daily_buy_list_num==3: | 584 | + elif self.db_to_realtime_daily_buy_list_num in [3,7]: |
| 582 | - au_query=f"select " | 585 | + realtime_daily_buy_list=list() |
| 586 | + self.sell_list=list() | ||
| 587 | + | ||
| 588 | + date_form=datetime.datetime.strptime(date_rows_yesterday,"%Y%m%d").date() | ||
| 589 | + weeks_ago=date_form-datetime.timedelta(14) | ||
| 590 | + weeks_ago=weeks_ago.strftime("%Y%m%d") | ||
| 591 | + query="SELECT table_name as tname FROM information_schema.tables " \ | ||
| 592 | + "WHERE table_schema ='daily_craw'" | ||
| 593 | + name_list=self.engine_daily_craw.execute(query).fetchall() | ||
| 594 | + for i in range(len(name_list)): | ||
| 595 | + name=name_list[i] | ||
| 596 | + name=name[0] | ||
| 597 | + au_query=f"select sum(d1_diff) from `{name}` where d1_diff>0 and " \ | ||
| 598 | + f"{weeks_ago}<=date and date<={date_rows_yesterday} " \ | ||
| 599 | + f"group by code" | ||
| 600 | + au=self.engine_daily_craw.execute(au_query).fetchall() | ||
| 601 | + ad_query=f"select sum(d1_diff) from `{name}` where d1_diff<0 and " \ | ||
| 602 | + f"{weeks_ago}<=date and date<={date_rows_yesterday} " \ | ||
| 603 | + f"group by code" | ||
| 604 | + ad=self.engine_daily_craw.execute(ad_query).fetchall() | ||
| 605 | + | ||
| 606 | + if len(au)==0 or len(ad)==0: | ||
| 607 | + continue | ||
| 608 | + | ||
| 609 | + au=au[0][0] | ||
| 610 | + ad=ad[0][0] | ||
| 611 | + | ||
| 612 | + au=float(au/14) | ||
| 613 | + ad=float(ad/14)*(-1) | ||
| 614 | + rsi=float(au/(au+ad)) | ||
| 615 | + | ||
| 616 | + if rsi<0.3: | ||
| 617 | + query=f"select * from `{date_rows_yesterday}` where code_name='{name}'" | ||
| 618 | + val=self.engine_daily_buy_list.execute(query).fetchall() | ||
| 619 | + realtime_daily_buy_list.append(val[0]) | ||
| 620 | + | ||
| 583 | # RMI | 621 | # RMI |
| 584 | - elif self.db_to_realtime_daily_buy_list_num==4: | 622 | + elif self.db_to_realtime_daily_buy_list_num in [4,8]: |
| 623 | + realtime_daily_buy_list = list() | ||
| 624 | + self.sell_list = list() | ||
| 625 | + | ||
| 626 | + date_form = datetime.datetime.strptime(date_rows_yesterday, "%Y%m%d").date() | ||
| 627 | + weeks_ago = date_form - datetime.timedelta(14) | ||
| 628 | + weeks_ago = weeks_ago.strftime("%Y%m%d") | ||
| 629 | + query = "SELECT table_name as tname FROM information_schema.tables " \ | ||
| 630 | + "WHERE table_schema ='daily_craw'" | ||
| 631 | + name_list = self.engine_daily_craw.execute(query).fetchall() | ||
| 632 | + for i in range(len(name_list)): | ||
| 633 | + name = name_list[i] | ||
| 634 | + name = name[0] | ||
| 635 | + mu_query = f"select sum(dn_diff) from `{name}` where dn_diff>0 and " \ | ||
| 636 | + f"{weeks_ago}<=date and date<={date_rows_yesterday} " \ | ||
| 637 | + f"group by code" | ||
| 638 | + mu = self.engine_daily_craw.execute(mu_query).fetchall() | ||
| 639 | + md_query = f"select sum(dn_diff) from `{name}` where dn_diff<0 and " \ | ||
| 640 | + f"{weeks_ago}<=date and date<={date_rows_yesterday} " \ | ||
| 641 | + f"group by code" | ||
| 642 | + md = self.engine_daily_craw.execute(md_query).fetchall() | ||
| 643 | + | ||
| 644 | + if len(mu) == 0 or len(md) == 0: | ||
| 645 | + continue | ||
| 646 | + | ||
| 647 | + mu = mu[0][0] | ||
| 648 | + md = md[0][0] | ||
| 649 | + | ||
| 650 | + mu = float(mu / 14) | ||
| 651 | + md = float(md / 14) * (-1) | ||
| 652 | + rmi = float(mu / (mu + md)) | ||
| 653 | + | ||
| 654 | + if rmi < 0.3: | ||
| 655 | + query = f"select * from `{date_rows_yesterday}` where code_name='{name}'" | ||
| 656 | + val = self.engine_daily_buy_list.execute(query).fetchall() | ||
| 657 | + realtime_daily_buy_list.append(val[0]) | ||
| 585 | 658 | ||
| 586 | else: | 659 | else: |
| 587 | logger.error("Invalid Algorithm Setting...") | 660 | logger.error("Invalid Algorithm Setting...") |
| 588 | - """ | 661 | + |
| 589 | # 알고리즘에 의해 선택된 항목이 존재한다면 데이터베이스에 해당 항목 업데이트 | 662 | # 알고리즘에 의해 선택된 항목이 존재한다면 데이터베이스에 해당 항목 업데이트 |
| 590 | if len(realtime_daily_buy_list) > 0: | 663 | if len(realtime_daily_buy_list) > 0: |
| 591 | df_realtime_daily_buy_list = DataFrame(realtime_daily_buy_list, | 664 | df_realtime_daily_buy_list = DataFrame(realtime_daily_buy_list, |
| ... | @@ -620,10 +693,10 @@ class simulator_api: | ... | @@ -620,10 +693,10 @@ class simulator_api: |
| 620 | 693 | ||
| 621 | # 딥러닝 알고리즘을 이용 | 694 | # 딥러닝 알고리즘을 이용 |
| 622 | if self.use_ai: | 695 | if self.use_ai: |
| 696 | + print(date_rows_today) | ||
| 623 | from ai_trader import ai_filter | 697 | from ai_trader import ai_filter |
| 624 | ai_filter(self.ai_num, engine=self.engine_simul, until=date_rows_yesterday) | 698 | ai_filter(self.ai_num, engine=self.engine_simul, until=date_rows_yesterday) |
| 625 | 699 | ||
| 626 | - | ||
| 627 | # 모의투자 / 실전투자 | 700 | # 모의투자 / 실전투자 |
| 628 | else: | 701 | else: |
| 629 | df_realtime_daily_buy_list['check_item'] = int(0) | 702 | df_realtime_daily_buy_list['check_item'] = int(0) |
| ... | @@ -851,6 +924,7 @@ class simulator_api: | ... | @@ -851,6 +924,7 @@ class simulator_api: |
| 851 | def auto_trade_sell_stock(self,date,i): | 924 | def auto_trade_sell_stock(self,date,i): |
| 852 | # 매도할 리스트를 저장 | 925 | # 매도할 리스트를 저장 |
| 853 | sell_list=self.get_sell_list(i) | 926 | sell_list=self.get_sell_list(i) |
| 927 | + print(sell_list) | ||
| 854 | 928 | ||
| 855 | for j in range(len(sell_list)): | 929 | for j in range(len(sell_list)): |
| 856 | sell_code=sell_list[j][0] | 930 | sell_code=sell_list[j][0] |
| ... | @@ -905,9 +979,16 @@ class simulator_api: | ... | @@ -905,9 +979,16 @@ class simulator_api: |
| 905 | sell_list=self.engine_simul.execute(query).fetchall() | 979 | sell_list=self.engine_simul.execute(query).fetchall() |
| 906 | 980 | ||
| 907 | # RSI | 981 | # RSI |
| 908 | - #elif self.sell_algorithm==3: | 982 | + elif self.sell_list_num==3: |
| 983 | + query=f"select code,rate,present_price,valuation_price from all_stocks " \ | ||
| 984 | + f"where sell_date='0' and (clo5<clo20 or rate<='{self.losscut_point}') group by code" | ||
| 985 | + sell_list=self.engine_simul.execute(query).fetchall() | ||
| 986 | + | ||
| 909 | # RMI | 987 | # RMI |
| 910 | - #elif self.sell_algorithm==4: | 988 | + elif self.sell_list_num==4: |
| 989 | + query=f"select code,rate, present_price,valuation_price from all_stocks " \ | ||
| 990 | + f"where sell_date='0' and (clo20<clo60 or rate<='{self.losscut_point}') group by code" | ||
| 991 | + sell_list=self.engine_simul.execute(query).fetchall() | ||
| 911 | 992 | ||
| 912 | else: | 993 | else: |
| 913 | logger.error("Invalid sell algorithm setting...") | 994 | logger.error("Invalid sell algorithm setting...") | ... | ... |
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
| ... | @@ -21,7 +21,7 @@ real_daily_craw_db_name = "daily_craw" | ... | @@ -21,7 +21,7 @@ real_daily_craw_db_name = "daily_craw" |
| 21 | real_daily_buy_list_db_name = "daily_buy_list" | 21 | real_daily_buy_list_db_name = "daily_buy_list" |
| 22 | 22 | ||
| 23 | # 시뮬레이션을 돌리기 시작할 날짜 | 23 | # 시뮬레이션을 돌리기 시작할 날짜 |
| 24 | -start_daily_buy_list='20190102' | 24 | +start_daily_buy_list='20150101' |
| 25 | 25 | ||
| 26 | # api를 최대 몇 번까지 호출 하고 봇을 끌지 설정 하는 옵션 | 26 | # api를 최대 몇 번까지 호출 하고 봇을 끌지 설정 하는 옵션 |
| 27 | max_api_call=998 | 27 | max_api_call=998 | ... | ... |
| ... | @@ -293,7 +293,7 @@ class collector_api(): | ... | @@ -293,7 +293,7 @@ class collector_api(): |
| 293 | 293 | ||
| 294 | # 특정 종목명(code_name)의 테이블이 존재하는 경우 | 294 | # 특정 종목명(code_name)의 테이블이 존재하는 경우 |
| 295 | if self.engine_bot.dialect.has_table(self.open_api.engine_daily_craw, code_name): | 295 | if self.engine_bot.dialect.has_table(self.open_api.engine_daily_craw, code_name): |
| 296 | - query=f"select * from {code_name} where date='{oldest_row['date']}' limit 1" | 296 | + query=f"select * from `{code_name}` where date='{oldest_row['date']}' limit 1" |
| 297 | check_row = self.open_api.engine_daily_craw.execute(query).fetchall() | 297 | check_row = self.open_api.engine_daily_craw.execute(query).fetchall() |
| 298 | # 종목명 테이블이 존재하지 않는 경우, 종목 리스트(stock_item_all) 테이블에 check_daily_crawler=4 업데이트 | 298 | # 종목명 테이블이 존재하지 않는 경우, 종목 리스트(stock_item_all) 테이블에 check_daily_crawler=4 업데이트 |
| 299 | else: | 299 | else: | ... | ... |
| ... | @@ -282,7 +282,6 @@ class open_api(QAxWidget): | ... | @@ -282,7 +282,6 @@ class open_api(QAxWidget): |
| 282 | # 국내주식 잔고전달 | 282 | # 국내주식 잔고전달 |
| 283 | elif sGubun=="1": | 283 | elif sGubun=="1": |
| 284 | chegyul_fail_amount=self.get_chejan_data(902) | 284 | chegyul_fail_amount=self.get_chejan_data(902) |
| 285 | - logger.debug("미체결 수량 : "+chegyul_fail_amount) | ||
| 286 | 285 | ||
| 287 | else: | 286 | else: |
| 288 | logger.debug("Invlid _receive_chejan_data") | 287 | logger.debug("Invlid _receive_chejan_data") |
| ... | @@ -325,7 +324,7 @@ class open_api(QAxWidget): | ... | @@ -325,7 +324,7 @@ class open_api(QAxWidget): |
| 325 | def sell_chegyul_fail_check(self,code): | 324 | def sell_chegyul_fail_check(self,code): |
| 326 | query = f"UPDATE all_stocks SET chegyul_check='1' WHERE code='{code}' and sell_date = '0' " \ | 325 | query = f"UPDATE all_stocks SET chegyul_check='1' WHERE code='{code}' and sell_date = '0' " \ |
| 327 | f"ORDER BY buy_date desc LIMIT 1" | 326 | f"ORDER BY buy_date desc LIMIT 1" |
| 328 | - self.engine_JB.execute(query) | 327 | + self.engine_bot.execute(query) |
| 329 | 328 | ||
| 330 | # OnReceiveChejan()이벤트가 호출될때 체결정보나 잔고정보를 얻어오는 함수 | 329 | # OnReceiveChejan()이벤트가 호출될때 체결정보나 잔고정보를 얻어오는 함수 |
| 331 | # param : nFid - 실시간 타입에 포함된 FID | 330 | # param : nFid - 실시간 타입에 포함된 FID |
| ... | @@ -767,7 +766,7 @@ class open_api(QAxWidget): | ... | @@ -767,7 +766,7 @@ class open_api(QAxWidget): |
| 767 | # daily_craw의 특정 종목 테이블에서 마지막으로 저장된 날짜를 가져오는 함수 | 766 | # daily_craw의 특정 종목 테이블에서 마지막으로 저장된 날짜를 가져오는 함수 |
| 768 | # 저장된 데이터가 없다면 '0'문자를 반환 | 767 | # 저장된 데이터가 없다면 '0'문자를 반환 |
| 769 | def get_daily_craw_db_last_date(self,code_name): | 768 | def get_daily_craw_db_last_date(self,code_name): |
| 770 | - query="select date from {} order by date desc limit 1" | 769 | + query="select date from `{}` order by date desc limit 1" |
| 771 | result=self.engine_daily_craw.execute(query.format(code_name)).fetchall() | 770 | result=self.engine_daily_craw.execute(query.format(code_name)).fetchall() |
| 772 | if len(result): | 771 | if len(result): |
| 773 | return result[0][0] | 772 | return result[0][0] |
| ... | @@ -895,7 +894,7 @@ class open_api(QAxWidget): | ... | @@ -895,7 +894,7 @@ class open_api(QAxWidget): |
| 895 | 894 | ||
| 896 | # min_craw 테이블에서 마지막에 저장한 행의 시간(분) 정보를 가져오는 함수 | 895 | # min_craw 테이블에서 마지막에 저장한 행의 시간(분) 정보를 가져오는 함수 |
| 897 | def get_craw_db_last_min(self,code_name): | 896 | def get_craw_db_last_min(self,code_name): |
| 898 | - query = f"SELECT date from {code_name} order by date desc limit 1" | 897 | + query = f"SELECT date from `{code_name}` order by date desc limit 1" |
| 899 | result = self.engine_craw.execute(query).fetchall() | 898 | result = self.engine_craw.execute(query).fetchall() |
| 900 | if len(result): | 899 | if len(result): |
| 901 | return result[0][0] | 900 | return result[0][0] | ... | ... |
| ... | @@ -14,7 +14,7 @@ class Trader(QMainWindow): | ... | @@ -14,7 +14,7 @@ class Trader(QMainWindow): |
| 14 | 14 | ||
| 15 | self.market_start_time=QTime(9,0,0) # 장시작 시간 | 15 | self.market_start_time=QTime(9,0,0) # 장시작 시간 |
| 16 | self.market_end_time=QTime(15,30,0) # 장마감 시간 | 16 | self.market_end_time=QTime(15,30,0) # 장마감 시간 |
| 17 | - self.buy_end_time=QTime(9,30,0) # 매수를 몇 시까지 할지 | 17 | + self.buy_end_time=QTime(15,31,0) # 매수를 몇 시까지 할지 |
| 18 | 18 | ||
| 19 | # 매수 함수 | 19 | # 매수 함수 |
| 20 | def auto_trade_stock(self): | 20 | def auto_trade_stock(self): | ... | ... |
proj/ui.py
0 → 100644
| 1 | +from collector import * | ||
| 2 | +from trader import * | ||
| 3 | +from graph import * | ||
| 4 | + | ||
| 5 | + | ||
| 6 | +class Ui(QWidget): | ||
| 7 | + def __init__(self): | ||
| 8 | + super().__init__() | ||
| 9 | + self.setWindowTitle("Menu Page") | ||
| 10 | + self.resize(820,465) | ||
| 11 | + | ||
| 12 | + self.using_dl=QLabel("----------* Deep Learning *------------",self) | ||
| 13 | + self.using_dl.setGeometry(QRect(50,20,800,30)) | ||
| 14 | + self.using_dl=QRadioButton("Using Deep Learning",self) | ||
| 15 | + self.using_dl.clicked.connect(self.__Rdl_Clicked) | ||
| 16 | + self.using_dl.setGeometry(QRect(50,70,800,30)) | ||
| 17 | + self.not_using_dl=QRadioButton("Not Using Deep Learning",self) | ||
| 18 | + self.not_using_dl.setGeometry(QRect(50,120,800,30)) | ||
| 19 | + self.not_using_dl.clicked.connect(self.__Rndl_Clicked) | ||
| 20 | + | ||
| 21 | + self.line=QLabel("----------* Algorithm *------------",self) | ||
| 22 | + self.line.setGeometry(QRect(50,170,800,30)) | ||
| 23 | + self.input=QLabel("Selection : ",self) | ||
| 24 | + self.input.setGeometry(QRect(50,200,150,40)) | ||
| 25 | + self.al=QLineEdit(self) | ||
| 26 | + self.al.setGeometry(QRect(200,200,150,40)) | ||
| 27 | + self.al1=QLabel("1. Golden/Dead Cross(5,20)",self) | ||
| 28 | + self.al1.setGeometry(QRect(50,250,800,30)) | ||
| 29 | + self.al2=QLabel("2. Golden/Dead Cross(20,60)",self) | ||
| 30 | + self.al2.setGeometry(QRect(50,300,800,30)) | ||
| 31 | + self.al3=QLabel("3. RSI",self) | ||
| 32 | + self.al3.setGeometry(QRect(50,350,800,30)) | ||
| 33 | + self.al4=QLabel("4. RMI",self) | ||
| 34 | + self.al4.setGeometry(QRect(50,400,800,30)) | ||
| 35 | + | ||
| 36 | + # 매매 프로그램 시작 | ||
| 37 | + self.btn_run=QPushButton("Trade",self) | ||
| 38 | + self.btn_run.setGeometry(QRect(600,50,200,70)) | ||
| 39 | + self.btn_run.clicked.connect(self.__bRun_Clicked) | ||
| 40 | + # 매매 후 결과 화면 | ||
| 41 | + self.btn_report=QPushButton("Report",self) | ||
| 42 | + self.btn_report.setGeometry(QRect(600,150,200,70)) | ||
| 43 | + self.btn_report.clicked.connect(self.__bReport_Clicked) | ||
| 44 | + # 컬렉터 | ||
| 45 | + self.btn_collector=QPushButton("Collector",self) | ||
| 46 | + self.btn_collector.setGeometry(QRect(600,250,200,70)) | ||
| 47 | + self.btn_collector.clicked.connect(self.__bCollector_Clicked) | ||
| 48 | + # 프로그램 종료 | ||
| 49 | + self.btn_exit=QPushButton("Exit",self) | ||
| 50 | + self.btn_exit.setGeometry(QRect(600,350,200,70)) | ||
| 51 | + self.btn_exit.clicked.connect(self.__bExit_Clicked) | ||
| 52 | + | ||
| 53 | + self.option=-1 | ||
| 54 | + | ||
| 55 | + def __Rdl_Clicked(self): | ||
| 56 | + if self.using_dl.isChecked(): | ||
| 57 | + self.option=0 | ||
| 58 | + | ||
| 59 | + def __Rndl_Clicked(self): | ||
| 60 | + if self.not_using_dl.isChecked(): | ||
| 61 | + self.option=4 | ||
| 62 | + | ||
| 63 | + # open selection page for rpa | ||
| 64 | + def __bRun_Clicked(self): | ||
| 65 | + trader = Trader() | ||
| 66 | + trader.run() | ||
| 67 | + | ||
| 68 | + def __bReport_Clicked(self): | ||
| 69 | + if self.al.text() not in ['1','2','3','4']: | ||
| 70 | + print("error") | ||
| 71 | + else: | ||
| 72 | + g=Graph(int(self.al.text())) | ||
| 73 | + g.exec() | ||
| 74 | + g.show() | ||
| 75 | + | ||
| 76 | + def __bCollector_Clicked(self): | ||
| 77 | + algorithm_num=0 | ||
| 78 | + if self.al.text()=="" or self.option==-1: | ||
| 79 | + print("error") | ||
| 80 | + else: | ||
| 81 | + algorithm_num=self.option+int(self.al.text()) | ||
| 82 | + | ||
| 83 | + c = Collector(algorithm_num) | ||
| 84 | + c.collecting() | ||
| 85 | + | ||
| 86 | + def __bExit_Clicked(self): | ||
| 87 | + self.close() | ||
| 88 | + sys.exit() | ||
| 89 | + | ||
| 90 | +if __name__=="__main__": | ||
| 91 | + app = QApplication(sys.argv) | ||
| 92 | + ui=Ui() | ||
| 93 | + ui.show() | ||
| 94 | + app.exec_() | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
No preview for this file type
-
Please register or login to post a comment