Beispiel #1
0
def testStockMst_ver_3() :
    "전체 주식 정보를 얻어낸다."
    from cxStockMgr  import stockMgr
    from cxCybosPlus import gCybosPlusClassDic
    from cxCybosPlus import constants
    from common import testBlockRequest
    from cxFile import cxFile
    import time

    cpCybos = gCybosPlusClassDic['cxCpCybos']
    stockList = stockMgr.getStockList()
    index = 0

    for stockCode, stockName, stockFullCode in stockList :
        paramList = [ [ 0, stockCode],]
        print testBlockRequest('cxCpStockMst', paramList, 1, 1, 0, 0 )

        remainCount = cpCybos.GetLimitRemainCount(constants.LT_NONTRADE_REQUEST)
        remainTime = cpCybos.LimitRequestRemainTime()
        print index,'remainCount : %d, remainTime : %d'%(remainCount,remainTime)
        index+=1
        if remainCount <= 0 :
            print 'time.sleep for %d sec.'%((remainTime/1000)+1)
            time.sleep((remainTime/1000) + 1)

    del stockMgr
Beispiel #2
0
def getAllStockMst() :
    import time

    from cxCybosPlus import constants
    from cxCybosPlus import gCybosPlusClassDic
    from cxStockMgr  import stockMgr
    cpCybos = gCybosPlusClassDic['cxCpCybos']
    stockMst = gCybosPlusClassDic['cxCpStockMst']
    stockList = stockMgr.getStockList()

    sep = u'\t'
    newLine = u'\n'
    
    fileName = u'StockMst.des'
    if common.checkFileExist(fileName) == True :
        os.remove(fileName)
    stockMstFile = cxFile(fileName)
    strLine = u''
    
    for key in stockMst.headerIndexDic.keys() :
        strLine += stockMst.headerIndexDic[key][1] + sep 
    strLine += newLine
    print strLine
    stockMstFile.write(strLine)
   
    #stockList = [[u'A000660',u'SK하이닉스']]
    for stockItem in stockList :
        print stockItem[0]
        stockMst.SetInputValue(u'0',stockItem[0])
        stockMst.BlockRequest()
        result = stockMst.getResult()
        
        print 'getResult (',result[0],')'
        
        if result[0] != 0 :
            print stockItem[0], ': BlockRequest is failed (%d).'%(result[0])
            continue
        
        strLine = u''
        for key in stockMst.headerIndexDic.keys() :
            strLine += unicode(result[5][0][key][2]) + sep
        strLine += newLine
        print strLine
        stockMstFile.write(strLine)
        
        remainCount = cpCybos.GetLimitRemainCount(constants.LT_NONTRADE_REQUEST)
        remainTime = cpCybos.LimitRequestRemainTime()
        print remainCount, remainTime
        if remainCount <= 0 :
            time.sleep((remainTime/1000)+1)

    stockMstFile.close()
Beispiel #3
0
    def install(self) :
        import time
        from cxCybosPlus import constants
        cpCybos = self.cpClsDic['cxCpCybos']
        self.updateFailedStockList = []
        stockList = stockMgr.getStockList()

        updateFailedStockCodeListFileName = self.basePath + u'updateFailedStockCodeList.txt'
        updateFailedStockCodeListFile = cxFile(updateFailedStockCodeListFileName)

        for chartType in self.chartType.keys() :
        #{
            for code, name, fullcode in stockList :
            #{
                print chartType, code, name,
                resultList = self.update(chartType,code)

                if resultList.result != u'ok' :
                #{
                    failedString = common.UNI(code) + u' ' + \
                                   common.UNI(name) + u' ' + \
                                   common.UNI(chartType) + u' ' + \
                                   common.UNI(resultList.result) + u'\n'
                    print failedString
                    updateFailedStockCodeListFile.write(failedString)
                    self.updateFailedStockList.append([ chartType, code, name ])
                #}

                remainCount = cpCybos.GetLimitRemainCount(constants.LT_NONTRADE_REQUEST)
                remainTime = cpCybos.LimitRequestRemainTime()
                print '\tremainCount : %d, remainTime : %d'%(remainCount, remainTime)

                if remainCount <= 0 :
                #{
                    print '\ttime.sleep for %d msec. [%d sec.]'%(remainTime, (remainTime/1000)+1 )
                    time.sleep((remainTime/1000) + 1)
                #}
            #}
        #}

        updateFailedStockCodeListFile.close()
        
        if len(self.updateFailedStockList) > 0 :
        #{
            print 'update failed stock list'
            for chartType, code, name in self.updateFailedStockList :
                print chartType, code, name
        #} 
        
        return True
Beispiel #4
0
def testCalculateStochaostic() :
    from cxFile import cxFile
    dataPath = u'database\\day\\'
    data1FileName = u'A005930.data' #u'A000660.data' #u'A000020.data'
    data2FileName = u'A000660.data' #u'A005930.data' #u'A000060.data'
    #print dataPath + data1FileName
    #print 'what\'s happened'
    data1File = cxFile(dataPath + data1FileName)
    data2File = cxFile(dataPath + data2FileName)
    data1Lines = data1File.readlines()
    data2Lines = data2File.readlines()

    print len(data1Lines), len(data2Lines)
    #print data1Lines[1]
    #print data2Lines[1]

    #print data1Lines[0]
    
    srcDic = {}
    cmpDic = {}

    for i in range(1, len(data1Lines)) :
        data1FieldDataList = getFieldDataList(data1Lines[i])
        srcDic[data1FieldDataList[0]] = i

    for i in range(1, len(data2Lines)) :
        data2FieldDataList = getFieldDataList(data2Lines[i])
        cmpDic[data2FieldDataList[0]] = i

    #print srcDic
    #print cmpDic
    intersectionKeyList = list(set(srcDic.keys()) & set(cmpDic.keys()))
    #print len(intersectionKeyList)

    if len(intersectionKeyList) == 0 :
        print 'no intersection period'
        return
    #print intersectionKeyList
    intersectionKeyList.sort()
    #print intersectionKeyList

    srcAcc = 0
    cmpAcc = 0
    amount = 0
    UpUp = 0
    UpDown = 0
    DownUp = 0
    DownDown = 0


    for i in range(1, len(intersectionKeyList) ) :
        srcDate = intersectionKeyList[i-1]
        cmpDate = intersectionKeyList[i]
        srcIndex = srcDic[srcDate]
        cmpIndex = cmpDic[cmpDate]
        srcValue = int(getFieldDataList(data1Lines[srcIndex])[6])
        cmpValue = int(getFieldDataList(data2Lines[cmpIndex])[6])
        srcAcc += srcValue
        cmpAcc += cmpValue
        amount += 1

        #print srcDate, srcValue, u'|', cmpDate, cmpValue

        if srcValue > 0 and cmpValue > 0 :
            UpUp += 1
        elif srcValue < 0 and cmpValue > 0 :
            DownUp += 1
        elif srcValue > 0 and cmpValue < 0 :
            UpDown += 1
        elif srcValue < 0 and cmpValue < 0 :
            DownDown += 1

    print float(srcAcc)/amount, amount, u'A000660', u'A005930',
    print intersectionKeyList[0], u'~', intersectionKeyList[-1]
    print u'UpUp', UpUp, float(UpUp)/amount
    print u'DownUp', DownUp, float(DownUp)/amount
    print u'UpDown', UpDown, float(UpDown)/amount
    print u'DownDown', DownDown, float(DownDown)/amount

    """
    for date in intersectionKeyList :
        srcIndex = srcDic[date]
        cmpIndex = cmpDic[date]
        srcValue = int(getFieldDataList(data1Lines[srcIndex])[6])
        cmpValue = int(getFieldDataList(data2Lines[cmpIndex])[6])
        srcAcc += srcValue
        cmpAcc += cmpValue
        print date, srcValue, cmpValue

    print srcAcc, cmpAcc
    print intersectionKeyList[0], u'~', intersectionKeyList[-1]
    """
    return

    #print data1FieldDataList[6] #전일대비
    #print data2FieldDataList[6] #전일대비
    

    #for 아이템1 에 대해 (전체 주식아이템 리스트 중)
        #해당 아이템1의 파일을 읽는다.
        #for 아이템2 에 대해 (아이템1을 제외한 리스트 중)
            #해당 아이템2의 파일을 읽는다.
            #for yesterdayValue (전날의 전일대비값) in 아이템1 리스트
                # todayValue = 아이템2의 오늘의 전일대비값
                #if yesterdayValue > 0 and todayValue > 0 :
                # 아이템1이 어제 올랐을 때, 아이템2가 오늘 올랐다. 
                # 정확히는 아이템1이 오늘 올랐을 때, 내일 아이템2가 오를 확률은?의 뜻이다.
                #   데이타[아이템1][아이템2][UpUp] += 1
                #elif yesterdayValue > 0 and todayValue < 0 :
                # 아이템1이 어제 올랐을 때, 아이템2가 오늘 내렸다.
                # 정확히는 아이템1이 오늘 올랐을 때, 내일 아이템2가 내릴 확률은?의 뜻이다.
                #   데이타[아이템1][아이템2][UpDown] += 1
                #elif yesterdayValue < 0 and todayValue > 0 :
                # 아이템1이 어제 내렸을 때, 아이템2가 오늘 올랐다.
                # 정확히는 아이템1이 오늘 내렸을 때, 내일 아이템2가 오를 확률은?의 뜻이다.
                #   데이타[아이템1][아이템2][DownUp] += 1
                #elif yesterdayValue < 0 and todayValue > 0 :
                # 아이템1이 어제 내렸을 때, 아이템2가 오늘 내렸다.
                # 정확히는 아이템1이 오늘 내렸을 때, 내일 아이템2가 내릴 확률은?의 뜻이다.
                #   데이타[아이템1][아이템2][DownDown] += 1
                #elif => y = 0 and t = 0, y = 0 and t < 0, y = 0 and t > 0, 
                #     => y > 0 and t = 0, y < 0 and t = 0, y = 0 and t = 0.
                # 이 부분들이 어떤 의미가 있을까? 생략해도 될 듯...
                #전체 카운트 증가.
            #아이템2의 파일을 닫는다
        #해당 

    from cxStockMgr     import stockMgr
    stockList = stockMgr.getStockList()
    dataPath = u'database\\day\\'
    srcStockFileName = u''
    cmpStockFileName = u''
    fileType = u'.data'
    for srcStockCode, srcStockName, srcStockFullCode in stockList :
        srcStockFileName = dataPath + srcStockCode + fileType
        srcStockFile = cxFile(srcStockFileName)
        srcDataLines = srcStockFile.readlines()
        srcStockFile.close()
        del srcStockFile
        for cmpStockCode, cmpStockName, cmpStockFullCode in stockList :
            if srcStockCode == cmpStockCode :
                continue
            cmpStockFileName = dataPath + cmpStockCode + fileType
            cmpStockFile = cxFile(cmpStockFileName)
            cmpDataLines = cmpStockFile.readlines()
            cmpStockFile.close()
            del cmpStockFile
            # find starting offset time for comparing each other.
            # or
            # travel reverse order from recent day time to most old day time.
            #for day in dayList[startingDay, lastDay] :
            srcFieldDataList = []
            cmpFieldDataList = []
            if len(srcDataLines) >= len(cmpDataLines) :
                numLines = len(cmpDataLines)
            else : numLines = len(srcDataLines)
            # src >= cmp , cmp
            # src < cmp, src

            # +++++++++++++++++++++++++++                       (src)
            #                 ++++++++++++++++++++++++++++++    (cmp)
            #                 |         |
            #                 Offset    (Offset+num) 


            #              ++++++++++++++++++++++++++++++++     (src)
            # ++++++++++++++++++++++++                          (cmp)
            #              |         |
            #              Offset    (Offset+num)


            #              +++++++++++++++++                    (src)
            # ++++++++++++++++++++++++++++++++++++++            (cmp)
            #              |               |
            #              Offset          (Offset+num)


            for i in range(1, numLines) :
                srcFieldDataList.append([ data for data in filter(lambda x : x!= u'\n', \
                                                            srcDataLines[i].split(u' '))])
                cmpFieldDataList.append([ data for data in filter(lambda x : x!= u'\n', \
                                                            cmpDataLines[i].split(u' '))])
            offset = 0
            num = 0
            i = 0
            minLen = numLines - 1

            while i < minLen :
                if int(srcFieldDataList[i][0]) > int(cmpFieldDataList[i][0]) :
                    for j in range(i, numLines) :
                        if int(srcFieldDataList[i][0]) == int(cmpFieldDataList[j][0]) :
                            offset = j
                            i = j
                            break
                elif int(srcFieldDataList[i][0]) < int(cmpFieldDataList[i][0]) :
                    for j in range(i, numLines) :
                        if int(srcFieldDataList[j][0]) == int(cmpFieldDataList[i][0]) :
                            offset = j
                            i = j
                            break
                else : num += 1
                i += 1

            print offset, num + offset
            for i in range(offset, offset + num) :
                print srcFieldDataList[i][0], cmpFieldDataList[i][0],
                if srcFieldDataList[i][0] != cmpFieldDataList[i][0] :
                    print 'Different!!'
                else : print
Beispiel #5
0
def getStockSize() :
    from cxStockMgr import stockMgr
    print 'number of stock : ', len(stockMgr.getStockList())
    print