示例#1
0
def parseStock(oneStock):
    symbol = oneStock["symbol"]
    data = getStockInfoData(stockInfoAPI, oneStock)

    try:
        #正常的操作#获取最新价格
        oneStock['current'] = data[symbol]['current']
    except:
        #发生异常,执行这块代码
        print '数据解析出错,可能是cookie问题,请尝试更新'

    #获取股票的近季度的利润情况
    oneStock['profit'] = FA.parseIncstatementData(symbol)

    #获取pe
    oneStock['pe_lyr'] = data[symbol]['pe_lyr']
    oneStock['pe_ttm'] = data[symbol]['pe_ttm']

    #获取最新pb
    latestPB = data[symbol]['pb']
    oneStock['latestPB'] = latestPB
    #根据pb获取配置额度
    money = getMoney(latestPB)
    oneStock['canUseMoney'] = money
    #是否可以继续配置
    if money - oneStock['latestCost'] > 0:
        canContinueBuy = True
        oneStock['canContinueBuy'] = canContinueBuy
    else:
        canContinueBuy = False
        oneStock['canContinueBuy'] = canContinueBuy
    #如果可以配置的话,还能配置多少股
    if canContinueBuy:
        nowCanUse = money - oneStock['latestCost']
        nowCanBuyStockNumber = nowCanUse / float(data[symbol]['current'])
        nowCanBuyStockNumber = int(round(nowCanBuyStockNumber, 0))
        nowCanBuyStockNumber2 = int(round(nowCanBuyStockNumber / 100)) * 100
        oneStock['nowCanUse'] = nowCanUse
        oneStock['nowCanBuyStockNumber'] = nowCanBuyStockNumber
        oneStock['nowCanBuyStockNumber2'] = nowCanBuyStockNumber2
    else:
        oneStock['nowCanUse'] = 0
        oneStock['nowCanBuyStockNumber'] = 0
        oneStock['nowCanBuyStockNumber2'] = 0
示例#2
0
def getAllData(page=0, stockArr=[]):

    data = {"count": 1, "list": [{"symbol": symbolCode, "name": symbolCode}]}

    arr = data["list"]

    #在函数中使用全局变量需要这里声明
    global dealNum

    # 股票总条数
    count = data["count"]
    totalPages = int(math.ceil(count / 30))

    #处理一页中,各个股票的数据
    for one in arr:

        #用来统计进度
        dealNum = dealNum + 1
        perc = round((dealNum / count), 3) * 100

        name = one['name']
        symbol = one['symbol']

        print('您查询的股票是:' + name)
        print(
            '---------------------------------------------------------------------------------------------------------------'
        )

        #判断股票是否存在
        # cursor = dataBase.getStock(symbol);
        # if cursor.count()>=1:
        #     for document in cursor:
        #         oneStock = document
        #     print(name+u' 已经存在数据库中,不再处理')
        #     print('--------------------------------------------------------------------------------------------------------------- '+str(perc)+'%')
        #     stockArr.append(oneStock);
        #     continue

        #非常核心的数据提炼部分1
        lows = getLowPriceArr(symbol, 6)
        #这里使用第2个接口
        #提炼低点占比
        percents = getSellPercent(lows)
        #提炼低点占比
        continueDays = lows[2]
        continueDaysText = lows[3]
        #提炼最近一天涨跌百分比 和 连续几天的涨跌百分比
        upOrDownPercent = lows[4]
        upOrDownContinuePercent = lows[5]

        #非常核心的数据提炼部分2
        info = getStockInfoData(stockInfoAPI, config3, symbol)
        #这里使用第3个接口

        #需要再增加一个key,用来排序
        averagePrecent = percents[1]
        #需要再增加一个key,用来排序
        lastPrecent = percents[0][0]

        #新增 停牌信息
        halt = info['halt']
        #新增 财务分析
        cashFlow = FA.parseCfstatementData(symbol)
        profit = FA.parseIncstatementData(symbol)

        #新增 名字(本来是第一个接口中就有的,因为改了,所以再获取下)
        nameStr = info['nameStr']

        #完成一个完整的股票分析
        oneStock = Stock(
            name,
            symbol,
            lows,
            percents,
            info,
            averagePrecent,
            lastPrecent,
            continueDays,
            continueDaysText,
            upOrDownPercent,
            upOrDownContinuePercent,
            halt,
            cashFlow,
            profit,
            nameStr,
        )

        #屏幕输出
        print(u"【" + oneStock['nameStr'] + u"】")
        print(oneStock['lows'][3].encode("utf-8") + ',合计涨/跌百分比:' +
              str(oneStock['lows'][5]) + '%,当天' + str(oneStock['lows'][4]) +
              '%')
        print('推荐购买' + str(oneStock['info']['buyNum2']) + '(' +
              str(oneStock['info']['buyNum']) + ')')
        print('成本为 ' + str(oneStock['info']['buyNum2'] * oneStock['lows'][1]) +
              ' 元(每股 ' + str(oneStock['lows'][1]) + ')')

        print('【PB/TTM/LYR】' + str(oneStock['info']['pb']) + '/' +
              str(oneStock['info']['pe_ttm']) + '/' +
              str(oneStock['info']['pe_lyr']))
        print('【EPS/每股净资产/ROE(季)/ROE(年)】' + str(oneStock['info']['eps']) +
              '/' + str(oneStock['info']['net_assets']) + '/' +
              str(oneStock['info']['roe'])) + '%/' + str(
                  oneStock['info']['roe2']) + '%'

        print('N年内低点 ' + str(oneStock['lows'][0]))
        print('N年内卖点占比 ' + str(oneStock['percents'][0]) + ',平均 ' +
              str(oneStock['percents'][1]))
        print('总股本' + str(oneStock['info']['totalShares2']) + '亿')
        print('最近季度利润' + str(oneStock['profit'][1]) + '亿')

        print(oneStock['profit'][0])
        print(oneStock['cashFlow'][0])
        print(oneStock['cashFlow'][1])
        print(oneStock['cashFlow'][2])
        print(
            '--------------------------------------------------------------------------------------------------------------- '
            + str(perc) + '%')

        #保存到数据库
        #dataBase.save(oneStock);

        #并保存到全局对象中(这个其实没啥用呢)
        #补充,现在有用了,最后的时候,用来作为全部数据导出到txt
        #为什么不是和数据库存入一样,在每一次中完成,而选择了最后一次性处理
        #因为主要是为了解决排序的问题
        stockArr.append(oneStock)

    return stockArr
示例#3
0
def getAllData(page=0,stockArr=[]):

    json = getScreenerData(screenerAPI,config,page);    #这里使用第1个接口

    try:
        #正常的操作
        data = Payload(json);
    except:
        #发生异常,执行这块代码
        print '【xm】股票筛选接口崩坏!'
        print json

    if(~~hasattr(data,'list')==0):
        print('获取数据的接口似乎有点问题哦=================> 请尝试更新cookie!');

    arr  = data.list;

    #在函数中使用全局变量需要这里声明
    global dealNum;

    # 股票总条数
    count = data.count;
    totalPages = int(math.ceil(count/30))
    if page == 0:
        page = 1;
    else:
        page = page+1;
        #处理一页中,各个股票的数据
        for one in arr:

            #用来统计进度
            dealNum = dealNum + 1;
            perc = round((dealNum/count),3)*100;

            name = one['name'];
            symbol = one['symbol'];

            #白云山A,已经退市不在处理
            if symbol=='SZ000522':
                print('============ 已经退市,跳过!===========')
                continue

            #判断股票是否存在
            cursor = dataBase.getStock(symbol);
            if cursor.count()>=1:
                for document in cursor:
                    oneStock = document
                print(name+u' 已经存在数据库中,不再处理')
                print('--------------------------------------------------------------------------------------------------------------- '+str(perc)+'%')
                stockArr.append(oneStock);
                continue


            #非常核心的数据提炼部分1
            lows     = getLowPriceArr(symbol,6);                      #这里使用第2个接口
            #提炼低点占比
            percents = getSellPercent(lows);
            #提炼低点占比
            continueDays     = lows[2];
            continueDaysText = lows[3];
            #提炼最近一天涨跌百分比 和 连续几天的涨跌百分比
            upOrDownPercent         = lows[4];
            upOrDownContinuePercent = lows[5];

            #非常核心的数据提炼部分2
            info     = getStockInfoData(stockInfoAPI,config3,symbol); #这里使用第3个接口

            #需要再增加一个key,用来排序
            averagePrecent = percents[1];
            #需要再增加一个key,用来排序
            lastPrecent    = percents[0][0];

            #新增 停牌信息
            halt = info['halt']
            #新增 财务分析
            cashFlow = FA.parseCfstatementData(symbol)
            profit = FA.parseIncstatementData(symbol)

            messages = industryConfig.get(symbol) # Check for key existence
            if messages is None:                  # Check if key is there, but None
                industryId   = 9999
                industryName = "未分类"
            else:
                industryId   = industryConfig[symbol]['id']
                industryName = industryConfig[symbol]['industry']

            messages2 = stockPoolConfig.get(symbol) 
            if messages2 is None:                 
                stockPoolInfo = {}
            else:
                stockPoolInfo = stockPoolConfig[symbol]
            


            #完成一个完整的股票分析
            oneStock = Stock(
                name,
                symbol,
                lows,
                percents,
                info,
                averagePrecent,
                lastPrecent,
                continueDays,
                continueDaysText,
                upOrDownPercent,
                upOrDownContinuePercent,
                halt,
                cashFlow,
                profit,
                industryId,
                industryName,

                stockPoolInfo,
            );

            #屏幕输出
            print(oneStock['name'])
            print(oneStock['info'])
            print(oneStock['lows'])
            print(oneStock['percents'])
            print(oneStock['continueDaysText'] + u',合计涨/跌百分比:' + str(oneStock['upOrDownContinuePercent']) )
            print(oneStock['profit'][0])
            print(oneStock['cashFlow'][0])
            print(oneStock['cashFlow'][1])
            print(oneStock['cashFlow'][2])
            print('--------------------------------------------------------------------------------------------------------------- '+str(perc)+'%')

            #保存到数据库
            dataBase.save(oneStock);

            #并保存到全局对象中(这个其实没啥用呢)
            #补充,现在有用了,最后的时候,用来作为全部数据导出到txt
            #为什么不是和数据库存入一样,在每一次中完成,而选择了最后一次性处理
            #因为主要是为了解决排序的问题
            stockArr.append(oneStock);

    if page<=totalPages:
        getAllData(page,stockArr);

    return stockArr;