modify src dir.
This commit is contained in:
0
stockapp/src/crawling/__init__.py
Normal file
0
stockapp/src/crawling/__init__.py
Normal file
360
stockapp/src/crawling/fund_etf_em.py
Normal file
360
stockapp/src/crawling/fund_etf_em.py
Normal file
@ -0,0 +1,360 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding:utf-8 -*-
|
||||
"""
|
||||
Date: 2023/1/4 12:18
|
||||
Desc: 东方财富-ETF 行情
|
||||
https://quote.eastmoney.com/sh513500.html
|
||||
"""
|
||||
from functools import lru_cache
|
||||
|
||||
import pandas as pd
|
||||
import requests
|
||||
|
||||
|
||||
def fund_etf_spot_em() -> pd.DataFrame:
|
||||
"""
|
||||
东方财富-ETF 实时行情
|
||||
https://quote.eastmoney.com/center/gridlist.html#fund_etf
|
||||
:return: ETF 实时行情
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "http://88.push2.eastmoney.com/api/qt/clist/get"
|
||||
params = {
|
||||
"pn": "1",
|
||||
"pz": "2000",
|
||||
"po": "1",
|
||||
"np": "1",
|
||||
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
|
||||
"fltt": "2",
|
||||
"invt": "2",
|
||||
"wbp2u": "|0|0|0|web",
|
||||
"fid": "f3",
|
||||
"fs": "b:MK0021,b:MK0022,b:MK0023,b:MK0024",
|
||||
"fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
|
||||
"_": "1672806290972",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["data"]["diff"])
|
||||
temp_df.rename(
|
||||
columns={
|
||||
"f12": "代码",
|
||||
"f14": "名称",
|
||||
"f2": "最新价",
|
||||
"f3": "涨跌幅",
|
||||
"f4": "涨跌额",
|
||||
"f5": "成交量",
|
||||
"f6": "成交额",
|
||||
"f17": "开盘价",
|
||||
"f15": "最高价",
|
||||
"f16": "最低价",
|
||||
"f18": "昨收",
|
||||
"f8": "换手率",
|
||||
"f21": "流通市值",
|
||||
"f20": "总市值",
|
||||
},
|
||||
inplace=True,
|
||||
)
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"代码",
|
||||
"名称",
|
||||
"最新价",
|
||||
"涨跌幅",
|
||||
"涨跌额",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"开盘价",
|
||||
"最高价",
|
||||
"最低价",
|
||||
"昨收",
|
||||
"换手率",
|
||||
"流通市值",
|
||||
"总市值",
|
||||
]
|
||||
]
|
||||
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce")
|
||||
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
|
||||
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce")
|
||||
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
|
||||
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
|
||||
temp_df["开盘价"] = pd.to_numeric(temp_df["开盘价"], errors="coerce")
|
||||
temp_df["最高价"] = pd.to_numeric(temp_df["最高价"], errors="coerce")
|
||||
temp_df["最低价"] = pd.to_numeric(temp_df["最低价"], errors="coerce")
|
||||
temp_df["昨收"] = pd.to_numeric(temp_df["昨收"], errors="coerce")
|
||||
temp_df["换手率"] = pd.to_numeric(temp_df["换手率"], errors="coerce")
|
||||
temp_df["流通市值"] = pd.to_numeric(temp_df["流通市值"], errors="coerce")
|
||||
temp_df["总市值"] = pd.to_numeric(temp_df["总市值"], errors="coerce")
|
||||
return temp_df
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def _fund_etf_code_id_map_em() -> dict:
|
||||
"""
|
||||
东方财富-ETF 代码和市场标识映射
|
||||
https://quote.eastmoney.com/center/gridlist.html#fund_etf
|
||||
:return: ETF 代码和市场标识映射
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "http://88.push2.eastmoney.com/api/qt/clist/get"
|
||||
params = {
|
||||
"pn": "1",
|
||||
"pz": "5000",
|
||||
"po": "1",
|
||||
"np": "1",
|
||||
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
|
||||
"fltt": "2",
|
||||
"invt": "2",
|
||||
"wbp2u": "|0|0|0|web",
|
||||
"fid": "f3",
|
||||
"fs": "b:MK0021,b:MK0022,b:MK0023,b:MK0024",
|
||||
"fields": "f12,f13",
|
||||
"_": "1672806290972",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["data"]["diff"])
|
||||
temp_dict = dict(zip(temp_df["f12"], temp_df["f13"]))
|
||||
return temp_dict
|
||||
|
||||
def fund_etf_hist_em(
|
||||
symbol: str = "159707",
|
||||
period: str = "daily",
|
||||
start_date: str = "19700101",
|
||||
end_date: str = "20500101",
|
||||
adjust: str = "",
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
东方财富-ETF 行情
|
||||
https://quote.eastmoney.com/sz159707.html
|
||||
:param symbol: ETF 代码
|
||||
:type symbol: str
|
||||
:param period: choice of {'daily', 'weekly', 'monthly'}
|
||||
:type period: str
|
||||
:param start_date: 开始日期
|
||||
:type start_date: str
|
||||
:param end_date: 结束日期
|
||||
:type end_date: str
|
||||
:param adjust: choice of {"qfq": "前复权", "hfq": "后复权", "": "不复权"}
|
||||
:type adjust: str
|
||||
:return: 每日行情
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
code_id_dict = _fund_etf_code_id_map_em()
|
||||
adjust_dict = {"qfq": "1", "hfq": "2", "": "0"}
|
||||
period_dict = {"daily": "101", "weekly": "102", "monthly": "103"}
|
||||
url = "http://push2his.eastmoney.com/api/qt/stock/kline/get"
|
||||
params = {
|
||||
"fields1": "f1,f2,f3,f4,f5,f6",
|
||||
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f116",
|
||||
"ut": "7eea3edcaed734bea9cbfc24409ed989",
|
||||
"klt": period_dict[period],
|
||||
"fqt": adjust_dict[adjust],
|
||||
"secid": f"{code_id_dict[symbol]}.{symbol}",
|
||||
"beg": start_date,
|
||||
"end": end_date,
|
||||
"_": "1623766962675",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
if not (data_json["data"] and data_json["data"]["klines"]):
|
||||
return pd.DataFrame()
|
||||
temp_df = pd.DataFrame([item.split(",") for item in data_json["data"]["klines"]])
|
||||
temp_df.columns = [
|
||||
"日期",
|
||||
"开盘",
|
||||
"收盘",
|
||||
"最高",
|
||||
"最低",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"振幅",
|
||||
"涨跌幅",
|
||||
"涨跌额",
|
||||
"换手率",
|
||||
]
|
||||
temp_df.index = pd.to_datetime(temp_df["日期"])
|
||||
temp_df.reset_index(inplace=True, drop=True)
|
||||
|
||||
temp_df["开盘"] = pd.to_numeric(temp_df["开盘"])
|
||||
temp_df["收盘"] = pd.to_numeric(temp_df["收盘"])
|
||||
temp_df["最高"] = pd.to_numeric(temp_df["最高"])
|
||||
temp_df["最低"] = pd.to_numeric(temp_df["最低"])
|
||||
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"])
|
||||
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"])
|
||||
temp_df["振幅"] = pd.to_numeric(temp_df["振幅"])
|
||||
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"])
|
||||
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"])
|
||||
temp_df["换手率"] = pd.to_numeric(temp_df["换手率"])
|
||||
return temp_df
|
||||
|
||||
|
||||
def fund_etf_hist_min_em(
|
||||
symbol: str = "159707",
|
||||
start_date: str = "1979-09-01 09:32:00",
|
||||
end_date: str = "2222-01-01 09:32:00",
|
||||
period: str = "5",
|
||||
adjust: str = "",
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
东方财富-ETF 行情
|
||||
https://quote.eastmoney.com/sz159707.html
|
||||
:param symbol: ETF 代码
|
||||
:type symbol: str
|
||||
:param start_date: 开始日期
|
||||
:type start_date: str
|
||||
:param end_date: 结束日期
|
||||
:type end_date: str
|
||||
:param period: choice of {'1', '5', '15', '30', '60'}
|
||||
:type period: str
|
||||
:param adjust: choice of {'', 'qfq', 'hfq'}
|
||||
:type adjust: str
|
||||
:return: 每日分时行情
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
code_id_dict = _fund_etf_code_id_map_em()
|
||||
adjust_map = {
|
||||
"": "0",
|
||||
"qfq": "1",
|
||||
"hfq": "2",
|
||||
}
|
||||
if period == "1":
|
||||
url = "https://push2his.eastmoney.com/api/qt/stock/trends2/get"
|
||||
params = {
|
||||
"fields1": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13",
|
||||
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58",
|
||||
"ut": "7eea3edcaed734bea9cbfc24409ed989",
|
||||
"ndays": "5",
|
||||
"iscr": "0",
|
||||
"secid": f"{code_id_dict[symbol]}.{symbol}",
|
||||
"_": "1623766962675",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(
|
||||
[item.split(",") for item in data_json["data"]["trends"]]
|
||||
)
|
||||
temp_df.columns = [
|
||||
"时间",
|
||||
"开盘",
|
||||
"收盘",
|
||||
"最高",
|
||||
"最低",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"最新价",
|
||||
]
|
||||
temp_df.index = pd.to_datetime(temp_df["时间"])
|
||||
temp_df = temp_df[start_date:end_date]
|
||||
temp_df.reset_index(drop=True, inplace=True)
|
||||
temp_df["开盘"] = pd.to_numeric(temp_df["开盘"])
|
||||
temp_df["收盘"] = pd.to_numeric(temp_df["收盘"])
|
||||
temp_df["最高"] = pd.to_numeric(temp_df["最高"])
|
||||
temp_df["最低"] = pd.to_numeric(temp_df["最低"])
|
||||
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"])
|
||||
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"])
|
||||
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"])
|
||||
temp_df["时间"] = pd.to_datetime(temp_df["时间"]).astype(str)
|
||||
return temp_df
|
||||
else:
|
||||
url = "http://push2his.eastmoney.com/api/qt/stock/kline/get"
|
||||
params = {
|
||||
"fields1": "f1,f2,f3,f4,f5,f6",
|
||||
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",
|
||||
"ut": "7eea3edcaed734bea9cbfc24409ed989",
|
||||
"klt": period,
|
||||
"fqt": adjust_map[adjust],
|
||||
"secid": f"{code_id_dict[symbol]}.{symbol}",
|
||||
"beg": "0",
|
||||
"end": "20500000",
|
||||
"_": "1630930917857",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(
|
||||
[item.split(",") for item in data_json["data"]["klines"]]
|
||||
)
|
||||
temp_df.columns = [
|
||||
"时间",
|
||||
"开盘",
|
||||
"收盘",
|
||||
"最高",
|
||||
"最低",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"振幅",
|
||||
"涨跌幅",
|
||||
"涨跌额",
|
||||
"换手率",
|
||||
]
|
||||
temp_df.index = pd.to_datetime(temp_df["时间"])
|
||||
temp_df = temp_df[start_date:end_date]
|
||||
temp_df.reset_index(drop=True, inplace=True)
|
||||
temp_df["开盘"] = pd.to_numeric(temp_df["开盘"])
|
||||
temp_df["收盘"] = pd.to_numeric(temp_df["收盘"])
|
||||
temp_df["最高"] = pd.to_numeric(temp_df["最高"])
|
||||
temp_df["最低"] = pd.to_numeric(temp_df["最低"])
|
||||
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"])
|
||||
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"])
|
||||
temp_df["振幅"] = pd.to_numeric(temp_df["振幅"])
|
||||
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"])
|
||||
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"])
|
||||
temp_df["换手率"] = pd.to_numeric(temp_df["换手率"])
|
||||
temp_df["时间"] = pd.to_datetime(temp_df["时间"]).astype(str)
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"时间",
|
||||
"开盘",
|
||||
"收盘",
|
||||
"最高",
|
||||
"最低",
|
||||
"涨跌幅",
|
||||
"涨跌额",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"振幅",
|
||||
"换手率",
|
||||
]
|
||||
]
|
||||
return temp_df
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
fund_etf_spot_em_df = fund_etf_spot_em()
|
||||
print(fund_etf_spot_em_df)
|
||||
|
||||
fund_etf_hist_hfq_em_df = fund_etf_hist_em(
|
||||
symbol="513500",
|
||||
period="daily",
|
||||
start_date="20000101",
|
||||
end_date="20230201",
|
||||
adjust="hfq",
|
||||
)
|
||||
print(fund_etf_hist_hfq_em_df)
|
||||
|
||||
fund_etf_hist_qfq_em_df = fund_etf_hist_em(
|
||||
symbol="513500",
|
||||
period="daily",
|
||||
start_date="20000101",
|
||||
end_date="20230201",
|
||||
adjust="qfq",
|
||||
)
|
||||
print(fund_etf_hist_qfq_em_df)
|
||||
|
||||
fund_etf_hist_em_df = fund_etf_hist_em(
|
||||
symbol="513500",
|
||||
period="daily",
|
||||
start_date="20000101",
|
||||
end_date="20230201",
|
||||
adjust="",
|
||||
)
|
||||
print(fund_etf_hist_em_df)
|
||||
|
||||
fund_etf_hist_min_em_df = fund_etf_hist_min_em(
|
||||
symbol="513500",
|
||||
period="5",
|
||||
adjust="hfq",
|
||||
start_date="2023-01-01 09:32:00",
|
||||
end_date="2023-01-04 14:40:00",
|
||||
)
|
||||
print(fund_etf_hist_min_em_df)
|
||||
139
stockapp/src/crawling/stock_cpbd.py
Normal file
139
stockapp/src/crawling/stock_cpbd.py
Normal file
@ -0,0 +1,139 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
# !/usr/bin/env python
|
||||
|
||||
import pandas as pd
|
||||
import requests
|
||||
import instock.core.tablestructure as tbs
|
||||
|
||||
__author__ = 'myh '
|
||||
__date__ = '2023/5/7 '
|
||||
|
||||
|
||||
|
||||
def stock_cpbd_em(symbol: str = "688041") -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-个股-操盘必读
|
||||
https://emweb.securities.eastmoney.com/PC_HSF10/OperationsRequired/Index?type=web&code=SH688041#
|
||||
:param symbol: 带市场标识的股票代码
|
||||
:type symbol: str
|
||||
:return: 操盘必读
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "https://emweb.securities.eastmoney.com/PC_HSF10/OperationsRequired/PageAjax"
|
||||
if symbol.startswith("6"):
|
||||
symbol = f"SH{symbol}"
|
||||
else:
|
||||
symbol = f"SZ{symbol}"
|
||||
params = {"code": symbol}
|
||||
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
zxzb = data_json["zxzb"] # 主要指标
|
||||
if len(zxzb) < 1:
|
||||
return None
|
||||
|
||||
data_dict = zxzb[0]
|
||||
zxzbOther = data_json["zxzbOther"] # 其它指标,计算出来
|
||||
if len(zxzbOther) > 0:
|
||||
zxzbOther = zxzbOther[0]
|
||||
data_dict = {**data_dict, **zxzbOther}
|
||||
|
||||
# zxzbhq = data_json["zxzbhq"] # 其它指标,计算出来
|
||||
# if len(zxzbhq) > 0:
|
||||
# data_dict = {**data_dict, **zxzbhq}
|
||||
|
||||
_ssbks = data_json["ssbk"] # 所属板块
|
||||
ssbk = None
|
||||
for s in _ssbks:
|
||||
_v = s.get('BOARD_NAME')
|
||||
if _v is not None:
|
||||
if ssbk is None:
|
||||
ssbk = f"{_v}"
|
||||
else:
|
||||
ssbk = f"{ssbk}、{_v}"
|
||||
data_dict["BOARD_NAME"] = ssbk
|
||||
|
||||
gdrs = data_json["gdrs"] # 股东分析
|
||||
if len(gdrs) > 0:
|
||||
gdrs = gdrs[0]
|
||||
data_dict = {**data_dict, **gdrs}
|
||||
|
||||
lhbd = data_json["lhbd"] # 龙虎榜单
|
||||
if len(lhbd) > 0:
|
||||
lhbd = lhbd[0]
|
||||
lhbd["LHBD_DATE"] = lhbd.pop("TRADE_DATE")
|
||||
data_dict = {**data_dict, **lhbd}
|
||||
|
||||
dzjy = data_json["dzjy"] # 大宗交易
|
||||
if len(dzjy) > 0:
|
||||
dzjy = dzjy[0]
|
||||
dzjy["DZJY_DATE"] = dzjy.pop("TRADE_DATE")
|
||||
data_dict = {**data_dict, **dzjy}
|
||||
|
||||
rzrq = data_json["rzrq"] # 融资融券
|
||||
if len(rzrq) > 0:
|
||||
rzrq = rzrq[0]
|
||||
rzrq["RZRQ_DATE"] = rzrq.pop("TRADE_DATE")
|
||||
data_dict = {**data_dict, **rzrq}
|
||||
|
||||
tbs.CN_STOCK_CPBD
|
||||
|
||||
|
||||
# temp_df["报告期"] = pd.to_datetime(temp_df["报告期"], errors="coerce").dt.date
|
||||
# temp_df["每股收益"] = pd.to_numeric(temp_df["每股收益"], errors="coerce")
|
||||
# temp_df["每股净资产"] = pd.to_numeric(temp_df["每股净资产"], errors="coerce")
|
||||
# temp_df["每股经营现金流"] = pd.to_numeric(temp_df["每股经营现金流"], errors="coerce")
|
||||
# temp_df["每股公积金"] = pd.to_numeric(temp_df["每股公积金"], errors="coerce")
|
||||
# temp_df["每股未分配利润"] = pd.to_numeric(temp_df["每股未分配利润"], errors="coerce")
|
||||
# temp_df["加权净资产收益率"] = pd.to_numeric(temp_df["加权净资产收益率"], errors="coerce")
|
||||
# temp_df["毛利率"] = pd.to_numeric(temp_df["毛利率"], errors="coerce")
|
||||
# temp_df["资产负债率"] = pd.to_numeric(temp_df["资产负债率"], errors="coerce")
|
||||
# temp_df["营业收入"] = pd.to_numeric(temp_df["营业收入"], errors="coerce")
|
||||
# temp_df["营业收入滚动环比增长"] = pd.to_numeric(temp_df["营业收入同比增长"], errors="coerce")
|
||||
# temp_df["营业收入同比增长"] = pd.to_numeric(temp_df["营业收入同比增长"], errors="coerce")
|
||||
# temp_df["归属净利润"] = pd.to_numeric(temp_df["归属净利润"], errors="coerce")
|
||||
# temp_df["归属净利润滚动环比增长"] = pd.to_numeric(temp_df["归属净利润滚动环比增长"], errors="coerce")
|
||||
# temp_df["归属净利润同比增长"] = pd.to_numeric(temp_df["归属净利润同比增长"], errors="coerce")
|
||||
# temp_df["扣非净利润"] = pd.to_numeric(temp_df["归属净利润"], errors="coerce")
|
||||
# temp_df["扣非净利润滚动环比增长"] = pd.to_numeric(temp_df["扣非净利润滚动环比增长"], errors="coerce")
|
||||
# temp_df["扣非净利润同比增长"] = pd.to_numeric(temp_df["扣非净利润同比增长"], errors="coerce")
|
||||
# temp_df["总股本"] = pd.to_numeric(temp_df["总股本"], errors="coerce")
|
||||
# temp_df["已流通股份"] = pd.to_numeric(temp_df["已流通股份"], errors="coerce")
|
||||
|
||||
|
||||
def stock_zjlx_em(symbol: str = "688041") -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-个股-资金流向
|
||||
https://data.eastmoney.com/zjlx/688041.html
|
||||
:param symbol: 带市场标识的股票代码
|
||||
:type symbol: str
|
||||
:return: 操盘必读
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "https://push2his.eastmoney.com/api/qt/stock/fflow/daykline/get"
|
||||
if symbol.startswith("6"):
|
||||
symbol = f"1.{symbol}"
|
||||
else:
|
||||
symbol = f"0.{symbol}"
|
||||
params = {
|
||||
"lmt": "0",
|
||||
"klt": "1",
|
||||
"fields1": "f1,f2,f3,f7",
|
||||
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f62,f63,f64,f65",
|
||||
"ut": "b2884a393a59ad64002292a3e90d46a5",
|
||||
"secid": symbol
|
||||
}
|
||||
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
klines = data_json["klines"] # 主要指标
|
||||
"日期","主力净流入额","小单净流入额","中单净流入额","大单净流入额","超大单净流入额","主力净流入占比", "小单净流入占比", "中单净流入占比", "大单净流入占比", "超大单净流入占比"
|
||||
"收盘价","涨跌幅"
|
||||
if len(klines) < 1:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
stock_cpbd_em_df = stock_cpbd_em(symbol="688041")
|
||||
print(stock_cpbd_em_df)
|
||||
535
stockapp/src/crawling/stock_dzjy_em.py
Normal file
535
stockapp/src/crawling/stock_dzjy_em.py
Normal file
@ -0,0 +1,535 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding:utf-8 -*-
|
||||
"""
|
||||
Date: 2022/5/16 15:31
|
||||
Desc: 东方财富网-数据中心-大宗交易-市场统计
|
||||
http://data.eastmoney.com/dzjy/dzjy_sctj.aspx
|
||||
"""
|
||||
import pandas as pd
|
||||
import requests
|
||||
|
||||
|
||||
def stock_dzjy_sctj() -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-大宗交易-市场统计
|
||||
http://data.eastmoney.com/dzjy/dzjy_sctj.aspx
|
||||
:return: 市场统计表
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
'sortColumns': 'TRADE_DATE',
|
||||
'sortTypes': '-1',
|
||||
'pageSize': '500',
|
||||
'pageNumber': '1',
|
||||
'reportName': 'PRT_BLOCKTRADE_MARKET_STA',
|
||||
'columns': 'TRADE_DATE,SZ_INDEX,SZ_CHANGE_RATE,BLOCKTRADE_DEAL_AMT,PREMIUM_DEAL_AMT,PREMIUM_RATIO,DISCOUNT_DEAL_AMT,DISCOUNT_RATIO',
|
||||
'source': 'WEB',
|
||||
'client': 'WEB',
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
total_page = int(data_json['result']["pages"])
|
||||
big_df = pd.DataFrame()
|
||||
for page in range(1, total_page+1):
|
||||
params.update({'pageNumber': page})
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json['result']["data"])
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
big_df.reset_index(inplace=True)
|
||||
big_df['index'] = big_df['index'] + 1
|
||||
big_df.columns = [
|
||||
"序号",
|
||||
"交易日期",
|
||||
"上证指数",
|
||||
"上证指数涨跌幅",
|
||||
"大宗交易成交总额",
|
||||
"溢价成交总额",
|
||||
"溢价成交总额占比",
|
||||
"折价成交总额",
|
||||
"折价成交总额占比",
|
||||
]
|
||||
big_df["交易日期"] = pd.to_datetime(big_df["交易日期"]).dt.date
|
||||
big_df["上证指数"] = pd.to_numeric(big_df["上证指数"])
|
||||
big_df["上证指数涨跌幅"] = pd.to_numeric(big_df["上证指数涨跌幅"])
|
||||
big_df["大宗交易成交总额"] = pd.to_numeric(big_df["大宗交易成交总额"])
|
||||
big_df["溢价成交总额"] = pd.to_numeric(big_df["溢价成交总额"])
|
||||
big_df["溢价成交总额占比"] = pd.to_numeric(big_df["溢价成交总额占比"])
|
||||
big_df["折价成交总额"] = pd.to_numeric(big_df["折价成交总额"])
|
||||
big_df["折价成交总额占比"] = pd.to_numeric(big_df["折价成交总额占比"])
|
||||
return big_df
|
||||
|
||||
|
||||
def stock_dzjy_mrmx(symbol: str = '基金', start_date: str = '20220104', end_date: str = '20220104') -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-大宗交易-每日明细
|
||||
http://data.eastmoney.com/dzjy/dzjy_mrmxa.aspx
|
||||
:param symbol: choice of {'A股', 'B股', '基金', '债券'}
|
||||
:type symbol: str
|
||||
:param start_date: 开始日期
|
||||
:type start_date: str
|
||||
:param end_date: 结束日期
|
||||
:type end_date: str
|
||||
:return: 每日明细
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
symbol_map = {
|
||||
'A股': '1',
|
||||
'B股': '2',
|
||||
'基金': '3',
|
||||
'债券': '4',
|
||||
}
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
'sortColumns': 'SECURITY_CODE',
|
||||
'sortTypes': '1',
|
||||
'pageSize': '5000',
|
||||
'pageNumber': '1',
|
||||
'reportName': 'RPT_DATA_BLOCKTRADE',
|
||||
'columns': 'TRADE_DATE,SECURITY_CODE,SECUCODE,SECURITY_NAME_ABBR,CHANGE_RATE,CLOSE_PRICE,DEAL_PRICE,PREMIUM_RATIO,DEAL_VOLUME,DEAL_AMT,TURNOVER_RATE,BUYER_NAME,SELLER_NAME,CHANGE_RATE_1DAYS,CHANGE_RATE_5DAYS,CHANGE_RATE_10DAYS,CHANGE_RATE_20DAYS,BUYER_CODE,SELLER_CODE',
|
||||
'source': 'WEB',
|
||||
'client': 'WEB',
|
||||
'filter': f"""(SECURITY_TYPE_WEB={symbol_map[symbol]})(TRADE_DATE>='{'-'.join([start_date[:4], start_date[4:6], start_date[6:]])}')(TRADE_DATE<='{'-'.join([end_date[:4], end_date[4:6], end_date[6:]])}')"""
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
if not data_json['result']["data"]:
|
||||
return pd.DataFrame()
|
||||
temp_df = pd.DataFrame(data_json['result']["data"])
|
||||
temp_df.reset_index(inplace=True)
|
||||
temp_df['index'] = temp_df.index + 1
|
||||
if symbol in {'A股'}:
|
||||
temp_df.columns = [
|
||||
"序号",
|
||||
"交易日期",
|
||||
"证券代码",
|
||||
"-",
|
||||
"证券简称",
|
||||
"涨跌幅",
|
||||
"收盘价",
|
||||
"成交价",
|
||||
"折溢率",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"成交额/流通市值",
|
||||
"买方营业部",
|
||||
"卖方营业部",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
]
|
||||
temp_df["交易日期"] = pd.to_datetime(temp_df["交易日期"]).dt.date
|
||||
temp_df = temp_df[[
|
||||
"序号",
|
||||
"交易日期",
|
||||
"证券代码",
|
||||
"证券简称",
|
||||
"涨跌幅",
|
||||
"收盘价",
|
||||
"成交价",
|
||||
"折溢率",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"成交额/流通市值",
|
||||
"买方营业部",
|
||||
"卖方营业部",
|
||||
]]
|
||||
temp_df['涨跌幅'] = pd.to_numeric(temp_df['涨跌幅'])
|
||||
temp_df['收盘价'] = pd.to_numeric(temp_df['收盘价'])
|
||||
temp_df['成交价'] = pd.to_numeric(temp_df['成交价'])
|
||||
temp_df['折溢率'] = pd.to_numeric(temp_df['折溢率'])
|
||||
temp_df['成交量'] = pd.to_numeric(temp_df['成交量'])
|
||||
temp_df['成交额'] = pd.to_numeric(temp_df['成交额'])
|
||||
temp_df['成交额/流通市值'] = pd.to_numeric(temp_df['成交额/流通市值'])
|
||||
if symbol in {'B股', '基金', '债券'}:
|
||||
temp_df.columns = [
|
||||
"序号",
|
||||
"交易日期",
|
||||
"证券代码",
|
||||
"-",
|
||||
"证券简称",
|
||||
"-",
|
||||
"-",
|
||||
"成交价",
|
||||
"-",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"-",
|
||||
"买方营业部",
|
||||
"卖方营业部",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
]
|
||||
temp_df["交易日期"] = pd.to_datetime(temp_df["交易日期"]).dt.date
|
||||
temp_df = temp_df[[
|
||||
"序号",
|
||||
"交易日期",
|
||||
"证券代码",
|
||||
"证券简称",
|
||||
"成交价",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"买方营业部",
|
||||
"卖方营业部",
|
||||
]]
|
||||
temp_df['成交价'] = pd.to_numeric(temp_df['成交价'])
|
||||
temp_df['成交量'] = pd.to_numeric(temp_df['成交量'])
|
||||
temp_df['成交额'] = pd.to_numeric(temp_df['成交额'])
|
||||
return temp_df
|
||||
|
||||
|
||||
def stock_dzjy_mrtj(start_date: str = '20220105', end_date: str = '20220105') -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-大宗交易-每日统计
|
||||
http://data.eastmoney.com/dzjy/dzjy_mrtj.aspx
|
||||
:param start_date: 开始日期
|
||||
:type start_date: str
|
||||
:param end_date: 结束日期
|
||||
:type end_date: str
|
||||
:return: 每日统计
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
'sortColumns': 'TURNOVERRATE',
|
||||
'sortTypes': '-1',
|
||||
'pageSize': '5000',
|
||||
'pageNumber': '1',
|
||||
'reportName': 'RPT_BLOCKTRADE_STA',
|
||||
'columns': 'TRADE_DATE,SECURITY_CODE,SECUCODE,SECURITY_NAME_ABBR,CHANGE_RATE,CLOSE_PRICE,AVERAGE_PRICE,PREMIUM_RATIO,DEAL_NUM,VOLUME,DEAL_AMT,TURNOVERRATE,D1_CLOSE_ADJCHRATE,D5_CLOSE_ADJCHRATE,D10_CLOSE_ADJCHRATE,D20_CLOSE_ADJCHRATE',
|
||||
'source': 'WEB',
|
||||
'client': 'WEB',
|
||||
'filter': f"(TRADE_DATE>='{'-'.join([start_date[:4], start_date[4:6], start_date[6:]])}')(TRADE_DATE<='{'-'.join([end_date[:4], end_date[4:6], end_date[6:]])}')"
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json['result']["data"])
|
||||
temp_df.reset_index(inplace=True)
|
||||
temp_df['index'] = temp_df.index + 1
|
||||
temp_df.columns = [
|
||||
"序号",
|
||||
"交易日期",
|
||||
"证券代码",
|
||||
"-",
|
||||
"证券简称",
|
||||
"涨跌幅",
|
||||
"收盘价",
|
||||
"成交价",
|
||||
"折溢率",
|
||||
"成交笔数",
|
||||
"成交总量",
|
||||
"成交总额",
|
||||
"成交总额/流通市值",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
]
|
||||
temp_df["交易日期"] = pd.to_datetime(temp_df["交易日期"]).dt.date
|
||||
temp_df = temp_df[[
|
||||
"序号",
|
||||
"交易日期",
|
||||
"证券代码",
|
||||
"证券简称",
|
||||
"收盘价",
|
||||
"涨跌幅",
|
||||
"成交价",
|
||||
"折溢率",
|
||||
"成交笔数",
|
||||
"成交总量",
|
||||
"成交总额",
|
||||
"成交总额/流通市值",
|
||||
]]
|
||||
temp_df['涨跌幅'] = pd.to_numeric(temp_df['涨跌幅'])
|
||||
temp_df['收盘价'] = pd.to_numeric(temp_df['收盘价'])
|
||||
temp_df['成交价'] = pd.to_numeric(temp_df['成交价'])
|
||||
temp_df['折溢率'] = pd.to_numeric(temp_df['折溢率'])
|
||||
temp_df['成交笔数'] = pd.to_numeric(temp_df['成交笔数'])
|
||||
temp_df['成交总量'] = pd.to_numeric(temp_df['成交总量'])
|
||||
temp_df['成交总额'] = pd.to_numeric(temp_df['成交总额'])
|
||||
temp_df['成交总额/流通市值'] = pd.to_numeric(temp_df['成交总额/流通市值'])
|
||||
return temp_df
|
||||
|
||||
|
||||
def stock_dzjy_hygtj(symbol: str = '近三月') -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-大宗交易-活跃 A 股统计
|
||||
http://data.eastmoney.com/dzjy/dzjy_hygtj.aspx
|
||||
:param symbol: choice of {'近一月', '近三月', '近六月', '近一年'}
|
||||
:type symbol: str
|
||||
:return: 活跃 A 股统计
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
period_map = {
|
||||
'近一月': '1',
|
||||
'近三月': '3',
|
||||
'近六月': '6',
|
||||
'近一年': '12',
|
||||
}
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
'sortColumns': 'DEAL_NUM,SECURITY_CODE',
|
||||
'sortTypes': '-1,-1',
|
||||
'pageSize': '5000',
|
||||
'pageNumber': '1',
|
||||
'reportName': 'RPT_BLOCKTRADE_ACSTA',
|
||||
'columns': 'SECURITY_CODE,SECUCODE,SECURITY_NAME_ABBR,CLOSE_PRICE,CHANGE_RATE,TRADE_DATE,DEAL_AMT,PREMIUM_RATIO,SUM_TURNOVERRATE,DEAL_NUM,PREMIUM_TIMES,DISCOUNT_TIMES,D1_AVG_ADJCHRATE,D5_AVG_ADJCHRATE,D10_AVG_ADJCHRATE,D20_AVG_ADJCHRATE,DATE_TYPE_CODE',
|
||||
'source': 'WEB',
|
||||
'client': 'WEB',
|
||||
'filter': f'(DATE_TYPE_CODE={period_map[symbol]})',
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
total_page = data_json['result']["pages"]
|
||||
big_df = pd.DataFrame()
|
||||
for page in range(1, int(total_page)+1):
|
||||
params.update({"pageNumber": page})
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json['result']["data"])
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
big_df.reset_index(inplace=True)
|
||||
big_df['index'] = big_df.index + 1
|
||||
big_df.columns = [
|
||||
"序号",
|
||||
"证券代码",
|
||||
"_",
|
||||
"证券简称",
|
||||
"最新价",
|
||||
"涨跌幅",
|
||||
"最近上榜日",
|
||||
"总成交额",
|
||||
"折溢率",
|
||||
"成交总额/流通市值",
|
||||
"上榜次数-总计",
|
||||
"上榜次数-溢价",
|
||||
"上榜次数-折价",
|
||||
"上榜日后平均涨跌幅-1日",
|
||||
"上榜日后平均涨跌幅-5日",
|
||||
"上榜日后平均涨跌幅-10日",
|
||||
"上榜日后平均涨跌幅-20日",
|
||||
"_",
|
||||
]
|
||||
big_df = big_df[[
|
||||
"序号",
|
||||
"证券代码",
|
||||
"证券简称",
|
||||
"最新价",
|
||||
"涨跌幅",
|
||||
"最近上榜日",
|
||||
"上榜次数-总计",
|
||||
"上榜次数-溢价",
|
||||
"上榜次数-折价",
|
||||
"总成交额",
|
||||
"折溢率",
|
||||
"成交总额/流通市值",
|
||||
"上榜日后平均涨跌幅-1日",
|
||||
"上榜日后平均涨跌幅-5日",
|
||||
"上榜日后平均涨跌幅-10日",
|
||||
"上榜日后平均涨跌幅-20日",
|
||||
]]
|
||||
big_df["最近上榜日"] = pd.to_datetime(big_df["最近上榜日"]).dt.date
|
||||
big_df["最新价"] = pd.to_numeric(big_df["最新价"])
|
||||
big_df["涨跌幅"] = pd.to_numeric(big_df["涨跌幅"])
|
||||
big_df["上榜次数-总计"] = pd.to_numeric(big_df["上榜次数-总计"])
|
||||
big_df["上榜次数-溢价"] = pd.to_numeric(big_df["上榜次数-溢价"])
|
||||
big_df["上榜次数-折价"] = pd.to_numeric(big_df["上榜次数-折价"])
|
||||
big_df["总成交额"] = pd.to_numeric(big_df["总成交额"])
|
||||
big_df["折溢率"] = pd.to_numeric(big_df["折溢率"])
|
||||
big_df["成交总额/流通市值"] = pd.to_numeric(big_df["成交总额/流通市值"])
|
||||
big_df["上榜日后平均涨跌幅-1日"] = pd.to_numeric(big_df["上榜日后平均涨跌幅-1日"])
|
||||
big_df["上榜日后平均涨跌幅-5日"] = pd.to_numeric(big_df["上榜日后平均涨跌幅-5日"])
|
||||
big_df["上榜日后平均涨跌幅-10日"] = pd.to_numeric(big_df["上榜日后平均涨跌幅-10日"])
|
||||
big_df["上榜日后平均涨跌幅-20日"] = pd.to_numeric(big_df["上榜日后平均涨跌幅-20日"])
|
||||
return big_df
|
||||
|
||||
|
||||
def stock_dzjy_hyyybtj(symbol: str = '近3日') -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-大宗交易-活跃营业部统计
|
||||
https://data.eastmoney.com/dzjy/dzjy_hyyybtj.html
|
||||
:param symbol: choice of {'当前交易日', '近3日', '近5日', '近10日', '近30日'}
|
||||
:type symbol: str
|
||||
:return: 活跃营业部统计
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
period_map = {
|
||||
'当前交易日': '1',
|
||||
'近3日': '3',
|
||||
'近5日': '5',
|
||||
'近10日': '10',
|
||||
'近30日': '30',
|
||||
}
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
'sortColumns': 'BUYER_NUM,TOTAL_BUYAMT',
|
||||
'sortTypes': '-1,-1',
|
||||
'pageSize': '5000',
|
||||
'pageNumber': '1',
|
||||
'reportName': 'RPT_BLOCKTRADE_OPERATEDEPTSTATISTICS',
|
||||
'columns': 'OPERATEDEPT_CODE,OPERATEDEPT_NAME,ONLIST_DATE,STOCK_DETAILS,BUYER_NUM,SELLER_NUM,TOTAL_BUYAMT,TOTAL_SELLAMT,TOTAL_NETAMT,N_DATE',
|
||||
'source': 'WEB',
|
||||
'client': 'WEB',
|
||||
'filter': f'(N_DATE=-{period_map[symbol]})',
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
total_page = data_json['result']["pages"]
|
||||
big_df = pd.DataFrame()
|
||||
for page in range(1, int(total_page)+1):
|
||||
params.update({"pageNumber": page})
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json['result']["data"])
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
big_df.reset_index(inplace=True)
|
||||
big_df['index'] = big_df.index + 1
|
||||
big_df.columns = [
|
||||
"序号",
|
||||
"_",
|
||||
"营业部名称",
|
||||
"最近上榜日",
|
||||
"买入的股票",
|
||||
"次数总计-买入",
|
||||
"次数总计-卖出",
|
||||
"成交金额统计-买入",
|
||||
"成交金额统计-卖出",
|
||||
"成交金额统计-净买入额",
|
||||
"_",
|
||||
]
|
||||
big_df = big_df[[
|
||||
"序号",
|
||||
"最近上榜日",
|
||||
"营业部名称",
|
||||
"次数总计-买入",
|
||||
"次数总计-卖出",
|
||||
"成交金额统计-买入",
|
||||
"成交金额统计-卖出",
|
||||
"成交金额统计-净买入额",
|
||||
"买入的股票",
|
||||
]]
|
||||
big_df["最近上榜日"] = pd.to_datetime(big_df["最近上榜日"]).dt.date
|
||||
big_df["次数总计-买入"] = pd.to_numeric(big_df["次数总计-买入"])
|
||||
big_df["次数总计-卖出"] = pd.to_numeric(big_df["次数总计-卖出"])
|
||||
big_df["成交金额统计-买入"] = pd.to_numeric(big_df["成交金额统计-买入"])
|
||||
big_df["成交金额统计-卖出"] = pd.to_numeric(big_df["成交金额统计-卖出"])
|
||||
big_df["成交金额统计-净买入额"] = pd.to_numeric(big_df["成交金额统计-净买入额"])
|
||||
return big_df
|
||||
|
||||
|
||||
def stock_dzjy_yybph(symbol: str = '近三月') -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-大宗交易-营业部排行
|
||||
http://data.eastmoney.com/dzjy/dzjy_yybph.aspx
|
||||
:param symbol: choice of {'近一月', '近三月', '近六月', '近一年'}
|
||||
:type symbol: str
|
||||
:return: 营业部排行
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
period_map = {
|
||||
'近一月': '30',
|
||||
'近三月': '90',
|
||||
'近六月': '120',
|
||||
'近一年': '360',
|
||||
}
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
'sortColumns': 'D5_BUYER_NUM,D1_AVERAGE_INCREASE',
|
||||
'sortTypes': '-1,-1',
|
||||
'pageSize': '5000',
|
||||
'pageNumber': '1',
|
||||
'reportName': 'RPT_BLOCKTRADE_OPERATEDEPT_RANK',
|
||||
'columns': 'OPERATEDEPT_CODE,OPERATEDEPT_NAME,D1_BUYER_NUM,D1_AVERAGE_INCREASE,D1_RISE_PROBABILITY,D5_BUYER_NUM,D5_AVERAGE_INCREASE,D5_RISE_PROBABILITY,D10_BUYER_NUM,D10_AVERAGE_INCREASE,D10_RISE_PROBABILITY,D20_BUYER_NUM,D20_AVERAGE_INCREASE,D20_RISE_PROBABILITY,N_DATE,RELATED_ORG_CODE',
|
||||
'source': 'WEB',
|
||||
'client': 'WEB',
|
||||
'filter': f'(N_DATE=-{period_map[symbol]})',
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
total_page = data_json['result']["pages"]
|
||||
big_df = pd.DataFrame()
|
||||
for page in range(1, int(total_page)+1):
|
||||
params.update({"pageNumber": page})
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json['result']["data"])
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
|
||||
big_df.reset_index(inplace=True)
|
||||
big_df['index'] = big_df.index + 1
|
||||
big_df.columns = [
|
||||
"序号",
|
||||
"_",
|
||||
"营业部名称",
|
||||
"上榜后1天-买入次数",
|
||||
"上榜后1天-平均涨幅",
|
||||
"上榜后1天-上涨概率",
|
||||
"上榜后5天-买入次数",
|
||||
"上榜后5天-平均涨幅",
|
||||
"上榜后5天-上涨概率",
|
||||
"上榜后10天-买入次数",
|
||||
"上榜后10天-平均涨幅",
|
||||
"上榜后10天-上涨概率",
|
||||
"上榜后20天-买入次数",
|
||||
"上榜后20天-平均涨幅",
|
||||
"上榜后20天-上涨概率",
|
||||
"_",
|
||||
"_",
|
||||
]
|
||||
big_df = big_df[[
|
||||
"序号",
|
||||
"营业部名称",
|
||||
"上榜后1天-买入次数",
|
||||
"上榜后1天-平均涨幅",
|
||||
"上榜后1天-上涨概率",
|
||||
"上榜后5天-买入次数",
|
||||
"上榜后5天-平均涨幅",
|
||||
"上榜后5天-上涨概率",
|
||||
"上榜后10天-买入次数",
|
||||
"上榜后10天-平均涨幅",
|
||||
"上榜后10天-上涨概率",
|
||||
"上榜后20天-买入次数",
|
||||
"上榜后20天-平均涨幅",
|
||||
"上榜后20天-上涨概率",
|
||||
]]
|
||||
big_df['上榜后1天-买入次数'] = pd.to_numeric(big_df['上榜后1天-买入次数'])
|
||||
big_df['上榜后1天-平均涨幅'] = pd.to_numeric(big_df['上榜后1天-平均涨幅'])
|
||||
big_df['上榜后1天-上涨概率'] = pd.to_numeric(big_df['上榜后1天-上涨概率'])
|
||||
big_df['上榜后5天-买入次数'] = pd.to_numeric(big_df['上榜后5天-买入次数'])
|
||||
big_df['上榜后5天-平均涨幅'] = pd.to_numeric(big_df['上榜后5天-平均涨幅'])
|
||||
big_df['上榜后5天-上涨概率'] = pd.to_numeric(big_df['上榜后5天-上涨概率'])
|
||||
big_df['上榜后10天-买入次数'] = pd.to_numeric(big_df['上榜后10天-买入次数'])
|
||||
big_df['上榜后10天-平均涨幅'] = pd.to_numeric(big_df['上榜后10天-平均涨幅'])
|
||||
big_df['上榜后10天-上涨概率'] = pd.to_numeric(big_df['上榜后10天-上涨概率'])
|
||||
big_df['上榜后20天-买入次数'] = pd.to_numeric(big_df['上榜后20天-买入次数'])
|
||||
big_df['上榜后20天-平均涨幅'] = pd.to_numeric(big_df['上榜后20天-平均涨幅'])
|
||||
big_df['上榜后20天-上涨概率'] = pd.to_numeric(big_df['上榜后20天-上涨概率'])
|
||||
return big_df
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
stock_dzjy_sctj_df = stock_dzjy_sctj()
|
||||
print(stock_dzjy_sctj_df)
|
||||
|
||||
stock_dzjy_mrmx_df = stock_dzjy_mrmx(symbol='债券', start_date='20201204', end_date='20201204')
|
||||
print(stock_dzjy_mrmx_df)
|
||||
|
||||
stock_dzjy_mrtj_df = stock_dzjy_mrtj(start_date='20201204', end_date='20201204')
|
||||
print(stock_dzjy_mrtj_df)
|
||||
|
||||
stock_dzjy_hygtj_df = stock_dzjy_hygtj(symbol='近三月')
|
||||
print(stock_dzjy_hygtj_df)
|
||||
|
||||
stock_dzjy_hyyybtj_df = stock_dzjy_hyyybtj(symbol='近3日')
|
||||
print(stock_dzjy_hyyybtj_df)
|
||||
|
||||
stock_dzjy_yybph_df = stock_dzjy_yybph(symbol='近三月')
|
||||
print(stock_dzjy_yybph_df)
|
||||
126
stockapp/src/crawling/stock_fhps_em.py
Normal file
126
stockapp/src/crawling/stock_fhps_em.py
Normal file
@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding:utf-8 -*-
|
||||
"""
|
||||
Date: 2023/4/7 15:22
|
||||
Desc: 东方财富网-数据中心-年报季报-分红送配
|
||||
https://data.eastmoney.com/yjfp/
|
||||
"""
|
||||
import pandas as pd
|
||||
import requests
|
||||
from tqdm import tqdm
|
||||
|
||||
__author__ = 'myh '
|
||||
__date__ = '2023/6/27 '
|
||||
|
||||
|
||||
def stock_fhps_em(date: str = "20210630") -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-年报季报-分红送配
|
||||
https://data.eastmoney.com/yjfp/
|
||||
:param date: 分红送配报告期
|
||||
:type date: str
|
||||
:return: 分红送配
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
"sortColumns": "PLAN_NOTICE_DATE",
|
||||
"sortTypes": "-1",
|
||||
"pageSize": "500",
|
||||
"pageNumber": "1",
|
||||
"reportName": "RPT_SHAREBONUS_DET",
|
||||
"columns": "ALL",
|
||||
"quoteColumns": "",
|
||||
"js": '{"data":(x),"pages":(tp)}',
|
||||
"source": "WEB",
|
||||
"client": "WEB",
|
||||
"filter": f"""(REPORT_DATE='{"-".join([date[:4], date[4:6], date[6:]])}')""",
|
||||
}
|
||||
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
total_pages = int(data_json["result"]["pages"])
|
||||
big_df = pd.DataFrame()
|
||||
for page in tqdm(range(1, total_pages + 1), leave=False):
|
||||
params.update({"pageNumber": page})
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["result"]["data"])
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
|
||||
big_df.columns = [
|
||||
"_",
|
||||
"名称",
|
||||
"_",
|
||||
"_",
|
||||
"代码",
|
||||
"送转股份-送转总比例",
|
||||
"送转股份-送转比例",
|
||||
"送转股份-转股比例",
|
||||
"现金分红-现金分红比例",
|
||||
"预案公告日",
|
||||
"股权登记日",
|
||||
"除权除息日",
|
||||
"_",
|
||||
"方案进度",
|
||||
"_",
|
||||
"最新公告日期",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
"每股收益",
|
||||
"每股净资产",
|
||||
"每股公积金",
|
||||
"每股未分配利润",
|
||||
"净利润同比增长",
|
||||
"总股本",
|
||||
"_",
|
||||
"现金分红-股息率",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
]
|
||||
big_df = big_df[
|
||||
[
|
||||
"代码",
|
||||
"名称",
|
||||
"送转股份-送转总比例",
|
||||
"送转股份-送转比例",
|
||||
"送转股份-转股比例",
|
||||
"现金分红-现金分红比例",
|
||||
"现金分红-股息率",
|
||||
"每股收益",
|
||||
"每股净资产",
|
||||
"每股公积金",
|
||||
"每股未分配利润",
|
||||
"净利润同比增长",
|
||||
"总股本",
|
||||
"预案公告日",
|
||||
"股权登记日",
|
||||
"除权除息日",
|
||||
"方案进度",
|
||||
"最新公告日期",
|
||||
]
|
||||
]
|
||||
big_df["送转股份-送转总比例"] = pd.to_numeric(big_df["送转股份-送转总比例"])
|
||||
big_df["送转股份-送转比例"] = pd.to_numeric(big_df["送转股份-送转比例"])
|
||||
big_df["送转股份-转股比例"] = pd.to_numeric(big_df["送转股份-转股比例"])
|
||||
big_df["现金分红-现金分红比例"] = pd.to_numeric(big_df["现金分红-现金分红比例"])
|
||||
big_df["现金分红-股息率"] = pd.to_numeric(big_df["现金分红-股息率"])
|
||||
big_df["每股收益"] = pd.to_numeric(big_df["每股收益"])
|
||||
big_df["每股净资产"] = pd.to_numeric(big_df["每股净资产"])
|
||||
big_df["每股公积金"] = pd.to_numeric(big_df["每股公积金"])
|
||||
big_df["每股未分配利润"] = pd.to_numeric(big_df["每股未分配利润"])
|
||||
big_df["净利润同比增长"] = pd.to_numeric(big_df["净利润同比增长"])
|
||||
big_df["总股本"] = pd.to_numeric(big_df["总股本"])
|
||||
|
||||
big_df["预案公告日"] = pd.to_datetime(big_df["预案公告日"], errors="coerce").dt.date
|
||||
big_df["股权登记日"] = pd.to_datetime(big_df["股权登记日"], errors="coerce").dt.date
|
||||
big_df["除权除息日"] = pd.to_datetime(big_df["除权除息日"], errors="coerce").dt.date
|
||||
big_df["最新公告日期"] = pd.to_datetime(big_df["最新公告日期"], errors="coerce").dt.date
|
||||
return big_df
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
stock_fhps_em_df = stock_fhps_em(date="20221231")
|
||||
print(stock_fhps_em_df)
|
||||
419
stockapp/src/crawling/stock_fund_em.py
Normal file
419
stockapp/src/crawling/stock_fund_em.py
Normal file
@ -0,0 +1,419 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding:utf-8 -*-
|
||||
"""
|
||||
Date: 2023/5/16 15:30
|
||||
Desc: 东方财富网-数据中心-资金流向
|
||||
https://data.eastmoney.com/zjlx/detail.html
|
||||
"""
|
||||
import json
|
||||
import time
|
||||
from functools import lru_cache
|
||||
|
||||
import pandas as pd
|
||||
import requests
|
||||
|
||||
__author__ = 'myh '
|
||||
__date__ = '2023/6/12 '
|
||||
|
||||
|
||||
def stock_individual_fund_flow_rank(indicator: str = "5日") -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-资金流向-排名
|
||||
https://data.eastmoney.com/zjlx/detail.html
|
||||
:param indicator: choice of {"今日", "3日", "5日", "10日"}
|
||||
:type indicator: str
|
||||
:return: 指定 indicator 资金流向排行
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
indicator_map = {
|
||||
"今日": [
|
||||
"f62",
|
||||
"f12,f14,f2,f3,f62,f184,f66,f69,f72,f75,f78,f81,f84,f87,f204,f205,f124",
|
||||
],
|
||||
"3日": [
|
||||
"f267",
|
||||
"f12,f14,f2,f127,f267,f268,f269,f270,f271,f272,f273,f274,f275,f276,f257,f258,f124",
|
||||
],
|
||||
"5日": [
|
||||
"f164",
|
||||
"f12,f14,f2,f109,f164,f165,f166,f167,f168,f169,f170,f171,f172,f173,f257,f258,f124",
|
||||
],
|
||||
"10日": [
|
||||
"f174",
|
||||
"f12,f14,f2,f160,f174,f175,f176,f177,f178,f179,f180,f181,f182,f183,f260,f261,f124",
|
||||
],
|
||||
}
|
||||
url = "http://push2.eastmoney.com/api/qt/clist/get"
|
||||
params = {
|
||||
"fid": indicator_map[indicator][0],
|
||||
"po": "1",
|
||||
"pz": "10000",
|
||||
"pn": "1",
|
||||
"np": "1",
|
||||
"fltt": "2",
|
||||
"invt": "2",
|
||||
"ut": "b2884a393a59ad64002292a3e90d46a5",
|
||||
"fs": "m:0+t:6+f:!2,m:0+t:13+f:!2,m:0+t:80+f:!2,m:1+t:2+f:!2,m:1+t:23+f:!2,m:0+t:7+f:!2,m:1+t:3+f:!2",
|
||||
"fields": indicator_map[indicator][1],
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["data"]["diff"])
|
||||
if indicator == "今日":
|
||||
temp_df.columns = [
|
||||
"最新价",
|
||||
"今日涨跌幅",
|
||||
"代码",
|
||||
"名称",
|
||||
"今日主力净流入-净额",
|
||||
"今日超大单净流入-净额",
|
||||
"今日超大单净流入-净占比",
|
||||
"今日大单净流入-净额",
|
||||
"今日大单净流入-净占比",
|
||||
"今日中单净流入-净额",
|
||||
"今日中单净流入-净占比",
|
||||
"今日小单净流入-净额",
|
||||
"今日小单净流入-净占比",
|
||||
"_",
|
||||
"今日主力净流入-净占比",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
]
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"代码",
|
||||
"名称",
|
||||
"最新价",
|
||||
"今日涨跌幅",
|
||||
"今日主力净流入-净额",
|
||||
"今日主力净流入-净占比",
|
||||
"今日超大单净流入-净额",
|
||||
"今日超大单净流入-净占比",
|
||||
"今日大单净流入-净额",
|
||||
"今日大单净流入-净占比",
|
||||
"今日中单净流入-净额",
|
||||
"今日中单净流入-净占比",
|
||||
"今日小单净流入-净额",
|
||||
"今日小单净流入-净占比",
|
||||
]
|
||||
]
|
||||
elif indicator == "3日":
|
||||
temp_df.columns = [
|
||||
"最新价",
|
||||
"代码",
|
||||
"名称",
|
||||
"_",
|
||||
"3日涨跌幅",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
"3日主力净流入-净额",
|
||||
"3日主力净流入-净占比",
|
||||
"3日超大单净流入-净额",
|
||||
"3日超大单净流入-净占比",
|
||||
"3日大单净流入-净额",
|
||||
"3日大单净流入-净占比",
|
||||
"3日中单净流入-净额",
|
||||
"3日中单净流入-净占比",
|
||||
"3日小单净流入-净额",
|
||||
"3日小单净流入-净占比",
|
||||
]
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"代码",
|
||||
"名称",
|
||||
"最新价",
|
||||
"3日涨跌幅",
|
||||
"3日主力净流入-净额",
|
||||
"3日主力净流入-净占比",
|
||||
"3日超大单净流入-净额",
|
||||
"3日超大单净流入-净占比",
|
||||
"3日大单净流入-净额",
|
||||
"3日大单净流入-净占比",
|
||||
"3日中单净流入-净额",
|
||||
"3日中单净流入-净占比",
|
||||
"3日小单净流入-净额",
|
||||
"3日小单净流入-净占比",
|
||||
]
|
||||
]
|
||||
elif indicator == "5日":
|
||||
temp_df.columns = [
|
||||
"最新价",
|
||||
"代码",
|
||||
"名称",
|
||||
"5日涨跌幅",
|
||||
"_",
|
||||
"5日主力净流入-净额",
|
||||
"5日主力净流入-净占比",
|
||||
"5日超大单净流入-净额",
|
||||
"5日超大单净流入-净占比",
|
||||
"5日大单净流入-净额",
|
||||
"5日大单净流入-净占比",
|
||||
"5日中单净流入-净额",
|
||||
"5日中单净流入-净占比",
|
||||
"5日小单净流入-净额",
|
||||
"5日小单净流入-净占比",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
]
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"代码",
|
||||
"名称",
|
||||
"最新价",
|
||||
"5日涨跌幅",
|
||||
"5日主力净流入-净额",
|
||||
"5日主力净流入-净占比",
|
||||
"5日超大单净流入-净额",
|
||||
"5日超大单净流入-净占比",
|
||||
"5日大单净流入-净额",
|
||||
"5日大单净流入-净占比",
|
||||
"5日中单净流入-净额",
|
||||
"5日中单净流入-净占比",
|
||||
"5日小单净流入-净额",
|
||||
"5日小单净流入-净占比",
|
||||
]
|
||||
]
|
||||
elif indicator == "10日":
|
||||
temp_df.columns = [
|
||||
"最新价",
|
||||
"代码",
|
||||
"名称",
|
||||
"_",
|
||||
"10日涨跌幅",
|
||||
"10日主力净流入-净额",
|
||||
"10日主力净流入-净占比",
|
||||
"10日超大单净流入-净额",
|
||||
"10日超大单净流入-净占比",
|
||||
"10日大单净流入-净额",
|
||||
"10日大单净流入-净占比",
|
||||
"10日中单净流入-净额",
|
||||
"10日中单净流入-净占比",
|
||||
"10日小单净流入-净额",
|
||||
"10日小单净流入-净占比",
|
||||
"_",
|
||||
"_",
|
||||
"_",
|
||||
]
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"代码",
|
||||
"名称",
|
||||
"最新价",
|
||||
"10日涨跌幅",
|
||||
"10日主力净流入-净额",
|
||||
"10日主力净流入-净占比",
|
||||
"10日超大单净流入-净额",
|
||||
"10日超大单净流入-净占比",
|
||||
"10日大单净流入-净额",
|
||||
"10日大单净流入-净占比",
|
||||
"10日中单净流入-净额",
|
||||
"10日中单净流入-净占比",
|
||||
"10日小单净流入-净额",
|
||||
"10日小单净流入-净占比",
|
||||
]
|
||||
]
|
||||
return temp_df
|
||||
|
||||
|
||||
def stock_sector_fund_flow_rank(
|
||||
indicator: str = "10日", sector_type: str = "行业资金流"
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-资金流向-板块资金流-排名
|
||||
https://data.eastmoney.com/bkzj/hy.html
|
||||
:param indicator: choice of {"今日", "5日", "10日"}
|
||||
:type indicator: str
|
||||
:param sector_type: choice of {"行业资金流", "概念资金流", "地域资金流"}
|
||||
:type sector_type: str
|
||||
:return: 指定参数的资金流排名数据
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
sector_type_map = {"行业资金流": "2", "概念资金流": "3", "地域资金流": "1"}
|
||||
indicator_map = {
|
||||
"今日": [
|
||||
"f62",
|
||||
"1",
|
||||
"f12,f14,f2,f3,f62,f184,f66,f69,f72,f75,f78,f81,f84,f87,f204,f205,f124",
|
||||
],
|
||||
"5日": [
|
||||
"f164",
|
||||
"5",
|
||||
"f12,f14,f2,f109,f164,f165,f166,f167,f168,f169,f170,f171,f172,f173,f257,f258,f124",
|
||||
],
|
||||
"10日": [
|
||||
"f174",
|
||||
"10",
|
||||
"f12,f14,f2,f160,f174,f175,f176,f177,f178,f179,f180,f181,f182,f183,f260,f261,f124",
|
||||
],
|
||||
}
|
||||
url = "http://push2.eastmoney.com/api/qt/clist/get"
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
|
||||
}
|
||||
params = {
|
||||
"pn": "1",
|
||||
"pz": "5000",
|
||||
"po": "1",
|
||||
"np": "1",
|
||||
"ut": "b2884a393a59ad64002292a3e90d46a5",
|
||||
"fltt": "2",
|
||||
"invt": "2",
|
||||
"fid0": indicator_map[indicator][0],
|
||||
"fs": f"m:90 t:{sector_type_map[sector_type]}",
|
||||
"stat": indicator_map[indicator][1],
|
||||
"fields": indicator_map[indicator][2],
|
||||
"rt": "52975239",
|
||||
"cb": "jQuery18308357908311220152_1589256588824",
|
||||
"_": int(time.time() * 1000),
|
||||
}
|
||||
r = requests.get(url, params=params, headers=headers)
|
||||
text_data = r.text
|
||||
json_data = json.loads(text_data[text_data.find("{") : -2])
|
||||
temp_df = pd.DataFrame(json_data["data"]["diff"])
|
||||
if indicator == "今日":
|
||||
temp_df.columns = [
|
||||
"-",
|
||||
"今日涨跌幅",
|
||||
"_",
|
||||
"名称",
|
||||
"今日主力净流入-净额",
|
||||
"今日超大单净流入-净额",
|
||||
"今日超大单净流入-净占比",
|
||||
"今日大单净流入-净额",
|
||||
"今日大单净流入-净占比",
|
||||
"今日中单净流入-净额",
|
||||
"今日中单净流入-净占比",
|
||||
"今日小单净流入-净额",
|
||||
"今日小单净流入-净占比",
|
||||
"-",
|
||||
"今日主力净流入-净占比",
|
||||
"今日主力净流入最大股",
|
||||
"今日主力净流入最大股代码",
|
||||
"是否净流入",
|
||||
]
|
||||
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"名称",
|
||||
"今日涨跌幅",
|
||||
"今日主力净流入-净额",
|
||||
"今日主力净流入-净占比",
|
||||
"今日超大单净流入-净额",
|
||||
"今日超大单净流入-净占比",
|
||||
"今日大单净流入-净额",
|
||||
"今日大单净流入-净占比",
|
||||
"今日中单净流入-净额",
|
||||
"今日中单净流入-净占比",
|
||||
"今日小单净流入-净额",
|
||||
"今日小单净流入-净占比",
|
||||
"今日主力净流入最大股",
|
||||
]
|
||||
]
|
||||
elif indicator == "5日":
|
||||
temp_df.columns = [
|
||||
"-",
|
||||
"_",
|
||||
"名称",
|
||||
"5日涨跌幅",
|
||||
"_",
|
||||
"5日主力净流入-净额",
|
||||
"5日主力净流入-净占比",
|
||||
"5日超大单净流入-净额",
|
||||
"5日超大单净流入-净占比",
|
||||
"5日大单净流入-净额",
|
||||
"5日大单净流入-净占比",
|
||||
"5日中单净流入-净额",
|
||||
"5日中单净流入-净占比",
|
||||
"5日小单净流入-净额",
|
||||
"5日小单净流入-净占比",
|
||||
"5日主力净流入最大股",
|
||||
"_",
|
||||
"_",
|
||||
]
|
||||
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"名称",
|
||||
"5日涨跌幅",
|
||||
"5日主力净流入-净额",
|
||||
"5日主力净流入-净占比",
|
||||
"5日超大单净流入-净额",
|
||||
"5日超大单净流入-净占比",
|
||||
"5日大单净流入-净额",
|
||||
"5日大单净流入-净占比",
|
||||
"5日中单净流入-净额",
|
||||
"5日中单净流入-净占比",
|
||||
"5日小单净流入-净额",
|
||||
"5日小单净流入-净占比",
|
||||
"5日主力净流入最大股",
|
||||
]
|
||||
]
|
||||
elif indicator == "10日":
|
||||
temp_df.columns = [
|
||||
"-",
|
||||
"_",
|
||||
"名称",
|
||||
"_",
|
||||
"10日涨跌幅",
|
||||
"10日主力净流入-净额",
|
||||
"10日主力净流入-净占比",
|
||||
"10日超大单净流入-净额",
|
||||
"10日超大单净流入-净占比",
|
||||
"10日大单净流入-净额",
|
||||
"10日大单净流入-净占比",
|
||||
"10日中单净流入-净额",
|
||||
"10日中单净流入-净占比",
|
||||
"10日小单净流入-净额",
|
||||
"10日小单净流入-净占比",
|
||||
"10日主力净流入最大股",
|
||||
"_",
|
||||
"_",
|
||||
]
|
||||
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"名称",
|
||||
"10日涨跌幅",
|
||||
"10日主力净流入-净额",
|
||||
"10日主力净流入-净占比",
|
||||
"10日超大单净流入-净额",
|
||||
"10日超大单净流入-净占比",
|
||||
"10日大单净流入-净额",
|
||||
"10日大单净流入-净占比",
|
||||
"10日中单净流入-净额",
|
||||
"10日中单净流入-净占比",
|
||||
"10日小单净流入-净额",
|
||||
"10日小单净流入-净占比",
|
||||
"10日主力净流入最大股",
|
||||
]
|
||||
]
|
||||
return temp_df
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
stock_individual_fund_flow_rank_df = stock_individual_fund_flow_rank(indicator="今日")
|
||||
print(stock_individual_fund_flow_rank_df)
|
||||
|
||||
stock_individual_fund_flow_rank_df = stock_individual_fund_flow_rank(indicator="3日")
|
||||
print(stock_individual_fund_flow_rank_df)
|
||||
|
||||
stock_individual_fund_flow_rank_df = stock_individual_fund_flow_rank(indicator="5日")
|
||||
print(stock_individual_fund_flow_rank_df)
|
||||
|
||||
stock_individual_fund_flow_rank_df = stock_individual_fund_flow_rank(
|
||||
indicator="10日"
|
||||
)
|
||||
print(stock_individual_fund_flow_rank_df)
|
||||
|
||||
stock_sector_fund_flow_rank_df = stock_sector_fund_flow_rank(
|
||||
indicator="5日", sector_type="概念资金流"
|
||||
)
|
||||
print(stock_sector_fund_flow_rank_df)
|
||||
|
||||
stock_sector_fund_flow_rank_df = stock_sector_fund_flow_rank(
|
||||
indicator="今日", sector_type="行业资金流"
|
||||
)
|
||||
print(stock_sector_fund_flow_rank_df)
|
||||
554
stockapp/src/crawling/stock_hist_em.py
Normal file
554
stockapp/src/crawling/stock_hist_em.py
Normal file
@ -0,0 +1,554 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding:utf-8 -*-
|
||||
"""
|
||||
Date: 2022/6/19 15:26
|
||||
Desc: 东方财富网-行情首页-沪深京 A 股
|
||||
"""
|
||||
import requests
|
||||
import pandas as pd
|
||||
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
def stock_zh_a_spot_em() -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-沪深京 A 股-实时行情
|
||||
https://quote.eastmoney.com/center/gridlist.html#hs_a_board
|
||||
:return: 实时行情
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "http://82.push2.eastmoney.com/api/qt/clist/get"
|
||||
params = {
|
||||
"pn": "1",
|
||||
"pz": "50000",
|
||||
"po": "1",
|
||||
"np": "1",
|
||||
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
|
||||
"fltt": "2",
|
||||
"invt": "2",
|
||||
"fid": "f3",
|
||||
"fs": "m:0 t:6,m:0 t:80,m:1 t:2,m:1 t:23,m:0 t:81 s:2048",
|
||||
"fields": "f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f14,f15,f16,f17,f18,f20,f21,f22,f23,f24,f25,f26,f37,f38,f39,f40,f41,f45,f46,f48,f49,f57,f61,f100,f112,f113,f114,f115,f221",
|
||||
"_": "1623833739532",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
if not data_json["data"]["diff"]:
|
||||
return pd.DataFrame()
|
||||
temp_df = pd.DataFrame(data_json["data"]["diff"])
|
||||
temp_df.columns = [
|
||||
"最新价",
|
||||
"涨跌幅",
|
||||
"涨跌额",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"振幅",
|
||||
"换手率",
|
||||
"市盈率动",
|
||||
"量比",
|
||||
"5分钟涨跌",
|
||||
"代码",
|
||||
"名称",
|
||||
"最高",
|
||||
"最低",
|
||||
"今开",
|
||||
"昨收",
|
||||
"总市值",
|
||||
"流通市值",
|
||||
"涨速",
|
||||
"市净率",
|
||||
"60日涨跌幅",
|
||||
"年初至今涨跌幅",
|
||||
"上市时间",
|
||||
"加权净资产收益率",
|
||||
"总股本",
|
||||
"已流通股份",
|
||||
"营业收入",
|
||||
"营业收入同比增长",
|
||||
"归属净利润",
|
||||
"归属净利润同比增长",
|
||||
"每股未分配利润",
|
||||
"毛利率",
|
||||
"资产负债率",
|
||||
"每股公积金",
|
||||
"所处行业",
|
||||
"每股收益",
|
||||
"每股净资产",
|
||||
"市盈率静",
|
||||
"市盈率TTM",
|
||||
"报告期"
|
||||
]
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"代码",
|
||||
"名称",
|
||||
"最新价",
|
||||
"涨跌幅",
|
||||
"涨跌额",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"振幅",
|
||||
"换手率",
|
||||
"量比",
|
||||
"今开",
|
||||
"最高",
|
||||
"最低",
|
||||
"昨收",
|
||||
"涨速",
|
||||
"5分钟涨跌",
|
||||
"60日涨跌幅",
|
||||
"年初至今涨跌幅",
|
||||
"市盈率动",
|
||||
"市盈率TTM",
|
||||
"市盈率静",
|
||||
"市净率",
|
||||
"每股收益",
|
||||
"每股净资产",
|
||||
"每股公积金",
|
||||
"每股未分配利润",
|
||||
"加权净资产收益率",
|
||||
"毛利率",
|
||||
"资产负债率",
|
||||
"营业收入",
|
||||
"营业收入同比增长",
|
||||
"归属净利润",
|
||||
"归属净利润同比增长",
|
||||
"报告期",
|
||||
"总股本",
|
||||
"已流通股份",
|
||||
"总市值",
|
||||
"流通市值",
|
||||
"所处行业",
|
||||
"上市时间"
|
||||
]
|
||||
]
|
||||
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"], errors="coerce")
|
||||
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
|
||||
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"], errors="coerce")
|
||||
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"], errors="coerce")
|
||||
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"], errors="coerce")
|
||||
temp_df["振幅"] = pd.to_numeric(temp_df["振幅"], errors="coerce")
|
||||
temp_df["量比"] = pd.to_numeric(temp_df["量比"], errors="coerce")
|
||||
temp_df["换手率"] = pd.to_numeric(temp_df["换手率"], errors="coerce")
|
||||
temp_df["最高"] = pd.to_numeric(temp_df["最高"], errors="coerce")
|
||||
temp_df["最低"] = pd.to_numeric(temp_df["最低"], errors="coerce")
|
||||
temp_df["今开"] = pd.to_numeric(temp_df["今开"], errors="coerce")
|
||||
temp_df["昨收"] = pd.to_numeric(temp_df["昨收"], errors="coerce")
|
||||
temp_df["涨速"] = pd.to_numeric(temp_df["涨速"], errors="coerce")
|
||||
temp_df["5分钟涨跌"] = pd.to_numeric(temp_df["5分钟涨跌"], errors="coerce")
|
||||
temp_df["60日涨跌幅"] = pd.to_numeric(temp_df["60日涨跌幅"], errors="coerce")
|
||||
temp_df["年初至今涨跌幅"] = pd.to_numeric(temp_df["年初至今涨跌幅"], errors="coerce")
|
||||
temp_df["市盈率动"] = pd.to_numeric(temp_df["市盈率动"], errors="coerce")
|
||||
temp_df["市盈率TTM"] = pd.to_numeric(temp_df["市盈率TTM"], errors="coerce")
|
||||
temp_df["市盈率静"] = pd.to_numeric(temp_df["市盈率静"], errors="coerce")
|
||||
temp_df["市净率"] = pd.to_numeric(temp_df["市净率"], errors="coerce")
|
||||
temp_df["每股收益"] = pd.to_numeric(temp_df["每股收益"], errors="coerce")
|
||||
temp_df["每股净资产"] = pd.to_numeric(temp_df["每股净资产"], errors="coerce")
|
||||
temp_df["每股公积金"] = pd.to_numeric(temp_df["每股公积金"], errors="coerce")
|
||||
temp_df["每股未分配利润"] = pd.to_numeric(temp_df["每股未分配利润"], errors="coerce")
|
||||
temp_df["加权净资产收益率"] = pd.to_numeric(temp_df["加权净资产收益率"], errors="coerce")
|
||||
temp_df["毛利率"] = pd.to_numeric(temp_df["毛利率"], errors="coerce")
|
||||
temp_df["资产负债率"] = pd.to_numeric(temp_df["资产负债率"], errors="coerce")
|
||||
temp_df["营业收入"] = pd.to_numeric(temp_df["营业收入"], errors="coerce")
|
||||
temp_df["营业收入同比增长"] = pd.to_numeric(temp_df["营业收入同比增长"], errors="coerce")
|
||||
temp_df["归属净利润"] = pd.to_numeric(temp_df["归属净利润"], errors="coerce")
|
||||
temp_df["归属净利润同比增长"] = pd.to_numeric(temp_df["归属净利润同比增长"], errors="coerce")
|
||||
temp_df["报告期"] = pd.to_datetime(temp_df["报告期"], format='%Y%m%d', errors="coerce")
|
||||
temp_df["总股本"] = pd.to_numeric(temp_df["总股本"], errors="coerce")
|
||||
temp_df["已流通股份"] = pd.to_numeric(temp_df["已流通股份"], errors="coerce")
|
||||
temp_df["总市值"] = pd.to_numeric(temp_df["总市值"], errors="coerce")
|
||||
temp_df["流通市值"] = pd.to_numeric(temp_df["流通市值"], errors="coerce")
|
||||
temp_df["上市时间"] = pd.to_datetime(temp_df["上市时间"], format='%Y%m%d', errors="coerce")
|
||||
|
||||
return temp_df
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def code_id_map_em() -> dict:
|
||||
"""
|
||||
东方财富-股票和市场代码
|
||||
http://quote.eastmoney.com/center/gridlist.html#hs_a_board
|
||||
:return: 股票和市场代码
|
||||
:rtype: dict
|
||||
"""
|
||||
url = "http://80.push2.eastmoney.com/api/qt/clist/get"
|
||||
params = {
|
||||
"pn": "1",
|
||||
"pz": "50000",
|
||||
"po": "1",
|
||||
"np": "1",
|
||||
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
|
||||
"fltt": "2",
|
||||
"invt": "2",
|
||||
"fid": "f3",
|
||||
"fs": "m:1 t:2,m:1 t:23",
|
||||
"fields": "f12",
|
||||
"_": "1623833739532",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
if not data_json["data"]["diff"]:
|
||||
return dict()
|
||||
temp_df = pd.DataFrame(data_json["data"]["diff"])
|
||||
temp_df["market_id"] = 1
|
||||
temp_df.columns = ["sh_code", "sh_id"]
|
||||
code_id_dict = dict(zip(temp_df["sh_code"], temp_df["sh_id"]))
|
||||
params = {
|
||||
"pn": "1",
|
||||
"pz": "50000",
|
||||
"po": "1",
|
||||
"np": "1",
|
||||
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
|
||||
"fltt": "2",
|
||||
"invt": "2",
|
||||
"fid": "f3",
|
||||
"fs": "m:0 t:6,m:0 t:80",
|
||||
"fields": "f12",
|
||||
"_": "1623833739532",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
if not data_json["data"]["diff"]:
|
||||
return dict()
|
||||
temp_df_sz = pd.DataFrame(data_json["data"]["diff"])
|
||||
temp_df_sz["sz_id"] = 0
|
||||
code_id_dict.update(dict(zip(temp_df_sz["f12"], temp_df_sz["sz_id"])))
|
||||
params = {
|
||||
"pn": "1",
|
||||
"pz": "50000",
|
||||
"po": "1",
|
||||
"np": "1",
|
||||
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
|
||||
"fltt": "2",
|
||||
"invt": "2",
|
||||
"fid": "f3",
|
||||
"fs": "m:0 t:81 s:2048",
|
||||
"fields": "f12",
|
||||
"_": "1623833739532",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
if not data_json["data"]["diff"]:
|
||||
return dict()
|
||||
temp_df_sz = pd.DataFrame(data_json["data"]["diff"])
|
||||
temp_df_sz["bj_id"] = 0
|
||||
code_id_dict.update(dict(zip(temp_df_sz["f12"], temp_df_sz["bj_id"])))
|
||||
return code_id_dict
|
||||
|
||||
|
||||
def stock_zh_a_hist(
|
||||
symbol: str = "000001",
|
||||
period: str = "daily",
|
||||
start_date: str = "19700101",
|
||||
end_date: str = "20500101",
|
||||
adjust: str = "",
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-行情首页-沪深京 A 股-每日行情
|
||||
https://quote.eastmoney.com/concept/sh603777.html?from=classic
|
||||
:param symbol: 股票代码
|
||||
:type symbol: str
|
||||
:param period: choice of {'daily', 'weekly', 'monthly'}
|
||||
:type period: str
|
||||
:param start_date: 开始日期
|
||||
:type start_date: str
|
||||
:param end_date: 结束日期
|
||||
:type end_date: str
|
||||
:param adjust: choice of {"qfq": "前复权", "hfq": "后复权", "": "不复权"}
|
||||
:type adjust: str
|
||||
:return: 每日行情
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
code_id_dict = code_id_map_em()
|
||||
adjust_dict = {"qfq": "1", "hfq": "2", "": "0"}
|
||||
period_dict = {"daily": "101", "weekly": "102", "monthly": "103"}
|
||||
url = "http://push2his.eastmoney.com/api/qt/stock/kline/get"
|
||||
params = {
|
||||
"fields1": "f1,f2,f3,f4,f5,f6",
|
||||
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61,f116",
|
||||
"ut": "7eea3edcaed734bea9cbfc24409ed989",
|
||||
"klt": period_dict[period],
|
||||
"fqt": adjust_dict[adjust],
|
||||
"secid": f"{code_id_dict[symbol]}.{symbol}",
|
||||
"beg": start_date,
|
||||
"end": end_date,
|
||||
"_": "1623766962675",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
if not (data_json["data"] and data_json["data"]["klines"]):
|
||||
return pd.DataFrame()
|
||||
temp_df = pd.DataFrame(
|
||||
[item.split(",") for item in data_json["data"]["klines"]]
|
||||
)
|
||||
temp_df.columns = [
|
||||
"日期",
|
||||
"开盘",
|
||||
"收盘",
|
||||
"最高",
|
||||
"最低",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"振幅",
|
||||
"涨跌幅",
|
||||
"涨跌额",
|
||||
"换手率",
|
||||
]
|
||||
temp_df.index = pd.to_datetime(temp_df["日期"])
|
||||
temp_df.reset_index(inplace=True, drop=True)
|
||||
|
||||
temp_df["开盘"] = pd.to_numeric(temp_df["开盘"])
|
||||
temp_df["收盘"] = pd.to_numeric(temp_df["收盘"])
|
||||
temp_df["最高"] = pd.to_numeric(temp_df["最高"])
|
||||
temp_df["最低"] = pd.to_numeric(temp_df["最低"])
|
||||
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"])
|
||||
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"])
|
||||
temp_df["振幅"] = pd.to_numeric(temp_df["振幅"])
|
||||
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"])
|
||||
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"])
|
||||
temp_df["换手率"] = pd.to_numeric(temp_df["换手率"])
|
||||
|
||||
return temp_df
|
||||
|
||||
|
||||
def stock_zh_a_hist_min_em(
|
||||
symbol: str = "000001",
|
||||
start_date: str = "1979-09-01 09:32:00",
|
||||
end_date: str = "2222-01-01 09:32:00",
|
||||
period: str = "5",
|
||||
adjust: str = "",
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-行情首页-沪深京 A 股-每日分时行情
|
||||
https://quote.eastmoney.com/concept/sh603777.html?from=classic
|
||||
:param symbol: 股票代码
|
||||
:type symbol: str
|
||||
:param start_date: 开始日期
|
||||
:type start_date: str
|
||||
:param end_date: 结束日期
|
||||
:type end_date: str
|
||||
:param period: choice of {'1', '5', '15', '30', '60'}
|
||||
:type period: str
|
||||
:param adjust: choice of {'', 'qfq', 'hfq'}
|
||||
:type adjust: str
|
||||
:return: 每日分时行情
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
code_id_dict = code_id_map_em()
|
||||
adjust_map = {
|
||||
"": "0",
|
||||
"qfq": "1",
|
||||
"hfq": "2",
|
||||
}
|
||||
if period == "1":
|
||||
url = "https://push2his.eastmoney.com/api/qt/stock/trends2/get"
|
||||
params = {
|
||||
"fields1": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13",
|
||||
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58",
|
||||
"ut": "7eea3edcaed734bea9cbfc24409ed989",
|
||||
"ndays": "5",
|
||||
"iscr": "0",
|
||||
"secid": f"{code_id_dict[symbol]}.{symbol}",
|
||||
"_": "1623766962675",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(
|
||||
[item.split(",") for item in data_json["data"]["trends"]]
|
||||
)
|
||||
temp_df.columns = [
|
||||
"时间",
|
||||
"开盘",
|
||||
"收盘",
|
||||
"最高",
|
||||
"最低",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"最新价",
|
||||
]
|
||||
temp_df.index = pd.to_datetime(temp_df["时间"])
|
||||
temp_df = temp_df[start_date:end_date]
|
||||
temp_df.reset_index(drop=True, inplace=True)
|
||||
temp_df["开盘"] = pd.to_numeric(temp_df["开盘"])
|
||||
temp_df["收盘"] = pd.to_numeric(temp_df["收盘"])
|
||||
temp_df["最高"] = pd.to_numeric(temp_df["最高"])
|
||||
temp_df["最低"] = pd.to_numeric(temp_df["最低"])
|
||||
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"])
|
||||
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"])
|
||||
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"])
|
||||
temp_df["时间"] = pd.to_datetime(temp_df["时间"]).astype(str)
|
||||
return temp_df
|
||||
else:
|
||||
url = "http://push2his.eastmoney.com/api/qt/stock/kline/get"
|
||||
params = {
|
||||
"fields1": "f1,f2,f3,f4,f5,f6",
|
||||
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",
|
||||
"ut": "7eea3edcaed734bea9cbfc24409ed989",
|
||||
"klt": period,
|
||||
"fqt": adjust_map[adjust],
|
||||
"secid": f"{code_id_dict[symbol]}.{symbol}",
|
||||
"beg": "0",
|
||||
"end": "20500000",
|
||||
"_": "1630930917857",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(
|
||||
[item.split(",") for item in data_json["data"]["klines"]]
|
||||
)
|
||||
temp_df.columns = [
|
||||
"时间",
|
||||
"开盘",
|
||||
"收盘",
|
||||
"最高",
|
||||
"最低",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"振幅",
|
||||
"涨跌幅",
|
||||
"涨跌额",
|
||||
"换手率",
|
||||
]
|
||||
temp_df.index = pd.to_datetime(temp_df["时间"])
|
||||
temp_df = temp_df[start_date:end_date]
|
||||
temp_df.reset_index(drop=True, inplace=True)
|
||||
temp_df["开盘"] = pd.to_numeric(temp_df["开盘"])
|
||||
temp_df["收盘"] = pd.to_numeric(temp_df["收盘"])
|
||||
temp_df["最高"] = pd.to_numeric(temp_df["最高"])
|
||||
temp_df["最低"] = pd.to_numeric(temp_df["最低"])
|
||||
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"])
|
||||
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"])
|
||||
temp_df["振幅"] = pd.to_numeric(temp_df["振幅"])
|
||||
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"])
|
||||
temp_df["涨跌额"] = pd.to_numeric(temp_df["涨跌额"])
|
||||
temp_df["换手率"] = pd.to_numeric(temp_df["换手率"])
|
||||
temp_df["时间"] = pd.to_datetime(temp_df["时间"]).astype(str)
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"时间",
|
||||
"开盘",
|
||||
"收盘",
|
||||
"最高",
|
||||
"最低",
|
||||
"涨跌幅",
|
||||
"涨跌额",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"振幅",
|
||||
"换手率",
|
||||
]
|
||||
]
|
||||
return temp_df
|
||||
|
||||
|
||||
def stock_zh_a_hist_pre_min_em(
|
||||
symbol: str = "000001",
|
||||
start_time: str = "09:00:00",
|
||||
end_time: str = "15:50:00",
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-行情首页-沪深京 A 股-每日分时行情包含盘前数据
|
||||
http://quote.eastmoney.com/concept/sh603777.html?from=classic
|
||||
:param symbol: 股票代码
|
||||
:type symbol: str
|
||||
:param start_time: 开始时间
|
||||
:type start_time: str
|
||||
:param end_time: 结束时间
|
||||
:type end_time: str
|
||||
:return: 每日分时行情包含盘前数据
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
code_id_dict = code_id_map_em()
|
||||
url = "https://push2.eastmoney.com/api/qt/stock/trends2/get"
|
||||
params = {
|
||||
"fields1": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13",
|
||||
"fields2": "f51,f52,f53,f54,f55,f56,f57,f58",
|
||||
"ut": "fa5fd1943c7b386f172d6893dbfba10b",
|
||||
"ndays": "1",
|
||||
"iscr": "1",
|
||||
"iscca": "0",
|
||||
"secid": f"{code_id_dict[symbol]}.{symbol}",
|
||||
"_": "1623766962675",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(
|
||||
[item.split(",") for item in data_json["data"]["trends"]]
|
||||
)
|
||||
temp_df.columns = [
|
||||
"时间",
|
||||
"开盘",
|
||||
"收盘",
|
||||
"最高",
|
||||
"最低",
|
||||
"成交量",
|
||||
"成交额",
|
||||
"最新价",
|
||||
]
|
||||
temp_df.index = pd.to_datetime(temp_df["时间"])
|
||||
date_format = temp_df.index[0].date().isoformat()
|
||||
temp_df = temp_df[
|
||||
date_format + " " + start_time : date_format + " " + end_time
|
||||
]
|
||||
temp_df.reset_index(drop=True, inplace=True)
|
||||
temp_df["开盘"] = pd.to_numeric(temp_df["开盘"])
|
||||
temp_df["收盘"] = pd.to_numeric(temp_df["收盘"])
|
||||
temp_df["最高"] = pd.to_numeric(temp_df["最高"])
|
||||
temp_df["最低"] = pd.to_numeric(temp_df["最低"])
|
||||
temp_df["成交量"] = pd.to_numeric(temp_df["成交量"])
|
||||
temp_df["成交额"] = pd.to_numeric(temp_df["成交额"])
|
||||
temp_df["最新价"] = pd.to_numeric(temp_df["最新价"])
|
||||
temp_df["时间"] = pd.to_datetime(temp_df["时间"]).astype(str)
|
||||
return temp_df
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
stock_zh_a_hist_df = stock_zh_a_hist(
|
||||
symbol="000858",
|
||||
period="daily",
|
||||
start_date="20220516",
|
||||
end_date="20220722",
|
||||
adjust="",
|
||||
)
|
||||
print(stock_zh_a_hist_df)
|
||||
exit(0)
|
||||
|
||||
stock_zh_a_spot_em_df = stock_zh_a_spot_em()
|
||||
print(stock_zh_a_spot_em_df)
|
||||
|
||||
code_id_map_em_df = code_id_map_em()
|
||||
print(code_id_map_em_df)
|
||||
|
||||
stock_zh_a_hist_df = stock_zh_a_hist(
|
||||
symbol="430090",
|
||||
period="daily",
|
||||
start_date="20220516",
|
||||
end_date="20220722",
|
||||
adjust="hfq",
|
||||
)
|
||||
print(stock_zh_a_hist_df)
|
||||
|
||||
stock_zh_a_hist_min_em_df = stock_zh_a_hist_min_em(symbol="833454", period="1")
|
||||
print(stock_zh_a_hist_min_em_df)
|
||||
|
||||
stock_zh_a_hist_pre_min_em_df = stock_zh_a_hist_pre_min_em(symbol="833454")
|
||||
print(stock_zh_a_hist_pre_min_em_df)
|
||||
|
||||
stock_zh_a_spot_em_df = stock_zh_a_spot_em()
|
||||
print(stock_zh_a_spot_em_df)
|
||||
|
||||
stock_zh_a_hist_min_em_df = stock_zh_a_hist_min_em(
|
||||
symbol="000001", period='1'
|
||||
)
|
||||
print(stock_zh_a_hist_min_em_df)
|
||||
|
||||
stock_zh_a_hist_df = stock_zh_a_hist(
|
||||
symbol="833454",
|
||||
period="daily",
|
||||
start_date="20170301",
|
||||
end_date="20211115",
|
||||
adjust="hfq",
|
||||
)
|
||||
print(stock_zh_a_hist_df)
|
||||
|
||||
888
stockapp/src/crawling/stock_lhb_em.py
Normal file
888
stockapp/src/crawling/stock_lhb_em.py
Normal file
@ -0,0 +1,888 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
# !/usr/bin/env python
|
||||
"""
|
||||
Date: 2022/3/15 17:32
|
||||
Desc: 东方财富网-数据中心-龙虎榜单
|
||||
https://data.eastmoney.com/stock/tradedetail.html
|
||||
"""
|
||||
import pandas as pd
|
||||
import requests
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
def stock_lhb_detail_em(
|
||||
start_date: str = "20230403", end_date: str = "20230417"
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-龙虎榜单-龙虎榜详情
|
||||
https://data.eastmoney.com/stock/tradedetail.html
|
||||
:param start_date: 开始日期
|
||||
:type start_date: str
|
||||
:param end_date: 结束日期
|
||||
:type end_date: str
|
||||
:return: 龙虎榜详情
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
start_date = "-".join([start_date[:4], start_date[4:6], start_date[6:]])
|
||||
end_date = "-".join([end_date[:4], end_date[4:6], end_date[6:]])
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
"sortColumns": "SECURITY_CODE,TRADE_DATE",
|
||||
"sortTypes": "1,-1",
|
||||
"pageSize": "5000",
|
||||
"pageNumber": "1",
|
||||
"reportName": "RPT_DAILYBILLBOARD_DETAILSNEW",
|
||||
"columns": "SECURITY_CODE,SECUCODE,SECURITY_NAME_ABBR,TRADE_DATE,EXPLAIN,CLOSE_PRICE,CHANGE_RATE,BILLBOARD_NET_AMT,BILLBOARD_BUY_AMT,BILLBOARD_SELL_AMT,BILLBOARD_DEAL_AMT,ACCUM_AMOUNT,DEAL_NET_RATIO,DEAL_AMOUNT_RATIO,TURNOVERRATE,FREE_MARKET_CAP,EXPLANATION,D1_CLOSE_ADJCHRATE,D2_CLOSE_ADJCHRATE,D5_CLOSE_ADJCHRATE,D10_CLOSE_ADJCHRATE,SECURITY_TYPE_CODE",
|
||||
"source": "WEB",
|
||||
"client": "WEB",
|
||||
"filter": f"(TRADE_DATE<='{end_date}')(TRADE_DATE>='{start_date}')",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
total_page_num = data_json["result"]["pages"]
|
||||
big_df = pd.DataFrame()
|
||||
for page in range(1, total_page_num + 1):
|
||||
params.update(
|
||||
{
|
||||
"pageNumber": page,
|
||||
}
|
||||
)
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["result"]["data"])
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
big_df.reset_index(inplace=True)
|
||||
big_df["index"] = big_df.index + 1
|
||||
big_df.rename(
|
||||
columns={
|
||||
"index": "序号",
|
||||
"SECURITY_CODE": "代码",
|
||||
"SECUCODE": "-",
|
||||
"SECURITY_NAME_ABBR": "名称",
|
||||
"TRADE_DATE": "上榜日",
|
||||
"EXPLAIN": "解读",
|
||||
"CLOSE_PRICE": "收盘价",
|
||||
"CHANGE_RATE": "涨跌幅",
|
||||
"BILLBOARD_NET_AMT": "龙虎榜净买额",
|
||||
"BILLBOARD_BUY_AMT": "龙虎榜买入额",
|
||||
"BILLBOARD_SELL_AMT": "龙虎榜卖出额",
|
||||
"BILLBOARD_DEAL_AMT": "龙虎榜成交额",
|
||||
"ACCUM_AMOUNT": "市场总成交额",
|
||||
"DEAL_NET_RATIO": "净买额占总成交比",
|
||||
"DEAL_AMOUNT_RATIO": "成交额占总成交比",
|
||||
"TURNOVERRATE": "换手率",
|
||||
"FREE_MARKET_CAP": "流通市值",
|
||||
"EXPLANATION": "上榜原因",
|
||||
"D1_CLOSE_ADJCHRATE": "上榜后1日",
|
||||
"D2_CLOSE_ADJCHRATE": "上榜后2日",
|
||||
"D5_CLOSE_ADJCHRATE": "上榜后5日",
|
||||
"D10_CLOSE_ADJCHRATE": "上榜后10日",
|
||||
},
|
||||
inplace=True,
|
||||
)
|
||||
|
||||
big_df = big_df[
|
||||
[
|
||||
"序号",
|
||||
"代码",
|
||||
"名称",
|
||||
"上榜日",
|
||||
"解读",
|
||||
"收盘价",
|
||||
"涨跌幅",
|
||||
"龙虎榜净买额",
|
||||
"龙虎榜买入额",
|
||||
"龙虎榜卖出额",
|
||||
"龙虎榜成交额",
|
||||
"市场总成交额",
|
||||
"净买额占总成交比",
|
||||
"成交额占总成交比",
|
||||
"换手率",
|
||||
"流通市值",
|
||||
"上榜原因",
|
||||
"上榜后1日",
|
||||
"上榜后2日",
|
||||
"上榜后5日",
|
||||
"上榜后10日",
|
||||
]
|
||||
]
|
||||
big_df["上榜日"] = pd.to_datetime(big_df["上榜日"]).dt.date
|
||||
|
||||
big_df["收盘价"] = pd.to_numeric(big_df["收盘价"], errors="coerce")
|
||||
big_df["涨跌幅"] = pd.to_numeric(big_df["涨跌幅"], errors="coerce")
|
||||
big_df["龙虎榜净买额"] = pd.to_numeric(big_df["龙虎榜净买额"], errors="coerce")
|
||||
big_df["龙虎榜买入额"] = pd.to_numeric(big_df["龙虎榜买入额"], errors="coerce")
|
||||
big_df["龙虎榜卖出额"] = pd.to_numeric(big_df["龙虎榜卖出额"], errors="coerce")
|
||||
big_df["龙虎榜成交额"] = pd.to_numeric(big_df["龙虎榜成交额"], errors="coerce")
|
||||
big_df["市场总成交额"] = pd.to_numeric(big_df["市场总成交额"], errors="coerce")
|
||||
big_df["净买额占总成交比"] = pd.to_numeric(big_df["净买额占总成交比"], errors="coerce")
|
||||
big_df["成交额占总成交比"] = pd.to_numeric(big_df["成交额占总成交比"], errors="coerce")
|
||||
big_df["换手率"] = pd.to_numeric(big_df["换手率"], errors="coerce")
|
||||
big_df["流通市值"] = pd.to_numeric(big_df["流通市值"], errors="coerce")
|
||||
big_df["上榜后1日"] = pd.to_numeric(big_df["上榜后1日"], errors="coerce")
|
||||
big_df["上榜后2日"] = pd.to_numeric(big_df["上榜后2日"], errors="coerce")
|
||||
big_df["上榜后5日"] = pd.to_numeric(big_df["上榜后5日"], errors="coerce")
|
||||
big_df["上榜后10日"] = pd.to_numeric(big_df["上榜后10日"], errors="coerce")
|
||||
return big_df
|
||||
|
||||
|
||||
def stock_lhb_stock_statistic_em(symbol: str = "近一月") -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-龙虎榜单-个股上榜统计
|
||||
https://data.eastmoney.com/stock/tradedetail.html
|
||||
:param symbol: choice of {"近一月", "近三月", "近六月", "近一年"}
|
||||
:type symbol: str
|
||||
:return: 个股上榜统计
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
symbol_map = {
|
||||
"近一月": "01",
|
||||
"近三月": "02",
|
||||
"近六月": "03",
|
||||
"近一年": "04",
|
||||
}
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
"sortColumns": "BILLBOARD_TIMES,LATEST_TDATE,SECURITY_CODE",
|
||||
"sortTypes": "-1,-1,1",
|
||||
"pageSize": "500",
|
||||
"pageNumber": "1",
|
||||
"reportName": "RPT_BILLBOARD_TRADEALL",
|
||||
"columns": "ALL",
|
||||
"source": "WEB",
|
||||
"client": "WEB",
|
||||
"filter": f'(STATISTICS_CYCLE="{symbol_map[symbol]}")',
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["result"]["data"])
|
||||
temp_df.reset_index(inplace=True)
|
||||
temp_df["index"] = temp_df.index + 1
|
||||
temp_df.columns = [
|
||||
"序号",
|
||||
"-",
|
||||
"代码",
|
||||
"最近上榜日",
|
||||
"名称",
|
||||
"近1个月涨跌幅",
|
||||
"近3个月涨跌幅",
|
||||
"近6个月涨跌幅",
|
||||
"近1年涨跌幅",
|
||||
"涨跌幅",
|
||||
"收盘价",
|
||||
"-",
|
||||
"龙虎榜总成交额",
|
||||
"龙虎榜净买额",
|
||||
"-",
|
||||
"-",
|
||||
"机构买入净额",
|
||||
"上榜次数",
|
||||
"龙虎榜买入额",
|
||||
"龙虎榜卖出额",
|
||||
"机构买入总额",
|
||||
"机构卖出总额",
|
||||
"买方机构次数",
|
||||
"卖方机构次数",
|
||||
"-",
|
||||
]
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"序号",
|
||||
"代码",
|
||||
"名称",
|
||||
"最近上榜日",
|
||||
"收盘价",
|
||||
"涨跌幅",
|
||||
"上榜次数",
|
||||
"龙虎榜净买额",
|
||||
"龙虎榜买入额",
|
||||
"龙虎榜卖出额",
|
||||
"龙虎榜总成交额",
|
||||
"买方机构次数",
|
||||
"卖方机构次数",
|
||||
"机构买入净额",
|
||||
"机构买入总额",
|
||||
"机构卖出总额",
|
||||
"近1个月涨跌幅",
|
||||
"近3个月涨跌幅",
|
||||
"近6个月涨跌幅",
|
||||
"近1年涨跌幅",
|
||||
]
|
||||
]
|
||||
temp_df["最近上榜日"] = pd.to_datetime(temp_df["最近上榜日"]).dt.date
|
||||
return temp_df
|
||||
|
||||
|
||||
def stock_lhb_jgmmtj_em(
|
||||
start_date: str = "20220906", end_date: str = "20220906"
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-龙虎榜单-机构买卖每日统计
|
||||
https://data.eastmoney.com/stock/jgmmtj.html
|
||||
:param start_date: 开始日期
|
||||
:type start_date: str
|
||||
:param end_date: 结束日期
|
||||
:type end_date: str
|
||||
:return: 机构买卖每日统计
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
start_date = "-".join([start_date[:4], start_date[4:6], start_date[6:]])
|
||||
end_date = "-".join([end_date[:4], end_date[4:6], end_date[6:]])
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
"sortColumns": "NET_BUY_AMT,TRADE_DATE,SECURITY_CODE",
|
||||
"sortTypes": "-1,-1,1",
|
||||
"pageSize": "5000",
|
||||
"pageNumber": "1",
|
||||
"reportName": "RPT_ORGANIZATION_TRADE_DETAILS",
|
||||
"columns": "ALL",
|
||||
"source": "WEB",
|
||||
"client": "WEB",
|
||||
"filter": f"(TRADE_DATE>='{start_date}')(TRADE_DATE<='{end_date}')",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["result"]["data"])
|
||||
temp_df.reset_index(inplace=True)
|
||||
temp_df["index"] = temp_df.index + 1
|
||||
temp_df.columns = [
|
||||
"序号",
|
||||
"-",
|
||||
"名称",
|
||||
"代码",
|
||||
"上榜日期",
|
||||
"收盘价",
|
||||
"涨跌幅",
|
||||
"买方机构数",
|
||||
"卖方机构数",
|
||||
"机构买入总额",
|
||||
"机构卖出总额",
|
||||
"机构买入净额",
|
||||
"市场总成交额",
|
||||
"机构净买额占总成交额比",
|
||||
"换手率",
|
||||
"流通市值",
|
||||
"上榜原因",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
]
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"序号",
|
||||
"代码",
|
||||
"名称",
|
||||
"收盘价",
|
||||
"涨跌幅",
|
||||
"买方机构数",
|
||||
"卖方机构数",
|
||||
"机构买入总额",
|
||||
"机构卖出总额",
|
||||
"机构买入净额",
|
||||
"市场总成交额",
|
||||
"机构净买额占总成交额比",
|
||||
"换手率",
|
||||
"流通市值",
|
||||
"上榜原因",
|
||||
"上榜日期",
|
||||
]
|
||||
]
|
||||
temp_df["上榜日期"] = pd.to_datetime(temp_df["上榜日期"]).dt.date
|
||||
temp_df["收盘价"] = pd.to_numeric(temp_df["收盘价"], errors="coerce")
|
||||
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"], errors="coerce")
|
||||
temp_df["买方机构数"] = pd.to_numeric(temp_df["买方机构数"], errors="coerce")
|
||||
temp_df["卖方机构数"] = pd.to_numeric(temp_df["卖方机构数"], errors="coerce")
|
||||
temp_df["机构买入总额"] = pd.to_numeric(temp_df["机构买入总额"], errors="coerce")
|
||||
temp_df["机构卖出总额"] = pd.to_numeric(temp_df["机构卖出总额"], errors="coerce")
|
||||
temp_df["机构买入净额"] = pd.to_numeric(temp_df["机构买入净额"], errors="coerce")
|
||||
temp_df["市场总成交额"] = pd.to_numeric(temp_df["市场总成交额"], errors="coerce")
|
||||
temp_df["机构净买额占总成交额比"] = pd.to_numeric(temp_df["机构净买额占总成交额比"], errors="coerce")
|
||||
temp_df["换手率"] = pd.to_numeric(temp_df["换手率"], errors="coerce")
|
||||
temp_df["流通市值"] = pd.to_numeric(temp_df["流通市值"], errors="coerce")
|
||||
|
||||
return temp_df
|
||||
|
||||
|
||||
def stock_lhb_jgstatistic_em(symbol: str = "近一月") -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-龙虎榜单-机构席位追踪
|
||||
https://data.eastmoney.com/stock/jgstatistic.html
|
||||
:param symbol: choice of {"近一月", "近三月", "近六月", "近一年"}
|
||||
:type symbol: str
|
||||
:return: 机构席位追踪
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
symbol_map = {
|
||||
"近一月": "01",
|
||||
"近三月": "02",
|
||||
"近六月": "03",
|
||||
"近一年": "04",
|
||||
}
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
"sortColumns": "ONLIST_TIMES,SECURITY_CODE",
|
||||
"sortTypes": "-1,1",
|
||||
"pageSize": "5000",
|
||||
"pageNumber": "1",
|
||||
"reportName": "RPT_ORGANIZATION_SEATNEW",
|
||||
"columns": "ALL",
|
||||
"source": "WEB",
|
||||
"client": "WEB",
|
||||
"filter": f'(STATISTICSCYCLE="{symbol_map[symbol]}")',
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
total_page = data_json["result"]["pages"]
|
||||
big_df = pd.DataFrame()
|
||||
for page in tqdm(range(1, total_page + 1), leave=False):
|
||||
params.update({"pageNumber": page})
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["result"]["data"])
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
big_df.reset_index(inplace=True)
|
||||
big_df["index"] = big_df.index + 1
|
||||
big_df.rename(
|
||||
columns={
|
||||
"index": "序号",
|
||||
"SECURITY_CODE": "代码",
|
||||
"SECURITY_NAME_ABBR": "名称",
|
||||
"CLOSE_PRICE": "收盘价",
|
||||
"CHANGE_RATE": "涨跌幅",
|
||||
"AMOUNT": "龙虎榜成交金额",
|
||||
"ONLIST_TIMES": "上榜次数",
|
||||
"BUY_AMT": "机构买入额",
|
||||
"BUY_TIMES": "机构买入次数",
|
||||
"SELL_AMT": "机构卖出额",
|
||||
"SELL_TIMES": "机构卖出次数",
|
||||
"NET_BUY_AMT": "机构净买额",
|
||||
"M1_CLOSE_ADJCHRATE": "近1个月涨跌幅",
|
||||
"M3_CLOSE_ADJCHRATE": "近3个月涨跌幅",
|
||||
"M6_CLOSE_ADJCHRATE": "近6个月涨跌幅",
|
||||
"Y1_CLOSE_ADJCHRATE": "近1年涨跌幅",
|
||||
},
|
||||
inplace=True,
|
||||
)
|
||||
big_df = big_df[
|
||||
[
|
||||
"序号",
|
||||
"代码",
|
||||
"名称",
|
||||
"收盘价",
|
||||
"涨跌幅",
|
||||
"龙虎榜成交金额",
|
||||
"上榜次数",
|
||||
"机构买入额",
|
||||
"机构买入次数",
|
||||
"机构卖出额",
|
||||
"机构卖出次数",
|
||||
"机构净买额",
|
||||
"近1个月涨跌幅",
|
||||
"近3个月涨跌幅",
|
||||
"近6个月涨跌幅",
|
||||
"近1年涨跌幅",
|
||||
]
|
||||
]
|
||||
|
||||
big_df["收盘价"] = pd.to_numeric(big_df["收盘价"], errors="coerce")
|
||||
big_df["涨跌幅"] = pd.to_numeric(big_df["涨跌幅"], errors="coerce")
|
||||
big_df["龙虎榜成交金额"] = pd.to_numeric(big_df["龙虎榜成交金额"], errors="coerce")
|
||||
big_df["上榜次数"] = pd.to_numeric(big_df["上榜次数"], errors="coerce")
|
||||
big_df["机构买入额"] = pd.to_numeric(big_df["机构买入额"], errors="coerce")
|
||||
big_df["机构买入次数"] = pd.to_numeric(big_df["机构买入次数"], errors="coerce")
|
||||
big_df["机构卖出额"] = pd.to_numeric(big_df["机构卖出额"], errors="coerce")
|
||||
big_df["机构卖出次数"] = pd.to_numeric(big_df["机构卖出次数"], errors="coerce")
|
||||
big_df["机构净买额"] = pd.to_numeric(big_df["机构净买额"], errors="coerce")
|
||||
big_df["近1个月涨跌幅"] = pd.to_numeric(big_df["近1个月涨跌幅"], errors="coerce")
|
||||
big_df["近3个月涨跌幅"] = pd.to_numeric(big_df["近3个月涨跌幅"], errors="coerce")
|
||||
big_df["近6个月涨跌幅"] = pd.to_numeric(big_df["近6个月涨跌幅"], errors="coerce")
|
||||
big_df["近1年涨跌幅"] = pd.to_numeric(big_df["近1年涨跌幅"], errors="coerce")
|
||||
return big_df
|
||||
|
||||
|
||||
def stock_lhb_hyyyb_em(
|
||||
start_date: str = "20220324", end_date: str = "20220324"
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-龙虎榜单-每日活跃营业部
|
||||
https://data.eastmoney.com/stock/jgmmtj.html
|
||||
:param start_date: 开始日期
|
||||
:type start_date: str
|
||||
:param end_date: 结束日期
|
||||
:type end_date: str
|
||||
:return: 每日活跃营业部
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
start_date = "-".join([start_date[:4], start_date[4:6], start_date[6:]])
|
||||
end_date = "-".join([end_date[:4], end_date[4:6], end_date[6:]])
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
"sortColumns": "TOTAL_NETAMT,ONLIST_DATE,OPERATEDEPT_CODE",
|
||||
"sortTypes": "-1,-1,1",
|
||||
"pageSize": "5000",
|
||||
"pageNumber": "1",
|
||||
"reportName": "RPT_OPERATEDEPT_ACTIVE",
|
||||
"columns": "ALL",
|
||||
"source": "WEB",
|
||||
"client": "WEB",
|
||||
"filter": f"(ONLIST_DATE>='{start_date}')(ONLIST_DATE<='{end_date}')",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
total_page = data_json["result"]["pages"]
|
||||
|
||||
big_df = pd.DataFrame()
|
||||
for page in tqdm(range(1, total_page + 1), leave=False):
|
||||
params.update({"pageNumber": page})
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["result"]["data"])
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
big_df.reset_index(inplace=True)
|
||||
big_df["index"] = big_df.index + 1
|
||||
big_df.columns = [
|
||||
"序号",
|
||||
"营业部名称",
|
||||
"上榜日",
|
||||
"买入个股数",
|
||||
"卖出个股数",
|
||||
"买入总金额",
|
||||
"卖出总金额",
|
||||
"总买卖净额",
|
||||
"-",
|
||||
"-",
|
||||
"买入股票",
|
||||
"-",
|
||||
"-",
|
||||
]
|
||||
big_df = big_df[
|
||||
[
|
||||
"序号",
|
||||
"营业部名称",
|
||||
"上榜日",
|
||||
"买入个股数",
|
||||
"卖出个股数",
|
||||
"买入总金额",
|
||||
"卖出总金额",
|
||||
"总买卖净额",
|
||||
"买入股票",
|
||||
]
|
||||
]
|
||||
|
||||
big_df["上榜日"] = pd.to_datetime(big_df["上榜日"]).dt.date
|
||||
big_df["买入个股数"] = pd.to_numeric(big_df["买入个股数"])
|
||||
big_df["卖出个股数"] = pd.to_numeric(big_df["卖出个股数"])
|
||||
big_df["买入总金额"] = pd.to_numeric(big_df["买入总金额"])
|
||||
big_df["卖出总金额"] = pd.to_numeric(big_df["卖出总金额"])
|
||||
big_df["总买卖净额"] = pd.to_numeric(big_df["总买卖净额"])
|
||||
return big_df
|
||||
|
||||
|
||||
def stock_lhb_yybph_em(symbol: str = "近一月") -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-龙虎榜单-营业部排行
|
||||
https://data.eastmoney.com/stock/yybph.html
|
||||
:param symbol: choice of {"近一月", "近三月", "近六月", "近一年"}
|
||||
:type symbol: str
|
||||
:return: 营业部排行
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
symbol_map = {
|
||||
"近一月": "01",
|
||||
"近三月": "02",
|
||||
"近六月": "03",
|
||||
"近一年": "04",
|
||||
}
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
"sortColumns": "TOTAL_BUYER_SALESTIMES_1DAY,OPERATEDEPT_CODE",
|
||||
"sortTypes": "-1,1",
|
||||
"pageSize": "5000",
|
||||
"pageNumber": "1",
|
||||
"reportName": "RPT_RATEDEPT_RETURNT_RANKING",
|
||||
"columns": "ALL",
|
||||
"source": "WEB",
|
||||
"client": "WEB",
|
||||
"filter": f'(STATISTICSCYCLE="{symbol_map[symbol]}")',
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
total_page = data_json["result"]["pages"]
|
||||
big_df = pd.DataFrame()
|
||||
for page in tqdm(range(1, total_page + 1), leave=False):
|
||||
params.update({"pageNumber": page})
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["result"]["data"])
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
big_df.reset_index(inplace=True)
|
||||
big_df["index"] = big_df.index + 1
|
||||
big_df.rename(
|
||||
columns={
|
||||
"index": "序号",
|
||||
"OPERATEDEPT_NAME": "营业部名称",
|
||||
"TOTAL_BUYER_SALESTIMES_1DAY": "上榜后1天-买入次数",
|
||||
"AVERAGE_INCREASE_1DAY": "上榜后1天-平均涨幅",
|
||||
"RISE_PROBABILITY_1DAY": "上榜后1天-上涨概率",
|
||||
"TOTAL_BUYER_SALESTIMES_2DAY": "上榜后2天-买入次数",
|
||||
"AVERAGE_INCREASE_2DAY": "上榜后2天-平均涨幅",
|
||||
"RISE_PROBABILITY_2DAY": "上榜后2天-上涨概率",
|
||||
"TOTAL_BUYER_SALESTIMES_3DAY": "上榜后3天-买入次数",
|
||||
"AVERAGE_INCREASE_3DAY": "上榜后3天-平均涨幅",
|
||||
"RISE_PROBABILITY_3DAY": "上榜后3天-上涨概率",
|
||||
"TOTAL_BUYER_SALESTIMES_5DAY": "上榜后5天-买入次数",
|
||||
"AVERAGE_INCREASE_5DAY": "上榜后5天-平均涨幅",
|
||||
"RISE_PROBABILITY_5DAY": "上榜后5天-上涨概率",
|
||||
"TOTAL_BUYER_SALESTIMES_10DAY": "上榜后10天-买入次数",
|
||||
"AVERAGE_INCREASE_10DAY": "上榜后10天-平均涨幅",
|
||||
"RISE_PROBABILITY_10DAY": "上榜后10天-上涨概率",
|
||||
},
|
||||
inplace=True,
|
||||
)
|
||||
big_df = big_df[
|
||||
[
|
||||
"序号",
|
||||
"营业部名称",
|
||||
"上榜后1天-买入次数",
|
||||
"上榜后1天-平均涨幅",
|
||||
"上榜后1天-上涨概率",
|
||||
"上榜后2天-买入次数",
|
||||
"上榜后2天-平均涨幅",
|
||||
"上榜后2天-上涨概率",
|
||||
"上榜后3天-买入次数",
|
||||
"上榜后3天-平均涨幅",
|
||||
"上榜后3天-上涨概率",
|
||||
"上榜后5天-买入次数",
|
||||
"上榜后5天-平均涨幅",
|
||||
"上榜后5天-上涨概率",
|
||||
"上榜后10天-买入次数",
|
||||
"上榜后10天-平均涨幅",
|
||||
"上榜后10天-上涨概率",
|
||||
]
|
||||
]
|
||||
|
||||
big_df["上榜后1天-买入次数"] = pd.to_numeric(big_df["上榜后1天-买入次数"], errors="coerce")
|
||||
big_df["上榜后1天-平均涨幅"] = pd.to_numeric(big_df["上榜后1天-平均涨幅"], errors="coerce")
|
||||
big_df["上榜后1天-上涨概率"] = pd.to_numeric(big_df["上榜后1天-上涨概率"], errors="coerce")
|
||||
|
||||
big_df["上榜后2天-买入次数"] = pd.to_numeric(big_df["上榜后2天-买入次数"], errors="coerce")
|
||||
big_df["上榜后2天-平均涨幅"] = pd.to_numeric(big_df["上榜后2天-平均涨幅"], errors="coerce")
|
||||
big_df["上榜后2天-上涨概率"] = pd.to_numeric(big_df["上榜后2天-上涨概率"], errors="coerce")
|
||||
|
||||
big_df["上榜后3天-买入次数"] = pd.to_numeric(big_df["上榜后3天-买入次数"], errors="coerce")
|
||||
big_df["上榜后3天-平均涨幅"] = pd.to_numeric(big_df["上榜后3天-平均涨幅"], errors="coerce")
|
||||
big_df["上榜后3天-上涨概率"] = pd.to_numeric(big_df["上榜后3天-上涨概率"], errors="coerce")
|
||||
|
||||
big_df["上榜后5天-买入次数"] = pd.to_numeric(big_df["上榜后5天-买入次数"], errors="coerce")
|
||||
big_df["上榜后5天-平均涨幅"] = pd.to_numeric(big_df["上榜后5天-平均涨幅"], errors="coerce")
|
||||
big_df["上榜后5天-上涨概率"] = pd.to_numeric(big_df["上榜后5天-上涨概率"], errors="coerce")
|
||||
|
||||
big_df["上榜后10天-买入次数"] = pd.to_numeric(big_df["上榜后10天-买入次数"], errors="coerce")
|
||||
big_df["上榜后10天-平均涨幅"] = pd.to_numeric(big_df["上榜后10天-平均涨幅"], errors="coerce")
|
||||
big_df["上榜后10天-上涨概率"] = pd.to_numeric(big_df["上榜后10天-上涨概率"], errors="coerce")
|
||||
return big_df
|
||||
|
||||
|
||||
def stock_lhb_traderstatistic_em(symbol: str = "近一月") -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-龙虎榜单-营业部统计
|
||||
https://data.eastmoney.com/stock/traderstatistic.html
|
||||
:param symbol: choice of {"近一月", "近三月", "近六月", "近一年"}
|
||||
:type symbol: str
|
||||
:return: 营业部统计
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
symbol_map = {
|
||||
"近一月": "01",
|
||||
"近三月": "02",
|
||||
"近六月": "03",
|
||||
"近一年": "04",
|
||||
}
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
"sortColumns": "AMOUNT,OPERATEDEPT_CODE",
|
||||
"sortTypes": "-1,1",
|
||||
"pageSize": "5000",
|
||||
"pageNumber": "1",
|
||||
"reportName": "RPT_OPERATEDEPT_LIST_STATISTICS",
|
||||
"columns": "ALL",
|
||||
"source": "WEB",
|
||||
"client": "WEB",
|
||||
"filter": f'(STATISTICSCYCLE="{symbol_map[symbol]}")',
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
total_page = data_json["result"]["pages"]
|
||||
big_df = pd.DataFrame()
|
||||
for page in tqdm(range(1, total_page + 1), leave=False):
|
||||
params.update({"pageNumber": page})
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["result"]["data"])
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
big_df.reset_index(inplace=True)
|
||||
big_df["index"] = big_df.index + 1
|
||||
big_df.rename(
|
||||
columns={
|
||||
"index": "序号",
|
||||
"OPERATEDEPT_NAME": "营业部名称",
|
||||
"AMOUNT": "龙虎榜成交金额",
|
||||
"SALES_ONLIST_TIMES": "上榜次数",
|
||||
"ACT_BUY": "买入额",
|
||||
"TOTAL_BUYER_SALESTIMES": "买入次数",
|
||||
"ACT_SELL": "卖出额",
|
||||
"TOTAL_SELLER_SALESTIMES": "卖出次数",
|
||||
},
|
||||
inplace=True,
|
||||
)
|
||||
big_df = big_df[
|
||||
[
|
||||
"序号",
|
||||
"营业部名称",
|
||||
"龙虎榜成交金额",
|
||||
"上榜次数",
|
||||
"买入额",
|
||||
"买入次数",
|
||||
"卖出额",
|
||||
"卖出次数",
|
||||
]
|
||||
]
|
||||
|
||||
big_df["龙虎榜成交金额"] = pd.to_numeric(big_df["龙虎榜成交金额"], errors="coerce")
|
||||
big_df["上榜次数"] = pd.to_numeric(big_df["上榜次数"], errors="coerce")
|
||||
big_df["买入额"] = pd.to_numeric(big_df["买入额"], errors="coerce")
|
||||
big_df["买入次数"] = pd.to_numeric(big_df["买入次数"], errors="coerce")
|
||||
big_df["卖出额"] = pd.to_numeric(big_df["卖出额"], errors="coerce")
|
||||
big_df["卖出次数"] = pd.to_numeric(big_df["卖出次数"], errors="coerce")
|
||||
return big_df
|
||||
|
||||
|
||||
def stock_lhb_stock_detail_date_em(symbol: str = "600077") -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-龙虎榜单-个股龙虎榜详情-日期
|
||||
https://data.eastmoney.com/stock/tradedetail.html
|
||||
:param symbol: 股票代码
|
||||
:type symbol: str
|
||||
:return: 个股龙虎榜详情-日期
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
"reportName": "RPT_LHB_BOARDDATE",
|
||||
"columns": "SECURITY_CODE,TRADE_DATE,TR_DATE",
|
||||
"filter": f'(SECURITY_CODE="{symbol}")',
|
||||
"pageNumber": "1",
|
||||
"pageSize": "1000",
|
||||
"sortTypes": "-1",
|
||||
"sortColumns": "TRADE_DATE",
|
||||
"source": "WEB",
|
||||
"client": "WEB",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["result"]["data"])
|
||||
temp_df.reset_index(inplace=True)
|
||||
temp_df["index"] = temp_df.index + 1
|
||||
temp_df.columns = [
|
||||
"序号",
|
||||
"股票代码",
|
||||
"交易日",
|
||||
"-",
|
||||
]
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"序号",
|
||||
"股票代码",
|
||||
"交易日",
|
||||
]
|
||||
]
|
||||
temp_df["交易日"] = pd.to_datetime(temp_df["交易日"]).dt.date
|
||||
return temp_df
|
||||
|
||||
|
||||
def stock_lhb_stock_detail_em(
|
||||
symbol: str = "000788", date: str = "20220315", flag: str = "卖出"
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-数据中心-龙虎榜单-个股龙虎榜详情
|
||||
https://data.eastmoney.com/stock/lhb/600077.html
|
||||
:param symbol: 股票代码
|
||||
:type symbol: str
|
||||
:param date: 查询日期; 需要通过 ak.stock_lhb_stock_detail_date_em(symbol="600077") 接口获取相应股票的有龙虎榜详情数据的日期
|
||||
:type date: str
|
||||
:param flag: choice of {"买入", "卖出"}
|
||||
:type flag: str
|
||||
:return: 个股龙虎榜详情
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
flag_map = {
|
||||
"买入": "BUY",
|
||||
"卖出": "SELL",
|
||||
}
|
||||
report_map = {
|
||||
"买入": "RPT_BILLBOARD_DAILYDETAILSBUY",
|
||||
"卖出": "RPT_BILLBOARD_DAILYDETAILSSELL",
|
||||
}
|
||||
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
||||
params = {
|
||||
"reportName": report_map[flag],
|
||||
"columns": "ALL",
|
||||
"filter": f"""(TRADE_DATE='{'-'.join([date[:4], date[4:6], date[6:]])}')(SECURITY_CODE="{symbol}")""",
|
||||
"pageNumber": "1",
|
||||
"pageSize": "500",
|
||||
"sortTypes": "-1",
|
||||
"sortColumns": flag_map[flag],
|
||||
"source": "WEB",
|
||||
"client": "WEB",
|
||||
"_": "1647338693644",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
temp_df = pd.DataFrame(data_json["result"]["data"])
|
||||
temp_df.reset_index(inplace=True)
|
||||
temp_df["index"] = temp_df.index + 1
|
||||
|
||||
if flag == "买入":
|
||||
temp_df.columns = [
|
||||
"序号",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"交易营业部名称",
|
||||
"类型",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"买入金额",
|
||||
"卖出金额",
|
||||
"净额",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"买入金额-占总成交比例",
|
||||
"卖出金额-占总成交比例",
|
||||
"-",
|
||||
]
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"序号",
|
||||
"交易营业部名称",
|
||||
"买入金额",
|
||||
"买入金额-占总成交比例",
|
||||
"卖出金额",
|
||||
"卖出金额-占总成交比例",
|
||||
"净额",
|
||||
"类型",
|
||||
]
|
||||
]
|
||||
temp_df["买入金额"] = pd.to_numeric(temp_df["买入金额"])
|
||||
temp_df["买入金额-占总成交比例"] = pd.to_numeric(temp_df["买入金额-占总成交比例"])
|
||||
temp_df["卖出金额"] = pd.to_numeric(temp_df["卖出金额"])
|
||||
temp_df["卖出金额-占总成交比例"] = pd.to_numeric(temp_df["卖出金额-占总成交比例"])
|
||||
temp_df.sort_values("类型", inplace=True)
|
||||
temp_df.reset_index(inplace=True, drop=True)
|
||||
temp_df["序号"] = range(1, len(temp_df["序号"]) + 1)
|
||||
else:
|
||||
temp_df.columns = [
|
||||
"序号",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"交易营业部名称",
|
||||
"类型",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"买入金额",
|
||||
"卖出金额",
|
||||
"净额",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"-",
|
||||
"买入金额-占总成交比例",
|
||||
"卖出金额-占总成交比例",
|
||||
"-",
|
||||
]
|
||||
temp_df = temp_df[
|
||||
[
|
||||
"序号",
|
||||
"交易营业部名称",
|
||||
"买入金额",
|
||||
"买入金额-占总成交比例",
|
||||
"卖出金额",
|
||||
"卖出金额-占总成交比例",
|
||||
"净额",
|
||||
"类型",
|
||||
]
|
||||
]
|
||||
temp_df["买入金额"] = pd.to_numeric(temp_df["买入金额"])
|
||||
temp_df["买入金额-占总成交比例"] = pd.to_numeric(temp_df["买入金额-占总成交比例"])
|
||||
temp_df["卖出金额"] = pd.to_numeric(temp_df["卖出金额"])
|
||||
temp_df["卖出金额-占总成交比例"] = pd.to_numeric(temp_df["卖出金额-占总成交比例"])
|
||||
temp_df.sort_values("类型", inplace=True)
|
||||
temp_df.reset_index(inplace=True, drop=True)
|
||||
temp_df["序号"] = range(1, len(temp_df["序号"]) + 1)
|
||||
return temp_df
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
stock_lhb_detail_em_df = stock_lhb_detail_em(
|
||||
start_date="20230403", end_date="20230417"
|
||||
)
|
||||
print(stock_lhb_detail_em_df)
|
||||
|
||||
stock_lhb_stock_statistic_em_df = stock_lhb_stock_statistic_em(symbol="近一月")
|
||||
print(stock_lhb_stock_statistic_em_df)
|
||||
|
||||
stock_lhb_stock_statistic_em_df = stock_lhb_stock_statistic_em(symbol="近三月")
|
||||
print(stock_lhb_stock_statistic_em_df)
|
||||
|
||||
stock_lhb_stock_statistic_em_df = stock_lhb_stock_statistic_em(symbol="近六月")
|
||||
print(stock_lhb_stock_statistic_em_df)
|
||||
|
||||
stock_lhb_stock_statistic_em_df = stock_lhb_stock_statistic_em(symbol="近一年")
|
||||
print(stock_lhb_stock_statistic_em_df)
|
||||
|
||||
stock_lhb_jgmmtj_em_df = stock_lhb_jgmmtj_em(
|
||||
start_date="20220904", end_date="20220906"
|
||||
)
|
||||
print(stock_lhb_jgmmtj_em_df)
|
||||
|
||||
stock_lhb_jgstatistic_em_df = stock_lhb_jgstatistic_em(symbol="近一月")
|
||||
print(stock_lhb_jgstatistic_em_df)
|
||||
|
||||
stock_lhb_hyyyb_em_df = stock_lhb_hyyyb_em(
|
||||
start_date="20220324", end_date="20220324"
|
||||
)
|
||||
print(stock_lhb_hyyyb_em_df)
|
||||
|
||||
stock_lhb_yybph_em_df = stock_lhb_yybph_em(symbol="近一月")
|
||||
print(stock_lhb_yybph_em_df)
|
||||
|
||||
stock_lhb_traderstatistic_em_df = stock_lhb_traderstatistic_em(symbol="近一月")
|
||||
print(stock_lhb_traderstatistic_em_df)
|
||||
|
||||
stock_lhb_stock_detail_date_em_df = stock_lhb_stock_detail_date_em(symbol="002901")
|
||||
print(stock_lhb_stock_detail_date_em_df)
|
||||
|
||||
stock_lhb_stock_detail_em_df = stock_lhb_stock_detail_em(
|
||||
symbol="002901", date="20221012", flag="买入"
|
||||
)
|
||||
print(stock_lhb_stock_detail_em_df)
|
||||
|
||||
stock_lhb_stock_detail_em_df = stock_lhb_stock_detail_em(
|
||||
symbol="600016", date="20220324", flag="买入"
|
||||
)
|
||||
print(stock_lhb_stock_detail_em_df)
|
||||
216
stockapp/src/crawling/stock_lhb_sina.py
Normal file
216
stockapp/src/crawling/stock_lhb_sina.py
Normal file
@ -0,0 +1,216 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding:utf-8 -*-
|
||||
"""
|
||||
Date: 2022/11/19 12:00
|
||||
Desc: 新浪财经-龙虎榜
|
||||
https://vip.stock.finance.sina.com.cn/q/go.php/vInvestConsult/kind/lhb/index.phtml
|
||||
"""
|
||||
import pandas as pd
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
def stock_lhb_detail_daily_sina(
|
||||
trade_date: str = "20200730", symbol: str = "当日无价格涨跌幅限制的A股,出现异常波动停牌的股票"
|
||||
) -> pd.DataFrame:
|
||||
"""
|
||||
龙虎榜-每日详情
|
||||
http://vip.stock.finance.sina.com.cn/q/go.php/vInvestConsult/kind/lhb/index.phtml
|
||||
:param trade_date: 交易日, e.g., trade_date="20200729"
|
||||
:type trade_date: str
|
||||
:param symbol: 指定标题
|
||||
:type symbol: str
|
||||
:return: 龙虎榜-每日详情
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
trade_date = "-".join([trade_date[:4], trade_date[4:6], trade_date[6:]])
|
||||
url = "http://vip.stock.finance.sina.com.cn/q/go.php/vInvestConsult/kind/lhb/index.phtml"
|
||||
params = {"tradedate": trade_date}
|
||||
r = requests.get(url, params=params)
|
||||
soup = BeautifulSoup(r.text, "lxml")
|
||||
table_name_list = [
|
||||
item.get_text().strip()
|
||||
for item in soup.find_all(
|
||||
"span", attrs={"style": "font-weight:bold;font-size:14px;"}
|
||||
)
|
||||
if item.get_text().strip() != ""
|
||||
]
|
||||
if symbol == "返回当前交易日所有可查询的指标":
|
||||
return table_name_list
|
||||
else:
|
||||
position_num = table_name_list.index(symbol)
|
||||
if len(table_name_list) == position_num + 1:
|
||||
temp_df_1 = pd.read_html(r.text, flavor='bs4', header=1)[position_num].iloc[0:, :]
|
||||
temp_df_2 = pd.read_html(r.text, flavor='bs4', header=1)[position_num + 1].iloc[0:, :]
|
||||
temp_df_3 = pd.read_html(r.text, flavor='bs4', header=1)[position_num + 2].iloc[0:, :]
|
||||
temp_df = pd.concat([temp_df_1, temp_df_2, temp_df_3], ignore_index=True)
|
||||
else:
|
||||
temp_df = pd.read_html(r.text, flavor='bs4', header=1)[position_num].iloc[0:, :]
|
||||
temp_df["股票代码"] = temp_df["股票代码"].astype(str).str.zfill(6)
|
||||
del temp_df["查看详情"]
|
||||
temp_df.columns = ["序号", "股票代码", "股票名称", "收盘价", "对应值", "成交量", "成交额"]
|
||||
return temp_df
|
||||
|
||||
|
||||
def _find_last_page(url: str = None, recent_day: str = "60"):
|
||||
url = "http://vip.stock.finance.sina.com.cn/q/go.php/vLHBData/kind/ggtj/index.phtml"
|
||||
params = {
|
||||
"last": recent_day,
|
||||
"p": "1",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
soup = BeautifulSoup(r.text, "lxml")
|
||||
try:
|
||||
previous_page = int(soup.find_all(attrs={"class": "page"})[-2].text)
|
||||
except:
|
||||
previous_page = 1
|
||||
if previous_page != 1:
|
||||
while True:
|
||||
params = {
|
||||
"last": recent_day,
|
||||
"p": previous_page,
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
soup = BeautifulSoup(r.text, "lxml")
|
||||
last_page = int(soup.find_all(attrs={"class": "page"})[-2].text)
|
||||
if last_page != previous_page:
|
||||
previous_page = last_page
|
||||
continue
|
||||
else:
|
||||
break
|
||||
return previous_page
|
||||
|
||||
|
||||
def stock_lhb_ggtj_sina(recent_day: str = "30") -> pd.DataFrame:
|
||||
"""
|
||||
龙虎榜-个股上榜统计
|
||||
http://vip.stock.finance.sina.com.cn/q/go.php/vLHBData/kind/ggtj/index.phtml
|
||||
:param recent_day: choice of {"5": 最近 5 天; "10": 最近 10 天; "30": 最近 30 天; "60": 最近 60 天;}
|
||||
:type recent_day: str
|
||||
:return: 龙虎榜-每日详情
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "http://vip.stock.finance.sina.com.cn/q/go.php/vLHBData/kind/ggtj/index.phtml"
|
||||
last_page_num = _find_last_page(url, recent_day)
|
||||
big_df = pd.DataFrame()
|
||||
for page in tqdm(range(1, last_page_num + 1), leave=False):
|
||||
params = {
|
||||
"last": recent_day,
|
||||
"p": page,
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
temp_df = pd.read_html(r.text)[0].iloc[0:, :]
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
big_df["股票代码"] = big_df["股票代码"].astype(str).str.zfill(6)
|
||||
big_df.columns = ["股票代码", "股票名称", "上榜次数", "累积购买额", "累积卖出额", "净额", "买入席位数", "卖出席位数"]
|
||||
return big_df
|
||||
|
||||
|
||||
def stock_lhb_yytj_sina(recent_day: str = "5") -> pd.DataFrame:
|
||||
"""
|
||||
龙虎榜-营业部上榜统计
|
||||
http://vip.stock.finance.sina.com.cn/q/go.php/vLHBData/kind/yytj/index.phtml
|
||||
:param recent_day: choice of {"5": 最近 5 天; "10": 最近 10 天; "30": 最近 30 天; "60": 最近 60 天;}
|
||||
:type recent_day: str
|
||||
:return: 龙虎榜-营业部上榜统计
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "http://vip.stock.finance.sina.com.cn/q/go.php/vLHBData/kind/yytj/index.phtml"
|
||||
last_page_num = _find_last_page(url, recent_day)
|
||||
big_df = pd.DataFrame()
|
||||
for page in tqdm(range(1, last_page_num + 1), leave=False):
|
||||
params = {
|
||||
"last": "5",
|
||||
"p": page,
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
temp_df = pd.read_html(r.text)[0].iloc[0:, :]
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
big_df.columns = ["营业部名称", "上榜次数", "累积购买额", "买入席位数", "累积卖出额", "卖出席位数", "买入前三股票"]
|
||||
big_df['上榜次数'] = pd.to_numeric(big_df['上榜次数'], errors="coerce")
|
||||
big_df['买入席位数'] = pd.to_numeric(big_df['买入席位数'], errors="coerce")
|
||||
big_df['卖出席位数'] = pd.to_numeric(big_df['卖出席位数'], errors="coerce")
|
||||
return big_df
|
||||
|
||||
|
||||
def stock_lhb_jgzz_sina(recent_day: str = "5") -> pd.DataFrame:
|
||||
"""
|
||||
龙虎榜-机构席位追踪
|
||||
http://vip.stock.finance.sina.com.cn/q/go.php/vLHBData/kind/jgzz/index.phtml
|
||||
:param recent_day: choice of {"5": 最近 5 天; "10": 最近 10 天; "30": 最近 30 天; "60": 最近 60 天;}
|
||||
:type recent_day: str
|
||||
:return: 龙虎榜-机构席位追踪
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "http://vip.stock.finance.sina.com.cn/q/go.php/vLHBData/kind/jgzz/index.phtml"
|
||||
last_page_num = _find_last_page(url, recent_day)
|
||||
big_df = pd.DataFrame()
|
||||
for page in tqdm(range(1, last_page_num + 1), leave=False):
|
||||
params = {
|
||||
"last": recent_day,
|
||||
"p": page,
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
temp_df = pd.read_html(r.text)[0].iloc[0:, :]
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
big_df["股票代码"] = big_df["股票代码"].astype(str).str.zfill(6)
|
||||
del big_df["当前价"]
|
||||
del big_df["涨跌幅"]
|
||||
big_df.columns = ["股票代码", "股票名称", "累积买入额", "买入次数", "累积卖出额", "卖出次数", "净额"]
|
||||
big_df['买入次数'] = pd.to_numeric(big_df['买入次数'], errors="coerce")
|
||||
big_df['卖出次数'] = pd.to_numeric(big_df['卖出次数'], errors="coerce")
|
||||
return big_df
|
||||
|
||||
|
||||
def stock_lhb_jgmx_sina() -> pd.DataFrame:
|
||||
"""
|
||||
龙虎榜-机构席位成交明细
|
||||
http://vip.stock.finance.sina.com.cn/q/go.php/vLHBData/kind/jgmx/index.phtml
|
||||
:return: 龙虎榜-机构席位成交明细
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "http://vip.stock.finance.sina.com.cn/q/go.php/vLHBData/kind/jgmx/index.phtml"
|
||||
params = {
|
||||
"p": "1",
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
soup = BeautifulSoup(r.text, "lxml")
|
||||
try:
|
||||
last_page_num = int(soup.find_all(attrs={"class": "page"})[-2].text)
|
||||
except:
|
||||
last_page_num = 1
|
||||
big_df = pd.DataFrame()
|
||||
for page in tqdm(range(1, last_page_num + 1), leave=False):
|
||||
params = {
|
||||
"p": page,
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
temp_df = pd.read_html(r.text)[0].iloc[0:, :]
|
||||
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
||||
big_df["股票代码"] = big_df["股票代码"].astype(str).str.zfill(6)
|
||||
return big_df
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
indicator_name_list = stock_lhb_detail_daily_sina(
|
||||
trade_date="20221118", symbol="返回当前交易日所有可查询的指标"
|
||||
)
|
||||
print(indicator_name_list)
|
||||
|
||||
stock_lhb_detail_daily_sina_df = stock_lhb_detail_daily_sina(
|
||||
trade_date="20221118", symbol="换手率达20%的证券"
|
||||
)
|
||||
print(stock_lhb_detail_daily_sina_df)
|
||||
|
||||
stock_lhb_ggtj_sina_df = stock_lhb_ggtj_sina(recent_day="60")
|
||||
print(stock_lhb_ggtj_sina_df)
|
||||
|
||||
stock_lhb_yytj_sina_df = stock_lhb_yytj_sina(recent_day="60")
|
||||
print(stock_lhb_yytj_sina_df)
|
||||
|
||||
stock_lhb_jgzz_sina_df = stock_lhb_jgzz_sina(recent_day="30")
|
||||
print(stock_lhb_jgzz_sina_df)
|
||||
|
||||
stock_lhb_jgmx_sina_df = stock_lhb_jgmx_sina()
|
||||
print(stock_lhb_jgmx_sina_df)
|
||||
79
stockapp/src/crawling/stock_selection.py
Normal file
79
stockapp/src/crawling/stock_selection.py
Normal file
@ -0,0 +1,79 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
# !/usr/bin/env python
|
||||
|
||||
import pandas as pd
|
||||
import requests
|
||||
import instock.core.tablestructure as tbs
|
||||
|
||||
__author__ = 'myh '
|
||||
__date__ = '2023/5/9 '
|
||||
|
||||
|
||||
def stock_selection() -> pd.DataFrame:
|
||||
"""
|
||||
东方财富网-个股-选股器
|
||||
https://data.eastmoney.com/xuangu/
|
||||
:return: 选股器
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
cols = tbs.TABLE_CN_STOCK_SELECTION['columns']
|
||||
sty = "" # 初始值 "SECUCODE,SECURITY_CODE,SECURITY_NAME_ABBR,CHANGE_RATE"
|
||||
for k in cols:
|
||||
sty = f"{sty},{cols[k]['map']}"
|
||||
url = "https://data.eastmoney.com/dataapi/xuangu/list"
|
||||
params = {
|
||||
"sty": sty[1:],
|
||||
"filter": "(MARKET+in+(\"上交所主板\",\"深交所主板\",\"深交所创业板\"))(NEW_PRICE>0)",
|
||||
"p": 1,
|
||||
"ps": 10000,
|
||||
"source": "SELECT_SECURITIES",
|
||||
"client": "WEB"
|
||||
}
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
data = data_json["result"]["data"]
|
||||
if not data:
|
||||
return pd.DataFrame()
|
||||
temp_df = pd.DataFrame(data)
|
||||
|
||||
mask = ~temp_df['CONCEPT'].isna()
|
||||
temp_df.loc[mask, 'CONCEPT'] = temp_df.loc[mask, 'CONCEPT'].apply(lambda x: ', '.join(x))
|
||||
mask = ~temp_df['STYLE'].isna()
|
||||
temp_df.loc[mask, 'STYLE'] = temp_df.loc[mask, 'STYLE'].apply(lambda x: ', '.join(x))
|
||||
|
||||
for k in cols:
|
||||
t = tbs.get_field_type_name(cols[k]["type"])
|
||||
if t == 'numeric':
|
||||
temp_df[cols[k]["map"]] = pd.to_numeric(temp_df[cols[k]["map"]], errors="coerce")
|
||||
elif t == 'datetime':
|
||||
temp_df[cols[k]["map"]] = pd.to_datetime(temp_df[cols[k]["map"]], errors="coerce").dt.date
|
||||
|
||||
return temp_df
|
||||
|
||||
|
||||
def stock_selection_params():
|
||||
"""
|
||||
东方财富网-个股-选股器-选股指标
|
||||
https://data.eastmoney.com/xuangu/
|
||||
:return: 选股器-选股指标
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "https://datacenter-web.eastmoney.com/wstock/selection/api/data/get"
|
||||
params = {
|
||||
"type": "RPTA_PCNEW_WHOLE",
|
||||
"sty": "ALL",
|
||||
"p": 1,
|
||||
"ps": 50000,
|
||||
"source": "SELECT_SECURITIES",
|
||||
"client": "WEB"
|
||||
}
|
||||
|
||||
r = requests.get(url, params=params)
|
||||
data_json = r.json()
|
||||
zxzb = data_json["zxzb"] # 指标
|
||||
print(zxzb)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
stock_selection_df = stock_selection()
|
||||
print(stock_selection)
|
||||
331
stockapp/src/crawling/trade_date_hist.py
Normal file
331
stockapp/src/crawling/trade_date_hist.py
Normal file
@ -0,0 +1,331 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding:utf-8 -*-
|
||||
"""
|
||||
Date: 2022/10/1 19:27
|
||||
Desc: 新浪财经-交易日历
|
||||
https://finance.sina.com.cn/realstock/company/klc_td_sh.txt
|
||||
此处可以用来更新 calendar.json 文件,注意末尾没有 "," 号
|
||||
"""
|
||||
import datetime
|
||||
import pandas as pd
|
||||
import requests
|
||||
from py_mini_racer import py_mini_racer
|
||||
|
||||
hk_js_decode = """
|
||||
function d(t) {
|
||||
var e, i, n, r, a, o, s, l = (arguments,
|
||||
864e5), u = 7657, c = [], h = [], d = ~(3 << 30), f = 1 << 30,
|
||||
p = [0, 3, 5, 6, 9, 10, 12, 15, 17, 18, 20, 23, 24, 27, 29, 30], m = Math, g = function () {
|
||||
var l, u;
|
||||
for (l = 0; 64 > l; l++)
|
||||
h[l] = m.pow(2, l),
|
||||
26 > l && (c[l] = v(l + 65),
|
||||
c[l + 26] = v(l + 97),
|
||||
10 > l && (c[l + 52] = v(l + 48)));
|
||||
for (c.push("+", "/"),
|
||||
c = c.join(""),
|
||||
i = t.split(""),
|
||||
n = i.length,
|
||||
l = 0; n > l; l++)
|
||||
i[l] = c.indexOf(i[l]);
|
||||
return r = {},
|
||||
e = o = 0,
|
||||
a = {},
|
||||
u = w([12, 6]),
|
||||
s = 63 ^ u[1],
|
||||
{
|
||||
_1479: T,
|
||||
_136: _,
|
||||
_200: S,
|
||||
_139: k,
|
||||
_197: _mi_run
|
||||
}["_" + u[0]] || function () {
|
||||
return []
|
||||
}
|
||||
}, v = String.fromCharCode, b = function (t) {
|
||||
return t === {}._
|
||||
}, N = function () {
|
||||
var t, e;
|
||||
for (t = y(),
|
||||
e = 1; ;) {
|
||||
if (!y())
|
||||
return e * (2 * t - 1);
|
||||
e++
|
||||
}
|
||||
}, y = function () {
|
||||
var t;
|
||||
return e >= n ? 0 : (t = i[e] & 1 << o,
|
||||
o++,
|
||||
o >= 6 && (o -= 6,
|
||||
e++),
|
||||
!!t)
|
||||
}, w = function (t, r, a) {
|
||||
var s, l, u, c, d;
|
||||
for (l = [],
|
||||
u = 0,
|
||||
r || (r = []),
|
||||
a || (a = []),
|
||||
s = 0; s < t.length; s++)
|
||||
if (c = t[s],
|
||||
u = 0,
|
||||
c) {
|
||||
if (e >= n)
|
||||
return l;
|
||||
if (t[s] <= 0)
|
||||
u = 0;
|
||||
else if (t[s] <= 30) {
|
||||
for (; d = 6 - o,
|
||||
d = c > d ? d : c,
|
||||
u |= (i[e] >> o & (1 << d) - 1) << t[s] - c,
|
||||
o += d,
|
||||
o >= 6 && (o -= 6,
|
||||
e++),
|
||||
c -= d,
|
||||
!(0 >= c);)
|
||||
;
|
||||
r[s] && u >= h[t[s] - 1] && (u -= h[t[s]])
|
||||
} else
|
||||
u = w([30, t[s] - 30], [0, r[s]]),
|
||||
a[s] || (u = u[0] + u[1] * h[30]);
|
||||
l[s] = u
|
||||
} else
|
||||
l[s] = 0;
|
||||
return l
|
||||
}, x = function (t) {
|
||||
var e, i, n;
|
||||
for (t > 1 && (e = 0),
|
||||
e = 0; t > e; e++)
|
||||
r.d++,
|
||||
n = r.d % 7,
|
||||
(3 == n || 4 == n) && (r.d += 5 - n);
|
||||
return i = new Date,
|
||||
i.setTime((u + r.d) * l),
|
||||
i
|
||||
}, S = function () {
|
||||
var t, i, a, o, l;
|
||||
if (s >= 1)
|
||||
return [];
|
||||
for (r.d = w([18], [1])[0] - 1,
|
||||
a = w([3, 3, 30, 6]),
|
||||
r.p = a[0],
|
||||
r.ld = a[1],
|
||||
r.cd = a[2],
|
||||
r.c = a[3],
|
||||
r.m = m.pow(10, r.p),
|
||||
r.pc = r.cd / r.m,
|
||||
i = [],
|
||||
t = 0; o = {
|
||||
d: 1
|
||||
},
|
||||
y() && (a = w([3])[0],
|
||||
0 == a ? o.d = w([6])[0] : 1 == a ? (r.d = w([18])[0],
|
||||
o.d = 0) : o.d = a),
|
||||
l = {
|
||||
day: x(o.d)
|
||||
},
|
||||
y() && (r.ld += N()),
|
||||
a = w([3 * r.ld], [1]),
|
||||
r.cd += a[0],
|
||||
l.close = r.cd / r.m,
|
||||
i.push(l),
|
||||
!(e >= n) && (e != n - 1 || 63 & (r.c ^ t + 1)); t++)
|
||||
;
|
||||
return i[0].prevclose = r.pc,
|
||||
i
|
||||
}, _ = function () {
|
||||
var t, i, a, o, l, u, c, h, d, f, p;
|
||||
if (s > 2)
|
||||
return [];
|
||||
for (c = [],
|
||||
d = {
|
||||
v: "volume",
|
||||
p: "price",
|
||||
a: "avg_price"
|
||||
},
|
||||
r.d = w([18], [1])[0] - 1,
|
||||
h = {
|
||||
day: x(1)
|
||||
},
|
||||
a = w(1 > s ? [3, 3, 4, 1, 1, 1, 5] : [4, 4, 4, 1, 1, 1, 3]),
|
||||
t = 0; 7 > t; t++)
|
||||
r[["la", "lp", "lv", "tv", "rv", "zv", "pp"][t]] = a[t];
|
||||
for (r.m = m.pow(10, r.pp),
|
||||
s >= 1 ? (a = w([3, 3]),
|
||||
r.c = a[0],
|
||||
a = a[1]) : (a = 5,
|
||||
r.c = 2),
|
||||
r.pc = w([6 * a])[0],
|
||||
h.pc = r.pc / r.m,
|
||||
r.cp = r.pc,
|
||||
r.da = 0,
|
||||
r.sa = r.sv = 0,
|
||||
t = 0; !(e >= n) && (e != n - 1 || 7 & (r.c ^ t)); t++) {
|
||||
for (l = {},
|
||||
o = {},
|
||||
f = r.tv ? y() : 1,
|
||||
i = 0; 3 > i; i++)
|
||||
if (p = ["v", "p", "a"][i],
|
||||
(f ? y() : 0) && (a = N(),
|
||||
r["l" + p] += a),
|
||||
u = "v" == p && r.rv ? y() : 1,
|
||||
a = w([3 * r["l" + p] + ("v" == p ? 7 * u : 0)], [!!i])[0] * (u ? 1 : 100),
|
||||
o[p] = a,
|
||||
"v" == p) {
|
||||
if (!(l[d[p]] = a) && (s > 1 || 241 > t) && (r.zv ? !y() : 1)) {
|
||||
o.p = 0;
|
||||
break
|
||||
}
|
||||
} else
|
||||
"a" == p && (r.da = (1 > s ? 0 : r.da) + o.a);
|
||||
r.sv += o.v,
|
||||
l[d.p] = (r.cp += o.p) / r.m,
|
||||
r.sa += o.v * r.cp,
|
||||
l[d.a] = b(o.a) ? t ? c[t - 1][d.a] : l[d.p] : r.sv ? ((m.floor((r.sa * (2e3 / r.m) + r.sv) / r.sv) >> 1) + r.da) / 1e3 : l[d.p] + r.da / 1e3,
|
||||
c.push(l)
|
||||
}
|
||||
return c[0].date = h.day,
|
||||
c[0].prevclose = h.pc,
|
||||
c
|
||||
}, T = function () {
|
||||
var t, e, i, n, a, o, l;
|
||||
if (s >= 1)
|
||||
return [];
|
||||
for (r.lv = 0,
|
||||
r.ld = 0,
|
||||
r.cd = 0,
|
||||
r.cv = [0, 0],
|
||||
r.p = w([6])[0],
|
||||
r.d = w([18], [1])[0] - 1,
|
||||
r.m = m.pow(10, r.p),
|
||||
a = w([3, 3]),
|
||||
r.md = a[0],
|
||||
r.mv = a[1],
|
||||
t = []; a = w([6]),
|
||||
a.length;) {
|
||||
if (i = {
|
||||
c: a[0]
|
||||
},
|
||||
n = {},
|
||||
i.d = 1,
|
||||
32 & i.c)
|
||||
for (; ;) {
|
||||
if (a = w([6])[0],
|
||||
63 == (16 | a)) {
|
||||
l = 16 & a ? "x" : "u",
|
||||
a = w([3, 3]),
|
||||
i[l + "_d"] = a[0] + r.md,
|
||||
i[l + "_v"] = a[1] + r.mv;
|
||||
break
|
||||
}
|
||||
if (32 & a) {
|
||||
o = 8 & a ? "d" : "v",
|
||||
l = 16 & a ? "x" : "u",
|
||||
i[l + "_" + o] = (7 & a) + r["m" + o];
|
||||
break
|
||||
}
|
||||
if (o = 15 & a,
|
||||
0 == o ? i.d = w([6])[0] : 1 == o ? (r.d = o = w([18])[0],
|
||||
i.d = 0) : i.d = o,
|
||||
!(16 & a))
|
||||
break
|
||||
}
|
||||
n.date = x(i.d);
|
||||
for (o in {
|
||||
v: 0,
|
||||
d: 0
|
||||
})
|
||||
b(i["x_" + o]) || (r["l" + o] = i["x_" + o]),
|
||||
b(i["u_" + o]) && (i["u_" + o] = r["l" + o]);
|
||||
for (i.l_l = [i.u_d, i.u_d, i.u_d, i.u_d, i.u_v],
|
||||
l = p[15 & i.c],
|
||||
1 & i.u_v && (l = 31 - l),
|
||||
16 & i.c && (i.l_l[4] += 2),
|
||||
e = 0; 5 > e; e++)
|
||||
l & 1 << 4 - e && i.l_l[e]++,
|
||||
i.l_l[e] *= 3;
|
||||
i.d_v = w(i.l_l, [1, 0, 0, 1, 1], [0, 0, 0, 0, 1]),
|
||||
o = r.cd + i.d_v[0],
|
||||
n.open = o / r.m,
|
||||
n.high = (o + i.d_v[1]) / r.m,
|
||||
n.low = (o - i.d_v[2]) / r.m,
|
||||
n.close = (o + i.d_v[3]) / r.m,
|
||||
a = i.d_v[4],
|
||||
"number" == typeof a && (a = [a, a >= 0 ? 0 : -1]),
|
||||
r.cd = o + i.d_v[3],
|
||||
l = r.cv[0] + a[0],
|
||||
r.cv = [l & d, r.cv[1] + a[1] + !!((r.cv[0] & d) + (a[0] & d) & f)],
|
||||
n.volume = (r.cv[0] & f - 1) + r.cv[1] * f,
|
||||
t.push(n)
|
||||
}
|
||||
return t
|
||||
}, k = function () {
|
||||
var t, e, i, n;
|
||||
if (s > 1)
|
||||
return [];
|
||||
for (r.l = 0,
|
||||
n = -1,
|
||||
r.d = w([18])[0] - 1,
|
||||
i = w([18])[0]; r.d < i;)
|
||||
e = x(1),
|
||||
0 >= n ? (y() && (r.l += N()),
|
||||
n = w([3 * r.l], [0])[0] + 1,
|
||||
t || (t = [e],
|
||||
n--)) : t.push(e),
|
||||
n--;
|
||||
return t
|
||||
};
|
||||
return _mi_run = function () {
|
||||
var t, i, a, o;
|
||||
if (s >= 1)
|
||||
return [];
|
||||
for (r.f = w([6])[0],
|
||||
r.c = w([6])[0],
|
||||
a = [],
|
||||
r.dv = [],
|
||||
r.dl = [],
|
||||
t = 0; t < r.f; t++)
|
||||
r.dv[t] = 0,
|
||||
r.dl[t] = 0;
|
||||
for (t = 0; !(e >= n) && (e != n - 1 || 7 & (r.c ^ t)); t++) {
|
||||
for (o = [],
|
||||
i = 0; i < r.f; i++)
|
||||
y() && (r.dl[i] += N()),
|
||||
r.dv[i] += w([3 * r.dl[i]], [1])[0],
|
||||
o[i] = r.dv[i];
|
||||
a.push(o)
|
||||
}
|
||||
return a
|
||||
}
|
||||
,
|
||||
g()()
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def tool_trade_date_hist_sina() -> pd.DataFrame:
|
||||
"""
|
||||
交易日历-历史数据
|
||||
https://finance.sina.com.cn/realstock/company/klc_td_sh.txt
|
||||
:return: 交易日历
|
||||
:rtype: pandas.DataFrame
|
||||
"""
|
||||
url = "https://finance.sina.com.cn/realstock/company/klc_td_sh.txt"
|
||||
r = requests.get(url)
|
||||
js_code = py_mini_racer.MiniRacer()
|
||||
js_code.eval(hk_js_decode)
|
||||
dict_list = js_code.call(
|
||||
"d", r.text.split("=")[1].split(";")[0].replace('"', "")
|
||||
) # 执行js解密代码
|
||||
temp_df = pd.DataFrame(dict_list)
|
||||
temp_df.columns = ["trade_date"]
|
||||
temp_df["trade_date"] = pd.to_datetime(temp_df["trade_date"]).dt.date
|
||||
temp_list = temp_df["trade_date"].to_list()
|
||||
temp_list.append(datetime.date(1992, 5, 4)) # 是交易日但是交易日历缺失该日期
|
||||
temp_list.sort()
|
||||
temp_df = pd.DataFrame(temp_list, columns=["trade_date"])
|
||||
return temp_df
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
tool_trade_date_hist_df = tool_trade_date_hist_sina()
|
||||
print(tool_trade_date_hist_df)
|
||||
Reference in New Issue
Block a user