Skip to content

Commit

Permalink
Date (#4390)
Browse files Browse the repository at this point in the history
* add version 1.12.11

* add stock_zh_index_spot_em

* update date
  • Loading branch information
albertandking authored Jan 4, 2024
1 parent 2e20975 commit 1277d14
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 22 deletions.
6 changes: 4 additions & 2 deletions akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2623,9 +2623,10 @@
1.12.8 fix: fix fund_open_fund_info_em interface
1.12.9 add: add fund_individual_basic_info_xq interface
1.12.10 fix: fix stock_add_stock interface
1.12.11 add: add stock_zh_index_spot_em interface
"""

__version__ = "1.12.10"
__version__ = "1.12.11"
__author__ = "AKFamily"

import sys
Expand Down Expand Up @@ -4652,7 +4653,8 @@
"""
from akshare.index.index_stock_zh import (
stock_zh_index_daily,
stock_zh_index_spot,
stock_zh_index_spot_sina,
stock_zh_index_spot_em,
stock_zh_index_daily_tx,
stock_zh_index_daily_em,
)
Expand Down
91 changes: 88 additions & 3 deletions akshare/index/index_stock_zh.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_zh_index_page_count() -> int:
return int(page_count) + 1


def stock_zh_index_spot() -> pd.DataFrame:
def stock_zh_index_spot_sina() -> pd.DataFrame:
"""
新浪财经-行情中心首页-A股-分类-所有指数
大量采集会被目标网站服务器封禁 IP, 如果被封禁 IP, 请 10 分钟后再试
Expand Down Expand Up @@ -124,6 +124,88 @@ def stock_zh_index_spot() -> pd.DataFrame:
return big_df


def stock_zh_index_spot_em(symbol: str = "上证系列指数") -> pd.DataFrame:
"""
东方财富网-行情中心-沪深京指数
https://quote.eastmoney.com/center/gridlist.html#index_sz
:param symbol: "上证系列指数"; choice of {"上证系列指数", "深证系列指数", "指数成份", "中证系列指数"}
:type symbol: str
:return: 指数的实时行情数据
:rtype: pandas.DataFrame
"""
url = "https://48.push2.eastmoney.com/api/qt/clist/get"
symbol_map = {
"上证系列指数": "m:1 s:2",
"深证系列指数": "m:0 t:5",
"指数成份": "m:1 s:3,m:0 t:5",
"中证系列指数": "m:2",
}
params = {
'pn': '1',
'pz': '5000',
'po': '1',
'np': '1',
'ut': 'bd1d9ddb04089700cf9c27f6f7426281',
'fltt': '2',
'invt': '2',
'wbp2u': '|0|0|0|web',
'fid': 'f3',
'fs': symbol_map[symbol],
'fields': 'f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f33,f11,f62,f128,f136,f115,f152',
'_': '1704327268532',
}
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame(data_json['data']['diff'])
temp_df.reset_index(inplace=True)
temp_df['index'] = temp_df['index'] + 1
temp_df.rename(columns={
'index': '序号',
'f2': '最新价',
'f3': '涨跌幅',
'f4': '涨跌额',
'f5': '成交量',
'f6': '成交额',
'f7': '振幅',
'f10': '量比',
'f12': '代码',
'f14': '名称',
'f15': '最高',
'f16': '最低',
'f17': '今开',
'f18': '昨收',
}, 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")
return temp_df



def stock_zh_index_daily(symbol: str = "sh000922") -> pd.DataFrame:
"""
新浪财经-指数-历史行情数据, 大量抓取容易封 IP
Expand Down Expand Up @@ -292,8 +374,11 @@ def stock_zh_index_daily_em(
stock_zh_index_daily_df = stock_zh_index_daily(symbol="sz399905")
print(stock_zh_index_daily_df)

stock_zh_index_spot_df = stock_zh_index_spot()
print(stock_zh_index_spot_df)
stock_zh_index_spot_sina_df = stock_zh_index_spot_sina()
print(stock_zh_index_spot_sina_df)

stock_zh_index_spot_em_df = stock_zh_index_spot_em(symbol="上证系列指数")
print(stock_zh_index_spot_em_df)

stock_zh_index_daily_tx_df = stock_zh_index_daily_tx(symbol="sh000919")
print(stock_zh_index_daily_tx_df)
Expand Down
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

| AKShare 版本 | 旧接口名称 | 新接口名称 | 修改日期 |
|------------|---------------------------------------------|---------------------------------------------|----------|
| 1.12.11 | stock_zh_index_spot | stock_zh_index_spot_sina | 20240104 |
| 1.11.64 | futures_sgx_daily | futures_settlement_price_sgx | 20231108 |
| 1.11.61 | fund_manager | fund_manager_em | 20231105 |
| 1.11.41 | weibo_index | index_weibo_sina | 20231020 |
Expand Down Expand Up @@ -70,6 +71,11 @@

## 更新说明详情

1.12.11 add: add stock_zh_index_spot_em interface

1. 新增 stock_zh_index_spot_em 接口
2. 重命名 stock_zh_index_spot 为 stock_zh_index_spot_sina

1.12.10 fix: fix stock_add_stock interface

1. 修复 stock_add_stock 接口
Expand Down Expand Up @@ -3308,6 +3314,8 @@

## 版本更新说明

1.12.11 add: add stock_zh_index_spot_em interface

1.12.10 fix: fix stock_add_stock interface

1.12.9 add: add fund_individual_basic_info_xq interface
Expand Down
93 changes: 78 additions & 15 deletions docs/data/index/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,71 @@

### A股股票指数数据

#### 实时行情数据
#### 实时行情数据-东财

接口: stock_zh_index_spot_em

目标地址: https://quote.eastmoney.com/center/gridlist.html#index_sz

描述: 东方财富网-行情中心-沪深京指数

限量: 单次返回所有指数的实时行情数据

输入参数

| 名称 | 类型 | 描述 |
|--------|-----|------------------------------------------------------------------|
| symbol | str | symbol="上证系列指数";choice of {"上证系列指数", "深证系列指数", "指数成份", "中证系列指数"} |

输出参数

| 名称 | 类型 | 描述 |
|-----|---------|---------|
| 序号 | int64 | - |
| 代码 | object | - |
| 名称 | object | - |
| 最新价 | float64 | - |
| 涨跌额 | float64 | - |
| 涨跌幅 | float64 | 注意单位: % |
| 成交量 | float64 | - |
| 成交额 | float64 | - |
| 振幅 | float64 | 注意单位: % |
| 最高 | float64 | - |
| 最低 | float64 | - |
| 今开 | float64 | - |
| 昨收 | float64 | - |
| 量比 | float64 | - |

接口示例

```python
import akshare as ak

stock_zh_index_spot_em_df = ak.stock_zh_index_spot_em(symbol="上证系列指数")
print(stock_zh_index_spot_em_df)
```

数据示例

```
序号 代码 名称 最新价 涨跌幅 涨跌额 ... 振幅 最高 最低 今开 昨收 量比
0 1 000116 信用100 183.69 0.01 0.02 ... 0.0 NaN NaN NaN 183.67 NaN
1 2 000101 5年信用 233.04 0.01 0.02 ... 0.0 NaN NaN NaN 233.02 NaN
2 3 000022 沪公司债 234.63 0.01 0.02 ... 0.0 NaN NaN NaN 234.61 NaN
3 4 000061 沪企债30 169.79 0.01 0.01 ... 0.0 NaN NaN NaN 169.78 NaN
4 5 000012 国债指数 206.03 0.00 0.01 ... 0.0 NaN NaN NaN 206.02 NaN
.. ... ... ... ... ... ... ... ... .. .. .. ... ..
174 175 000005 商业指数 2351.11 0.00 0.00 ... 0.0 NaN NaN NaN 2351.11 NaN
175 176 000004 工业指数 2703.99 0.00 0.00 ... 0.0 NaN NaN NaN 2703.99 NaN
176 177 000003 B股指数 234.19 0.00 0.00 ... 0.0 NaN NaN NaN 234.19 NaN
177 178 000002 A股指数 3111.03 0.00 0.00 ... 0.0 NaN NaN NaN 3111.03 NaN
178 179 000001 上证指数 2967.25 0.00 0.00 ... 0.0 NaN NaN NaN 2967.25 NaN
[179 rows x 14 columns]
```

#### 实时行情数据-新浪

接口: stock_zh_index_spot
接口: stock_zh_index_spot_sina

目标地址: http://vip.stock.finance.sina.com.cn/mkt/#hs_s

Expand Down Expand Up @@ -39,25 +101,26 @@
```python
import akshare as ak

stock_zh_index_spot_df = ak.stock_zh_index_spot()
print(stock_zh_index_spot_df)
stock_zh_index_spot_sina_df = ak.stock_zh_index_spot_sina()
print(stock_zh_index_spot_sina_df)
```

数据示例

```
代码 名称 最新价 ... 最低 成交量 成交额
0 sh000001 上证指数 3484.3924 ... 3462.8321 262654873 317953200768
1 sh000002 A股指数 3652.2918 ... 3629.6721 262507126 317711821774
2 sh000003 B股指数 246.1128 ... 245.3968 121902 62088261
3 sh000004 工业指数 3084.5617 ... 3051.0834 162642330 224198720298
4 sh000005 商业指数 3161.1518 ... 3150.4813 14486730 19213540155
代码 名称 最新价 ... 最低 成交量 成交额
0 sh000001 上证指数 2967.2472 ... 2953.2901 285455945 321018391310
1 sh000002 A股指数 3111.0281 ... 3096.3842 285134140 320788878153
2 sh000003 B股指数 234.1943 ... 232.4912 297879 160673330
3 sh000004 工业指数 2703.9886 ... 2690.2040 168709808 228294788620
4 sh000005 商业指数 2351.1093 ... 2339.6375 23082870 23470835715
.. ... ... ... ... ... ... ...
575 sz399998 中证煤炭 1395.7690 ... 1392.0210 788677823 4900473791
576 sz980001 1690.5910 ... 1679.6590 2458615064 60754965378
577 sz980017 9014.4380 ... 8679.3360 835190754 34070561457
578 sz980023 2957.4530 ... 2950.4640 489534394 8813329425
579 sz980068 2165.8470 ... 2154.3910 439360589 4552661981
552 sz980015 疫苗生科 8560.3130 ... 8533.3370 421452161 12430783309
553 sz980016 公卫健康 6844.2740 ... 6824.8810 572854058 16723915499
554 sz980028 龙头家电 9330.1080 ... 9296.8940 296504548 7181802948
555 sz980030 消费电子 4393.0420 ... 4372.5400 1645434624 24770906620
556 sz980032 新能电池 8862.8690 ... 8791.8960 344385538 13001077515
[557 rows x 11 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-01-03**
1. 本文档更新时间:**2024-01-04**
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. 如果您的问题未能在文档中找到答案,您也可以加入 **AKShare-VIP QQ 群**: 为了提高问答质量,此群为收费群(一杯咖啡钱即可入群,赠送[《AKShare-初阶-使用教学》](https://zmj.xet.tech/s/wck86)视频课),可以添加 **AKShare-小助手** QQ:1254836886,由小助手邀请入群! ![](https://jfds-1252952517.cos.ap-chengdu.myqcloud.com/akshare/readme/qrcode/qr_code_1254836886.jpg)
Expand Down
3 changes: 2 additions & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
"stock_zh_index_daily" # 股票指数历史行情数据
"stock_zh_index_daily_tx" # 股票指数历史行情数据-腾讯
"stock_zh_index_daily_em" # 股票指数历史行情数据-东方财富
"stock_zh_index_spot" # 股票指数实时行情数据
"stock_zh_index_spot_sina" # 股票指数实时行情数据-新浪
"stock_zh_index_spot_em" # 股票指数实时行情数据-东财
# 股票分笔数据
"stock_zh_a_tick_tx_js" # A 股票分笔行情数据-腾讯-当日数据
# 世界各地区日出和日落数据-日
Expand Down

0 comments on commit 1277d14

Please sign in to comment.