akshare 1.16.46__py3-none-any.whl → 1.16.47__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
akshare/__init__.py CHANGED
@@ -3055,9 +3055,10 @@ amac_manager_cancelled_info # 中国证券投资基金业协会-信息公示-诚
3055
3055
  1.16.44 fix: fix stock_board_concept_hist_em interface
3056
3056
  1.16.45 fix: fix option_risk_analysis_em interface
3057
3057
  1.16.46 fix: fix stock_hk_index_spot_em interface
3058
+ 1.16.47 fix: fix stock_hsgt_stock_statistics_em interface
3058
3059
  """
3059
3060
 
3060
- __version__ = "1.16.46"
3061
+ __version__ = "1.16.47"
3061
3062
  __author__ = "AKFamily"
3062
3063
 
3063
3064
  import sys
@@ -3079,10 +3080,19 @@ if sys.version_info < (3, 9):
3079
3080
 
3080
3081
  del sys
3081
3082
 
3083
+ """
3084
+ 异步接口
3085
+ """
3086
+ from akshare.stock_a.stock_zh_a_spot import stock_zh_a_spot_em
3087
+
3082
3088
  """
3083
3089
  雪球-个股-公司概况-公司简介
3084
3090
  """
3085
- from akshare.stock_fundamental.stock_basic_info_xq import stock_individual_basic_info_xq
3091
+ from akshare.stock_fundamental.stock_basic_info_xq import (
3092
+ stock_individual_basic_info_xq,
3093
+ stock_individual_basic_info_hk_xq,
3094
+ stock_individual_basic_info_us_xq,
3095
+ )
3086
3096
 
3087
3097
  """
3088
3098
  新浪财经-行情中心-环球市场
@@ -4161,7 +4171,7 @@ from akshare.stock_feature.stock_pankou_em import (
4161
4171
  A 股东方财富
4162
4172
  """
4163
4173
  from akshare.stock_feature.stock_hist_em import (
4164
- stock_zh_a_spot_em,
4174
+ # stock_zh_a_spot_em,
4165
4175
  stock_bj_a_spot_em,
4166
4176
  stock_new_a_spot_em,
4167
4177
  stock_kc_a_spot_em,
File without changes
@@ -0,0 +1,234 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding:utf-8 -*-
3
+ """
4
+ Date: 2025/3/16 12:00
5
+ Desc: 东方财富网-行情首页-沪深京 A 股
6
+ https://quote.eastmoney.com/
7
+ 异步接口-测试版
8
+ """
9
+
10
+ import asyncio
11
+ from typing import Dict, List
12
+
13
+ import aiohttp
14
+ import pandas as pd
15
+
16
+
17
+ async def fetch_single_page(
18
+ session: aiohttp.ClientSession, url: str, params: Dict
19
+ ) -> Dict:
20
+ """异步获取单页数据"""
21
+ async with session.get(url, params=params) as response:
22
+ return await response.json()
23
+
24
+
25
+ async def fetch_all_pages_async(url: str, base_params: Dict) -> List[Dict]:
26
+ """异步获取所有页面数据"""
27
+ # 首先获取总数以计算页数
28
+ first_page_params = base_params.copy()
29
+ first_page_params["pn"] = "1"
30
+
31
+ async with aiohttp.ClientSession() as session:
32
+ first_page_data = await fetch_single_page(session, url, first_page_params)
33
+
34
+ # 检查是否成功获取数据
35
+ if first_page_data.get("rc") != 0 or not first_page_data.get("data"):
36
+ return [first_page_data] # 返回错误信息
37
+
38
+ total = first_page_data["data"]["total"]
39
+ page_size = int(base_params["pz"])
40
+ total_pages = (total + page_size - 1) // page_size
41
+
42
+ # 限制页数,避免过大请求
43
+ total_pages = min(total_pages, 100)
44
+
45
+ # 创建所有页面的任务
46
+ tasks = []
47
+ for page in range(1, total_pages + 1):
48
+ page_params = base_params.copy()
49
+ page_params["pn"] = str(page)
50
+ tasks.append(fetch_single_page(session, url, page_params))
51
+
52
+ # 并发执行所有任务
53
+ results = await asyncio.gather(*tasks)
54
+ return results
55
+
56
+
57
+ def process_data(page_results: List[Dict]) -> pd.DataFrame:
58
+ """处理获取到的数据,转换为DataFrame"""
59
+ all_data = []
60
+
61
+ # 保存每个页面的结果和页码
62
+ page_number = 1
63
+ items_per_page = 100 # 假设每页100条
64
+
65
+ for result in page_results:
66
+ if result.get("rc") == 0 and result.get("data") and result["data"].get("diff"):
67
+ page_data = result["data"]["diff"]
68
+
69
+ # 添加页面信息以便后续计算序号
70
+ for item in page_data:
71
+ item["page_number"] = page_number
72
+ item["page_index"] = page_data.index(item)
73
+
74
+ all_data.extend(page_data)
75
+ page_number += 1
76
+
77
+ if not all_data:
78
+ return pd.DataFrame()
79
+
80
+ df = pd.DataFrame(all_data)
81
+
82
+ # 计算正确的序号
83
+ df["序号"] = df.apply(
84
+ lambda row: (row["page_number"] - 1) * items_per_page + row["page_index"] + 1,
85
+ axis=1,
86
+ )
87
+
88
+ # 删除临时列
89
+ df.drop(columns=["page_number", "page_index"], inplace=True, errors="ignore")
90
+
91
+ # 设置列名 - 修正了5分钟涨跌的映射 (f11 是正确的5分钟涨跌字段)
92
+ column_map = {
93
+ "f1": "原序号",
94
+ "f2": "最新价",
95
+ "f3": "涨跌幅",
96
+ "f4": "涨跌额",
97
+ "f5": "成交量",
98
+ "f6": "成交额",
99
+ "f7": "振幅",
100
+ "f8": "换手率",
101
+ "f9": "市盈率-动态",
102
+ "f10": "量比",
103
+ "f11": "5分钟涨跌",
104
+ "f12": "代码",
105
+ "f13": "_",
106
+ "f14": "名称",
107
+ "f15": "最高",
108
+ "f16": "最低",
109
+ "f17": "今开",
110
+ "f18": "昨收",
111
+ "f20": "总市值",
112
+ "f21": "流通市值",
113
+ "f22": "涨速",
114
+ "f23": "市净率",
115
+ "f24": "60日涨跌幅",
116
+ "f25": "年初至今涨跌幅",
117
+ "f62": "-",
118
+ "f115": "-",
119
+ "f128": "-",
120
+ "f136": "-",
121
+ "f152": "-",
122
+ }
123
+
124
+ df.rename(columns=column_map, inplace=True)
125
+
126
+ # 选择需要的列并确保所有需要的列都存在
127
+ desired_columns = [
128
+ "序号",
129
+ "代码",
130
+ "名称",
131
+ "最新价",
132
+ "涨跌幅",
133
+ "涨跌额",
134
+ "成交量",
135
+ "成交额",
136
+ "振幅",
137
+ "最高",
138
+ "最低",
139
+ "今开",
140
+ "昨收",
141
+ "量比",
142
+ "换手率",
143
+ "市盈率-动态",
144
+ "市净率",
145
+ "总市值",
146
+ "流通市值",
147
+ "涨速",
148
+ "5分钟涨跌",
149
+ "60日涨跌幅",
150
+ "年初至今涨跌幅",
151
+ ]
152
+
153
+ # 过滤出存在的列
154
+ available_columns = [col for col in desired_columns if col in df.columns]
155
+ df = df[available_columns]
156
+
157
+ # 转换数值类型
158
+ numeric_columns = [
159
+ "最新价",
160
+ "涨跌幅",
161
+ "涨跌额",
162
+ "成交量",
163
+ "成交额",
164
+ "振幅",
165
+ "最高",
166
+ "最低",
167
+ "今开",
168
+ "昨收",
169
+ "量比",
170
+ "换手率",
171
+ "市盈率-动态",
172
+ "市净率",
173
+ "总市值",
174
+ "流通市值",
175
+ "涨速",
176
+ "5分钟涨跌",
177
+ "60日涨跌幅",
178
+ "年初至今涨跌幅",
179
+ ]
180
+
181
+ for col in numeric_columns:
182
+ if col in df.columns:
183
+ df[col] = pd.to_numeric(df[col], errors="coerce")
184
+
185
+ # 按涨跌幅降序排序
186
+ df.sort_values(by="涨跌幅", ascending=False, inplace=True)
187
+
188
+ # 重新生成序号
189
+ df.reset_index(drop=True, inplace=True)
190
+ df["序号"] = df.index + 1
191
+
192
+ return df
193
+
194
+
195
+ async def stock_zh_a_spot_em_async() -> pd.DataFrame:
196
+ """
197
+ 异步获取东方财富网-沪深京 A 股-实时行情
198
+ https://quote.eastmoney.com/center/gridlist.html#hs_a_board
199
+ :return: 实时行情
200
+ :rtype: pandas.DataFrame
201
+ """
202
+ url = "https://82.push2.eastmoney.com/api/qt/clist/get"
203
+ params = {
204
+ "pn": "1",
205
+ "pz": "100",
206
+ "po": "1",
207
+ "np": "1",
208
+ "ut": "bd1d9ddb04089700cf9c27f6f7426281",
209
+ "fltt": "2",
210
+ "invt": "2",
211
+ "fid": "f12",
212
+ "fs": "m:0 t:6,m:0 t:80,m:1 t:2,m:1 t:23,m:0 t:81 s:2048",
213
+ "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,"
214
+ "f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
215
+ "_": "1623833739532",
216
+ }
217
+
218
+ results = await fetch_all_pages_async(url, params)
219
+ return process_data(results)
220
+
221
+
222
+ def stock_zh_a_spot_em() -> pd.DataFrame:
223
+ """
224
+ 东方财富网-沪深京 A 股-实时行情 (同步接口)
225
+ https://quote.eastmoney.com/center/gridlist.html#hs_a_board
226
+ :return: 实时行情
227
+ :rtype: pandas.DataFrame
228
+ """
229
+ return asyncio.run(stock_zh_a_spot_em_async())
230
+
231
+
232
+ if __name__ == "__main__":
233
+ stock_zh_a_spot_em_df = stock_zh_a_spot_em()
234
+ print(stock_zh_a_spot_em_df)
@@ -398,8 +398,8 @@ def stock_hsgt_stock_statistics_em(
398
398
  "-",
399
399
  "-",
400
400
  "-",
401
- "持股数量",
402
401
  "持股市值",
402
+ "持股数量",
403
403
  "-",
404
404
  "-",
405
405
  "-",
@@ -1551,7 +1551,7 @@ if __name__ == "__main__":
1551
1551
  print(stock_hsgt_stock_statistics_em_df)
1552
1552
 
1553
1553
  stock_hsgt_stock_statistics_em_df = stock_hsgt_stock_statistics_em(
1554
- symbol="南向持股", start_date="20240110", end_date="20240110"
1554
+ symbol="南向持股", start_date="20250314", end_date="20250314"
1555
1555
  )
1556
1556
  print(stock_hsgt_stock_statistics_em_df)
1557
1557
 
@@ -1,7 +1,7 @@
1
1
  # !/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2025/3/10 20:00
4
+ Date: 2025/3/16 11:00
5
5
  Desc: 雪球-个股-公司概况-公司简介
6
6
  https://xueqiu.com/snowman/S/SH601127/detail#/GSJJ
7
7
  """
@@ -41,8 +41,76 @@ def stock_individual_basic_info_xq(
41
41
  return temp_df
42
42
 
43
43
 
44
+ def stock_individual_basic_info_us_xq(
45
+ symbol: str = "NVDA", token: str = None, timeout: float = None
46
+ ) -> pd.DataFrame:
47
+ """
48
+ 雪球-个股-公司概况-公司简介
49
+ https://xueqiu.com/snowman/S/NVDA/detail#/GSJJ
50
+ :param symbol: 证券代码
51
+ :type symbol: str
52
+ :param token: 雪球财经的 token
53
+ :type token: str
54
+ :param timeout: 设置超时时间
55
+ :type timeout: float
56
+ :return: 公司简介
57
+ :rtype: pandas.DataFrame
58
+ """
59
+ xq_a_token = token or "afb2d000c59b0e6fa5539ff13798ca8e64330985"
60
+ url = "https://stock.xueqiu.com/v5/stock/f10/us/company.json"
61
+ params = {
62
+ "symbol": symbol,
63
+ }
64
+ headers.update({"cookie": f"xq_a_token={xq_a_token};"})
65
+ r = requests.get(url, params=params, headers=headers, timeout=timeout)
66
+ data_json = r.json()
67
+ temp_df = pd.DataFrame(data_json["data"])
68
+ temp_df.reset_index(inplace=True)
69
+ temp_df.columns = ["item", "value"]
70
+ return temp_df
71
+
72
+
73
+ def stock_individual_basic_info_hk_xq(
74
+ symbol: str = "02097", token: str = None, timeout: float = None
75
+ ) -> pd.DataFrame:
76
+ """
77
+ 雪球-个股-公司概况-公司简介
78
+ https://xueqiu.com/snowman/S/NVDA/detail#/GSJJ
79
+ :param symbol: 证券代码
80
+ :type symbol: str
81
+ :param token: 雪球财经的 token
82
+ :type token: str
83
+ :param timeout: 设置超时时间
84
+ :type timeout: float
85
+ :return: 公司简介
86
+ :rtype: pandas.DataFrame
87
+ """
88
+ xq_a_token = token or "afb2d000c59b0e6fa5539ff13798ca8e64330985"
89
+ url = "https://stock.xueqiu.com/v5/stock/f10/hk/company.json"
90
+ params = {
91
+ "symbol": symbol,
92
+ }
93
+ headers.update({"cookie": f"xq_a_token={xq_a_token};"})
94
+ r = requests.get(url, params=params, headers=headers, timeout=timeout)
95
+ data_json = r.json()
96
+ temp_df = pd.DataFrame(data_json["data"])
97
+ temp_df.reset_index(inplace=True)
98
+ temp_df.columns = ["item", "value"]
99
+ return temp_df
100
+
101
+
44
102
  if __name__ == "__main__":
45
103
  stock_individual_basic_info_xq_df = stock_individual_basic_info_xq(
46
104
  symbol="SH601127"
47
105
  )
48
106
  print(stock_individual_basic_info_xq_df)
107
+
108
+ stock_us_individual_basic_info_us_xq_df = stock_individual_basic_info_us_xq(
109
+ symbol="NVDA"
110
+ )
111
+ print(stock_us_individual_basic_info_us_xq_df)
112
+
113
+ stock_individual_basic_info_hk_xq_df = stock_individual_basic_info_hk_xq(
114
+ symbol="02097"
115
+ )
116
+ print(stock_individual_basic_info_hk_xq_df)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: akshare
3
- Version: 1.16.46
3
+ Version: 1.16.47
4
4
  Summary: AKShare is an elegant and simple financial data interface library for Python, built for human beings!
5
5
  Home-page: https://github.com/akfamily/akshare
6
6
  Author: AKFamily
@@ -18,6 +18,7 @@ Classifier: Operating System :: OS Independent
18
18
  Requires-Python: >=3.8
19
19
  Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
+ Requires-Dist: aiohttp>=3.11.13
21
22
  Requires-Dist: beautifulsoup4>=4.9.1
22
23
  Requires-Dist: lxml>=4.2.1
23
24
  Requires-Dist: pandas>=0.25
@@ -1,4 +1,4 @@
1
- akshare/__init__.py,sha256=IdhhyoCSc6vByWKKn47EhyfXyp7Fqx2I7H1kwZW0uLA,191050
1
+ akshare/__init__.py,sha256=YGOeSMziZFIOV20GP3AA0os96e-CZLXr9nvdZDvp3AM,191282
2
2
  akshare/datasets.py,sha256=rKuRNZrqi6IMsZ9nyvO3Rx02js0tH3zMLjz8HQNAoPQ,963
3
3
  akshare/exceptions.py,sha256=WEJjIhSmJ_xXNW6grwV4nufE_cfmmyuhmueVGiN1VAg,878
4
4
  akshare/request.py,sha256=HtFFf9MhfEibR-ETWe-1Tts6ELU4VKSqA-ghaXjegQM,4252
@@ -288,6 +288,8 @@ akshare/stock/stock_zh_ah_tx.py,sha256=1DfvP1xF9G4jDnqlacZiYIMWZBujxW9Kycre3yr6M
288
288
  akshare/stock/stock_zh_b_sina.py,sha256=-sd0wG4zETsgrJSXivww4YieXfnVMNSfh3phsX_XBBc,16058
289
289
  akshare/stock/stock_zh_kcb_report.py,sha256=7zRovNGqXrPIYtUj9C3ivlYzfiudkaeBNiYPYlzDWkQ,2914
290
290
  akshare/stock/stock_zh_kcb_sina.py,sha256=ZKFoyq9Y-6LhBoYERc4Oqv5q3Llpne7ngDIZcCs8Yq0,9862
291
+ akshare/stock_a/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
292
+ akshare/stock_a/stock_zh_a_spot.py,sha256=oBfe0oZXFVk9r0LVh3RJ_IKKSQbRvv4MyTHD36n8Ags,6424
291
293
  akshare/stock_feature/__init__.py,sha256=c2VDBGyg8nWZYLvtnnSqUoQ92Cu6dJ7UFOeJsB2Gff8,82
292
294
  akshare/stock_feature/cons.py,sha256=UgwXlae3UpVRuhTt33nP-jmhNyug2mZLzuMgLja6pbA,465
293
295
  akshare/stock_feature/stock_a_below_net_asset_statistics.py,sha256=XrhZI-wLuXXufI5Nh1l9gUx9x7f0iDtdtKa14wexo54,2653
@@ -322,7 +324,7 @@ akshare/stock_feature/stock_hist_em.py,sha256=vC3gWA1hTgWdwk4VFfk6HOwfWuzlYO2xa5
322
324
  akshare/stock_feature/stock_hist_tx.py,sha256=WpLsbkG2didSx7lYNkSbTWNTrLhUKbcopfD18WO2Rlc,3397
323
325
  akshare/stock_feature/stock_hk_valuation_baidu.py,sha256=_sErx4UhNsSXJgXyPfrL0aPxkW53Mg1zH9gEKoziaCA,1968
324
326
  akshare/stock_feature/stock_hot_xq.py,sha256=NmoH4x-0hiDztj-YwzMFVIyOICQ2wUUBbhjt91q-tq4,9112
325
- akshare/stock_feature/stock_hsgt_em.py,sha256=-BN09F02MXMjP-8lmXUpaYuueVYuZooYxKh6Cd6GIqY,57698
327
+ akshare/stock_feature/stock_hsgt_em.py,sha256=S6aYVXiL2DJNQD0iJ3oc1EuR0T0tSHFOYUi1Kq6vBPY,57698
326
328
  akshare/stock_feature/stock_hsgt_exchange_rate.py,sha256=-oJZ83FUQrNJX_4GB5hS562IdrfJbCwr0d5ioYXtPrQ,7212
327
329
  akshare/stock_feature/stock_hsgt_min_em.py,sha256=KLeez7MQwBAcO-RT7n41LOikUfvXDGK0-G1n9av5mtY,2883
328
330
  akshare/stock_feature/stock_info.py,sha256=JSmJWrSzzq4sP4CgOU0mYGVcbXeWlRDQxNYtbSjJmiM,9043
@@ -359,7 +361,7 @@ akshare/stock_feature/stock_zh_vote_baidu.py,sha256=SsSNnCq7PDFMzWFcPFcC_MSc9rua
359
361
  akshare/stock_feature/stock_ztb_em.py,sha256=hMi0NSlBs-qEid3oXKOAempZSItNApPDQKvcsdtF8j8,18141
360
362
  akshare/stock_feature/ths.js,sha256=AWPkHf3L2Il1UUL0F5qDqNn1dfU0OlZBNUbMf8AmI3Y,39664
361
363
  akshare/stock_fundamental/__init__.py,sha256=jiXoO9OXiMxB0wHaPQkuxNckYuoFKtzuhZL1ytnE2nQ,82
362
- akshare/stock_fundamental/stock_basic_info_xq.py,sha256=qtLYKqv-zNIgJy2Y-F2nHVXP1VCiNgoSZkY80Mbftxs,1390
364
+ akshare/stock_fundamental/stock_basic_info_xq.py,sha256=ApptWTCY1lnr92bvhuVIhYAXkdU36_0DgCUCZLEWY0U,3622
363
365
  akshare/stock_fundamental/stock_finance_hk_em.py,sha256=cCiaWX6ZyKe4W2H9qe-ttpMeVMWp6tHdvnjhRuYQhl8,7017
364
366
  akshare/stock_fundamental/stock_finance_sina.py,sha256=432EjGHWFtG0L32PNSC_HWpVLDntabNt9koyUtNG77E,30718
365
367
  akshare/stock_fundamental/stock_finance_ths.py,sha256=nS9bt_hzklzh7pBTCH1PjOa69OUcNZ41Z_zSHiz9Y1U,11527
@@ -389,8 +391,8 @@ akshare/utils/token_process.py,sha256=K4rGXjh_tgugbRcyOK2h2x0jP3PT65IIK7nxhUKhOe
389
391
  akshare/utils/tqdm.py,sha256=MuPNwcswkOGjwWQOMWXi9ZvQ_RmW4obCWRj2i7HM7FE,847
390
392
  tests/__init__.py,sha256=gNzhlO0UPjFq6Ieb38kaVIODXv4cTDByrdohAZnDYt4,82
391
393
  tests/test_func.py,sha256=j1MGYbZI2if2j_LY1S4FLsf4qfq4NwVqD5wmRlv5Log,832
392
- akshare-1.16.46.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
393
- akshare-1.16.46.dist-info/METADATA,sha256=tIY4Km-jXwh3JiNvg_gRhFBCANVtJocGGftLNoeKreA,13653
394
- akshare-1.16.46.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
395
- akshare-1.16.46.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
396
- akshare-1.16.46.dist-info/RECORD,,
394
+ akshare-1.16.47.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
395
+ akshare-1.16.47.dist-info/METADATA,sha256=-LTQkIDw_SPxWqbqkm6052bM19n-VpP0Wq5Xzoc4PAM,13685
396
+ akshare-1.16.47.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
397
+ akshare-1.16.47.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
398
+ akshare-1.16.47.dist-info/RECORD,,