不灭的焱

革命尚未成功,同志仍须努力

作者:php-note.com  发布于:2021-09-30 17:47  分类:Python数据采集分析  编辑

个股行情报价页面,如:雅化集团 http://quote.eastmoney.com/sz002497.html

1.【行情报价】

http://push2.eastmoney.com/api/qt/stock/get?ut=fa5fd1943c7b386f172d6893dbfba10b&invt=2&fltt=2&fields=f43,f57,f58,f169,f170,f46,f44,f51,f168,f47,f164,f163,f116,f60,f45,f52,f50,f48,f167,f117,f71,f161,f49,f530,f135,f136,f137,f138,f139,f141,f142,f144,f145,f147,f148,f140,f143,f146,f149,f55,f62,f162,f92,f173,f104,f105,f84,f85,f183,f184,f185,f186,f187,f188,f189,f190,f191,f192,f107,f111,f86,f177,f78,f110,f262,f263,f264,f267,f268,f250,f251,f252,f253,f254,f255,f256,f257,f258,f266,f269,f270,f271,f273,f274,f275,f127,f199,f128,f193,f196,f194,f195,f197,f80,f280,f281,f282,f284,f285,f286,f287,f292&secid=0.002497&_=1632995105757

// 返回字段解释

{
	"rc": 0,
	"rt": 4,
	"svr": 182993885,
	"lt": 1,
	"full": 1,
	"data": {
		"f43": 33.1,			// 最新价(元)
		"f44": 33.55,			// 最高价(元)
		"f45": 31.22,			// 最低价(元)
		"f46": 31.26,			// 开盘价(元)
		"f47": 705757,			// 总手数(手)
		"f48": 2303402672,		// 总金额(元)
		"f49": 371817,			// 外盘(手) 买入
		"f50": 0.98,			// 量比(%)
		"f51": 34.16,			// 涨停价(元)
		"f52": 27.95,			// 跌停价(元)
		"f55": 0.286424359,
		"f57": "002497",		// 股票代码
		"f58": "雅化集团",		// 股票名称
		"f60": 31.05,			// 昨天收盘价(元)
		"f62": 2,
		"f71": 32.64,			// 均价(元)
		"f78": 0,
		"f80": "[{\"b\":202109300930,\"e\":202109301130},{\"b\":202109301300,\"e\":202109301500}]",
		"f84": 1152562520,
		"f85": 1042248327,
		"f86": 1632987243,     // 分时时间戳,如:2021-09-30 15:34:03
		"f92": 4.9294981,
		"f104": 4081994890.16,
		"f105": 330121980.43,
		"f107": 0,
		"f110": 0,
		"f111": 6,
		"f116": 38149819412,
		"f117": 34498419623.700008,
		"f127": "化工行业",		// 所属行业
		"f128": "四川板块",		// 所属版块
		"f135": 1182999216,
		"f136": 1000536400,
		"f137": 182462816,		// 今日主力净流入(元)
		"f138": 410992880,		// 流入.超大单(元)
		"f139": 311475808,		// 流出.超大单(元)
		"f140": 99517072,		// 今日超大单净流入(元)
		"f141": 772006336,		// 流入.大单(元)
		"f142": 689060592,		// 流出.大单(元)
		"f143": 82945744,		// 今日大单净流入(元)
		"f144": 636076256,		// 流入.中单(元)
		"f145": 654104192,		// 流出.中单(元)
		"f146": -18027936,		// 今日中单净流入(元)
		"f147": 451481232,		// 流入.小单(元)
		"f148": 615916096,		// 流出.小单(元)
		"f149": -164434864,		// 今日小单净流入(元)
		"f161": 333940,			// 内盘(手) 卖出
		"f162": 57.78,			// 市盈率(动)
		"f163": 117.8,
		"f164": 73.02,
		"f167": 6.71,			// 市净率(%)
		"f168": 6.77,			// 换手率(%)
		"f169": 2.05,			// 涨跌
		"f170": 6.6,			// 涨跌幅(%)
		"f173": 6.09,			// ROE
		"f177": 1089,
		"f183": 2124437269.36,		// 【公司核心数据】总营收(元)
		"f184": 64.353693337,		// 【公司核心数据】总营收.同比(%)
		"f185": 151.009110738454,	// 【公司核心数据】净利润.同比(%)
		"f186": 32.6366068422,		// 【公司核心数据】毛利率(%)
		"f187": 16.726336094,		// 【公司核心数据】净利率(%)
		"f188": 21.4630459073,		// 【公司核心数据】负债率(%)
		"f189": 20101109,
		"f190": 1.571551713299,		// 【公司核心数据】每股未分配利润(元)
		"f191": 40.34,				// 【行情报价】委比
		"f192": 1479,				// 【行情报价】委差
		"f193": 7.92,				// 主力净比(%)
		"f194": 4.32,
		"f195": 3.6,
		"f196": -0.78,
		"f197": -7.14,
		"f199": 90,
		"f250": "-",
		"f251": "-",
		"f252": "-",
		"f253": "-",
		"f254": "-",
		"f255": 0,
		"f256": "-",
		"f257": 0,
		"f258": "-",
		"f262": "-",
		"f263": 0,
		"f264": "-",
		"f266": "-",
		"f267": "-",
		"f268": "-",
		"f269": "-",
		"f270": 0,
		"f271": "-",
		"f273": "-",
		"f274": "-",
		"f275": "-",
		"f280": "-",
		"f281": "-",
		"f282": "-",
		"f284": 0,
		"f285": "-",
		"f286": 0,
		"f287": "-",
		"f292": 5,
		"f31": 33.14,		// 卖五价格(元)
		"f32": 52,			// 卖五数量(手)
		"f33": 33.13,		// 卖四价格
		"f34": 118,			// 卖四数量
		"f35": 33.12,		// 卖三价格
		"f36": 307,			// 卖三数量
		"f37": 33.11,		// 卖二价格
		"f38": 128,			// 卖二数量
		"f39": 33.1,		// 卖一价格
		"f40": 489,			// 卖一数量
		"f19": 33.09,		// 买一价格
		"f20": 1300,		// 买一数量
		"f17": 33.08,		// 买二价格
		"f18": 897,			// 买二数量
		"f15": 33.07,		// 买三价格
		"f16": 56,			// 买三数量
		"f13": 33.06,		// 买四价格
		"f14": 32,			// 买四数量
		"f11": 33.05,		// 买五价格
		"f12": 288			// 买五数量
	}
}

用Python获取【股票行情】数据

from framework.utils.json_util import json_decode
from framework.utils.map_util import map_get
from framework.utils.stock_util import stock_get_jys
from framework.utils.string_util import string_random
from urllib.request import urlopen, Request

"""
东方财富网 数据接口
http://quote.eastmoney.com/sz002497.html
"""


class Eastmoney:
    @staticmethod
    def get_stock_secid(stock_code=''):
        """
        获取股票的secid
        :return:
        """
        jys = stock_get_jys(stock_code)
        if jys == 'sz':
            code = '0.' + stock_code
        else:
            code = '1.' + stock_code
        return code

    @staticmethod
    def get_realtime_quotes(stock_code='',
                            field=('f86,f43,f44,f45,f46,f47,f48,f51,f52,f60,f71,f170,'
                                   'f530,f31,f32,f33,f34,f35,f36,f37,f38,f39,f40,f19,f20,f17,f18,f15,f16,f13,f14,f11,f12')):
        """
        获取股票的“行情报价”
        http://push2.eastmoney.com/api/qt/stock/get?ut=fa5fd1943c7b386f172d6893dbfba10b&invt=2&fltt=2&fields=f43,f57,f58,f169,f170,f46,f44,f51,f168,f47,f164,f163,f116,f60,f45,f52,f50,f48,f167,f117,f71,f161,f49,f530,f135,f136,f137,f138,f139,f141,f142,f144,f145,f147,f148,f140,f143,f146,f149,f55,f62,f162,f92,f173,f104,f105,f84,f85,f183,f184,f185,f186,f187,f188,f189,f190,f191,f192,f107,f111,f86,f177,f78,f110,f262,f263,f264,f267,f268,f250,f251,f252,f253,f254,f255,f256,f257,f258,f266,f269,f270,f271,f273,f274,f275,f127,f199,f128,f193,f196,f194,f195,f197,f80,f280,f281,f282,f284,f285,f286,f287,f292&secid=0.002497&_=1632995105757
        :param stock_code: 股票代码
        :param field: 查询字段
                     【特别注意】如果要返回“五档交易数据”,就必须传入字段 f530
        """
        code = Eastmoney.get_stock_secid(stock_code)
        url = 'http://push2.eastmoney.com/api/qt/stock/get?ut=fa5fd1943c7b386f172d6893dbfba10b&invt=2&fltt=2&secid=%s&fields=%s&_=%s' % (
            code, field, string_random())
        try:
            re = Request(url)
            lines = urlopen(re, timeout=10).read()
            info = json_decode(lines)
            return map_get(info, 'data', [])
        except Exception as e:
            print(e)
            return {}

2.【行情中心】

http://quote.eastmoney.com/center/gridlist.html#hs_a_board

3.【自选股】

http://quote.eastmoney.com/zixuan/?from=quotecenter

基于 长连接 推送自选股票信息

https://88.push2.eastmoney.com/api/qt/ulist/sse?invt=3&pi=0&pz=12&mpi=2000&secids=1.600703,1.600720,0.000422,0.002396,1.600590,1.000001,0.002127,0.002162,0.000999,1.601985,1.688658,1.688169&ut=6d2ffaa6a585d612eda28417681d58fb&fields=f12,f13,f19,f14,f139,f148,f2,f4,f1,f125,f18,f3,f152,f5,f30,f31,f32,f6,f8,f7,f10,f22,f9,f112,f100,f102,f103,f15,f16,f17,f62,f63,f64,f65,f66,f69,f70,f71,f72,f75,f76,f77,f78,f81,f82,f83,f84,f87,f88,f153,f89,f90,f91,f92,f94,f95,f97,f98,f99,f38,f39,f36,f113,f37,f40,f41,f42,f43,f44,f45,f46,f47,f48,f49,f50,f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f26&po=1