더북(TheBook)

Kiwoom.py

def _on_receive_tr_data(self, screen_no, rqname, trcode, record_name, next, unused1, unused2, unused3, unused4):
    print("[Kiwoom] _on_receive_tr_data is called {} / {} / {}".format(screen_no, rqname, trcode))
    tr_data_cnt = self.dynamicCall("GetRepeatCnt(QString, QString)", trcode, rqname)

    if next == '2':
        self.has_next_tr_data = True
    else:
        self.has_next_tr_data = False

    if rqname == "opt10081_req":
        ohlcv = {'date': [], 'open': [], 'high': [], 'low': [], 'close': [], 'volume': []}

        for i in range(tr_data_cnt):
            date = self.dynamicCall("GetCommData(QString, QString, int, QString", trcode, rqname, i, "일자")
            open = self.dynamicCall("GetCommData(QString, QString, int, QString", trcode, rqname, i, "시가")
            high = self.dynamicCall("GetCommData(QString, QString, int, QString", trcode, rqname, i, "고가")
            low = self.dynamicCall("GetCommData(QString, QString, int, QString", trcode, rqname, i, "저가")
            close = self.dynamicCall("GetCommData(QString, QString, int, QString", trcode, rqname, i, "현재가")
            volume = self.dynamicCall("GetCommData(QString, QString, int, QString", trcode, rqname, i, "거래량")

            ohlcv['date'].append(date.strip())
            ohlcv['open'].append(int(open))
            ohlcv['high'].append(int(high))
            ohlcv['low'].append(int(low))
            ohlcv['close'].append(int(close))
            ohlcv['volume'].append(int(volume))
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.