예제 #1
0
파일: pytrader.py 프로젝트: Heez27/AI_Edu
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.kiwoom = Kiwoom()  # Kiwoom 인스턴스 생성
        self.kiwoom.comm_connect()  # 로그인

        self.timer = QTimer(self)
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)

        self.timer2 = QTimer(self)
        self.timer2.start(1000 * 10)
        self.timer2.timeout.connect(self.timeout2)

        accouns_num = int(
            self.kiwoom.get_login_info("ACCOUNT_CNT"))  # 보유계좌 갯수 (ex. 2)
        accounts = self.kiwoom.get_login_info(
            "ACCNO")  # 구분자 ';'로 연결된 보유계좌 목록을 반환 (ex. 8165088111;8753740831;)

        accounts_list = accounts.split(';')[0:accouns_num]  # 계좌번호를 리스트로 저장
        self.comboBox.addItems(accounts_list)  # 계좌번호를 comboBox에 넣음

        self.lineEdit.textChanged.connect(self.code_changed)  # 종목코드 입력시
        self.pushButton.clicked.connect(self.send_order)  # [현금주문] 버튼 누를시
        self.pushButton_2.clicked.connect(self.check_balance)  # [조회] 버튼 누를시
예제 #2
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.trade_stocks_done = False

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        self.run()
        self.currentTime = datetime.datetime.now()

        self.timer = QTimer(self)
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)

        # Timer2 실시간 조회 체크박스 체크하면 10초에 한 번씩 데이터 자동 갱신
        self.timer2 = QTimer(self)
        self.timer2.start(1000 * 10)
        self.timer2.timeout.connect(self.timeout2)

        # 선정 종목 리스트
        self.load_buy_sell_list()

        accouns_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
        accounts = self.kiwoom.get_login_info("ACCNO")

        accounts_list = accounts.split(';')[0:accouns_num]
        self.comboBox.addItems(accounts_list)

        #self.pushButton_2.clicked.connect(self.check_balance)
        self.check_balance()
        self.save_final_stock()
예제 #3
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.kiwoom = Kiwoom()
        self.kiwoom.CommConnect()

        # Timer
        self.timer = QTimer(self)
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)

        # Timer2
        self.timer2 = QTimer(self)
        self.timer2.start(1000*10)
        self.timer2.timeout.connect(self.timeout2)

        # Get Account Number
        accouns_num = int(self.kiwoom.GetLoginInfo("ACCOUNT_CNT"))
        accounts = self.kiwoom.GetLoginInfo("ACCNO")
        accounts_list = accounts.split(';')[0:accouns_num]
        self.comboBox.addItems(accounts_list)

        self.lineEdit.textChanged.connect(self.code_changed)
        self.pushButton.clicked.connect(self.send_order)
        self.pushButton_2.clicked.connect(self.check_balance)

        self.conduct_buy_sell()
        self.load_buy_sell_list()
예제 #4
0
파일: Main.py 프로젝트: kwj2126/DLC_PROJECT
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.kiwoom = Kiwoom()
        self.kiwoom.log_in()

        code_list = self.kiwoom.get_code_list(0)  # 코스피
        code_list += self.kiwoom.get_code_list(10)  # 코스닥

        screen_no = 1000
        reg_cnt = 0
        for code in code_list:  # 호가정보 실시간 등록
            fid_list = ''
            for i in range(41, 81):
                if i != 41:
                    fid_list += ';'
                fid_list += str(i)

            reg_cnt += 1
            if reg_cnt == 100:
                reg_cnt = 0
                screen_no += 1

            self.kiwoom.set_real_reg(screen_no, code, fid_list, 1)
예제 #5
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        self.timer = QTimer(self)
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)

        self.lineEdit.textChanged.connect(self.code_changed)

        accouns_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
        accounts = self.kiwoom.get_login_info("ACCNO")

        accounts_list = accounts.split(';')[0:accouns_num]
        self.comboBox.addItems(accounts_list)

        self.pushButton.clicked.connect(self.send_order)
        self.pushButton_2.clicked.connect(self.check_balance)

        # Timer2
        self.timer2 = QTimer(self)
        self.timer2.start(1000 * 10)
        self.timer2.timeout.connect(self.timeout2)
예제 #6
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        self.trade_stocks_done = False

        self.timer = QTimer(self)
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)

        self.timer2 = QTimer(self)
        self.timer2.start(1000 * 10)  #10초에 한번임
        self.timer2.timeout.connect(self.timeout2)

        #계좌정보 관련련
        accouns_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
        accounts = self.kiwoom.get_login_info("ACCNO")

        accounts_list = accounts.split(';')[0:accouns_num]
        self.comboBox_Acc.addItems(accounts_list)

        #종목코드 입력하면 호출되는 슬롯
        self.lineEdit_Stock_Code.textChanged.connect(self.code_changed)
        #주문 버튼
        self.pushButton_order.clicked.connect(self.send_order)
        #조회버튼
        self.pushButton_look.clicked.connect(self.check_balance)

        # 선정 종목 정보 출력 메서드
        self.load_buy_sell_list()
예제 #7
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        # Timer1 - 1초에 한 번씩 이벤트가 발생한다.
        self.timer = QTimer(self)
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)

        # Account 정보 가져오기
        accounts_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
        accounts = self.kiwoom.get_login_info("ACCNO")
        accounts_list = accounts.split(';')[0:accounts_num]
        self.lineEdit.textChanged.connect(self.code_changed)
        self.comboBox.addItems(accounts_list)
        self.comboBox_2.addItems(['신규주문', '신규매도', '매수취소', '매도취소'])
        self.comboBox_3.addItems(['지정가', '시장가'])

        # Order
        self.pushButton.clicked.connect(self.send_order)

        # Balance
        self.pushButton_2.clicked.connect(self.check_balance)

        # Timer2 - 10초에 한 번씩 이벤트를 발생한다.
        self.timer2 = QTimer(self)
        self.timer2.start(1000 * 10)
        self.timer2.timeout.connect(self.timeout2)
예제 #8
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()  #키움 로그인

        self.trade_stocks_done = False  #자동 주문

        self.timer = QTimer(self)
        self.timer.start(1000)  #1초에 한 번씩 주기적으로 timeout 시그널이 발생
        self.timer.timeout.connect(
            self.timeout)  #timeout 시그널이 발생할 때 이를 처리할 슬롯으로 self.timeout을 설정
        #StatusBar 위젯에 서버 연결 상태 및 현재 시간을 출력

        self.lineEdit.textChanged.connect(
            self.code_changed)  #lineEdit 객체가 변경될 때 호출되는 슬롯을 지정
        self.pushButton.clicked.connect(self.send_order)  #현금주문

        accouns_num = int(self.kiwoom.get_login_info(
            "ACCOUNT_CNT"))  #계좌 정보를 QComboBox 위젯에 출력하는 코드
        accounts = self.kiwoom.get_login_info("ACCNO")  #로그인 정보 가져오기
        accounts_list = accounts.split(';')[
            0:accouns_num]  #계좌가 여러 개인 경우 각 계좌는';'를 통해 구분

        self.comboBox.addItems(accounts_list)

        self.pushButton_2.clicked.connect(
            self.check_balance)  #시그널과 슬롯을 연결하는 코드

        self.load_buy_sell_list()  #선정 종목 리스트 출력
예제 #9
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.trade_stocks_done = False
        self.bucket = list()
        self.item_list = list()
        self.code_list = list()

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        self.timer2 = QTimer(self)
        self.timer2.start(1000 * 10)
        self.timer2.timeout.connect(self.timeout2)

        accounts_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
        accounts = self.kiwoom.get_login_info("ACCNO")

        accounts_list = accounts.split(';')[0:accounts_num]
        self.comboBox.addItems(accounts_list)
        self.comboBox_2.addItems(accounts_list)

        self.codeLineEdit.textChanged.connect(self.code_changed)
        self.codeLineEdit_2.textChanged.connect(self.code_changed_2)
        self.viewButton.clicked.connect(self.check_balance)
        self.resetButton.clicked.connect(self.reset_bucket)
        self.addButton.clicked.connect(self.add_to_bucket)
        self.showButton.clicked.connect(self.show_bucket)
        self.downButton.clicked.connect(self.download_data)
        self.optButton.clicked.connect(self.optimize_weights)
        self.sendButton.clicked.connect(self.send_initial_order)
        self.spinBox.valueChanged.connect(self.asset_num)

        self.LogDisplay = LogDisplay(self)
예제 #10
0
    def __init__(self):
        super().__init__()
        #QtGui.QMainWindow.__init__(self,parent)
        #self.setupUi(self)

        # 키움 API 접속
        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        #키움 API 신호
        #self.kiwoom.OnEventConnect.connect(self._event_connect)
        #self.kiwoom.OnReceiveTrData.connect(self._receive_tr_data)

        # 타이틀 설정
        self.setWindowTitle("종목 코드")
        self.setGeometry(300, 300, 300, 180)

        #1초 타이머 설정
        self.timer1s = QTimer(self)
        self.timer1s.start(1000)
        self.timer1s.timeout.connect(self.timer1sec)

        # 400ms 타이머 설정
        self.timer10ms = QTimer(self)
        self.timer10ms.start(400)
        self.timer10ms.timeout.connect(self.getdatatimer)
        self.getdataflag = 0
        self.getdatacount = -1

        self.prvFilename = ""

        self.temp = 0

        self.setupUI()
예제 #11
0
 def dc_download(self):
     app = QApplication([''])
     self.k = Kiwoom()
     # should iterate over dates and code
     # may require to use multiprocessing
     dt1 = self.daecha_trading_record_mkt('20200901', '20200908')
     dt2 = self.daecha_trading_record_code('20200901', '20200908', '005930')
     print(dt1)
     print(dt2)
예제 #12
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        self.timer = QTimer(self)
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)
예제 #13
0
    def __init__(self):
        print("Ui_class입니다.")

        self.app = QApplication(sys.argv)

        self.Kiwoom = Kiwoom()

        ##사용자가 직접 종료시키지 않는한 계속 실행됨

        self.app.exec_()
예제 #14
0
 def bi_download_singlerun(self, codelist):
     app = QApplication([''])
     self.k = Kiwoom()
     for code in codelist:
         print(code)
         bi_buy = self.investor_history_singlecase(code, netbuysell='1')
         bi_sell = self.investor_history_singlecase(code, netbuysell='2')
         con = sqlite3.connect(BYINVESTOR_DB)
         bi_buy.to_sql(f'buy{code}', con, if_exists='replace', index = False)
         bi_sell.to_sql(f'sell{code}', con, if_exists='replace', index = False)
         con.close()
예제 #15
0
 def __init__(self):
     super().__init__()
     self.setupUi(self)
     self.kiwoom = Kiwoom()
     self.kiwoom.comm_connect()
     self.lineEdit.textChanged.connect(self.code_changed)
     accouns_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
     accounts = self.kiwoom.get_login_info("ACCNO")
     accounts_list = accounts.split(';')[0:accouns_num]
     self.comboBox.addItems(accounts_list)
     self.pushButton.clicked.connect(self.send_order)
예제 #16
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()
        self.timer = QTimer()
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)
        self.lineEdit.textChanged.connect(self.code_changed)

        accouns_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
        accounts = self.kiwoom.get_login_info("ACCNO")
예제 #17
0
    def __init__(self):
        super().__init__()

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        self.kiwoom.ohlcv = {
            'date': [],
            'open': [],
            'high': [],
            'low': [],
            'close': [],
            'volume': []
        }
        self.kiwoom.df_10001 = {
            'code': [],
            'name': [],
            'month': [],
            'face_value': [],
            'capital': []
        }
        self.kiwoom.df_10002 = {
            'code': [],
            'name': [],
            '매도거래원명1': [],
            '매도거래원1': [],
            '매도거래량1': [],
            '매수거래원명1': [],
            '매수거래원1': [],
            '매수거래량1': []
        }
        self.kiwoom.df_10003 = {'시간': [], '현재가': [], '누적거래량': []}
        self.kiwoom.df_10004 = {
            '총매도잔량': [],
            '총매수잔량': [],
            '시간외매도잔량': [],
            '시간외매수잔량': []
        }
        self.kiwoom.df_10005 = {
            '날짜': [],
            '시가': [],
            '고가': [],
            '저가': [],
            '종가': []
        }
        self.kiwoom.df_10006 = {
            '날짜': [],
            '시가': [],
            '고가': [],
            '저가': [],
            '종가': []
        }
        self.kiwoom.df_20006 = {'일자': [], '시가': [], '고가': [], '저가': []}
예제 #18
0
파일: pytrader.py 프로젝트: lemeap/Fintech
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        self.timer = QTimer(self)
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)
        self.lineEdit.textChanged.connect(self.code_changed)
        self.
예제 #19
0
파일: pytrader.py 프로젝트: anikwon/Kiwoom
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.trade_stocks_done = False

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        self.timer = QTimer(self)
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)

        self.lineEdit.textChanged.connect(self.code_changed)

        self.pushButton.clicked.connect(self.send_order)
        self.pushButton_2.clicked.connect(self.check_balance)

        # Timer2
        self.timer2 = QTimer(self)
        self.timer2.start(1000 * 10)
        self.timer2.timeout.connect(self.timeout2)

        self.load_buy_sell_list()
        row_count = len(buy_list) + len(sell_list)
        self.tableWidget_4.setRowCount(row_count)

        # buy list
        for j in range(len(buy_list)):
            row_data = buy_list[j]
            split_row_data = row_data.split(';')
            split_row_data[1] = self.kiwoom.get_master_code_name(
                split_row_data[1].rsplit())

            for i in range(len(split_row_data)):
                item = QTableWidgetItem(split_row_data[i].rstrip())
                item.setTextAlignment(Qt.AlignVCenter | Qt.AlignCenter)
                self.tableWidget_4.setItem(j, i, item)

        # sell list
        for j in range(len(sell_list)):
            row_data = sell_list[j]
            split_row_data = row_data.split(';')
            split_row_data[1] = self.kiwoom.get_master_code_name(
                split_row_data[1].rsplit())

            for i in range(len(split_row_data)):
                item = QTableWidgetItem(split_row_data[i].rstrip())
                item.setTextAlignment(Qt.AlignVCenter | Qt.AlignCenter)
                self.tableWidget_4.setItem(len(buy_list) + j, i, item)

        self.tableWidget_4.resizeRowsToContens()
        self.load_buy_sell_list()
예제 #20
0
 def __init__(self, simctrl_instance=None):
     self.ext_command_last_excution_time_ = datetime.now(
     )  # last execution set to __init__ time initiation
     if USE_SIMULATOR:
         self.km = Simulator(simctrl_instance)
     else:
         self.km = Kiwoom()
     if not self.km.connect_status:
         tl_print("System exits")
         sys.exit()
     self.bounds_table = bounds_prep()
     self.prev_mbf_exists = os.path.exists(MASTER_BOOK_FILE)
     self.trtrade_list = pd.DataFrame(
         columns=['code', 'amount', 'buy_sell', 'note'])
     self.master_book_initiator(START_CASH, replace=CREATE_NEW_MASTER_BOOK)
     if not USE_SIMULATOR:
         self.master_book_integrity_checker()
예제 #21
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        self.kiwoom.excelfile_initiator()
        self.kospi_codes = self.kiwoom.get_code_list_by_market(MARKET_KOSPI)
        self.kosdaq_codes = self.kiwoom.get_code_list_by_market(MARKET_KOSDAQ)
        self.candidate_codes = [
            '005930', '252670', '122630', '000660', '207940', '035420',
            '006400', '035720', '005380', '034730', '036570', '017670',
            '105560', '096770', '090430', '097950', '018260', '003550',
            '006800', '078930'
        ]

        # There can be limits in the number of timers
        self.timer = QTimer(self)
        self.timer.start(
            1000 * 10)  # Timer for time update: refresh at every 10*1000ms
        self.timer.timeout.connect(self.timeout)

        # self.timer_balance_check = QTimer(self)
        # self.timer_balance_check.start(1000*10)
        # self.timer_balance_check.timeout.connect(self.check_balance)

        self.timer_autotrade_run = QTimer(self)
        self.timer_autotrade_run.start(1000 * AUTOTRADE_INTERVAL)
        self.timer_autotrade_run.timeout.connect(self.timeout_autotrade_run)

        accouns_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
        accounts = self.kiwoom.get_login_info("ACCNO")
        accounts_list = accounts.split(';')[0:accouns_num]
        self.comboBox.addItems(accounts_list)

        self.lineEdit.textChanged.connect(self.code_changed)
        self.pushButton.clicked.connect(self.send_order_ui)
        self.pushButton_2.clicked.connect(self.check_balance)
        self.pushButton_3.clicked.connect(self.timeout_autotrade_run)

        self.check_balance()
예제 #22
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.kiwoom = Kiwoom()
        self.kiwoom.commConnect()

        # get user account ID/PW
        self.account = []
        with open("account.txt", 'r') as f:
            self.account = f.readlines()

        # get account info
        account_cnt = int(self.kiwoom.getLoginInfo("ACCOUNT_CNT"))
        account_no = self.kiwoom.getLoginInfo("ACCNO")
        account_list = account_no.split(';')[0:account_cnt]

        # timer in status bar
        self.timer_status_bar = QTimer(self)
        self.timer_status_bar.start(1000)
        self.timer_status_bar.timeout.connect(self.timeoutStatusBar)

        # timer in table widgets
        self.timer_table = QTimer(self)
        self.timer_table.start(10000)
        self.timer_table.timeout.connect(self.timeoutBalanceTable)

        # Window forms
        self.qtOrder_comboBox_account.addItems(account_list)
        self.qtOrder_lineEdit_item.textChanged.connect(self.itemCodeChanged)
        self.qtOrder_pushButton_sendOrder.clicked.connect(self.sendOrder)
        self.qtTrade_pushButton_check.clicked.connect(self.checkBalance)

        # execute methods
        # self.conductBuySell()     # 현재 '주문완료' 전 일 경우 shutdown 오류 발생
        self.loadBuySellList()
        self.saveDayData()

        # DB
        df = pd.DataFrame(self.kiwoom.ohlcv, self.kiwoom.ohlcv['date'],
                          ['open', 'high', 'low', 'close'])
        con = sqlite3.connect("stock.db")
        df.to_sql('039490', con, if_exists='replace')
예제 #23
0
    def __init__(self):

        super().__init__()
        self.setupUi(self)
        self.trade_stocks_done = False
        self.kiwoom = Kiwoom()

        ########계좌번호####################
        self.account = 5624118510
        #####################################

        ########변수####################
        # 공통
        self.check = None
        self.count = 0
        self.profit = 0
        self.amount = {}
        self.bid_price = {}
        self.ask_price = {}

        # algo_1
        self.spread_1 = []
        # algo_2
        self.spread_2 = []
        # algo_3
        self.spread_3 = []
        # algo_4
        self.spread_4 = []
        # algo_7
        self.short_spread_7 = []
        self.long_spread_7 = []
        #################################

        ########종목코드 실시간 등록##############
        code_two = '069500;102110'
        code_five = '005930;005935'
        code_six = '364690;365040'
        code_seven = '069500;102780'
        code_eight = '069500;364690'
        codes = code_eight  #code_two  + ';' + code_five + ';' +
        self.kiwoom.subscribe_stock_conclusion('2000', codes)
예제 #24
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.saveditem = Saveditem()

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        fname = "ongoing_list.txt"
        if not os.path.isfile(fname):
            f = open(fname, 'wt')
            f.close()

        # 선정 종목 리스트
        self.load_buy_sell_list()
        self.file_upload()

        self.timer = QTimer(self)
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)

        #실시간 현재가
        self.scrnum = 5000
        self.set_current()
        self.kiwoom.OnReceiveRealData.connect(self.kiwoom._receive_real_data)
        self.kiwoom.sig_cl.sig_.connect(self.stockgridview)

        accouns_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
        accounts = self.kiwoom.get_login_info("ACCNO")
        accounts_list = accounts.split(';')[0:accouns_num]

        self.comboBox.addItems(accounts_list)
        self.exe_save = 0
        self.pushButton.clicked.connect(self.save_ongoing)
        #self.check_chejan_balance()
        self.check_balance()

        # 주문 들어가는 부분
        self.timer3 = QTimer(self)
        self.timer3.start(1000 * 10)
        self.timer3.timeout.connect(self.timeout3)
예제 #25
0
파일: htrader.py 프로젝트: wnwjq462/HTrader
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.trade_stocks_done = False
        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        # Database 연결
        self.con = sqlite3.connect("HBase.db")
        self.cursor = self.con.cursor()

        #보유종목현황 / 선정 종목 버튼 리스트
        self.btn_list1 = []
        self.btn1_num = 0
        self.btn_list2 = []
        self.btn2_num = 0

        #현재 시간을 알려주기 위한 Timer
        self.timer = QTimer(self)
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)

        #실시간 잔고 및 보유종목 현황을 보여주기 위한 Timer
        self.timer2 = QTimer(self)
        self.timer.start(5000)
        self.timer.timeout.connect(self.timeout2)

        #종목코드 입력
        self.lineEdit.textChanged.connect(self.code_change)
        #계좌번호 출력
        accounts_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
        accounts = self.kiwoom.get_login_info("ACCNO")
        accounts_list = accounts.split(';')[0:accounts_num]
        self.comboBox.addItems(accounts_list)
        #주문버튼 / 잔고 조회 버튼
        self.pushButton.clicked.connect(self.send_order)
        self.pushButton_2.clicked.connect(self.check_balance)
        #선정 종목 정보 출력
        self.load_buy_sell_list()
예제 #26
0
    def __init__(self):
        super().__init__()
        # 한번에 한 종목에 들어갈 돈 세팅
        self.one_buy_money = 10000000

        self.setupUi(self)
        self.load_data_lock = False
        self.trade_stocks_done = False
        self.choose_buy_done = False
        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        self.timer = QTimer(self)
        self.timer.start(1000)
        self.timer.timeout.connect(self.timeout)

        self.lineEdit.textChanged.connect(self.code_changed)
        self.pushButton_2.clicked.connect(self.check_balance)

        self.load_buy_sell_list()

        # Timer2
        self.timer2 = QTimer(self)
        #3 sec로 세팅 ms단위
        self.timer2.start(1000 * 10)
        self.timer2.timeout.connect(self.timeout2)

        accouns_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
        accounts = self.kiwoom.get_login_info("ACCNO")
        accounts_list = accounts.split(';')[0:accouns_num]
        self.comboBox.addItems(accounts_list)

        self.pushButton.clicked.connect(self.send_order)
        # 처음에 조회
        self.check_balance()
        self.kiwoom.dynamicCall("GetConditionLoad()")
        self.kiwoom.tr_event_loop = QEventLoop()
        self.kiwoom.tr_event_loop.exec_()
예제 #27
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        # PyTrader 최초 실행 시 주문 여부 False
        self.trade_stocks_done = False
        # PyTrader 프로그램이 실행될 때 키움 로그인이 진행되도록 생성자에서 키움 객체를 생성한 후 comm_connect 메서드를 호출
        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        # 매수매도 종목 파일 읽기
        self.load_buy_sell_list()

        self.lineEdit.textChanged.connect(
            self.code_changed)  # lineEdit 객체에 종목코드를 입력

        accounts_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
        accounts = self.kiwoom.get_login_info("ACCNO")
        accounts_list = accounts.split(';')[0:accounts_num]
        self.comboBox.addItems(accounts_list)  # 계좌를 combobox에 출력
        self.pushButton.clicked.connect(
            self.send_order)  # 현금주문 클릭 시 send_order 실행
        self.pushButton_2.clicked.connect(
            self.check_balance)  # 보유종목 현황 클릭 check_balance 실행

        # Timer1
        self.timer = QTimer(self)
        self.timer.start(1000)  # 1초마다 주기적으로 timeout 시그널 발생
        self.timer.timeout.connect(
            self.timeout)  # timeout 시그널 처리할 슬롯으로 self.timeout 설정

        # Timer2
        # [실시간 조회] 체크박스를 체크하면 10초에 한 번씩 데이터가 자동으로 갱신
        # 다른 TR의 요청이 많은 경우에는 주의(TR 요청 초과 될수도 있으므로)
        self.timer2 = QTimer(self)
        self.timer2.start(1000 * 10)
        self.timer2.timeout.connect(self.timeout2)
예제 #28
0
    def info_download(self):
        app = QApplication([''])
        self.k = Kiwoom()
        if os.path.exists(INFO_DB): 
            print("infodb.db file exists")
            sys.exit()
        self.codelist = self.k.get_codelist_by_market(0).split(';')[:-1]
        self.codelist += self.k.get_codelist_by_market(10).split(';')[:-1]
        self.infodb = pd.DataFrame(columns = ['code', 'cprice', 'total_shares', 'trade_shares', 'fgn_weight', 'PER', 'EPS', 'ROE', 'PBR', 'EV', 'BPS', 'mktcap', 
                                              'sales', 'EBIT', 'netprofit', 'date', 'status', 'name', 'note']).astype({
                                            'code': 'object', 'cprice': 'int64', 'total_shares': 'int64', 'trade_shares': 'int64', 'fgn_weight': 'int64', 
                                            'PER': 'float64', 'EPS': 'int64', 'ROE': 'float64', 'PBR': 'float64', 'EV': 'float64', 'BPS': 'int64', 'mktcap': 'int64', 
                                            'sales': 'int64', 'EBIT': 'int64', 'netprofit': 'int64', 'date': 'object', 'status': 'object', 'name': 'object', 'note': 'object'})
        con = sqlite3.connect(INFO_DB)
        resume_location = 0 # that is the last number printed or INFO_DOWNLOAD_CHUNK * num saved 
        self.infodb.to_sql(INFO_DB_TABLE, con, if_exists = 'append', index = False) # adjust 'replace' as needed
        con.close()

        i = 0
        for code in self.codelist[resume_location:]:
            print('.', end="")
            i += 1
            info_code = self.k.get_basic_info(code)
            info_code['date'] = pd.Timestamp.now().strftime("%Y%m%d")
            self.infodb.loc[len(self.infodb)] = info_code
            if i % INFO_DOWNLOAD_CHUNK == 0:
                print(f' {i}')
                con = sqlite3.connect(INFO_DB)
                self.infodb.to_sql(INFO_DB_TABLE, con, if_exists = 'append', index = False)
                con.close()
                self.infodb.drop(self.infodb.index, inplace = True)
                time.sleep(WAIT_INTERVAL)

        con = sqlite3.connect(INFO_DB)
        self.infodb.to_sql(INFO_DB_TABLE, con, if_exists = 'append', index = False)
        con.close()
        self.infodb.drop(self.infodb.index, inplace = True)
예제 #29
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        self.timer = QTimer(self)
        self.timer.start(500)
        self.timer.timeout.connect(self.timeout)

        accouns_num = int(self.kiwoom.get_login_info("ACCOUNT_CNT"))
        accounts = self.kiwoom.get_login_info("ACCNO")

        accounts_list = accounts.split(';')[0:accouns_num]
        self.comboBox.addItems(accounts_list)

        self.lineEdit.textChanged.connect(self.code_changed)
        self.pushButton.clicked.connect(self.send_order)
        
        ## 조건검색식 관련 추가
        self.load_condition_list()
        self.checkBox_cond.setChecked(True)
        self.pushButton_cond.clicked.connect(self.start_cond)
예제 #30
0
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.token = ""

        self.kiwoom = Kiwoom()
        self.kiwoom.comm_connect()

        self.code = '093320'
        self.name = self.kiwoom.get_master_code_name(self.code)
        self.kiwoom.current = {}

        self.past_price = 0
        self.past_ratio = 0
        self.past_amount = 0

        # Timer1 - 1초에 한 번씩 이벤트가 발생한다.
        self.timer = QTimer(self)
        self.timer.start(1000 * 15)
        self.timer.timeout.connect(self.timeout_visualize)

        self.timer = QTimer(self)
        self.timer.start(1000 * 30)
        self.timer.timeout.connect(self.timeout_message)