Skip to content

Commit

Permalink
fix(stock_repurchase_em): fix stock_repurchase_em interface
Browse files Browse the repository at this point in the history
fix stock_repurchase_em interface
  • Loading branch information
ak-quant committed May 10, 2022
1 parent 5c15c02 commit 4600753
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 166 deletions.
3 changes: 2 additions & 1 deletion akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1984,9 +1984,10 @@
1.5.62 add: add stock_cash_flow_sheet_by_quarterly_em interface
1.5.63 fix: fix import path problem
1.5.64 fix: fix stock_cash_flow_sheet_by_yearly_em interface
1.5.65 fix: fix stock_repurchase_em interface
"""

__version__ = "1.5.64"
__version__ = "1.5.65"
__author__ = "AKFamily"

import sys
Expand Down
6 changes: 3 additions & 3 deletions akshare/stock/stock_repurchase_em.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
"""
Date: 2021/12/2 15:48
Date: 2022/5/10 17:30
Desc: 东方财富网-数据中心-股票回购-股票回购数据
https://data.eastmoney.com/gphg/hglist.html
"""
Expand Down Expand Up @@ -31,12 +31,12 @@ def stock_repurchase_em() -> pd.DataFrame:
data_json = r.json()
total_page = data_json["result"]["pages"]
big_df = pd.DataFrame()
for page in tqdm(range(1, int(total_page) + 1)):
for page in tqdm(range(1, int(total_page) + 1), leave=False):
params.update({"p": page})
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame(data_json["result"]["data"])
big_df = big_df.append(temp_df, ignore_index=True)
big_df = pd.concat([big_df, temp_df], ignore_index=True)
big_df.rename(
{
"dim_scode": "股票代码",
Expand Down
4 changes: 2 additions & 2 deletions akshare/stock/stock_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import requests


def stock_staq_net_stop():
def stock_staq_net_stop() -> pd.DataFrame:
"""
东方财富网-行情中心-沪深个股-两网及退市
http://quote.eastmoney.com/center/gridlist.html#staq_net_board
Expand All @@ -34,7 +34,7 @@ def stock_staq_net_stop():
data_json = r.json()
temp_df = pd.DataFrame(data_json['data']['diff'])
temp_df.reset_index(inplace=True)
temp_df['index'] = range(1, len(temp_df)+1)
temp_df['index'] = temp_df.index + 1
temp_df.columns = ['序号', '代码', '名称']
return temp_df

Expand Down
131 changes: 63 additions & 68 deletions akshare/stock/stock_summary.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2021/12/30 11:31
Date: 2022/5/10 17:00
Desc: 股票数据-总貌-市场总貌
股票数据-总貌-成交概括
http://www.szse.cn/market/overview/index.html
Expand All @@ -10,12 +10,9 @@
import warnings
from io import BytesIO

from akshare.utils import demjson
import pandas as pd
import requests

warnings.filterwarnings('ignore')


def stock_szse_summary(date: str = "20200619") -> pd.DataFrame:
"""
Expand All @@ -35,25 +32,19 @@ def stock_szse_summary(date: str = "20200619") -> pd.DataFrame:
"random": "0.39339437497296137",
}
r = requests.get(url, params=params)
temp_df = pd.read_excel(BytesIO(r.content))
with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
temp_df = pd.read_excel(BytesIO(r.content), engine="openpyxl")
temp_df["证券类别"] = temp_df["证券类别"].str.strip()
temp_df.iloc[:, 2:] = temp_df.iloc[:, 2:].applymap(lambda x: x.replace(",", ""))
temp_df.columns = [
'证券类别',
'数量',
'成交金额',
'成交量',
'总股本',
'总市值',
'流通股本',
'流通市值']
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['总股本'], 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.columns = ["证券类别", "数量", "成交金额", "成交量", "总股本", "总市值", "流通股本", "流通市值"]
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["总股本"], 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


Expand All @@ -66,20 +57,20 @@ def stock_sse_summary() -> pd.DataFrame:
"""
url = "http://query.sse.com.cn/commonQuery.do"
params = {
'sqlId': 'COMMON_SSE_SJ_GPSJ_GPSJZM_TJSJ_L',
'PRODUCT_NAME': '股票,主板,科创板',
'type': 'inParams',
'_': '1640855495128',
"sqlId": "COMMON_SSE_SJ_GPSJ_GPSJZM_TJSJ_L",
"PRODUCT_NAME": "股票,主板,科创板",
"type": "inParams",
"_": "1640855495128",
}
headers = {
"Referer": "http://www.sse.com.cn/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36",
}
r = requests.get(url, params=params, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json['result']).T
temp_df = pd.DataFrame(data_json["result"]).T
temp_df.reset_index(inplace=True)
temp_df['index'] = [
temp_df["index"] = [
"流通股本",
"总市值",
"平均市盈率",
Expand All @@ -91,12 +82,12 @@ def stock_sse_summary() -> pd.DataFrame:
"总股本",
"项目",
]
temp_df = temp_df[temp_df['index'] != '-'].iloc[:-1, :]
temp_df = temp_df[temp_df["index"] != "-"].iloc[:-1, :]
temp_df.columns = [
'项目',
'股票',
'科创板',
'主板',
"项目",
"股票",
"科创板",
"主板",
]
return temp_df

Expand Down Expand Up @@ -183,18 +174,18 @@ def stock_sse_deal_daily(date: str = "20220331") -> pd.DataFrame:
temp_df["单日情况"].cat.set_categories(list_custom_new)
temp_df.sort_values("单日情况", ascending=True, inplace=True)
temp_df.reset_index(drop=True, inplace=True)
temp_df['股票'] = pd.to_numeric(temp_df['股票'], errors="coerce")
temp_df['主板A'] = pd.to_numeric(temp_df['主板A'], errors="coerce")
temp_df['主板B'] = pd.to_numeric(temp_df['主板B'], 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["主板A"] = pd.to_numeric(temp_df["主板A"], errors="coerce")
temp_df["主板B"] = pd.to_numeric(temp_df["主板B"], errors="coerce")
temp_df["科创板"] = pd.to_numeric(temp_df["科创板"], errors="coerce")
temp_df["股票回购"] = pd.to_numeric(temp_df["股票回购"], errors="coerce")
return temp_df
elif int(date) <= 20220224:
url = "http://query.sse.com.cn/commonQuery.do"
params = {
'sqlId': 'COMMON_SSE_SJ_GPSJ_CJGK_MRGK_C',
'SEARCH_DATE': "-".join([date[:4], date[4:6], date[6:]]),
'_': '1640836561673',
"sqlId": "COMMON_SSE_SJ_GPSJ_CJGK_MRGK_C",
"SEARCH_DATE": "-".join([date[:4], date[4:6], date[6:]]),
"_": "1640836561673",
}
headers = {
"Referer": "http://www.sse.com.cn/",
Expand All @@ -216,12 +207,14 @@ def stock_sse_deal_daily(date: str = "20220331") -> pd.DataFrame:
"-",
"-",
]
temp_df = temp_df[[
"单日情况",
"主板A",
"主板B",
"科创板",
]]
temp_df = temp_df[
[
"单日情况",
"主板A",
"主板B",
"科创板",
]
]
temp_df["单日情况"] = [
"市价总值",
"成交量",
Expand Down Expand Up @@ -250,18 +243,18 @@ def stock_sse_deal_daily(date: str = "20220331") -> pd.DataFrame:
temp_df["单日情况"].cat.set_categories(list_custom_new)
temp_df.sort_values("单日情况", ascending=True, inplace=True)
temp_df.reset_index(inplace=True, drop=True)
temp_df['主板A'] = pd.to_numeric(temp_df['主板A'], errors="coerce")
temp_df['主板B'] = pd.to_numeric(temp_df['主板B'], errors="coerce")
temp_df['科创板'] = pd.to_numeric(temp_df['科创板'], errors="coerce")
temp_df["主板A"] = pd.to_numeric(temp_df["主板A"], errors="coerce")
temp_df["主板B"] = pd.to_numeric(temp_df["主板B"], errors="coerce")
temp_df["科创板"] = pd.to_numeric(temp_df["科创板"], errors="coerce")
return temp_df
else:
url = "http://query.sse.com.cn/commonQuery.do"
params = {
'sqlId': 'COMMON_SSE_SJ_GPSJ_CJGK_MRGK_C',
'PRODUCT_CODE': '01,02,03,11,17',
'type': 'inParams',
'SEARCH_DATE': "-".join([date[:4], date[4:6], date[6:]]),
'_': '1640836561673',
"sqlId": "COMMON_SSE_SJ_GPSJ_CJGK_MRGK_C",
"PRODUCT_CODE": "01,02,03,11,17",
"type": "inParams",
"SEARCH_DATE": "-".join([date[:4], date[4:6], date[6:]]),
"_": "1640836561673",
}
headers = {
"Referer": "http://www.sse.com.cn/",
Expand All @@ -280,7 +273,7 @@ def stock_sse_deal_daily(date: str = "20220331") -> pd.DataFrame:
"科创板",
"股票",
]
temp_df['股票回购'] = '-'
temp_df["股票回购"] = "-"
else:
temp_df.columns = [
"单日情况",
Expand All @@ -290,14 +283,16 @@ def stock_sse_deal_daily(date: str = "20220331") -> pd.DataFrame:
"股票回购",
"股票",
]
temp_df = temp_df[[
"单日情况",
"股票",
"主板A",
"主板B",
"科创板",
"股票回购",
]]
temp_df = temp_df[
[
"单日情况",
"股票",
"主板A",
"主板B",
"科创板",
"股票回购",
]
]
temp_df["单日情况"] = [
"市价总值",
"成交量",
Expand Down Expand Up @@ -326,11 +321,11 @@ def stock_sse_deal_daily(date: str = "20220331") -> pd.DataFrame:
temp_df["单日情况"].cat.set_categories(list_custom_new)
temp_df.sort_values("单日情况", ascending=True, inplace=True)
temp_df.reset_index(inplace=True, drop=True)
temp_df['主板A'] = pd.to_numeric(temp_df['主板A'], errors="coerce")
temp_df['主板B'] = pd.to_numeric(temp_df['主板B'], 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["主板A"] = pd.to_numeric(temp_df["主板A"], errors="coerce")
temp_df["主板B"] = pd.to_numeric(temp_df["主板B"], 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


Expand Down
92 changes: 0 additions & 92 deletions akshare/stock/stock_us_yahoo.py

This file was deleted.

6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

## 更新说明

1.5.65 fix: fix stock_repurchase_em interface

1. 修复 stock_repurchase_em 接口,获取股票回购-股票回购数据

1.5.64 fix: fix stock_cash_flow_sheet_by_yearly_em interface

1. 修复 stock_cash_flow_sheet_by_yearly_em 接口,获取现金流量表-按年度接口
Expand Down Expand Up @@ -533,6 +537,8 @@

## 版本更新说明

1.5.65 fix: fix stock_repurchase_em interface

1.5.64 fix: fix stock_cash_flow_sheet_by_yearly_em interface

1.5.63 fix: fix import path problem
Expand Down

0 comments on commit 4600753

Please sign in to comment.