Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #4231

Merged
merged 5 commits into from
Oct 28, 2023
Merged

Dev #4231

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2567,9 +2567,10 @@
1.11.51 fix: fix stock_zh_a_daily interface
1.11.52 fix: fix fund_scale_change_em interface
1.11.53 add: add stock_zh_a_hist_tx interface
1.11.54 fix: fix fund_portfolio_hold_em interface
"""

__version__ = "1.11.53"
__version__ = "1.11.54"
__author__ = "AKFamily"

import sys
Expand Down Expand Up @@ -3525,7 +3526,6 @@
"""

from akshare.stock_feature.stock_cls_alerts import (
stock_zh_a_alerts_cls,
stock_telegraph_cls,
)

Expand Down Expand Up @@ -4801,8 +4801,6 @@
macro_china_whxd,
macro_china_wbck,
macro_china_bond_public,
macro_china_gksccz,
macro_china_hb,
macro_china_xfzxx,
macro_china_reserve_requirement_ratio,
macro_china_consumer_goods_retail,
Expand Down
132 changes: 1 addition & 131 deletions akshare/economic/macro_china.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2023/10/8 20:20
Date: 2023/10/28 18:20
Desc: 宏观数据-中国
"""
import json
Expand Down Expand Up @@ -3332,130 +3332,6 @@ def macro_china_wbck() -> pd.DataFrame:
return temp_df


def macro_china_hb(symbol: str = "weekly") -> pd.DataFrame:
"""
中国-货币净投放与净回笼
http://www.chinamoney.com.cn/chinese/hb/
:param symbol: choice of {"weekly", "monthly"}
:type symbol: str
:return: 货币净投放与净回笼
:rtype: pandas.DataFrame
"""
import warnings

warnings.warn("由于目标网站未更新数据,该接口即将移除", DeprecationWarning)

# if symbol == "weekly":
# current_year = datetime.today().year
# url = "https://www.chinamoney.com.cn/ags/ms/cm-u-bond-publish/TicketPutAndBackStatByWeek"
# params = {
# "t": "1597986289666",
# "t": "1597986289666",
# }
# big_df = pd.DataFrame()
# for year in tqdm(range(1997, current_year + 1)):
# payload = {
# "startWeek": f"{year}-01",
# "endWeek": f"{year}-52",
# "pageSize": "5000",
# "pageNo": "1",
# }
# r = requests.post(url, params=params, data=payload)
# temp_df = pd.DataFrame(r.json()["data"]["resultList"])
# big_df = big_df.append(temp_df, ignore_index=True)
# big_df = big_df.sort_values(by=["startDate"])
# big_df.reset_index(inplace=True, drop=True)
# big_df.columns = ["日期", "投放量", "回笼量", "净投放", "开始日期", "结束日期"]
# big_df = big_df[["日期", "开始日期", "结束日期", "投放量", "回笼量", "净投放"]]
# big_df["开始日期"] = pd.to_datetime(big_df["开始日期"]).dt.date
# 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["净投放"])
# return big_df
# else:
# current_year = datetime.today().year
# url = "https://www.chinamoney.com.cn/ags/ms/cm-u-bond-publish/TicketPutAndBackStatByMonth"
# params = {
# "t": "1597986289666",
# "t": "1597986289666",
# }
# big_df = pd.DataFrame()
# for year in tqdm(range(1997, current_year + 1)):
# payload = {
# "startMonth": f"{year}-01",
# "endMonth": f"{year}-12",
# "pageSize": "5000",
# "pageNo": "1",
# }
# r = requests.post(url, params=params, data=payload)
# temp_df = pd.DataFrame(r.json()["data"]["resultList"])
# big_df = big_df.append(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["净投放"])
# return big_df


def macro_china_gksccz() -> pd.DataFrame:
"""
中国外汇交易中心暨全国银行间同业拆借中心-央行公开市场操作
http://www.chinamoney.com.cn/chinese/yhgkscczh/
:return: 央行公开市场操作
:rtype: pandas.DataFrame
"""
import warnings

warnings.warn("由于目标网站未更新数据,该接口即将移除", DeprecationWarning)
# url = "https://www.chinamoney.com.cn/ags/ms/cm-u-bond-publish/TicketHandle"
# params = {
# "t": "1597986289666",
# "t": "1597986289666",
# }
# payload = {
# "pageSize": "15",
# "pageNo": "1",
# }
# headers = {
# "Accept": "application/json, text/javascript, */*; q=0.01",
# "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
# "Referer": "https://www.chinamoney.com.cn/chinese/yhgkscczh/",
# "sec-ch-ua": '" Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"',
# "sec-ch-ua-mobile": "?0",
# "sec-ch-ua-platform": '"Windows"',
# "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36",
# "X-Requested-With": "XMLHttpRequest",
# }
# r = requests.post(url, params=params, data=payload, headers=headers)
# data_json = r.json()
# total_page = data_json["data"]["pageTotal"]
# big_df = pd.DataFrame()
# for page in tqdm(range(1, total_page + 1)):
# payload.update(
# {
# "pageNo": page,
# }
# )
# r = requests.post(url, params=params, data=payload)
# data_json = r.json()
# temp_df = pd.DataFrame(data_json["data"]["resultList"])
# big_df = big_df.append(temp_df, ignore_index=True)
# 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["中标利率"])
# return big_df


def macro_china_bond_public() -> pd.DataFrame:
"""
中国-债券信息披露-债券发行
Expand Down Expand Up @@ -4499,12 +4375,6 @@ def macro_china_real_estate() -> pd.DataFrame:
macro_china_wbck_df = macro_china_wbck()
print(macro_china_wbck_df)

macro_china_hb_df = macro_china_hb(symbol="weekly")
print(macro_china_hb_df)

macro_china_gksccz_df = macro_china_gksccz()
print(macro_china_gksccz_df)

macro_china_bond_public_df = macro_china_bond_public()
print(macro_china_bond_public_df)

Expand Down
35 changes: 18 additions & 17 deletions akshare/fund/fund_portfolio_em.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2022/3/21 17:40
Date: 2023/10/28 18:30
Desc: 天天基金网-基金档案-投资组合
https://fundf10.eastmoney.com/ccmx_000001.html
"""
from io import StringIO

import pandas as pd
import requests
from bs4 import BeautifulSoup
Expand All @@ -13,7 +15,7 @@


def fund_portfolio_hold_em(
symbol: str = "162411", date: str = "2020"
symbol: str = "162411", date: str = "2020"
) -> pd.DataFrame:
"""
天天基金网-基金档案-投资组合-基金持仓
Expand All @@ -36,15 +38,15 @@ def fund_portfolio_hold_em(
}
r = requests.get(url, params=params)
data_text = r.text
data_json = demjson.decode(data_text[data_text.find("{") : -1])
data_json = demjson.decode(data_text[data_text.find("{"): -1])
soup = BeautifulSoup(data_json["content"], "lxml")
item_label = [
item.text.split("\xa0\xa0")[1]
for item in soup.find_all("h4", attrs={"class": "t"})
]
big_df = pd.DataFrame()
for item in range(len(item_label)):
temp_df = pd.read_html(data_json["content"], converters={"股票代码": str})[
temp_df = pd.read_html(StringIO(data_json["content"]), converters={"股票代码": str})[
item
]
del temp_df["相关资讯"]
Expand All @@ -67,7 +69,6 @@ def fund_portfolio_hold_em(
columns={"持股数 (万股)": "持股数", "持仓市值 (万元人民币)": "持仓市值"}, inplace=True
)


temp_df["季度"] = item_label[item]
temp_df = temp_df[
[
Expand All @@ -89,11 +90,11 @@ def fund_portfolio_hold_em(


def fund_portfolio_bond_hold_em(
symbol: str = "000001", date: str = "2021"
symbol: str = "000001", date: str = "2021"
) -> pd.DataFrame:
"""
天天基金网-基金档案-投资组合-债券持仓
http://fundf10.eastmoney.com/ccmx1_000001.html
https://fundf10.eastmoney.com/ccmx1_000001.html
:param symbol: 基金代码
:type symbol: str
:param date: 查询年份
Expand All @@ -110,15 +111,15 @@ def fund_portfolio_bond_hold_em(
}
r = requests.get(url, params=params)
data_text = r.text
data_json = demjson.decode(data_text[data_text.find("{") : -1])
data_json = demjson.decode(data_text[data_text.find("{"): -1])
soup = BeautifulSoup(data_json["content"], "lxml")
item_label = [
item.text.split("\xa0\xa0")[1]
for item in soup.find_all("h4", attrs={"class": "t"})
]
big_df = pd.DataFrame()
for item in range(len(item_label)):
temp_df = pd.read_html(data_json["content"], converters={"债券代码": str})[
temp_df = pd.read_html(StringIO(data_json["content"]), converters={"债券代码": str})[
item
]
temp_df["占净值比例"] = (
Expand All @@ -144,11 +145,11 @@ def fund_portfolio_bond_hold_em(


def fund_portfolio_industry_allocation_em(
symbol: str = "000001", date: str = "2021"
symbol: str = "000001", date: str = "2021"
) -> pd.DataFrame:
"""
天天基金网-基金档案-投资组合-行业配置
http://fundf10.eastmoney.com/hytz_000001.html
https://fundf10.eastmoney.com/hytz_000001.html
:param symbol: 基金代码
:type symbol: str
:param date: 查询年份
Expand Down Expand Up @@ -176,7 +177,7 @@ def fund_portfolio_industry_allocation_em(
}
r = requests.get(url, params=params, headers=headers)
data_text = r.text
data_json = demjson.decode(data_text[data_text.find("{") : -1])
data_json = demjson.decode(data_text[data_text.find("{"): -1])
temp_list = []
for item in data_json["Data"]["QuarterInfos"]:
temp_list.extend(item["HYPZInfo"])
Expand Down Expand Up @@ -211,17 +212,17 @@ def fund_portfolio_industry_allocation_em(
"截止时间",
]
]
temp_df["市值"] = pd.to_numeric(temp_df["市值"])
temp_df["市值"] = pd.to_numeric(temp_df["市值"], errors="coerce")
temp_df["占净值比例"] = pd.to_numeric(temp_df["占净值比例"], errors="coerce")
return temp_df


def fund_portfolio_change_em(
symbol: str = "003567", indicator: str = "累计买入", date: str = "2020"
symbol: str = "003567", indicator: str = "累计买入", date: str = "2020"
) -> pd.DataFrame:
"""
天天基金网-基金档案-投资组合-重大变动
http://fundf10.eastmoney.com/ccbd_000001.html
https://fundf10.eastmoney.com/ccbd_000001.html
:param symbol: 基金代码
:type symbol: str
:param indicator: choice of {"累计买入", "累计卖出"}
Expand All @@ -245,15 +246,15 @@ def fund_portfolio_change_em(
}
r = requests.get(url, params=params)
data_text = r.text
data_json = demjson.decode(data_text[data_text.find("{") : -1])
data_json = demjson.decode(data_text[data_text.find("{"): -1])
soup = BeautifulSoup(data_json["content"], "lxml")
item_label = [
item.text.split("\xa0\xa0")[1]
for item in soup.find_all("h4", attrs={"class": "t"})
]
big_df = pd.DataFrame()
for item in range(len(item_label)):
temp_df = pd.read_html(data_json["content"], converters={"股票代码": str})[
temp_df = pd.read_html(StringIO(data_json["content"]), converters={"股票代码": str})[
item
]
del temp_df["相关资讯"]
Expand Down
Loading