Exemplo n.º 1
0
def getStockPosition(code, market):
    """
    处理股票盘口数据分析,分析所占的百分比率
    http://qt.gtimg.cn/q=s_pksz000858
    v_s_pksz000858="0.196~0.258~0.221~0.325";
    以 ~ 分割字符串中内容,下标从0开始,依次为:
    0: 买盘大单
    1: 买盘小单
    2: 卖盘大单
    3: 卖盘小单
    所占有的百分比百分比率
    """
    if code and market:
        url = "http://qt.gtimg.cn/q=s_pk%s%s" % (market, code)
        content = httpGetContent(url)
        if content:
            result_list = _get_content(content)
            if result_list:
                stock_dict = {}
                stock_dict["code"] = code
                stock_dict["market"] = market
                stock_dict["buy_big_percent"] = float(result_list[0])     # 买盘大单所占百分比
                stock_dict["buy_small_percent"] = float(result_list[1])   # 买盘小单所占百分比
                stock_dict["sell_big_percent"] = float(result_list[2])    # 卖盘大单所占比重
                stock_dict["sell_small_percent"] = float(result_list[3])  # 买盘小单所占比重
                stock_dict["date"] = datetime.date.today()
                return stock_dict
Exemplo n.º 2
0
def stock_day_history_Yahoo(code, market):
    """
    雅虎股票数据接口
    得到yahoo股票的历史数据信息
    深市数据链接:http://table.finance.yahoo.com/table.csv?s=000001.sz
    上市数据链接:http://table.finance.yahoo.com/table.csv?s=600000.ss
    Date 日期
    Open 开盘价格
    High 最高价格
    Low  最低价格
    Close 结束价格
    Volume 量
    Adj Close 收盘加权价格
    """
    if market not in ('sz', 'ss'):
        return
    url = "http://table.finance.yahoo.com/table.csv?s=%s.%s" % (code, market)
    content = httpGetContent(url=url)
    if content:
        data = cStringIO.StringIO(content)
        reader = csv.reader(data)
        for i, row in enumerate(reader):
            stock_dict = {}
            if i == 0:
                continue
            stock_dict['date'] = row[0]             # 日期
            stock_dict['open'] = float(row[1])      # 开盘价格
            stock_dict['high'] = float(row[2])      # 最高价格
            stock_dict['low'] = float(row[3])       # 最低价格
            stock_dict['close'] = float(row[4])     # 结束价格
            stock_dict['volume'] = float(row[5])    # 量
            stock_dict['adj_close'] = float(row[6]) # 几日收盘加权价格?
            yield stock_dict
Exemplo n.º 3
0
def stock_industry_day():
    """
    根据同花顺得到板块数据分析
    http://q.10jqka.com.cn/stock/thshy/
    http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/1/quote/quote
    """
    urls = (
        'http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/1/quote/quote',
        'http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/2/quote/quote')
    for url in urls:
        content = httpGetContent(url)
        if content:
            json_stock = json.loads(content)
            industry_list = json_stock["data"]

            for industry in industry_list:
                industry_dict = {}
                industry_dict["date"] = str_to_date(json_stock["rtime"][:10],
                                                    "%Y-%m-%d")
                industry_dict["name"] = industry["platename"]
                industry_dict["industry_code"] = industry["platecode"]
                industry_dict["price"] = float(industry["zxj"])  # 最近价格
                industry_dict["volume"] = float(industry["cjl"])  # 总成交量多少万手
                industry_dict["total"] = float(industry["cje"])  # 总成交额多少亿元数据
                industry_dict["rise_percent"] = float(industry["zdf"])  # 涨跌幅
                industry_dict["rise_price"] = float(
                    industry["zde"])  # 涨跌额度(价格)
                industry_dict["net_inflow"] = float(
                    industry["jlr"])  # 净流入(亿元数据)
                yield industry_dict
Exemplo n.º 4
0
def getStockPosition(code, market):
    """
    处理股票盘口数据分析,分析所占的百分比率
    http://qt.gtimg.cn/q=s_pksz000858
    v_s_pksz000858="0.196~0.258~0.221~0.325";
    以 ~ 分割字符串中内容,下标从0开始,依次为:
    0: 买盘大单
    1: 买盘小单
    2: 卖盘大单
    3: 卖盘小单
    所占有的百分比百分比率
    """
    if code and market:
        url = "http://qt.gtimg.cn/q=s_pk%s%s" % (market, code)
        content = httpGetContent(url)
        if content:
            result_list = _get_content(content)
            if result_list:
                stock_dict = {}
                stock_dict["code"] = code
                stock_dict["market"] = market
                stock_dict["buy_big_percent"] = float(result_list[0])     # 买盘大单所占百分比
                stock_dict["buy_small_percent"] = float(result_list[1])   # 买盘小单所占百分比
                stock_dict["sell_big_percent"] = float(result_list[2])    # 卖盘大单所占比重
                stock_dict["sell_small_percent"] = float(result_list[3])  # 买盘小单所占比重
                stock_dict["date"] = datetime.date.today()
                return stock_dict
Exemplo n.º 5
0
def getStockMarket(code):
    """
    大盘数据接口信息
    上证:code:000001 set=zs
    深证:code:399001 set=zs
    中小板:code:399005 set=zs
    创业板: code:399006 set=zs
    http://q.stock.sohu.com/qp/hq?type=snapshot&code=000001&set=zs

    """
    url = "http://q.stock.sohu.com/qp/hq?type=snapshot&code=%s&set=zs" % code

    result = httpGetContent(url=url, charset="gbk")
    if result:
        result = eval(result)
        stock_dict = {}
        stock_dict["date"] = result[0][:10] #日期
        stock_dict["name"] = unicode(result[2], 'utf8') #名称
        stock_dict["range_price"] = float(result[4]) #上涨价格
        stock_dict["range_percent"] = float(result[5].strip("%")) #涨幅

        stock_dict["start"] = float(result[9]) #开盘价格
        stock_dict["high"] = float(result[11]) #最高价格
        stock_dict["low"] = float(result[13]) #最低价格
        stock_dict["last_closing"] = float(result[7]) #昨日收
        stock_dict["end"] = float(result[3]) #收盘价格

        stock_dict["total_sum"] = int(result[18]) #多少万元

        stock_dict["volume"] = int(result[14]) #多少手

        return stock_dict
Exemplo n.º 6
0
def stock_industry_day():
    """
    根据同花顺得到板块数据分析
    http://q.10jqka.com.cn/stock/thshy/
    http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/1/quote/quote
    """
    urls = ('http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/1/quote/quote',
            'http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/2/quote/quote')
    for url in urls:
        content = httpGetContent(url)
        if content:
            json_stock = json.loads(content)
            industry_list = json_stock["data"]

            for industry in industry_list:
                industry_dict = {}
                industry_dict["date"] = str_to_date( json_stock["rtime"][:10],"%Y-%m-%d")
                industry_dict["name"] = industry["platename"]
                industry_dict["industry_code"] = industry["platecode"]
                industry_dict["price"] = float(industry["zxj"])        # 最近价格
                industry_dict["volume"] = float(industry["cjl"])       # 总成交量多少万手
                industry_dict["total"] = float(industry["cje"])        # 总成交额多少亿元数据
                industry_dict["rise_percent"] = float(industry["zdf"]) # 涨跌幅
                industry_dict["rise_price"] = float(industry["zde"])   # 涨跌额度(价格)
                industry_dict["net_inflow"] = float(industry["jlr"])   # 净流入(亿元数据)
                yield industry_dict
Exemplo n.º 7
0
def getStockMarket(code):
    """
    大盘数据接口信息
    上证:code:000001 set=zs
    深证:code:399001 set=zs
    中小板:code:399005 set=zs
    创业板: code:399006 set=zs
    http://q.stock.sohu.com/qp/hq?type=snapshot&code=000001&set=zs
    """
    url = "http://q.stock.sohu.com/qp/hq?type=snapshot&code=%s&set=zs" % code

    result = httpGetContent(url=url, charset="gbk")
    if result:
        result = eval(result)
        stock_dict = {}
        stock_dict["date"] = result[0][:10] #日期
        stock_dict["name"] = unicode(result[2], 'utf8') #名称
        stock_dict["range_price"] = float(result[4]) #上涨价格
        stock_dict["range_percent"] = float(result[5].strip("%")) #涨幅

        stock_dict["start"] = float(result[9]) #开盘价格
        stock_dict["high"] = float(result[11]) #最高价格
        stock_dict["low"] = float(result[13]) #最低价格
        stock_dict["last_closing"] = float(result[7]) #昨日收
        stock_dict["end"] = float(result[3]) #收盘价格

        stock_dict["total_sum"] = int(result[18]) #多少万元

        stock_dict["volume"] = int(result[14]) #多少手

        return stock_dict
Exemplo n.º 8
0
def stock_day_history_Yahoo(code, market):
    """
    雅虎股票数据接口
    得到yahoo股票的历史数据信息
    深市数据链接:http://table.finance.yahoo.com/table.csv?s=000001.sz
    上市数据链接:http://table.finance.yahoo.com/table.csv?s=600000.ss
    Date 日期
    Open 开盘价格
    High 最高价格
    Low  最低价格
    Close 结束价格
    Volume 量
    Adj Close 收盘加权价格
    """
    if market not in ('sz', 'ss'):
        return
    url = "http://table.finance.yahoo.com/table.csv?s=%s.%s" % (code, market)
    content = httpGetContent(url=url)
    if content:
        data = cStringIO.StringIO(content)
        reader = csv.reader(data)
        for i, row in enumerate(reader):
            stock_dict = {}
            if i == 0:
                continue
            stock_dict['date'] = row[0]  # 日期
            stock_dict['open'] = float(row[1])  # 开盘价格
            stock_dict['high'] = float(row[2])  # 最高价格
            stock_dict['low'] = float(row[3])  # 最低价格
            stock_dict['close'] = float(row[4])  # 结束价格
            stock_dict['volume'] = float(row[5])  # 量
            stock_dict['adj_close'] = float(row[6])  # 几日收盘加权价格?
            yield stock_dict
Exemplo n.º 9
0
def getStockMonthHistory(code, market, type=''):
    """
    http://qd.10jqka.com.cn/api.php?p=stock_month&info=k_sz_000671&fq=
    """
    url = "http://qd.10jqka.com.cn/api.php?p=stock_month&info=k_%s_%s&fq=%s" % (market, code, type)
    content = httpGetContent(url)
    if content:
        pass
Exemplo n.º 10
0
def getStockMonthHistory(code, market, type=''):
    """
    http://qd.10jqka.com.cn/api.php?p=stock_month&info=k_sz_000671&fq=
    """
    url = "http://qd.10jqka.com.cn/api.php?p=stock_month&info=k_%s_%s&fq=%s" % (market, code, type)
    content = httpGetContent(url)
    if content:
        pass
Exemplo n.º 11
0
def getStockWeekHistory(code, market, year='2012,2013', type=''):
    """
    xhttp://qd.10jqka.com.cn/api.php?p=stock_week&info=k_sz_000005&year=2011,2012,2013&fq=
    pass
    """
    url = "http://qd.10jqka.com.cn/api.php?p=stock_week&info=k_%s_%s&year=%s&fq=%s" % (market, code, year, type )
    content = httpGetContent(url, tonghuashun_headers)
    if content:
        return __convert_week(content)
Exemplo n.º 12
0
def getStockWeekHistory(code, market, year='2012,2013', type=''):
    """
    xhttp://qd.10jqka.com.cn/api.php?p=stock_week&info=k_sz_000005&year=2011,2012,2013&fq=
    pass
    """
    url = "http://qd.10jqka.com.cn/api.php?p=stock_week&info=k_%s_%s&year=%s&fq=%s" % (market, code, year, type )
    content = httpGetContent(url, tonghuashun_headers)
    if content:
        return __convert_week(content)
Exemplo n.º 13
0
def stock_industry():
    """
    @注意该股票会包含部分st股票,但是实际选股票数据不会包含st股票数据
    得到股票的板块历史数据信息
    http://q.10jqka.com.cn/stock/thshy/
    http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/1/quote/quote
    """
    url = (
        'http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/1/quote/quote',
        'http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/2/quote/quote')
    for u in url:
        content = httpGetContent(u)
        if content:
            json_stock = json.loads(content)
            industry_list = json_stock['data']
            for industry in industry_list:
                num = int(industry['num'])
                industry_str = industry['hycode']

                industry_dict = {}
                industry_dict['industry_id'] = industry['platecode']
                industry_dict['industry_str'] = industry_str
                industry_dict['name'] = industry['platename']
                industry_dict['num'] = num

                #/用于处理判定数量的请求信息
                if num / 50 >= 1:
                    url_no = [n for n in range(1, num / 50 + 2)]
                elif num / 50 == 0 or num == 50:
                    url_no = [1]
                industry_url_list = ['http://q.10jqka.com.cn/interface/stock/detail/zdf/desc/%s/1/%s' \
                                     % (i, industry_str) for i in url_no]
                code_list = []
                for industry_url in industry_url_list:
                    industry_content = httpGetContent(industry_url)
                    if industry_content:
                        stock_dict = json.loads(industry_content)
                        stock_list = stock_dict['data']
                        for n in stock_list:
                            code_list.append(n['stockcode'])
                industry_dict['stock'] = code_list
                yield industry_dict
Exemplo n.º 14
0
def getStock15MIN(code, market, type=''):
    """
    15分钟数据接口
    http://qd.10jqka.com.cn/api.php?p=stock_min15&info=k_sz_000005&fq=
    """
    if market not in ('sz', 'sh'):
        return
    url = "http://qd.10jqka.com.cn/api.php?p=stock_min15&info=k_%s_%s&fq=%s" % (market, code, type)
    content = httpGetContent(url=url)
    if content:
        return __convert_MIN(content)
Exemplo n.º 15
0
def getStock15MIN(code, market, type=''):
    """
    15分钟数据接口
    http://qd.10jqka.com.cn/api.php?p=stock_min15&info=k_sz_000005&fq=
    """
    if market not in ('sz', 'sh'):
        return
    url = "http://qd.10jqka.com.cn/api.php?p=stock_min15&info=k_%s_%s&fq=%s" % (market, code, type)
    content = httpGetContent(url=url)
    if content:
        return __convert_MIN(content)
Exemplo n.º 16
0
def getStockDayHistory(code, market, year='2013', type=''):
    """
    http://qd.10jqka.com.cn/api.php?p=stock_day&info=k_sz_000005&year=2012,2013&fq=
    sz:深证
    sh:上海
    return dict
    """
    url = "http://qd.10jqka.com.cn/api.php?p=stock_day&info=k_%s_%s&year=%s&fq=%s" % (market, code, year, type)
    content = httpGetContent(url=url)
    if content:
        return __convert_day(content)
Exemplo n.º 17
0
def getStockDayHistory(code, market, year='2013', type=''):
    """
    http://qd.10jqka.com.cn/api.php?p=stock_day&info=k_sz_000005&year=2012,2013&fq=
    sz:深证
    sh:上海
    return dict
    """
    url = "http://qd.10jqka.com.cn/api.php?p=stock_day&info=k_%s_%s&year=%s&fq=%s" % (market, code, year, type)
    content = httpGetContent(url=url)
    if content:
        return __convert_day(content)
Exemplo n.º 18
0
def stock_industry():
    """
    @注意该股票会包含部分st股票,但是实际选股票数据不会包含st股票数据
    得到股票的板块历史数据信息
    http://q.10jqka.com.cn/stock/thshy/
    http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/1/quote/quote
    """
    url = ('http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/1/quote/quote',
           'http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/2/quote/quote')
    for u in url:
        content = httpGetContent(u)
        if content:
            json_stock = json.loads(content)
            industry_list = json_stock['data']
            for industry in industry_list:
                num = int(industry['num'])
                industry_str = industry['hycode']

                industry_dict = {}
                industry_dict['industry_id'] = industry['platecode']
                industry_dict['industry_str'] = industry_str
                industry_dict['name'] = industry['platename']
                industry_dict['num'] = num

                #/用于处理判定数量的请求信息
                if num / 50 >= 1:
                    url_no = [n for n in range(1, num / 50 + 2)]
                elif num / 50 == 0 or num == 50:
                    url_no = [1]
                industry_url_list = ['http://q.10jqka.com.cn/interface/stock/detail/zdf/desc/%s/1/%s' \
                                     % (i, industry_str) for i in url_no]
                code_list = []
                for industry_url in industry_url_list:
                    industry_content = httpGetContent(industry_url)
                    if industry_content:
                        stock_dict = json.loads(industry_content)
                        stock_list = stock_dict['data']
                        for n in stock_list:
                            code_list.append(n['stockcode'])
                industry_dict['stock'] = code_list
                yield industry_dict
Exemplo n.º 19
0
def stock_day_history_sina(stock_code, year, qr):
    """
    stockcode:股票代码
    market:市场
    year:2013
    qr:季度1,2,3,4格式
    货的股票历史数据
    返回数据格式
    日期2013-03-29
    开盘:10.030
    最高:10.210
    停盘:10.130
    最低9.910
    数据量131028760
    价格:1315731584
    API:http://money.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/600000.phtml?year=2013&jidu=1
    """
    #todo 没有复权价格


    url = "http://money.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/%s.phtml?year=%s&jidu=%s" \
          % (stock_code, year, qr)
    content = httpGetContent(url=url)
    if content:
        soap = BeautifulSoup(content)
        table = soap.select('table#FundHoldSharesTable>tbody')
        if table:
            tr_list = table[0].select('tr')
            for i, tr in enumerate(tr_list):
                stock = {}
                if i == 0 or i == 1:
                    continue
                td_list = tr.select('td')

                for j, td in enumerate(td_list):
                    if j == 0:  #日期
                        stock['date'] = td.div.a.text
                    elif j == 1:  #开盘价格
                        stock['start'] = float(td.div.text)
                    elif j == 2:  #
                        stock['high'] = float(td.div.text)
                    elif j == 3:
                        stock['end'] = float(td.div.text)
                    elif j == 4:
                        stock['low'] = float(td.div.text)
                    elif j == 5:
                        stock['rate'] = int(round(int(td.div.text) / 100.0, 0))
                    elif j == 6:
                        stock['money'] = int(
                            round(int(td.div.text) / 10000.0, 0))
                yield stock
Exemplo n.º 20
0
def stock_day_history_sina(stock_code, year, qr):
    """
    stockcode:股票代码
    market:市场
    year:2013
    qr:季度1,2,3,4格式
    货的股票历史数据
    返回数据格式
    日期2013-03-29
    开盘:10.030
    最高:10.210
    停盘:10.130
    最低9.910
    数据量131028760
    价格:1315731584
    API:http://money.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/600000.phtml?year=2013&jidu=1
    """
    #todo 没有复权价格


    url = "http://money.finance.sina.com.cn/corp/go.php/vMS_MarketHistory/stockid/%s.phtml?year=%s&jidu=%s" \
          % (stock_code, year, qr)
    content = httpGetContent(url=url)
    if content:
        soap = BeautifulSoup(content)
        table = soap.select('table#FundHoldSharesTable>tbody')
        if table:
            tr_list = table[0].select('tr')
            for i, tr in enumerate(tr_list):
                stock = {}
                if i == 0 or i == 1:
                    continue
                td_list = tr.select('td')

                for j, td in enumerate(td_list):
                    if j == 0: #日期
                        stock['date'] = td.div.a.text
                    elif j == 1: #开盘价格
                        stock['start'] = float(td.div.text)
                    elif j == 2: #
                        stock['high'] = float(td.div.text)
                    elif j == 3:
                        stock['end'] = float(td.div.text)
                    elif j == 4:
                        stock['low'] = float(td.div.text)
                    elif j == 5:
                        stock['rate'] = int(round(int(td.div.text) / 100.0, 0))
                    elif j == 6:
                        stock['money'] = int(round(int(td.div.text) / 10000.0, 0))
                yield stock
Exemplo n.º 21
0
def getStockCashFlow(code, market):
    """得到股票是资金流入流出
    http://qt.gtimg.cn/q=ff_sz000858
    v_ff_sz000858="sz000858~41773.67~48096.67~-6322.99~-5.53~10200.89~14351.02~-4150.13~-3.63~114422.25~53015.90~59770.57~五 粮 液~20121221";
    以 ~ 分割字符串中内容,下标从0开始,依次为:
     0: 代码
     1: 主力流入
     2: 主力流出
     3: 主力净流入
     4: 主力净流入/资金流入流出总和
     5: 散户流入
     6: 散户流出
     7: 散户净流入
     8: 散户净流入/资金流入流出总和
     9: 资金流入流出总和1+2+5+6
    10: 未知
    11: 未知
    12: 名字
    13: 日期
    """
    if code and market:
        url = "http://qt.gtimg.cn/q=ff_%s%s" % (market, code)
        content = httpGetContent(url)
        if content:
            result_list = _get_content(content)
            if result_list:
                stock_dict = {}
                stock_dict["code"] = code
                stock_dict["main_inflow"] = float(result_list[1])  # 主力流入
                stock_dict["main_outflow"] = float(result_list[2])  # 主力流出
                stock_dict["main_netflow"] = float(result_list[3])  # 主力净流入

                stock_dict["small_inflow"] = float(result_list[5])  # 散户流入
                stock_dict["small_outflow"] = float(result_list[6])  # 散户流出
                stock_dict["small_netflow"] = float(result_list[7])  # 散户净流入

                income = stock_dict["main_inflow"] + stock_dict["small_inflow"]
                outcome = stock_dict["main_outflow"] + stock_dict[
                    "main_outflow"]
                print income
                print outcome
                print income - outcome

                stock_dict["unknown_1"] = float(result_list[10])
                stock_dict["unknwon_2"] = float(result_list[11])
                stock_dict["date"] = result_list[13]  # 日期

                return stock_dict
Exemplo n.º 22
0
def stock_base_info(code):
    """
    得到股票其他的基础数据信息
    包含:
    pe_trands 市盈率(动态):47.98
    type 分类 :big(大盘股)medium (中盘股)small(小盘股)
    pe_static 市盈率(静态):8.61
    total_capital 总股本 44.7亿股
    ciculate_capital 流通股本 44.7亿股
    pb 市净率 1.24

    """
    url = "http://basic.10jqka.com.cn/%s/" % code
    content = httpGetContent(url)
    if content:
        stock_dict = {}
        soup = BeautifulSoup(content)
        profile = soup.select('div#profile')
        table = profile[0].select('table')[1]
        td_list = table.select('td')
        td_select = lambda td: td.select('span')[1].text
        # regex = re.compile(r'^([0-9]{1,}[.][0-9]*|-[0-9]{1,}[.][0-9]*|\d+|-\d+)')
        # find = lambda value: float(re.findall(regex, value)[0]) if re.findall(regex, value) else None
        stock_dict["code"] = code
        for i, td in enumerate(td_list):
            if i == 0:  # 市盈率(动态):
                stock_dict["pe_ratio_dynamic"] = validate_decimal(
                    td_select(td))
            elif i == 3:  # 分类
                text = td_select(td)
                if text == u"大盘股":
                    stock_dict['type'] = 'big'
                elif text == u'中盘股':
                    stock_dict['type'] = 'medium'
                elif text == u"小盘股":
                    stock_dict['type'] = 'small'
                else:
                    stock_dict['type'] = text
            elif i == 4:  # 市盈率(静态)
                stock_dict['pe_ratio_static'] = validate_decimal(td_select(td))
            elif i == 7:  # 总股本
                stock_dict['total_capital'] = validate_decimal(td_select(td))
            elif i == 8:  # 市净率
                stock_dict['pb'] = validate_decimal(td_select(td))
            elif i == 11:  # 流通股本
                stock_dict['circulate_capital'] = validate_decimal(
                    td_select(td))
        return stock_dict
Exemplo n.º 23
0
def getStockCashFlow(code, market):
    """得到股票是资金流入流出
    http://qt.gtimg.cn/q=ff_sz000858
    v_ff_sz000858="sz000858~41773.67~48096.67~-6322.99~-5.53~10200.89~14351.02~-4150.13~-3.63~114422.25~53015.90~59770.57~五 粮 液~20121221";
    以 ~ 分割字符串中内容,下标从0开始,依次为:
     0: 代码
     1: 主力流入
     2: 主力流出
     3: 主力净流入
     4: 主力净流入/资金流入流出总和
     5: 散户流入
     6: 散户流出
     7: 散户净流入
     8: 散户净流入/资金流入流出总和
     9: 资金流入流出总和1+2+5+6
    10: 未知
    11: 未知
    12: 名字
    13: 日期
    """
    if code and market:
        url = "http://qt.gtimg.cn/q=ff_%s%s" % (market, code)
        content = httpGetContent(url)
        if content:
            result_list = _get_content(content)
            if result_list:
                stock_dict = {}
                stock_dict["code"] = code
                stock_dict["main_inflow"] = float(result_list[1])   # 主力流入
                stock_dict["main_outflow"] = float(result_list[2])  # 主力流出
                stock_dict["main_netflow"] = float(result_list[3])  # 主力净流入

                stock_dict["small_inflow"] = float(result_list[5])  # 散户流入
                stock_dict["small_outflow"] = float(result_list[6]) # 散户流出
                stock_dict["small_netflow"] = float(result_list[7]) # 散户净流入

                income = stock_dict["main_inflow"] + stock_dict["small_inflow"]
                outcome = stock_dict["main_outflow"] + stock_dict["main_outflow"]
                print income
                print outcome
                print income - outcome

                stock_dict["unknown_1"] = float(result_list[10])
                stock_dict["unknwon_2"] = float(result_list[11])
                stock_dict["date"] = result_list[13]                # 日期

                return stock_dict
Exemplo n.º 24
0
def stock_finical_quarter(code):
    """
    通过同花顺行业数据得到数据报告信息。
    指标\日期	  基本每股收益	摊薄每股收益	每股净资产	每股现金流	每股未分配利润	每股公积金	主营收入	 利润总额	     净利润	 净资产收益率	销售毛利率	主营收入同比增长率	净利润同比增长率
    2013-3-31	0.04	      0.04	       5.33	      -0.68	       2.66	          1.37	    425230.9 37821.37	18722.95	0.79	26.43	143.93	19.68
    http://basic.10jqka.com.cn/600383/xls/Important_declaredate.xls"
    """
    url = "http://basic.10jqka.com.cn/%s/xls/Important_declaredate.xls" % (
        code)
    content = httpGetContent(url)
    stock_dict = {}
    if content:
        content = content.decode('gb2312').encode('utf8')
        data = cStringIO.StringIO(content)
        for i, line in enumerate(data):
            if i == 1:
                item = line.strip('\n').split('\t')
                date = str_to_date(item[0], "%Y-%m-%d")  # 日期
                earnings = decimal(item[2])  # 摊薄每股收益(数据相对准确)不以基本每股收益为准 0.04
                net_asset_value = decimal(item[3])  # 每股净资产 5.33
                cash_flow = decimal(item[4])  # 每股现金流 -0.86
                profit_per_share = decimal(item[5])  # 每股未分配利润
                capital_fund = decimal(item[6])  # 每股公积金
                main_income = decimal(item[7])  # 主营业收入
                total_profit = decimal(item[8])  # 利润总额
                total_net_profit = decimal(item[9])  # 净利润
                return_on_asserts = decimal(item[10])  # 净资产收益率 0.79%
                income_rise = decimal(item[12])  # 主营业收入同比增长率 143.93%
                net_profit_rise = decimal(item[13])  # 净利润同比增长率 19.68%
                stock_dict = {
                    "code": code,
                    "date": date,
                    "earnings": earnings,
                    "net_asset_value": net_asset_value,
                    "cash_flow": cash_flow,
                    "return_on_asserts": return_on_asserts,
                    "income_rise": income_rise,
                    "net_profit_rise": net_profit_rise,
                    "profit_per_share": profit_per_share,
                    "capital_fund": capital_fund,
                    "main_income": main_income,
                    "total_profit": total_profit,
                    "total_net_profit": total_net_profit
                }
                break
    return stock_dict
Exemplo n.º 25
0
def stock_base_info(code):
    """
    得到股票其他的基础数据信息
    包含:
    pe_trands 市盈率(动态):47.98
    type 分类 :big(大盘股)medium (中盘股)small(小盘股)
    pe_static 市盈率(静态):8.61
    total_capital 总股本 44.7亿股
    ciculate_capital 流通股本 44.7亿股
    pb 市净率 1.24

    """
    url = "http://basic.10jqka.com.cn/%s/" % code
    content = httpGetContent(url)
    if content:
        stock_dict = {}
        soup = BeautifulSoup(content)
        profile = soup.select('div#profile')
        table = profile[0].select('table')[1]
        td_list = table.select('td')
        td_select = lambda td: td.select('span')[1].text
        # regex = re.compile(r'^([0-9]{1,}[.][0-9]*|-[0-9]{1,}[.][0-9]*|\d+|-\d+)')
        # find = lambda value: float(re.findall(regex, value)[0]) if re.findall(regex, value) else None
        stock_dict["code"] = code
        for i, td in enumerate(td_list):
            if i == 0:    # 市盈率(动态):
                stock_dict["pe_ratio_dynamic"] = validate_decimal(td_select(td))
            elif i == 3:  # 分类
                text = td_select(td)
                if text == u"大盘股":
                    stock_dict['type'] = 'big'
                elif text == u'中盘股':
                    stock_dict['type'] = 'medium'
                elif text == u"小盘股":
                    stock_dict['type'] = 'small'
                else:
                    stock_dict['type'] = text
            elif i == 4:  # 市盈率(静态)
                stock_dict['pe_ratio_static'] = validate_decimal(td_select(td))
            elif i == 7:  # 总股本
                stock_dict['total_capital'] = validate_decimal(td_select(td))
            elif i == 8:  # 市净率
                stock_dict['pb'] = validate_decimal(td_select(td))
            elif i == 11: # 流通股本
                stock_dict['circulate_capital'] = validate_decimal(td_select(td))
        return stock_dict
Exemplo n.º 26
0
def stock_finical_quarter(code):
    """
    通过同花顺行业数据得到数据报告信息。
    指标\日期	  基本每股收益	摊薄每股收益	每股净资产	每股现金流	每股未分配利润	每股公积金	主营收入	 利润总额	     净利润	 净资产收益率	销售毛利率	主营收入同比增长率	净利润同比增长率
    2013-3-31	0.04	      0.04	       5.33	      -0.68	       2.66	          1.37	    425230.9 37821.37	18722.95	0.79	26.43	143.93	19.68
    http://basic.10jqka.com.cn/600383/xls/Important_declaredate.xls"
    """
    url = "http://basic.10jqka.com.cn/%s/xls/Important_declaredate.xls" % (code)
    content = httpGetContent(url)
    stock_dict = {}
    if content:
        content = content.decode('gb2312').encode('utf8')
        data = cStringIO.StringIO(content)
        for i, line in enumerate(data):
            if i == 1:
                item = line.strip('\n').split('\t')
                date = str_to_date(item[0], "%Y-%m-%d")   # 日期
                earnings = decimal(item[2])               # 摊薄每股收益(数据相对准确)不以基本每股收益为准 0.04
                net_asset_value = decimal(item[3])        # 每股净资产 5.33
                cash_flow = decimal(item[4])              # 每股现金流 -0.86
                profit_per_share = decimal(item[5])       # 每股未分配利润
                capital_fund = decimal(item[6])           # 每股公积金
                main_income = decimal(item[7])            # 主营业收入
                total_profit = decimal(item[8])           # 利润总额
                total_net_profit = decimal(item[9])       # 净利润
                return_on_asserts = decimal(item[10])     # 净资产收益率 0.79%
                income_rise = decimal(item[12])           # 主营业收入同比增长率 143.93%
                net_profit_rise = decimal(item[13])       # 净利润同比增长率 19.68%
                stock_dict = {
                    "code": code,
                    "date": date,
                    "earnings": earnings,
                    "net_asset_value": net_asset_value,
                    "cash_flow": cash_flow,
                    "return_on_asserts": return_on_asserts,
                    "income_rise": income_rise,
                    "net_profit_rise": net_profit_rise,
                    "profit_per_share": profit_per_share,
                    "capital_fund": capital_fund,
                    "main_income": main_income,
                    "total_profit": total_profit,
                    "total_net_profit": total_net_profit
                }
                break
    return stock_dict
Exemplo n.º 27
0
def getStock60MIN(code, market, type=''):
    """
    不推荐向后复权
    得到股票60分钟数据线
    API接口数据
    http://qd.10jqka.com.cn/api.php?p=stock_min60&info=k_sz_000005&fq=q
    q是向前复权
    b事项后复权
    q= 空是不复权
    """
    if market not in ('sz', 'sh'):
        return

    url = "http://qd.10jqka.com.cn/api.php?p=stock_min60&info=k_%s_%s&fq=%s" % (market, code, type)

    content = httpGetContent(url=url)
    if content:
        return __convert_MIN(content)
Exemplo n.º 28
0
def getStock60MIN(code, market, type=''):
    """
    不推荐向后复权
    得到股票60分钟数据线
    API接口数据
    http://qd.10jqka.com.cn/api.php?p=stock_min60&info=k_sz_000005&fq=q
    q是向前复权
    b事项后复权
    q= 空是不复权
    """
    if market not in ('sz', 'sh'):
        return

    url = "http://qd.10jqka.com.cn/api.php?p=stock_min60&info=k_%s_%s&fq=%s" % (market, code, type)

    content = httpGetContent(url=url)
    if content:
        return __convert_MIN(content)
Exemplo n.º 29
0
def getStockCurrentDay(code, Market):
    '''
    获取股票当日数据
    腾讯API
    API地址:http://qt.gtimg.cn/q=sh600383
    sh:上海
    sz:深圳
    返回当天成交数据
    code:股票代码
    market:股票市场
    数据返回@return dict
    '''
    if code and Market:
        url = 'http://qt.gtimg.cn/q=%s%s' % (Market, code)
        headers = {'Content-type': 'application/x-javascript; charset=GBK'}
        result = httpGetContent(url=url, headers=headers, charset='gbk')
        if result:
            stocklist = _get_content(result)
            if stocklist:
                stockdict = {}
                stockdict['code'] = code  # 股票代码
                stockdict['name'] = unicode(stocklist[1], 'utf8')  # 股票名称
                stockdict['last_closing'] = float(stocklist[4])  # 昨日收盘价格
                stockdict['start'] = float(stocklist[5])  # 开盘价格
                stockdict['end'] = float(stocklist[3])  # 当前收盘价格(可以是当前价格)
                stockdict['high'] = float(stocklist[33])  # 最高价格
                stockdict['low'] = float(stocklist[34])  # 最低价格
                stockdict['buyvol'] = int(stocklist[7])  # 外盘 todo 数据对不上
                stockdict["sellvol"] = int(stocklist[8])  # 内盘 todo 数据对不上

                stockdict['range_price'] = float(stocklist[31])  # 涨跌价格
                stockdict['range_percent'] = float(stocklist[32])  # 涨跌比%

                stockdict['volume'] = int(stocklist[6])  # 成交量(手)
                stockdict['total_price'] = int(stocklist[37])  # 成交额(万元)
                stockdict['change_rate'] = decimal(stocklist[38])  # 换手率
                stockdict['pe'] = decimal(stocklist[39])  # 市盈率
                stockdict['swing'] = float(stocklist[43])  # 振幅

                stockdict['pb'] = float(stocklist[46])  # 股票市净率
                stockdict['date'] = stocklist[30][:8]  # 时间
                stockdict[
                    "block"] = False if stockdict["start"] else True  #股票是否停牌
                return stockdict
Exemplo n.º 30
0
def getStockCurrentDay(code, Market):
    '''
    获取股票当日数据
    腾讯API
    API地址:http://qt.gtimg.cn/q=sh600383
    sh:上海
    sz:深圳
    返回当天成交数据
    code:股票代码
    market:股票市场
    数据返回@return dict
    '''
    if code and Market:
        url = 'http://qt.gtimg.cn/q=%s%s' % (Market, code)
        headers = {'Content-type': 'application/x-javascript; charset=GBK'}
        result = httpGetContent(url=url, headers=headers, charset='gbk')
        if result:
            stocklist = _get_content(result)
            if stocklist:
                stockdict = {}
                stockdict['code'] = code                           # 股票代码
                stockdict['name'] = unicode(stocklist[1], 'utf8')  # 股票名称
                stockdict['last_closing'] = float(stocklist[4])    # 昨日收盘价格
                stockdict['start'] = float(stocklist[5])           # 开盘价格
                stockdict['end'] = float(stocklist[3])             # 当前收盘价格(可以是当前价格)
                stockdict['high'] = float(stocklist[33])           # 最高价格
                stockdict['low'] = float(stocklist[34])            # 最低价格
                stockdict['buyvol'] = int(stocklist[7])             # 外盘 todo 数据对不上
                stockdict["sellvol"] = int(stocklist[8])           # 内盘 todo 数据对不上

                stockdict['range_price'] = float(stocklist[31])    # 涨跌价格
                stockdict['range_percent'] = float(stocklist[32])  # 涨跌比%

                stockdict['volume'] = int(stocklist[6])            # 成交量(手)
                stockdict['total_price'] = int(stocklist[37])      # 成交额(万元)
                stockdict['change_rate'] = decimal(stocklist[38]) # 换手率
                stockdict['pe'] = decimal(stocklist[39])          # 市盈率
                stockdict['swing'] = float(stocklist[43])           # 振幅

                stockdict['pb'] = float(stocklist[46])              # 股票市净率
                stockdict['date'] = stocklist[30][:8]               # 时间
                stockdict["block"] = False if stockdict["start"] else True #股票是否停牌
                return stockdict
Exemplo n.º 31
0
def stock_finical_post():
    """抓取同花顺业绩公告板块
    http://data.10jqka.com.cn/financial/yjgg/
    http://data.10jqka.com.cn/financial/yjgg/page/56/ajax/1/
    """
    headers = {
        "Host": "data.10jqka.com.cn",
        "Referer": "http://data.10jqka.com.cn/financial/yjyg/",
        "X-Requested-With": "XMLHttpRequest"
    }
    count = range(1, 60)
    urls = [
        "http://data.10jqka.com.cn/financial/yjgg/page/%s/ajax/1/" % num
        for num in count
    ]
    for url in urls:
        content = httpGetContent(url, headers, "gb2312")
        if content:
            soup = BeautifulSoup(content)
            stock_item = soup.select("tbody > tr")
            for item in stock_item:
                tds = item.select('td')
                stock_dict = {}
                for i, td in enumerate(tds):
                    if i == 1:  # 代码
                        stock_dict["code"] = td.select('a')[0].string
                    elif i == 3:  # 日期
                        stock_dict["date"] = str_to_date(td.string, "%Y-%m-%d")
                    elif i == 4:  # 每股收益
                        stock_dict["earnings"] = decimal(td.string)
                    elif i == 5:  # 营业收入
                        stock_dict["main_income"] = decimal(td.string)
                    elif i == 6:  # 营业收入同比增长%
                        stock_dict["income_rise"] = validate_decimal(td.string)
                    elif i == 7:  # 净利润 万元
                        stock_dict["net_profit"] = decimal(td.string)
                    elif i == 8:  #净利润同比增长%
                        stock_dict["net_profit_rise"] = validate_decimal(
                            td.string)
                yield stock_dict
Exemplo n.º 32
0
def stock_finical_post():
    """抓取同花顺业绩公告板块
    http://data.10jqka.com.cn/financial/yjgg/
    http://data.10jqka.com.cn/financial/yjgg/page/56/ajax/1/
    """
    headers = {
        "Host": "data.10jqka.com.cn",
        "Referer": "http://data.10jqka.com.cn/financial/yjyg/",
        "X-Requested-With": "XMLHttpRequest"
    }
    count = range(1, 60)
    urls = ["http://data.10jqka.com.cn/financial/yjgg/page/%s/ajax/1/" % num for num in count]
    for url in urls:
        content = httpGetContent(url, headers, "gb2312")
        if content:
            soup = BeautifulSoup(content)
            stock_item = soup.select("tbody > tr")
            for item in stock_item:
                tds = item.select('td')
                stock_dict = {}
                for i, td in enumerate(tds):
                    if i == 1:   # 代码
                        stock_dict["code"] = td.select('a')[0].string
                    elif i == 3: # 日期
                        stock_dict["date"] = str_to_date(td.string, "%Y-%m-%d")
                    elif i == 4: # 每股收益
                        stock_dict["earnings"] = decimal(td.string)
                    elif i == 5: # 营业收入
                        stock_dict["main_income"] = decimal(td.string)
                    elif i == 6: # 营业收入同比增长%
                        stock_dict["income_rise"] = validate_decimal(td.string)
                    elif i == 7: # 净利润 万元
                        stock_dict["net_profit"] = decimal(td.string)
                    elif i == 8: #净利润同比增长%
                        stock_dict["net_profit_rise"] = validate_decimal(td.string)
                yield stock_dict
Exemplo n.º 33
0
def stock_base_info(code):
    """
    得到股票其他的基础数据信息
    包含:
    pe_trands 市盈率(动态):47.98
    type 分类 :big(大盘股)medium (中盘股)small(小盘股)
    pe_static 市盈率(静态):8.61
    total_capital 总股本 44.7亿股
    ciculate_capital 流通股本 44.7亿股
    pb 市净率 1.24

    """
    url = "http://basic.10jqka.com.cn/%s/" % code
    content = httpGetContent(url)
    if content:
        stock_dict = {}
        soup = BeautifulSoup(content)
        profile = soup.select('div#profile')

        table = profile[0].select('table')[0]
        td_list = table.select('td')
        td_select_key = lambda td: td.select('span')[0].text.strip().replace(
            '\t', '')
        td_select_value = lambda td: td.select('span')[1].text.strip().replace(
            '\t', '')
        for i, td in enumerate(td_list):
            #print td_select_key(td), td_select_value(td)
            #stock_dict[td_select_key(td)] = td_select_value(td)
            if i == 0:  # 主营业务:
                stock_dict["main_busyness"] = td_select_value(td)
            elif i == 1:  # 所属行业:
                stock_dict["industry"] = td_select_value(td)
            elif i == 2:  # 涉及概念:
                stock_dict["concept"] = td_select_value(td)

        table = profile[0].select('table')[1]
        td_list = table.select('td')
        td_select_key = lambda td: td.select('span')[0].text.strip().replace(
            '\t', '')
        #td_select_value = lambda td: td.select('span')[1].text.strip().replace('\t','')
        td_select = lambda td: td.select('span')[1].text.strip().replace(
            '\t', '')
        for i, td in enumerate(td_list):
            #print td_select_key(td), td_select_value(td)
            #stock_dict[td_select_key(td)] = td_select_value(td)
            stock_dict["code"] = code
            if i == 0:  # 市盈率(动态):
                stock_dict["pe_ratio_dynamic"] = validate_decimal(
                    td_select(td))
            elif i == 2:  # 净资产收益率
                stock_dict['return_on_equity'] = validate_decimal(
                    td_select(td))
            elif i == 3:  # 分类
                text = td_select(td)
                if text == u"大盘股":
                    stock_dict['type'] = 'big'
                elif text == u'中盘股':
                    stock_dict['type'] = 'medium'
                elif text == u"小盘股":
                    stock_dict['type'] = 'small'
                else:
                    stock_dict['type'] = text
            elif i == 4:  # 市盈率(静态)
                stock_dict['pe_ratio_static'] = validate_decimal(td_select(td))
            elif i == 5:  # 营业收入
                stock_dict['income'] = validate_decimal(td_select(td))
            elif i == 6:  # 每股净资产
                stock_dict['assert_per_share'] = validate_decimal(
                    td_select(td))
            elif i == 7:  # 总股本
                stock_dict['total_capital'] = validate_decimal(td_select(td))
            elif i == 8:  # 市净率
                stock_dict['pb'] = validate_decimal(td_select(td))
            elif i == 9:  # 净利润
                stock_dict['net_profit'] = validate_decimal(td_select(td))
            elif i == 10:  # 每股现金流
                stock_dict['cash_flow_per_share'] = validate_decimal(
                    td_select(td))
            elif i == 11:  # 流通股本
                stock_dict['circulate_capital'] = validate_decimal(
                    td_select(td))

        #for item in stock_dict:
        #    print item, stock_dict[item]

        return stock_dict