def updateDataList(self, argChartType, #[u'M',u'W',u'D',u'm',u'T'] argRequestType, #요청방식:기간요청(u'period'), # 갯수요청(u'count') argRequestArg, #요청방식이 기간요청일 경우, list argCorrPriceType, #수정 주가 여부 [0,1] argFieldList, argStockCode ): chartTypeResult = self.getChartType(argChartType) if chartTypeResult.result != u'ok': return cxReturnValue(None, u'invalid argChartType "%s"'%argChartType) chartType = ord(chartTypeResult.value) #if argChartType in self.chartType.values() : # chartType = ord(argChartType) #else : # return cxReturnValue(None, # u'invalid argChartType "%s"'%argChartType) if argRequestType == u'P' or \ argRequestType == u'p' or \ argRequestType == u'Period' or \ argRequestType == u'period' : requestType = ord(u'1') elif argRequestType == u'C' or \ argRequestType == u'c' or \ argRequestType == u'Count' or \ argRequestType == u'count' : requestType = ord(u'2') else : return cxReturnValue(None, u'invalid argRequestType "%s"'%argRequestType) if requestType == ord(u'1') : if isinstance(argRequestArg,list) == False : return cxReturnValue(None, u'invalid argRequestArg : not list') else : startTime = argRequestArg[0] endTime = argRequestArg[1] #print '(',startTime,'-',endTime,')' #print type(startTime),type(endTime) if requestType == ord(u'2') : if isinstance(argRequestArg,int) == False : return cxReturnValue(None, u'invalid argReqeustArg : not int') else : count = argRequestArg if argCorrPriceType in [0, 1] : corrPriceType = ord(unicode(argCorrPriceType)) else : return cxReturnValue(None, u'invalid argCorrPriceType "%d"'%argCorrPriceType) if argFieldList == [] or argFieldList == None : return cxReturnValue(None, u'invalid argFieldList') fieldList = self.getFieldList(argFieldList) if fieldList.result != u'ok' : return cxReturnValue(None, fieldList.value, fieldList.result) paramList = [] if requestType == ord(u'1') : #period paramList = [ [ 0, argStockCode ], [ 1, requestType ], [ 2, endTime ], [ 3, startTime ], [ 5 ] + fieldList.value, [ 6, chartType ], #[ 7, 1 ], # 주기 (default - 1) [ 8, ord('0') ], # 갭보정여부 ('0'-갭무보정,'1'-갭보정) [ 9, corrPriceType ], [10, ord(u'3') ], # 시간외 거래량 모두 제외 ] else : #requestType == ord('2') #count paramList = [ [ 0, argStockCode ], [ 1, requestType ], [ 4, count ], [ 5 ] + fieldList.value, [ 6, chartType ], #[ 7, 1 ], # 주기 (default - 1) [ 8, ord('0') ], # 갭보정여부 ('0'-갭무보정,'1'-갭보정) [ 9, corrPriceType ], [10, ord(u'3') ], # 시간외 거래량 모두 제외 ] #print paramList #print 'argChartType=',argChartType stockChart = self.cpClsDic['cxStockChart'] resultList = common.templateBlockRequest(stockChart, paramList) if resultList == None : return cxReturnValue(None, u'templateBlockRequest result is None') if len(resultList) == 0 : return cxReturnValue(None, u'templateBlockRequest result is []') return cxReturnValue(resultList, u'ok')
def makeLogData(self, stockCode, chartType ) : cpStockCode = self.cpClsDic['cxCpStockCode'] stockName = cpStockCode.CodeToName(stockCode) #print '"%s"'%(stockName) if stockName == u'' : print 'Can not find stock name for stock code "%s".'%(stockCode) return False path = 'log\\%s\\'%(chartType.lower()) fileName = u'%s%s_%s.log'%(path,stockCode,stockName) if checkFileExist(fileName) == True : return True try : ct = self.chartTypeDic[chartType] except KeyError : print 'ERROR: cxStockLogData.makeLogData : param chartType : "%s" is not valid.\n'%\ (chartType) return False fieldList = [ 0, # 날짜 1, # 시간 3, # 고가 4, # 저가 5, # 종가 8, # 거래량 9, # 거래대금 25, # 주식회전율 ] #if ct == 'T' or ct == 'm' : # fieldList += [1] # 시간 - hhmm paramList = [ [ 0, stockCode ], [ 1, ord(u'1') ], # 기간요청 [ 3, 19500101 ], [ 4, len(fieldList) ], [ 5 ] + fieldList, [ 6, ord(ct) ], # 차트종류 [ 9, ord(u'1') ], # 수정주가 [ 10, ord(u'3') ] # 시간외거래량 모두 제외 ] stockChart = getCybosPlusClassDic()[u'cxStockChart'] resultList = templateBlockRequest( stockChart, paramList ) if resultList == None : print 'templateBlockRequest("cxStockChart"): result is none.\n' return False if len(resultList) == 0 : print 'templateBlockRequest("cxStockChart") : result length is zero.\n' return False bFirst = 1 fieldNum = 0 storeList = [] dataNum = 0 for result in resultList : if getResultDibStatus(result) != 0 : break headerList = result[5] if len(headerList) == 0 : print 'header result is empty.' continue dataNum += headerList[0][3][2] print 'dataNum', dataNum, type(dataNum) if bFirst == 1 : fieldNum = headerList[0][1][2] fieldNameList = headerList[0][2][2] print 'fieldNum', fieldNum, type(fieldNum) print 'fieldNameList' for fieldName in fieldNameList : print fieldName, print storeList.insert(3,fieldNum) storeList.insert(4,fieldNameList) bFirst = 0 dataList = result[6] print 'len of dataList', len(dataList) if len(dataList) == 0 : print 'failed to make data list for %s'%(stockCode) self.failedList.append([stockCode,chartType]) return True #return False tmpList = [] for dataDic in dataList : tmpList = [] for fieldType in range( 0, fieldNum ) : key = stockChart.fieldNameDic[fieldNameList[fieldType]] tmpList.append( dataDic[key][2] ) storeList.append(tmpList) storeList.insert(0,dataNum) storeList.insert(1,storeList[len(storeList)-1][0]) storeList.insert(2,storeList[4][0]) print 'len of storeList',len(storeList) #print storeList """ [0] : dataNum [1] : start date [2] : end date [3] : fieldNum [4] : field Name List [5] ~ : data """ print fileName dataFile = cxFile(fileName) dataFile.write('%s\n'%(storeList[0])) dataFile.write('%s\n'%(storeList[1])) dataFile.write('%s\n'%(storeList[2])) dataFile.write('%s\n'%(storeList[3])) for fieldName in storeList[4] : dataFile.write('%s\t'%(fieldName)) dataFile.write('\n') tmpList = storeList[5:] tmpList.reverse() for itemList in tmpList : for item in itemList : dataFile.write('%s\t'%(item)) dataFile.write('\n') dataFile.close() del dataFile return True
def updateData(self, argStockCode, argChartType, argFileName = u'') : import common import os cpStockCode = self.cpClsDic['cxCpStockCode'] stockName = cpStockCode.CodeToName(argStockCode) if stockName == u'' : return E_FIND_STOCK_NAME chartType = self.getChartTypeParam(argChartType) if chartType == u'' : return E_FIND_CHART_TYPE if argFileName == u'' : path = u'log\\%s\\'%(chartType.lower()) if os.path.exists(path) == False : os.makedirs(path) fileName = u'%s%s_%s.log' %\ ( path, argStockCode, stockName ) else : fileName = argFileName if common.checkFileExist(fileName) == True : os.remove(fileName) #return W_FILE_EXIST fieldList = [ 0, # 날짜 1, # 시간 3, # 고가 4, # 저가 5, # 종가 8, # 거래량 9, # 거래대금 ] # refer to CybosPlus manual paramList = [ [ 0, argStockCode ], [ 1, ord(u'1') ], # 기간요청 [ 3, 19500101 ], # 1950.01.01 ~ # [ 3, 20121124 ], # 1950.01.01 ~ [ 4, len(fieldList) ], [5] + fieldList , # Field List [ 6, ord(chartType) ], # Chart Type [ 9, ord(u'1') ], # 수정주가 [ 10, ord(u'3') ], # 시간외 거래량 모두 제외 ] stockChart = self.cpClsDic[u'cxStockChart'] resultList = common.templateBlockRequest( stockChart, paramList ) if resultList == None : return E_BLOCKREQUEST_RESULT_NONE if len(resultList) == 0 : return E_BLOCKREQUEST_RESULT_BLANK #print common.dumpList(resultList) bFirstLoop = True dataNum = 0 fieldNameList = [] fileHeader = [] fileData = [] for result in resultList : #print common.getResultStringLandscape( result, # statusOption=1, # headerValue=1, # dataValue=1, # titleOption=1 ) dibStatus = common.getResultDibStatus(result) if dibStatus != 0 : return E_DIB_STATUS dataList = common.getResultDataList(result) for dataDic in dataList : tempList = [] for key in dataDic.keys() : tempList.append(dataDic[key][2]) if bFirstLoop == True : fieldNameList.append(dataDic[key][1]) fileData.append(tempList) bFirstLoop = False fileHeader.append(fieldNameList) #end of 'for result in resultList :' #print common.dumpList(fieldNameList) #print common.dumpList(fileData) """ [0] : field list [1] ~ : data """ from cxFile import cxFile dataLogFile = cxFile(fileName) fieldNameString = u'' for fieldName in fieldNameList : fieldNameString += fieldName + u' ' fieldNameString += u'\n' dataLogFile.write(fieldNameString) #print fieldNameString for i in range(len(fileData)-1,-1,-1): itemString = u'' itemList = fileData[i] for item in itemList : itemString += common.UNI(item) + u' ' itemString += u'\n' dataLogFile.write(itemString) #print itemString dataLogFile.close() return 0
def makeLogData(self, stockCode, chartType ) : cpStockCode = self.cpClsDic['cxCpStockCode'] stockName = cpStockCode.CodeToName(stockCode) #print '"%s"'%(stockName) if stockName == u'' : print 'Can not find stock name for stock code "%s".'%(stockCode) return False path = 'log\\%s\\'%(chartType.lower()) fileName = u'%s%s_%s.log'%(path,stockCode,stockName) if checkFileExist(fileName) == True : return True try : ct = self.chartTypeDic[chartType] except KeyError : print 'ERROR: cxEmulator.makeLogData : param chartType : "%s" is not valid.\n'%\ (chartType) return False fieldList = [ 0, # 날짜 1, # 시간 3, # 고가 4, # 저가 5, # 종가 8, # 거래량 9, # 거래대금 25, # 주식회전율 ] #if ct == 'T' or ct == 'm' : # fieldList += [1] # 시간 - hhmm paramList = [ [ 0, stockCode ], [ 1, ord(u'1') ], # 기간요청 [ 3, 19500101 ], [ 4, len(fieldList) ], [ 5 ] + fieldList, [ 6, ord(ct) ], # 차트종류 [ 9, ord(u'1') ], # 수정주가 [ 10, ord(u'3') ] # 시간외거래량 모두 제외 ] stockChart = getCybosPlusClassDic()[u'cxStockChart'] resultList = templateBlockRequest( stockChart, paramList ) if resultList == None : print 'templateBlockRequest("cxStockChart"): result is none.\n' return False if len(resultList) == 0 : print 'templateBlockRequest("cxStockChart") : result length is zero.\n' return False bFirst = 1 fieldNum = 0 storeList = [] dataNum = 0 for result in resultList : if getResultDibStatus(result) != 0 : break headerList = result[5] if len(headerList) == 0 : print 'header result is empty.' continue dataNum += headerList[0][3][2] print 'dataNum', dataNum, type(dataNum) if bFirst == 1 : fieldNum = headerList[0][1][2] fieldNameList = headerList[0][2][2] print 'fieldNum', fieldNum, type(fieldNum) print 'fieldNameList' for fieldName in fieldNameList : print fieldName, print storeList.insert(3,fieldNum) storeList.insert(4,fieldNameList) bFirst = 0 dataList = result[6] print 'len of dataList', len(dataList) if len(dataList) == 0 : print 'failed to make data list for %s'%(stockCode) self.failedList.append([stockCode,chartType]) return True #return False tmpList = [] for dataDic in dataList : tmpList = [] for fieldType in range( 0, fieldNum ) : key = stockChart.fieldNameDic[fieldNameList[fieldType]] tmpList.append( dataDic[key][2] ) storeList.append(tmpList) storeList.insert(0,dataNum) storeList.insert(1,storeList[len(storeList)-1][0]) storeList.insert(2,storeList[4][0]) print 'len of storeList',len(storeList) #print storeList """ [0] : dataNum [1] : start date [2] : end date [3] : fieldNum [4] : field Name List [5] ~ : data """ print fileName dataFile = cxFile(fileName) dataFile.write('%s\n'%(storeList[0])) dataFile.write('%s\n'%(storeList[1])) dataFile.write('%s\n'%(storeList[2])) dataFile.write('%s\n'%(storeList[3])) for fieldName in storeList[4] : dataFile.write('%s\t'%(fieldName)) dataFile.write('\n') tmpList = storeList[5:] tmpList.reverse() for itemList in tmpList : for item in itemList : dataFile.write('%s\t'%(item)) dataFile.write('\n') dataFile.close() del dataFile return True