def OnReceiveChejanData(self, sGubun, nItemCnt, sFidList): Logger.instance().log('OnReceiveChejanData ', sGubun, nItemCnt, sFidList) ''' 9203 주문번호 302 종목명 900 주문수량 901 주문가격 902 미체결수량 904 원주문번호 905 주문구분 908 주문/체결시간 909 체결번호 910 체결가 911 체결량 10 현재가, 체결가, 실시간종가 ''' order = self.GetChejanData(9203) name = self.GetChejanData(302) quantity = self.GetChejanData(900) price = self.GetChejanData(901) remainQuantity = self.GetChejanData(902) tradeQuantity = self.GetChejanData(910) tradePrice = self.GetChejanData(911) Logger.instance().log('OnReceiveChejanData ', order, name, quantity, price, remainQuantity, tradeQuantity, tradePrice)
def OnReceiveTrData(self, ScrNo, RQName, TrCode, RecordName, PrevNext, DataLength, ErrCode, Message, SplmMsg): # cnt = self.GetRepeatCnt(TrCode, RQName) if RQName == 'opt20001': currentValue = self.CommGetData(TrCode, "", RQName, 0, '현재가') fluctuations = self.CommGetData(TrCode, "", RQName, 0, '전일대비') if self.callback_requestKospi != None: self.callback_requestKospi(currentValue, fluctuations) # elif RQName == 'opw00013': # currentValue = self.CommGetData(TrCode, "", RQName, 0, '현금금액') # currentValue = format(int(currentValue), ',d') # if self.callback_requestCashBalance != None: # self.callback_requestCashBalance(currentValue) elif RQName == 'opt10001': code = self.CommGetData(TrCode, "", RQName, 0, '종목코드') name = self.CommGetData(TrCode, "", RQName, 0, '종목명') currentValue = self.CommGetData(TrCode, "", RQName, 0, '현재가') fluctuations = self.CommGetData(TrCode, "", RQName, 0, '등락률') diffbefore = self.CommGetData(TrCode, "", RQName, 0, '전일대비') self.callback_request_stock_info((code, name, currentValue, fluctuations, diffbefore)) elif RQName == 'opw00004': accountValue = {} accountValue['계좌명'] = self.CommGetData(TrCode, "", RQName, 0, '계좌명') accountValue['지점명'] = self.CommGetData(TrCode, "", RQName, 0, '지점명') accountValue['예수금'] = int(self.CommGetData(TrCode, "", RQName, 0, '예수금')) accountValue['유가잔고평가액'] = int(self.CommGetData(TrCode, "", RQName, 0, '유가잔고평가액')) accountValue['예탁자산평가액'] = int(self.CommGetData(TrCode, "", RQName, 0, '예탁자산평가액')) accountValue['총매입금액'] = int(self.CommGetData(TrCode, "", RQName, 0, '총매입금액')) accountValue['추정예탁자산'] = int(self.CommGetData(TrCode, "", RQName, 0, '추정예탁자산')) accountValue['매도담보대출금'] = int(self.CommGetData(TrCode, "", RQName, 0, '매도담보대출금')) accountValue['당일투자원금'] = int(self.CommGetData(TrCode, "", RQName, 0, '당일투자원금')) accountValue['당월투자원금'] = int(self.CommGetData(TrCode, "", RQName, 0, '당월투자원금')) accountValue['누적투자원금'] = int(self.CommGetData(TrCode, "", RQName, 0, '누적투자원금')) accountValue['당일투자손익'] = int(self.CommGetData(TrCode, "", RQName, 0, '당일투자손익')) accountValue['당월투자손익'] = int(self.CommGetData(TrCode, "", RQName, 0, '당월투자손익')) accountValue['누적투자손익'] = int(self.CommGetData(TrCode, "", RQName, 0, '누적투자손익')) x = 0 try: x = float(self.CommGetData(TrCode, "", RQName, 0, '당일손익률')) except ValueError: x = 0 accountValue['당일손익률'] = x try: x = float(self.CommGetData(TrCode, "", RQName, 0, '당월손익률')) except ValueError: x = 0 accountValue['당월손익률'] = x try: x = float(self.CommGetData(TrCode, "", RQName, 0, '누적손익률')) except ValueError: x = 0 accountValue['누적손익률'] = x Logger.instance().log(accountValue) cnt = self.GetRepeatCnt(TrCode, RQName) accountStocks = {} for i in range(cnt): name = self.CommGetData(TrCode, "", RQName, i, '종목명') value_rate = format(float(self.CommGetData(TrCode, "", RQName, i, '손익율')), '.2f') amount = format(int(self.CommGetData(TrCode, "", RQName, i, '보유수량')), ',d') value_cur = format(int(self.CommGetData(TrCode, "", RQName, i, '현재가')), ',d') value_avg = format(int(self.CommGetData(TrCode, "", RQName, i, '평균단가')), ',d') value_val = format(int(self.CommGetData(TrCode, "", RQName, i, '평가금액')), ',d') value_buy = format(int(self.CommGetData(TrCode, "", RQName, i, '매입금액')), ',d') accountStocks[name] = [value_rate, amount, value_cur, value_avg, value_val, value_buy] Logger.instance().log(name, ' 손익율', value_rate, ' 보유수량', amount, ' 현재가', value_cur, ' 평균단가', value_avg, ' 평가금액', value_val, ' 매입금액', value_buy) self.callback_requestCurrentAccountValue(accountValue, accountStocks)
def SendOrder(self, sRQName, sScreenNo, sAccNo, nOrderType, sCode, nQty, nPrice, sHogaGb, sOrgOrderNo): Logger.instance().log('SendOrder', sRQName, sScreenNo, sAccNo, nOrderType, sCode, nQty, nPrice, sHogaGb, sOrgOrderNo) ret = self.ocx.dynamicCall('SendOrder(QString, QString, QString, int, QString, int, int, QString, QString)', [sRQName, sScreenNo, sAccNo, nOrderType, sCode, nQty, nPrice, sHogaGb, sOrgOrderNo]) Logger.instance().log(self.convertErrorCode(ret))
def CommConnect(self, callbackConnect): self.callbackConnect = callbackConnect rt = self.ocx.dynamicCall('CommConnect()') Logger.instance().log('CommConnect', rt)
def OnReceiveTrCondition(self, sScrNo, strCodeList, strConditionName, nIndex, nNext): Logger.instance().log('OnReceiveTrCondition ', sScrNo, strCodeList, strConditionName, nIndex, nNext)
def OnReceiveConditionVer(self, lRet, sMsg): Logger.instance().log('OnReceiveConditionVer ', lRet, sMsg)
def OnReceiveCondition(self, strCode, strType, strConditionName, strConditionIndex): Logger.instance().log('OnReceiveCondition ', strCode, strType, strConditionName, strConditionIndex)
def OnReceiveMsg(self, sScrNo, sRQName, sTrCode, sMsg): Logger.instance().log('OnReceiveMsg ', sRQName, sTrCode, sMsg) pass
def OnReceiveRealData(self, sJongmokCode, sRealType, sRealData): Logger.instance().log('OnReceiveRealData ', sJongmokCode, sRealType, sRealData)
def on_table_have_stock_currentCellChagned(self, currentCol, b, previousCol, d): stockNameitem = self.table_have_stock.verticalHeaderItem(currentCol) self.on_list_all_stock_item_selection_changed(stockNameitem, None) Logger.instance().log("currentCol ", currentCol, 'previousCol ', previousCol, 'item ', stockNameitem.text()) pass
def setup_components(self): self.kiwoom = KiWoom(QAxWidget("KHOPENAPI.KHOpenAPICtrl.1")) Logger.instance().setCallback(self.onLogCollect)