Exemplo n.º 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
Exemplo n.º 2
0
def testStockMst_ver_2() :
    from common import testBlockRequest
    from cxFile import cxFile

    stockCode = u'A000660'
    paramList = [ [ 0, stockCode ], ]
    option = 1
    if option == 1 :
        print testBlockRequest('cxCpStockMst', paramList, 1, 1, 0, 0)
    else :
        resultFile = cxFile()
        testBlockRequest( 'cxCpStockMst', paramList, 1, 1, 0, 0,resultFile )
        resultFile.close()
Exemplo n.º 3
0
def testFutureMst() :
    "전체 선물 정보를 얻어낸다."
    from cxCybosPlus import gCybosPlusClassDic
    from cxCybosPlus import constants
    from common import testBlockRequest
    from cxFile import cxFile
    import time

    #cpFutureMst = gCybosPlusClassDic['cxFutureMst']
    cpFutureCode = gCybosPlusClassDic['cxCpFutureCode']
    cpCybos = gCybosPlusClassDic['cxCpCybos']

    futureNum = cpFutureCode.GetCount()

    futureList = []

    for i in range(0,futureNum) :
        futureCode = cpFutureCode.GetData(0, i)
        futureName = cpFutureCode.GetData(1, i)
        futureList.append([futureCode, futureName])
        #print futureCode, '"',futureName,'"'

    index = 0

    for futureCode, futureName in futureList :
        paramList = [ [ 0, futureCode],]
        print testBlockRequest('cxFutureMst', paramList, 1, 1, 0, 0 )

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

        print index, futureCode, futureName
        index+=1
Exemplo n.º 4
0
def test_getStockDayData() :

    from cxCybosPlus import cxCpStockCode

    from cxFile import cxFile

    #stockCode = u'A000660'  #하이닉스
    #stockCode = u'A005930'  #삼성전자
    stockCode = u'A005380'  #현대자동차
    #stockCode = u'A004990'  #롯데제과

    cpStockCode = cxCpStockCode()

    stockName = cpStockCode.CodeToName(stockCode)

    chartType = u'D'

    fileName = u'%s_%s_%s.log'%(stockCode, stockName, chartType)

    refreshLog = 1 
    
    if refreshLog == 1 :

        resultFile = cxFile(fileName)
   
        fieldList = [ 
            0, # 날짜
            3, # 고가
            4, # 저가
            5, # 종가
            8, # 거래량
            9, # 거래대금
            25, # 주식회전율
        ]

        paramList = [
            [ 0, stockCode ],
            [ 1, ord(u'1') ],
            [ 3, 19920901 ],
            [ 4, len(fieldList) ],
            [ 5 ] + fieldList,
            [ 6, ord(chartType) ],
            [ 9, ord(u'1') ],        # 수정주가
            [ 10, ord(u'3') ]
        ]

        testBlockRequest(u'cxStockChart', paramList, 0, 0, 1, 1, resultFile )

        resultFile.close()
    
    
    resultFile = cxFile(fileName)

    lines = resultFile.readlines()

    """
    value = lines[1].split(u'\t')
    print value
    print value[0], value[3]
    """

    dataLog = []
    
    for i in range(0, len(lines)) :
        if i == 0 : continue
        value = lines[i].split(u'\t')
        #print value[0],value[3]
        dataLog.append( [ value[0], value[3] ] )
    
    resultFile.close()

    dataLogLen = len(dataLog)

    print dataLogLen
    flagBuy = False

    earningMoney = 0

    resultFile = cxFile()
    buyCount = 0
    buyedMoney = 0
    maxBuyedMoney = 0

    for i in range(dataLogLen -1 -20, -1, -1 ) :
        currentValue = int(dataLog[i][1])
        avr = 0
        total = 0
        maxValue = 0
        minValue = 10000000000
        #resultFile.write(u'%d\t'%(i))
        resultFile.write(u'%s\t'%(dataLog[i][0]))
        for j in range(i+20,i,-1) :
            oldValue = int(dataLog[j][1])
            #resultFile.write(u'%d(%s,%d),'%(j,dataLog[i][0],oldValue))
            total += oldValue
            if maxValue < oldValue :
                maxValue = oldValue
            if minValue > oldValue :
                minValue = oldValue
        resultFile.write(u' ')
        avr = int(total/20)
        resultFile.write(u'current:%d,avr:%d,20s min:%d,20s max:%d\n'%( currentValue,
                                                                      avr,
                                                                      minValue,
                                                                      maxValue))
        if (currentValue > maxValue) and (flagBuy == False) :
            resultFile.write(u'BUY at cv:%d for mv:%d in bm:%d (em:%d, bc:%d)\n'%( currentValue, 
                                                                maxValue, 
                                                                buyedMoney,
                                                                earningMoney,
                                                                buyCount))
            flagBuy = True
            buyedMoney += currentValue
            buyCount += 1
            maxBuyedMoney = max(maxBuyedMoney, buyedMoney)
        elif flagBuy == True and currentValue < minValue :
            earningMoney += (currentValue*buyCount)-buyedMoney
            resultFile.write(u'SELL at cv:%d for mv:%d in bm:%d (em:%d, bc:%d)\n'%( currentValue, 
                                                                 minValue, 
                                                                 buyedMoney,
                                                                 earningMoney,
                                                                 buyCount))
            flagBuy = False
            buyCount = 0
            buyedMoney = 0

    resultFile.write(u'earned Money :%d, max buyed money : %d, (%f)\n'%(earningMoney,
                                                                  maxBuyedMoney,
                                                                  float(earningMoney)/float(maxBuyedMoney)*(100.0)))
    resultFile.write(u'%s~%s:%d~%d(%d)\n'%( dataLog[dataLogLen-1][0],
                                            dataLog[0][0],
                                            int(dataLog[dataLogLen-1][1]),
                                            int(dataLog[0][1]),
                                            int(int(dataLog[0][1])/int(dataLog[dataLogLen-1][1]))))

    print
Exemplo n.º 5
0
def test_getStockDayData() :

    from cxCybosPlus import cxCpStockCode

    from cxFile import cxFile

    #stockCode = u'A000660'  #하이닉스
    #stockCode = u'A005930'  #삼성전자
    stockCode = u'A005380'  #현대자동차
    #stockCode = u'A004990'  #롯데제과

    cpStockCode = cxCpStockCode()

    stockName = cpStockCode.CodeToName(stockCode)

    chartType = u'D'

    fileName = u'%s_%s_%s.log'%(stockCode, stockName, chartType)

    refreshLog = 1 
    
    if refreshLog == 1 :

        resultFile = cxFile(fileName)
   
        fieldList = [ 
            0, # 날짜
            3, # 고가
            4, # 저가
            5, # 종가
            8, # 거래량
            9, # 거래대금
            25, # 주식회전율
        ]

        paramList = [
            [ 0, stockCode ],
            [ 1, ord(u'1') ],
            [ 3, 19920901 ],
            [ 4, len(fieldList) ],
            [ 5 ] + fieldList,
            [ 6, ord(chartType) ],
            [ 9, ord(u'1') ],        # 수정주가
            [ 10, ord(u'3') ]
        ]

        testBlockRequest(u'cxStockChart', paramList, 0, 0, 1, 1, resultFile )

        resultFile.close()
    
    
    resultFile = cxFile(fileName)

    lines = resultFile.readlines()

    """
    value = lines[1].split(u'\t')
    print value
    print value[0], value[3]
    """

    dataLog = []
    
    for i in range(0, len(lines)) :
        if i == 0 : continue
        value = lines[i].split(u'\t')
        #print value[0],value[3]
        dataLog.append( [ value[0], value[3] ] )
    
    resultFile.close()

    dataLogLen = len(dataLog)

    print dataLogLen
    flagBuy = False

    earningMoney = 0

    resultFile = cxFile()
    buyCount = 0
    buyedMoney = 0
    maxBuyedMoney = 0

    for i in range(dataLogLen -1 -20, -1, -1 ) :
        currentValue = int(dataLog[i][1])
        avr = 0
        total = 0
        maxValue = 0
        minValue = 10000000000
        #resultFile.write(u'%d\t'%(i))
        resultFile.write(u'%s\t'%(dataLog[i][0]))
        for j in range(i+20,i,-1) :
            oldValue = int(dataLog[j][1])
            #resultFile.write(u'%d(%s,%d),'%(j,dataLog[i][0],oldValue))
            total += oldValue
            if maxValue < oldValue :
                maxValue = oldValue
            if minValue > oldValue :
                minValue = oldValue
        resultFile.write(u' ')
        avr = int(total/20)
        resultFile.write(u'current:%d,avr:%d,20s min:%d,20s max:%d\n'%( currentValue,
                                                                      avr,
                                                                      minValue,
                                                                      maxValue))
        if (currentValue > maxValue) and (flagBuy == False) :
            resultFile.write(u'BUY at cv:%d for mv:%d in bm:%d (em:%d, bc:%d)\n'%( currentValue, 
                                                                maxValue, 
                                                                buyedMoney,
                                                                earningMoney,
                                                                buyCount))
            flagBuy = True
            buyedMoney += currentValue
            buyCount += 1
            maxBuyedMoney = max(maxBuyedMoney, buyedMoney)
        elif flagBuy == True and currentValue < minValue :
            earningMoney += (currentValue*buyCount)-buyedMoney
            resultFile.write(u'SELL at cv:%d for mv:%d in bm:%d (em:%d, bc:%d)\n'%( currentValue, 
                                                                 minValue, 
                                                                 buyedMoney,
                                                                 earningMoney,
                                                                 buyCount))
            flagBuy = False
            buyCount = 0
            buyedMoney = 0

    resultFile.write(u'earned Money :%d, max buyed money : %d, (%f)\n'%(earningMoney,
                                                                  maxBuyedMoney,
                                                                  float(earningMoney)/float(maxBuyedMoney)*(100.0)))
    resultFile.write(u'%s~%s:%d~%d(%d)\n'%( dataLog[dataLogLen-1][0],
                                            dataLog[0][0],
                                            int(dataLog[dataLogLen-1][1]),
                                            int(dataLog[0][1]),
                                            int(int(dataLog[0][1])/int(dataLog[dataLogLen-1][1]))))

    print