예제 #1
0
def getStockWeightData(stockcode):
    weightdata = []
    if (stockcode[:3] == 'sh0'):  #index
        return weightdata

    weightfilename = globals.qlweightbase + '/{}.wgt'.format(stockcode[2:])

    content = utils.file_get_contents(weightfilename, 'rb')
    if (not content):
        return False

    for i in range(0, len(content), 36):
        d = content[i:i + 36]
        data = struct.unpack('iiiiiiiii', d)
        y = data[0] >> 20
        m = (data[0] & 0xf0000) >> 16
        d = (data[0] & 0xffff) >> 11

        row = {}
        row['date'] = '{}{:02d}{:02d}'.format(y, m, d)
        row['songgu'] = data[1] / 100000
        row['peigu'] = data[2] / 100000
        row['peigu_price'] = data[3] / 10000
        row['fenhong'] = data[4] / 10000
        row['zhuanzeng'] = data[5] / 100000
        weightdata.append(row)

    return weightdata
예제 #2
0
def getStockList():
    stocklistfile = globals.datapath + '/stocklist.txt'
    stocklistdata = utils.file_get_contents(stocklistfile)
    if (not stocklistdata):
        utils.output('股票列表载入失败, 请先运行update stocklist', 'red')
        return False

    stocklist = {}
    lines = stocklistdata.split("\n")
    for line in lines:
        if (line):
            stockArr = line.split(',')
            if (len(stockArr) == 2):
                scode = normalizeStockCode(stockArr[0])
                stocklist[scode] = stockArr[1]

    return stocklist
예제 #3
0
def getStockDayData(stockcode):
    daydata = []
    dayfilename = globals.tdxdaybase + '/{}.day'.format(stockcode)

    content = utils.file_get_contents(dayfilename, 'rb')
    if (not content):
        return False

    for i in range(0, len(content), 32):
        d = content[i:i + 32]
        data = struct.unpack('iiiiifii', d)
        row = {}
        row['date'] = '{}'.format(data[0])
        row['open'] = data[1] / 100
        row['high'] = data[2] / 100
        row['low'] = data[3] / 100
        row['close'] = data[4] / 100
        row['amount'] = data[5] / 1000
        row['volume'] = data[6]
        daydata.append(row)

    return daydata