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 #5308

Merged
merged 6 commits into from
Nov 5, 2024
Merged

Dev #5308

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
4 changes: 3 additions & 1 deletion akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2922,9 +2922,10 @@
1.15.10 add: add volatility_yz_rv indicator
1.15.11 fix: fix stock_individual_spot_xq indicator
1.15.12 fix: fix stock_shareholder_change_ths indicator
1.15.13 fix: fix stock_inner_trade_xq indicator
"""

__version__ = "1.15.12"
__version__ = "1.15.13"
__author__ = "AKFamily"

import sys
Expand Down Expand Up @@ -3206,6 +3207,7 @@
stock_financial_debt_ths,
stock_financial_benefit_ths,
stock_financial_cash_ths,
stock_management_change_ths,
stock_shareholder_change_ths,
)

Expand Down
70 changes: 39 additions & 31 deletions akshare/stock_feature/stock_inner_trade_xq.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding:utf-8 -*-
# !/usr/bin/env python
"""
Date: 2022/4/29 17:01
Date: 2024/11/5 16:00
Desc: 雪球-行情中心-沪深股市-内部交易
https://xueqiu.com/hq/insider
"""

import pandas as pd
import requests

Expand All @@ -18,10 +19,10 @@ def stock_inner_trade_xq() -> pd.DataFrame:
"""
url = "https://xueqiu.com/service/v5/stock/f10/cn/skholderchg"
params = {
'size': '100000',
'page': '1',
'extend': 'true',
'_': '1651223013040',
"size": "100000",
"page": "1",
"extend": "true",
"_": "1651223013040",
}
headers = {
"Accept": "*/*",
Expand All @@ -38,39 +39,46 @@ def stock_inner_trade_xq() -> pd.DataFrame:
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/100.0.4896.127 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
}
r = requests.get(url, params=params, headers=headers)
data_json = r.json()
temp_df = pd.DataFrame(data_json["data"]["items"])
temp_df.columns = [
'股票代码',
'股票名称',
'变动人',
'-',
'变动日期',
'变动股数',
'成交均价',
'变动后持股数',
'与董监高关系',
'董监高职务',
"股票代码",
"股票名称",
"变动人",
"-",
"变动日期",
"变动股数",
"成交均价",
"变动后持股数",
"与董监高关系",
"董监高职务",
]
temp_df = temp_df[
[
"股票代码",
"股票名称",
"变动日期",
"变动人",
"变动股数",
"成交均价",
"变动后持股数",
"与董监高关系",
"董监高职务",
]
]
temp_df = temp_df[[
'股票代码',
'股票名称',
'变动日期',
'变动人',
'变动股数',
'成交均价',
'变动后持股数',
'与董监高关系',
'董监高职务',
]]
temp_df['变动日期'] = pd.to_datetime(temp_df['变动日期'], unit="ms").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_datetime(temp_df["变动日期"], unit="ms", utc=True)
.dt.tz_convert("Asia/Shanghai")
.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")
return temp_df


Expand Down
54 changes: 53 additions & 1 deletion akshare/stock_fundamental/stock_finance_ths.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pandas as pd
import requests
from bs4 import BeautifulSoup

from akshare.utils.cons import headers


Expand Down Expand Up @@ -163,13 +164,61 @@ def stock_financial_cash_ths(
return temp_df


def stock_management_change_ths(symbol: str = "688981") -> pd.DataFrame:
"""
同花顺-公司大事-高管持股变动
https://basic.10jqka.com.cn/new/688981/event.html
:param symbol: 股票代码
:type symbol: str
:return: 同花顺-公司大事-高管持股变动
:rtype: pandas.DataFrame
"""
url = f"https://basic.10jqka.com.cn/new/{symbol}/event.html"
r = requests.get(url, headers=headers)
r.encoding = "gb2312"
soup = BeautifulSoup(r.text, features="lxml")
soup_find = soup.find(name="table", attrs={"class": "data_table_1 m_table m_hl"})
if soup_find is not None:
content_list = [item.text.strip() for item in soup_find]
column_names = content_list[1].split("\n")
row = (
content_list[3]
.replace(" ", "")
.replace("\t", "")
.replace("\n\n", "")
.replace(" ", "\n")
.replace("\n\n", "\n")
.split("\n")
)
row = [item for item in row if item != ""]
new_rows = []
step = len(column_names)
for i in range(0, len(row), step):
new_rows.append(row[i : i + step])
temp_df = pd.DataFrame(new_rows, columns=column_names)
temp_df.sort_values(by="变动日期", ignore_index=True, inplace=True)
temp_df["变动日期"] = pd.to_datetime(
temp_df["变动日期"], errors="coerce"
).dt.date
temp_df.rename(
columns={
"变动数量(股)": "变动数量",
"交易均价(元)": "交易均价",
"剩余股数(股)": "剩余股数",
},
inplace=True,
)
return temp_df
return pd.DataFrame()


def stock_shareholder_change_ths(symbol: str = "688981") -> pd.DataFrame:
"""
同花顺-公司大事-股东持股变动
https://basic.10jqka.com.cn/new/688981/event.html
:param symbol: 股票代码
:type symbol: str
:return: 同花顺-财务指标-主要指标
:return: 同花顺-公司大事-股东持股变动
:rtype: pandas.DataFrame
"""
url = f"https://basic.10jqka.com.cn/new/{symbol}/event.html"
Expand Down Expand Up @@ -267,5 +316,8 @@ def stock_shareholder_change_ths(symbol: str = "688981") -> pd.DataFrame:
)
print(stock_financial_cash_ths_df)

stock_management_change_ths_df = stock_management_change_ths(symbol="688981")
print(stock_management_change_ths_df)

stock_shareholder_change_ths_df = stock_shareholder_change_ths(symbol="688981")
print(stock_shareholder_change_ths_df)
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@

## 更新说明详情

1.15.13 fix: fix stock_inner_trade_xq indicator

1. 修复 stock_inner_trade_xq 接口
2. 新增 stock_management_change_ths 接口

1.15.12 fix: fix stock_shareholder_change_ths indicator

1. 修复 stock_shareholder_change_ths 接口
Expand Down Expand Up @@ -4695,6 +4700,8 @@

## 版本更新说明

1.15.13 fix: fix stock_inner_trade_xq indicator

1.15.12 fix: fix stock_shareholder_change_ths indicator

1.15.11 fix: fix stock_individual_spot_xq indicator
Expand Down
80 changes: 68 additions & 12 deletions docs/data/stock/stock.md
Original file line number Diff line number Diff line change
Expand Up @@ -11998,6 +11998,61 @@ print(stock_gdfx_holding_change_em_df)
33900 33901 ... 000761|本钢板材,200761|本钢板B
```


#### 高管持股变动统计

接口: stock_management_change_ths

目标地址: https://basic.10jqka.com.cn/new/688981/event.html

描述: 同花顺-公司大事-高管持股变动

限量: 单次返回所有数据

输入参数

| 名称 | 类型 | 描述 |
|--------|-----|-----------------------|
| symbol | str | symbol="688981"; 股票代码 |

输出参数

| 名称 | 类型 | 描述 |
|---------|--------|---------|
| 公告日期 | object | - |
| 变动人 | object | - |
| 与公司高管关系 | object | - |
| 变动数量 | object | 注意单位: 股 |
| 交易均价 | object | 注意单位: 元 |
| 剩余股数 | object | 注意单位: 股 |
| 变动途径 | object | - |

接口示例

```python
import akshare as ak

stock_management_change_ths_df = ak.stock_management_change_ths(symbol="688981")
print(stock_management_change_ths_df)
```

数据示例

```
变动日期 变动人 与公司高管关系 ... 交易均价 剩余股数 股份变动途径
0 2022-09-01 张昕 核心技术人员 ... 20.00 9.60万 股权激励
1 2022-09-01 金达 核心技术人员 ... 20.00 4.80万 股权激励
2 2022-09-01 阎大勇 核心技术人员 ... 20.00 4.20万 股权激励
3 2022-10-10 阎大勇 核心技术人员 减持4.20万 37.98 0.00 二级市场买卖
... ... ...
10 2024-09-05 阎大勇 核心技术人员 增持3.50万 20.00 7.00万 股权激励实施
11 2024-09-05 张昕 核心技术人员 增持8.00万 20.00 16.00万 股权激励实施
12 2024-09-25 张昕 核心技术人员 减持1.80万 45.31 14.20万 二级市场买卖
13 2024-09-30 金达 核心技术人员 减持4.00万 54.87 4.00万 二级市场买卖
[13 rows x 7 columns]
```


#### 股东持股变动统计

接口: stock_shareholder_change_ths
Expand Down Expand Up @@ -21211,18 +21266,19 @@ print(stock_inner_trade_xq_df)
数据示例

```
股票代码 股票名称 变动日期 ... 变动后持股数 与董监高关系 董监高职务
0 SH688019 安集科技 2022-04-27 ... 3364.0 核心技术人员
1 SH603668 天马科技 2022-04-27 ... 9283431.0 本人 董事
2 SH603668 天马科技 2022-04-27 ... 6228100.0 本人 董事
3 SH603656 泰禾智能 2022-04-27 ... 199700.0 本人 董事
4 SZ300931 通用电梯 2022-04-26 ... 1591200.0 本人 董事
... ... ... ... ... ... ...
15971 SH601838 成都银行 2021-01-03 ... 160000.0 本人 董事
15972 SH601107 四川成渝 2021-01-03 ... 30000.0 本人 董事
15973 SH600988 赤峰黄金 2021-01-03 ... 2000.0 本人 监事
15974 SH600760 中航沈飞 2021-01-03 ... 79000.0 本人 高级管理人员
15975 SH600760 中航沈飞 2021-01-03 ... 35100.0 本人 高级管理人员
股票代码 股票名称 变动日期 变动人 ... 成交均价 变动后持股数 与董监高关系 董监高职务
0 SH688787 海天瑞声 2024-11-04 吕思遥 ... 63.00 42850.0 本人 董事
1 SH688550 瑞联新材 2024-11-04 胡湛 ... 31.11 39014.0 本人 高级管理人员
2 SH600868 梅雁吉祥 2024-11-04 李明 ... 2.39 26650702.0 本人 董事
3 SZ301206 三元生物 2024-11-01 聂在建 ... 27.71 93698700.0 本人 董事
4 SZ300963 中洲特材 2024-11-01 韩明 ... 9.69 32119500.0 本人 董事
... ... ... ... ... ... ... ... ... ...
23300 SH601028 玉龙股份 2023-01-03 张鹏 ... 11.69 7000.0 本人 董事
23301 SH600875 东方电气 2023-01-03 胡修奎 ... 22.60 65000.0 本人 高级管理人员
23302 SH600089 特变电工 2023-01-03 胡有成 ... 6.51 700000.0 本人 高级管理人员
23303 SH600079 人福医药 2023-01-03 王学海 ... 24.00 4615346.0 本人 董事
23304 SH600079 人福医药 2023-01-03 徐华斌 ... 25.04 14300716.0
[23305 rows x 9 columns]
```

#### 个股人气榜-最新排名
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
**风险提示**:[AKShare](https://github.com/akfamily/akshare) 开源财经数据接口库所采集的数据皆来自公开的数据源,不涉及任何个人隐私数据和非公开数据。
同时本项目提供的数据接口及相关数据仅用于学术研究,任何个人、机构及团体使用本项目的数据接口及相关数据请注意商业风险。

1. 本文档更新时间:**2024-11-03**;
1. 本文档更新时间:**2024-11-05**;
2. 如有 [AKShare](https://github.com/akfamily/akshare) 库、文档及数据的相关问题,请在 [AKShare Issues](https://github.com/akfamily/akshare/issues) 中提 Issues;
3. 欢迎关注 **数据科学实战** 微信公众号;<div><img src="https://jfds-1252952517.cos.ap-chengdu.myqcloud.com/akshare/readme/qrcode/ds.png"></div>
4. **知识星球【数据科学实战】** 2024 全新改版,聚焦于量化投资内容,欢迎加入 **知识星球【数据科学实战】** 高质量社区,里面有丰富的视频课程、问答、文章、书籍及代码等内容:
Expand Down
1 change: 1 addition & 0 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,7 @@
"qdii_a_index_jsl" # 集思录-T+0 QDII-亚洲市场-亚洲指数
# 同花顺-公司大事-股东持股变动
"stock_shareholder_change_ths" # 同花顺-公司大事-股东持股变动
"stock_management_change_ths" # 同花顺-公司大事-高管持股变动

# 计算指标
"volatility_yz_rv" # 已实现波动率计算
Expand Down