akshare 1.16.35__py3-none-any.whl → 1.16.37__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
@@ -3044,9 +3044,11 @@ amac_manager_cancelled_info # 中国证券投资基金业协会-信息公示-诚
3044
3044
  1.16.33 fix: fix fund_open_fund_daily_em interface
3045
3045
  1.16.34 fix: fix stock_individual_fund_flow_rank interface
3046
3046
  1.16.35 fix: fix futures_global_spot_em interface
3047
+ 1.16.36 fix: fix stock_intraday_em interface
3048
+ 1.16.37 fix: fix stock_board_concept_hist_em interface
3047
3049
  """
3048
3050
 
3049
- __version__ = "1.16.35"
3051
+ __version__ = "1.16.37"
3050
3052
  __author__ = "AKFamily"
3051
3053
 
3052
3054
  import sys
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2025/2/17 20:30
4
+ Date: 2025/3/10 18:30
5
5
  Desc: 股票指数数据-新浪-东财-腾讯
6
6
  所有指数-实时行情数据和历史行情数据
7
7
  https://finance.sina.com.cn/realstock/company/sz399552/nc.shtml
@@ -11,8 +11,8 @@ import datetime
11
11
  import re
12
12
 
13
13
  import pandas as pd
14
- import requests
15
14
  import py_mini_racer
15
+ import requests
16
16
 
17
17
  from akshare.index.cons import (
18
18
  zh_sina_index_stock_payload,
@@ -22,6 +22,7 @@ from akshare.index.cons import (
22
22
  )
23
23
  from akshare.stock.cons import hk_js_decode
24
24
  from akshare.utils import demjson
25
+ from akshare.utils.func import fetch_paginated_data
25
26
  from akshare.utils.tqdm import get_tqdm
26
27
 
27
28
 
@@ -135,9 +136,9 @@ def __stock_zh_main_spot_em() -> pd.DataFrame:
135
136
  url = "https://33.push2.eastmoney.com/api/qt/clist/get"
136
137
  params = {
137
138
  "pn": "1",
138
- "pz": "50000",
139
+ "pz": "100",
139
140
  "po": "1",
140
- "np": "2",
141
+ "np": "1",
141
142
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
142
143
  "fltt": "2",
143
144
  "invt": "2",
@@ -151,7 +152,7 @@ def __stock_zh_main_spot_em() -> pd.DataFrame:
151
152
  }
152
153
  r = requests.get(url, params=params)
153
154
  data_json = r.json()
154
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
155
+ temp_df = pd.DataFrame(data_json["data"]["diff"])
155
156
  temp_df.reset_index(inplace=True)
156
157
  temp_df["index"] = temp_df["index"].astype(int) + 1
157
158
  temp_df.rename(
@@ -205,7 +206,7 @@ def __stock_zh_main_spot_em() -> pd.DataFrame:
205
206
  return temp_df
206
207
 
207
208
 
208
- def stock_zh_index_spot_em(symbol: str = "沪深重要指数") -> pd.DataFrame:
209
+ def stock_zh_index_spot_em(symbol: str = "上证系列指数") -> pd.DataFrame:
209
210
  """
210
211
  东方财富网-行情中心-沪深京指数
211
212
  https://quote.eastmoney.com/center/gridlist.html#index_sz
@@ -219,31 +220,27 @@ def stock_zh_index_spot_em(symbol: str = "沪深重要指数") -> pd.DataFrame:
219
220
 
220
221
  url = "https://48.push2.eastmoney.com/api/qt/clist/get"
221
222
  symbol_map = {
222
- "上证系列指数": "m:1 s:2",
223
+ "上证系列指数": "m:1+t:1",
223
224
  "深证系列指数": "m:0 t:5",
224
- "指数成份": "m:1 s:3,m:0 t:5",
225
+ "指数成份": "m:1+s:3,m:0+t:5",
225
226
  "中证系列指数": "m:2",
226
227
  }
227
228
  params = {
228
229
  "pn": "1",
229
- "pz": "20000",
230
+ "pz": "100",
230
231
  "po": "1",
231
- "np": "2",
232
+ "np": "1",
232
233
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
233
234
  "fltt": "2",
234
235
  "invt": "2",
235
236
  "wbp2u": "|0|0|0|web",
236
- "fid": "f3",
237
+ "fid": "f12",
237
238
  "fs": symbol_map[symbol],
238
239
  "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,"
239
240
  "f26,f22,f33,f11,f62,f128,f136,f115,f152",
240
241
  "_": "1704327268532",
241
242
  }
242
- r = requests.get(url, params=params)
243
- data_json = r.json()
244
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
245
- temp_df.reset_index(inplace=True)
246
- temp_df["index"] = temp_df["index"].astype(int) + 1
243
+ temp_df = fetch_paginated_data(url, params)
247
244
  temp_df.rename(
248
245
  columns={
249
246
  "index": "序号",
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2025/2/28 16:30
4
+ Date: 2025/3/10 18:30
5
5
  Desc: 东方财富-沪深板块-概念板块
6
6
  https://quote.eastmoney.com/center/boardlist.html#concept_board
7
7
  """
@@ -12,6 +12,8 @@ from functools import lru_cache
12
12
  import pandas as pd
13
13
  import requests
14
14
 
15
+ from akshare.utils.func import fetch_paginated_data
16
+
15
17
 
16
18
  @lru_cache()
17
19
  def __stock_board_concept_name_em() -> pd.DataFrame:
@@ -24,22 +26,18 @@ def __stock_board_concept_name_em() -> pd.DataFrame:
24
26
  url = "https://79.push2.eastmoney.com/api/qt/clist/get"
25
27
  params = {
26
28
  "pn": "1",
27
- "pz": "50000",
29
+ "pz": "100",
28
30
  "po": "1",
29
- "np": "2",
31
+ "np": "1",
30
32
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
31
33
  "fltt": "2",
32
34
  "invt": "2",
33
- "fid": "f3",
35
+ "fid": "f12",
34
36
  "fs": "m:90 t:3 f:!50",
35
37
  "fields": "f2,f3,f4,f8,f12,f14,f15,f16,f17,f18,f20,f21,f24,f25,f22,f33,f11,f62,f128,f124,f107,f104,f105,f136",
36
38
  "_": "1626075887768",
37
39
  }
38
- r = requests.get(url, params=params)
39
- data_json = r.json()
40
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
41
- temp_df.reset_index(inplace=True)
42
- temp_df["index"] = range(1, len(temp_df) + 1)
40
+ temp_df = fetch_paginated_data(url, params)
43
41
  temp_df.columns = [
44
42
  "排名",
45
43
  "最新价",
@@ -108,9 +106,9 @@ def stock_board_concept_name_em() -> pd.DataFrame:
108
106
  url = "https://79.push2.eastmoney.com/api/qt/clist/get"
109
107
  params = {
110
108
  "pn": "1",
111
- "pz": "50000",
109
+ "pz": "100",
112
110
  "po": "1",
113
- "np": "2",
111
+ "np": "1",
114
112
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
115
113
  "fltt": "2",
116
114
  "invt": "2",
@@ -119,11 +117,7 @@ def stock_board_concept_name_em() -> pd.DataFrame:
119
117
  "fields": "f2,f3,f4,f8,f12,f14,f15,f16,f17,f18,f20,f21,f24,f25,f22,f33,f11,f62,f128,f124,f107,f104,f105,f136",
120
118
  "_": "1626075887768",
121
119
  }
122
- r = requests.get(url, params=params)
123
- data_json = r.json()
124
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
125
- temp_df.reset_index(inplace=True)
126
- temp_df["index"] = range(1, len(temp_df) + 1)
120
+ temp_df = fetch_paginated_data(url, params)
127
121
  temp_df.columns = [
128
122
  "排名",
129
123
  "最新价",
@@ -451,9 +445,9 @@ def stock_board_concept_cons_em(symbol: str = "融资融券") -> pd.DataFrame:
451
445
  url = "https://29.push2.eastmoney.com/api/qt/clist/get"
452
446
  params = {
453
447
  "pn": "1",
454
- "pz": "50000",
448
+ "pz": "100",
455
449
  "po": "1",
456
- "np": "2",
450
+ "np": "1",
457
451
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
458
452
  "fltt": "2",
459
453
  "invt": "2",
@@ -463,11 +457,7 @@ def stock_board_concept_cons_em(symbol: str = "融资融券") -> pd.DataFrame:
463
457
  "f24,f25,f22,f11,f62,f128,f136,f115,f152,f45",
464
458
  "_": "1626081702127",
465
459
  }
466
- r = requests.get(url, params=params)
467
- data_json = r.json()
468
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
469
- temp_df.reset_index(inplace=True)
470
- temp_df["index"] = range(1, len(temp_df) + 1)
460
+ temp_df = fetch_paginated_data(url, params)
471
461
  temp_df.columns = [
472
462
  "序号",
473
463
  "_",
@@ -1,91 +1,17 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2025/2/24 18:00
4
+ Date: 2025/3/10 18:00
5
5
  Desc: 东财财富-日内分时数据
6
6
  https://quote.eastmoney.com/f1.html?newcode=0.000001
7
7
  """
8
8
 
9
9
  import json
10
- from functools import lru_cache
11
10
 
12
11
  import pandas as pd
13
12
  import requests
14
13
 
15
14
 
16
- @lru_cache()
17
- def __code_id_map_em() -> dict:
18
- """
19
- 东方财富-股票和市场代码
20
- https://quote.eastmoney.com/center/gridlist.html#hs_a_board
21
- :return: 股票和市场代码
22
- :rtype: dict
23
- """
24
- url = "https://80.push2.eastmoney.com/api/qt/clist/get"
25
- params = {
26
- "pn": "1",
27
- "pz": "50000",
28
- "po": "1",
29
- "np": "2",
30
- "ut": "bd1d9ddb04089700cf9c27f6f7426281",
31
- "fltt": "2",
32
- "invt": "2",
33
- "fid": "f3",
34
- "fs": "m:1 t:2,m:1 t:23",
35
- "fields": "f12",
36
- "_": "1623833739532",
37
- }
38
- r = requests.get(url, params=params)
39
- data_json = r.json()
40
- if not data_json["data"]["diff"]:
41
- return dict()
42
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
43
- temp_df["market_id"] = 1
44
- temp_df.columns = ["sh_code", "sh_id"]
45
- code_id_dict = dict(zip(temp_df["sh_code"], temp_df["sh_id"]))
46
- params = {
47
- "pn": "1",
48
- "pz": "50000",
49
- "po": "1",
50
- "np": "2",
51
- "ut": "bd1d9ddb04089700cf9c27f6f7426281",
52
- "fltt": "2",
53
- "invt": "2",
54
- "fid": "f3",
55
- "fs": "m:0 t:6,m:0 t:80",
56
- "fields": "f12",
57
- "_": "1623833739532",
58
- }
59
- r = requests.get(url, params=params)
60
- data_json = r.json()
61
- if not data_json["data"]["diff"]:
62
- return dict()
63
- temp_df_sz = pd.DataFrame(data_json["data"]["diff"]).T
64
- temp_df_sz["sz_id"] = 0
65
- code_id_dict.update(dict(zip(temp_df_sz["f12"], temp_df_sz["sz_id"])))
66
- params = {
67
- "pn": "1",
68
- "pz": "50000",
69
- "po": "1",
70
- "np": "2",
71
- "ut": "bd1d9ddb04089700cf9c27f6f7426281",
72
- "fltt": "2",
73
- "invt": "2",
74
- "fid": "f3",
75
- "fs": "m:0 t:81 s:2048",
76
- "fields": "f12",
77
- "_": "1623833739532",
78
- }
79
- r = requests.get(url, params=params)
80
- data_json = r.json()
81
- if not data_json["data"]["diff"]:
82
- return dict()
83
- temp_df_sz = pd.DataFrame(data_json["data"]["diff"]).T
84
- temp_df_sz["bj_id"] = 0
85
- code_id_dict.update(dict(zip(temp_df_sz["f12"], temp_df_sz["bj_id"])))
86
- return code_id_dict
87
-
88
-
89
15
  def __event_stream(url, params):
90
16
  # 使用 stream=True 参数来启用流式请求
91
17
  response = requests.get(url, params=params, stream=True)
@@ -102,14 +28,14 @@ def __event_stream(url, params):
102
28
 
103
29
  def stock_intraday_em(symbol: str = "000001") -> pd.DataFrame:
104
30
  """
105
- 东财财富-分时数据
31
+ 东方财富-分时数据
106
32
  https://quote.eastmoney.com/f1.html?newcode=0.000001
107
33
  :param symbol: 股票代码
108
34
  :type symbol: str
109
35
  :return: 分时数据
110
36
  :rtype: pandas.DataFrame
111
37
  """
112
- code_id_map_em_dict = __code_id_map_em()
38
+ market_code = 1 if symbol.startswith("6") else 0
113
39
  url = "https://70.push2.eastmoney.com/api/qt/stock/details/sse"
114
40
  params = {
115
41
  "fields1": "f1,f2,f3,f4",
@@ -118,7 +44,7 @@ def stock_intraday_em(symbol: str = "000001") -> pd.DataFrame:
118
44
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
119
45
  "fltt": "2",
120
46
  "pos": "-0",
121
- "secid": f"{code_id_map_em_dict[symbol]}.{symbol}",
47
+ "secid": f"{market_code}.{symbol}",
122
48
  "wbp2u": "|0|0|0|web",
123
49
  }
124
50
 
@@ -1,16 +1,15 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2025/3/9 18:00
4
+ Date: 2025/3/10 18:00
5
5
  Desc: 东方财富网-行情首页-沪深京 A 股
6
6
  https://quote.eastmoney.com/
7
7
  """
8
8
 
9
- import math
10
-
11
9
  import pandas as pd
12
10
  import requests
13
- from akshare.utils.tqdm import get_tqdm
11
+
12
+ from akshare.utils.func import fetch_paginated_data
14
13
 
15
14
 
16
15
  def stock_zh_a_spot_em() -> pd.DataFrame:
@@ -23,7 +22,7 @@ def stock_zh_a_spot_em() -> pd.DataFrame:
23
22
  url = "https://82.push2.eastmoney.com/api/qt/clist/get"
24
23
  params = {
25
24
  "pn": "1",
26
- "pz": "200",
25
+ "pz": "100",
27
26
  "po": "1",
28
27
  "np": "1",
29
28
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
@@ -35,23 +34,9 @@ def stock_zh_a_spot_em() -> pd.DataFrame:
35
34
  "f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
36
35
  "_": "1623833739532",
37
36
  }
38
- r = requests.get(url, params=params, timeout=15)
39
- data_json = r.json()
40
- total_page = math.ceil(data_json["data"]["total"] / 200)
41
- temp_list = []
42
- tqdm = get_tqdm()
43
- for page in tqdm(range(1, total_page + 1), leave=False):
44
- params.update(
45
- {
46
- "pn": page,
47
- }
48
- )
49
- r = requests.get(url, params=params, timeout=15)
50
- data_json = r.json()
51
- inner_temp_df = pd.DataFrame(data_json["data"]["diff"])
52
- temp_list.append(inner_temp_df)
53
- temp_df = pd.concat(temp_list, ignore_index=True)
37
+ temp_df = fetch_paginated_data(url, params)
54
38
  temp_df.columns = [
39
+ "index",
55
40
  "_",
56
41
  "最新价",
57
42
  "涨跌幅",
@@ -84,8 +69,6 @@ def stock_zh_a_spot_em() -> pd.DataFrame:
84
69
  "-",
85
70
  "-",
86
71
  ]
87
- temp_df.reset_index(inplace=True)
88
- temp_df["index"] = temp_df.index + 1
89
72
  temp_df.rename(columns={"index": "序号"}, inplace=True)
90
73
  temp_df = temp_df[
91
74
  [
@@ -149,24 +132,21 @@ def stock_sh_a_spot_em() -> pd.DataFrame:
149
132
  url = "https://82.push2.eastmoney.com/api/qt/clist/get"
150
133
  params = {
151
134
  "pn": "1",
152
- "pz": "50000",
135
+ "pz": "100",
153
136
  "po": "1",
154
- "np": "2",
137
+ "np": "1",
155
138
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
156
139
  "fltt": "2",
157
140
  "invt": "2",
158
- "fid": "f3",
141
+ "fid": "f12",
159
142
  "fs": "m:1 t:2,m:1 t:23",
160
143
  "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,"
161
144
  "f24,f25,f22,f11,f62,f128,f136,f115,f152",
162
145
  "_": "1623833739532",
163
146
  }
164
- r = requests.get(url, timeout=15, params=params)
165
- data_json = r.json()
166
- if not data_json["data"]["diff"]:
167
- return pd.DataFrame()
168
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
147
+ temp_df = fetch_paginated_data(url, params)
169
148
  temp_df.columns = [
149
+ "序号",
170
150
  "_",
171
151
  "最新价",
172
152
  "涨跌幅",
@@ -199,9 +179,6 @@ def stock_sh_a_spot_em() -> pd.DataFrame:
199
179
  "-",
200
180
  "-",
201
181
  ]
202
- temp_df.reset_index(inplace=True)
203
- temp_df["index"] = temp_df.index + 1
204
- temp_df.rename(columns={"index": "序号"}, inplace=True)
205
182
  temp_df = temp_df[
206
183
  [
207
184
  "序号",
@@ -264,9 +241,9 @@ def stock_sz_a_spot_em() -> pd.DataFrame:
264
241
  url = "https://82.push2.eastmoney.com/api/qt/clist/get"
265
242
  params = {
266
243
  "pn": "1",
267
- "pz": "50000",
244
+ "pz": "100",
268
245
  "po": "1",
269
- "np": "2",
246
+ "np": "1",
270
247
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
271
248
  "fltt": "2",
272
249
  "invt": "2",
@@ -276,12 +253,9 @@ def stock_sz_a_spot_em() -> pd.DataFrame:
276
253
  "f25,f22,f11,f62,f128,f136,f115,f152",
277
254
  "_": "1623833739532",
278
255
  }
279
- r = requests.get(url, timeout=15, params=params)
280
- data_json = r.json()
281
- if not data_json["data"]["diff"]:
282
- return pd.DataFrame()
283
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
256
+ temp_df = fetch_paginated_data(url, params)
284
257
  temp_df.columns = [
258
+ "序号",
285
259
  "_",
286
260
  "最新价",
287
261
  "涨跌幅",
@@ -314,9 +288,6 @@ def stock_sz_a_spot_em() -> pd.DataFrame:
314
288
  "-",
315
289
  "-",
316
290
  ]
317
- temp_df.reset_index(inplace=True)
318
- temp_df["index"] = temp_df.index + 1
319
- temp_df.rename(columns={"index": "序号"}, inplace=True)
320
291
  temp_df = temp_df[
321
292
  [
322
293
  "序号",
@@ -379,9 +350,9 @@ def stock_bj_a_spot_em() -> pd.DataFrame:
379
350
  url = "https://82.push2.eastmoney.com/api/qt/clist/get"
380
351
  params = {
381
352
  "pn": "1",
382
- "pz": "50000",
353
+ "pz": "100",
383
354
  "po": "1",
384
- "np": "2",
355
+ "np": "1",
385
356
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
386
357
  "fltt": "2",
387
358
  "invt": "2",
@@ -391,12 +362,9 @@ def stock_bj_a_spot_em() -> pd.DataFrame:
391
362
  ",f25,f22,f11,f62,f128,f136,f115,f152",
392
363
  "_": "1623833739532",
393
364
  }
394
- r = requests.get(url, params=params, timeout=15)
395
- data_json = r.json()
396
- if not data_json["data"]["diff"]:
397
- return pd.DataFrame()
398
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
365
+ temp_df = fetch_paginated_data(url, params)
399
366
  temp_df.columns = [
367
+ "序号",
400
368
  "_",
401
369
  "最新价",
402
370
  "涨跌幅",
@@ -429,9 +397,6 @@ def stock_bj_a_spot_em() -> pd.DataFrame:
429
397
  "-",
430
398
  "-",
431
399
  ]
432
- temp_df.reset_index(inplace=True)
433
- temp_df["index"] = temp_df.index + 1
434
- temp_df.rename(columns={"index": "序号"}, inplace=True)
435
400
  temp_df = temp_df[
436
401
  [
437
402
  "序号",
@@ -494,9 +459,9 @@ def stock_new_a_spot_em() -> pd.DataFrame:
494
459
  url = "https://82.push2.eastmoney.com/api/qt/clist/get"
495
460
  params = {
496
461
  "pn": "1",
497
- "pz": "50000",
462
+ "pz": "100",
498
463
  "po": "1",
499
- "np": "2",
464
+ "np": "1",
500
465
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
501
466
  "fltt": "2",
502
467
  "invt": "2",
@@ -507,12 +472,9 @@ def stock_new_a_spot_em() -> pd.DataFrame:
507
472
  "f25,f26,f22,f11,f62,f128,f136,f115,f152",
508
473
  "_": "1623833739532",
509
474
  }
510
- r = requests.get(url, timeout=15, params=params)
511
- data_json = r.json()
512
- if not data_json["data"]["diff"]:
513
- return pd.DataFrame()
514
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
475
+ temp_df = fetch_paginated_data(url, params)
515
476
  temp_df.columns = [
477
+ "序号",
516
478
  "_",
517
479
  "最新价",
518
480
  "涨跌幅",
@@ -546,9 +508,6 @@ def stock_new_a_spot_em() -> pd.DataFrame:
546
508
  "-",
547
509
  "-",
548
510
  ]
549
- temp_df.reset_index(inplace=True)
550
- temp_df["index"] = temp_df.index + 1
551
- temp_df.rename(columns={"index": "序号"}, inplace=True)
552
511
  temp_df = temp_df[
553
512
  [
554
513
  "序号",
@@ -614,9 +573,9 @@ def stock_cy_a_spot_em() -> pd.DataFrame:
614
573
  url = "https://7.push2.eastmoney.com/api/qt/clist/get"
615
574
  params = {
616
575
  "pn": "1",
617
- "pz": "50000",
576
+ "pz": "100",
618
577
  "po": "1",
619
- "np": "2",
578
+ "np": "1",
620
579
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
621
580
  "fltt": "2",
622
581
  "invt": "2",
@@ -627,12 +586,9 @@ def stock_cy_a_spot_em() -> pd.DataFrame:
627
586
  "f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
628
587
  "_": "1623833739532",
629
588
  }
630
- r = requests.get(url, timeout=15, params=params)
631
- data_json = r.json()
632
- if not data_json["data"]["diff"]:
633
- return pd.DataFrame()
634
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
589
+ temp_df = fetch_paginated_data(url, params)
635
590
  temp_df.columns = [
591
+ "序号",
636
592
  "_",
637
593
  "最新价",
638
594
  "涨跌幅",
@@ -665,9 +621,6 @@ def stock_cy_a_spot_em() -> pd.DataFrame:
665
621
  "-",
666
622
  "-",
667
623
  ]
668
- temp_df.reset_index(inplace=True)
669
- temp_df["index"] = temp_df.index + 1
670
- temp_df.rename(columns={"index": "序号"}, inplace=True)
671
624
  temp_df = temp_df[
672
625
  [
673
626
  "序号",
@@ -730,9 +683,9 @@ def stock_kc_a_spot_em() -> pd.DataFrame:
730
683
  url = "https://7.push2.eastmoney.com/api/qt/clist/get"
731
684
  params = {
732
685
  "pn": "1",
733
- "pz": "50000",
686
+ "pz": "100",
734
687
  "po": "1",
735
- "np": "2",
688
+ "np": "1",
736
689
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
737
690
  "fltt": "2",
738
691
  "invt": "2",
@@ -743,12 +696,9 @@ def stock_kc_a_spot_em() -> pd.DataFrame:
743
696
  "f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
744
697
  "_": "1623833739532",
745
698
  }
746
- r = requests.get(url, params=params, timeout=15)
747
- data_json = r.json()
748
- if not data_json["data"]["diff"]:
749
- return pd.DataFrame()
750
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
699
+ temp_df = fetch_paginated_data(url, params)
751
700
  temp_df.columns = [
701
+ "序号",
752
702
  "_",
753
703
  "最新价",
754
704
  "涨跌幅",
@@ -781,9 +731,6 @@ def stock_kc_a_spot_em() -> pd.DataFrame:
781
731
  "-",
782
732
  "-",
783
733
  ]
784
- temp_df.reset_index(inplace=True)
785
- temp_df["index"] = temp_df.index + 1
786
- temp_df.rename(columns={"index": "序号"}, inplace=True)
787
734
  temp_df = temp_df[
788
735
  [
789
736
  "序号",
@@ -846,9 +793,9 @@ def stock_zh_b_spot_em() -> pd.DataFrame:
846
793
  url = "https://28.push2.eastmoney.com/api/qt/clist/get"
847
794
  params = {
848
795
  "pn": "1",
849
- "pz": "50000",
796
+ "pz": "100",
850
797
  "po": "1",
851
- "np": "2",
798
+ "np": "1",
852
799
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
853
800
  "fltt": "2",
854
801
  "invt": "2",
@@ -858,12 +805,9 @@ def stock_zh_b_spot_em() -> pd.DataFrame:
858
805
  ",f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
859
806
  "_": "1623833739532",
860
807
  }
861
- r = requests.get(url, params=params, timeout=15)
862
- data_json = r.json()
863
- if not data_json["data"]["diff"]:
864
- return pd.DataFrame()
865
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
808
+ temp_df = fetch_paginated_data(url, params)
866
809
  temp_df.columns = [
810
+ "序号",
867
811
  "_",
868
812
  "最新价",
869
813
  "涨跌幅",
@@ -896,9 +840,6 @@ def stock_zh_b_spot_em() -> pd.DataFrame:
896
840
  "-",
897
841
  "-",
898
842
  ]
899
- temp_df.reset_index(inplace=True)
900
- temp_df["index"] = temp_df.index + 1
901
- temp_df.rename(columns={"index": "序号"}, inplace=True)
902
843
  temp_df = temp_df[
903
844
  [
904
845
  "序号",
@@ -1239,9 +1180,9 @@ def stock_hk_spot_em() -> pd.DataFrame:
1239
1180
  url = "https://72.push2.eastmoney.com/api/qt/clist/get"
1240
1181
  params = {
1241
1182
  "pn": "1",
1242
- "pz": "50000",
1183
+ "pz": "100",
1243
1184
  "po": "1",
1244
- "np": "2",
1185
+ "np": "1",
1245
1186
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
1246
1187
  "fltt": "2",
1247
1188
  "invt": "2",
@@ -1251,12 +1192,9 @@ def stock_hk_spot_em() -> pd.DataFrame:
1251
1192
  "f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
1252
1193
  "_": "1624010056945",
1253
1194
  }
1254
- r = requests.get(url, timeout=15, params=params)
1255
- data_json = r.json()
1256
- if not data_json["data"]["diff"]:
1257
- return pd.DataFrame()
1258
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
1195
+ temp_df = fetch_paginated_data(url, params)
1259
1196
  temp_df.columns = [
1197
+ "序号",
1260
1198
  "_",
1261
1199
  "最新价",
1262
1200
  "涨跌幅",
@@ -1289,9 +1227,6 @@ def stock_hk_spot_em() -> pd.DataFrame:
1289
1227
  "_",
1290
1228
  "_",
1291
1229
  ]
1292
- temp_df.reset_index(inplace=True)
1293
- temp_df["index"] = temp_df.index + 1
1294
- temp_df.rename(columns={"index": "序号"}, inplace=True)
1295
1230
  temp_df = temp_df[
1296
1231
  [
1297
1232
  "序号",
@@ -1331,9 +1266,9 @@ def stock_hk_main_board_spot_em() -> pd.DataFrame:
1331
1266
  url = "https://81.push2.eastmoney.com/api/qt/clist/get"
1332
1267
  params = {
1333
1268
  "pn": "1",
1334
- "pz": "50000",
1269
+ "pz": "100",
1335
1270
  "po": "1",
1336
- "np": "2",
1271
+ "np": "1",
1337
1272
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
1338
1273
  "fltt": "2",
1339
1274
  "invt": "2",
@@ -1343,10 +1278,9 @@ def stock_hk_main_board_spot_em() -> pd.DataFrame:
1343
1278
  "f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
1344
1279
  "_": "1624010056945",
1345
1280
  }
1346
- r = requests.get(url, params=params, timeout=15)
1347
- data_json = r.json()
1348
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
1281
+ temp_df = fetch_paginated_data(url, params)
1349
1282
  temp_df.columns = [
1283
+ "序号",
1350
1284
  "_",
1351
1285
  "最新价",
1352
1286
  "涨跌幅",
@@ -1379,9 +1313,6 @@ def stock_hk_main_board_spot_em() -> pd.DataFrame:
1379
1313
  "_",
1380
1314
  "_",
1381
1315
  ]
1382
- temp_df.reset_index(inplace=True)
1383
- temp_df["index"] = temp_df.index + 1
1384
- temp_df.rename(columns={"index": "序号"}, inplace=True)
1385
1316
  temp_df = temp_df[
1386
1317
  [
1387
1318
  "序号",
@@ -1624,9 +1555,9 @@ def stock_us_spot_em() -> pd.DataFrame:
1624
1555
  url = "https://72.push2.eastmoney.com/api/qt/clist/get"
1625
1556
  params = {
1626
1557
  "pn": "1",
1627
- "pz": "50000",
1558
+ "pz": "100",
1628
1559
  "po": "1",
1629
- "np": "2",
1560
+ "np": "1",
1630
1561
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
1631
1562
  "fltt": "2",
1632
1563
  "invt": "2",
@@ -1636,12 +1567,9 @@ def stock_us_spot_em() -> pd.DataFrame:
1636
1567
  "f21,f23,f24,f25,f26,f22,f33,f11,f62,f128,f136,f115,f152",
1637
1568
  "_": "1624010056945",
1638
1569
  }
1639
- r = requests.get(url, params=params, timeout=15)
1640
- data_json = r.json()
1641
- if not data_json["data"]["diff"]:
1642
- return pd.DataFrame()
1643
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
1570
+ temp_df = fetch_paginated_data(url, params)
1644
1571
  temp_df.columns = [
1572
+ "序号",
1645
1573
  "_",
1646
1574
  "最新价",
1647
1575
  "涨跌幅",
@@ -1676,9 +1604,6 @@ def stock_us_spot_em() -> pd.DataFrame:
1676
1604
  "_",
1677
1605
  "_",
1678
1606
  ]
1679
- temp_df.reset_index(inplace=True)
1680
- temp_df["index"] = range(1, len(temp_df) + 1)
1681
- temp_df.rename(columns={"index": "序号"}, inplace=True)
1682
1607
  temp_df["代码"] = temp_df["编码"].astype(str) + "." + temp_df["简称"]
1683
1608
  temp_df = temp_df[
1684
1609
  [
akshare/utils/func.py CHANGED
@@ -1,12 +1,59 @@
1
1
  # !/usr/bin/env python
2
2
  """
3
- Date: 2024/4/7 15:30
3
+ Date: 2025/3/10 18:00
4
4
  Desc: 通用帮助函数
5
5
  """
6
6
 
7
- from typing import List
7
+ import math
8
+ from typing import List, Dict
8
9
 
9
10
  import pandas as pd
11
+ import requests
12
+
13
+ from akshare.utils.tqdm import get_tqdm
14
+
15
+
16
+ def fetch_paginated_data(url: str, base_params: Dict, timeout: int = 15):
17
+ """
18
+ 东方财富-分页获取数据并合并结果
19
+ https://quote.eastmoney.com/f1.html?newcode=0.000001
20
+ :param url: 股票代码
21
+ :type url: str
22
+ :param base_params: 基础请求参数
23
+ :type base_params: dict
24
+ :param timeout: 请求超时时间
25
+ :type timeout: str
26
+ :return: 合并后的数据
27
+ :rtype: pandas.DataFrame
28
+ """
29
+ # 复制参数以避免修改原始参数
30
+ params = base_params.copy()
31
+ # 获取第一页数据,用于确定分页信息
32
+ r = requests.get(url, params=params, timeout=timeout)
33
+ data_json = r.json()
34
+ # 计算分页信息
35
+ per_page_num = len(data_json["data"]["diff"])
36
+ total_page = math.ceil(data_json["data"]["total"] / per_page_num)
37
+ # 存储所有页面数据
38
+ temp_list = []
39
+ # 添加第一页数据
40
+ temp_list.append(pd.DataFrame(data_json["data"]["diff"]))
41
+ # 获取进度条
42
+ tqdm = get_tqdm()
43
+ # 获取剩余页面数据
44
+ for page in tqdm(range(2, total_page + 1), leave=False):
45
+ params.update({"pn": page})
46
+ r = requests.get(url, params=params, timeout=timeout)
47
+ data_json = r.json()
48
+ inner_temp_df = pd.DataFrame(data_json["data"]["diff"])
49
+ temp_list.append(inner_temp_df)
50
+ # 合并所有数据
51
+ temp_df = pd.concat(temp_list, ignore_index=True)
52
+ temp_df["f3"] = pd.to_numeric(temp_df["f3"], errors="coerce")
53
+ temp_df.sort_values(by=["f3"], ascending=False, inplace=True, ignore_index=True)
54
+ temp_df.reset_index(inplace=True)
55
+ temp_df["index"] = temp_df["index"].astype(int) + 1
56
+ return temp_df
10
57
 
11
58
 
12
59
  def set_df_columns(df: pd.DataFrame, cols: List[str]) -> pd.DataFrame:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: akshare
3
- Version: 1.16.35
3
+ Version: 1.16.37
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
@@ -1,4 +1,4 @@
1
- akshare/__init__.py,sha256=vAG55v1T8N_eCiPJG-o7jIrXQtUZpcwbcqVeE4tEZ9M,190342
1
+ akshare/__init__.py,sha256=diiFL-n_yvjQPu7e9YeRy0_N1BP1cQwp8RLJ86xIojc,190442
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
@@ -172,7 +172,7 @@ akshare/index/index_research_sw.py,sha256=Mm1YtiP-PXhDysJwmFidX3RZSZZ92AyXpjl_tV
172
172
  akshare/index/index_spot.py,sha256=meTBTCp2DPVTX_N3qpCLtkI-0q3XhrJ3gndNugRBGKg,1767
173
173
  akshare/index/index_stock_hk.py,sha256=eCtL477XlLpbOvBRWG_ooDlFV4kFRk8na0k2r_rr_GU,9795
174
174
  akshare/index/index_stock_us_sina.py,sha256=IxOk4G49oasv7EfEQenL9-GLuelyUus6c4JPyRlaOzY,1551
175
- akshare/index/index_stock_zh.py,sha256=T79qIxZbRub4yprZ5ukEllWqfj-WV2Zkx4i7KyEwGjE,17860
175
+ akshare/index/index_stock_zh.py,sha256=P0kO15gezzmvSrZrhZRzUlh40Vb7NnE0ePTNuqhUAPQ,17739
176
176
  akshare/index/index_stock_zh_csindex.py,sha256=sRVoDD-fitqAMuDs0XPm1oCz2nZ2QTkvNswL1WvXpwo,4164
177
177
  akshare/index/index_sugar.py,sha256=B_Nj9Q6JP-Y_d7myZ0C79izTxxrbuZIp1Vv_CilVMOc,5006
178
178
  akshare/index/index_sw.py,sha256=hETMmFszQb7JDY8UHjLK8szfwkr7Ui_6QcseOoEfxaI,10456
@@ -236,7 +236,7 @@ akshare/stock/__init__.py,sha256=jSa9260d6aNZajaW68chI2mpPkDSXLOgi3eXrqo4MQ8,82
236
236
  akshare/stock/cons.py,sha256=0oyUW5Pu-iQ3qgh-TFemM_O5f1fAwVe-PsI4Qa8EYpQ,42956
237
237
  akshare/stock/stock_allotment_cninfo.py,sha256=OVjVdWp2XVRNbJvVgtgVVoBmPBJgBB4RyIIgA_9QHM8,6066
238
238
  akshare/stock/stock_ask_bid_em.py,sha256=bo7VNkp1PmK4Z-GPZuVn_I-IAdzeW8cs3W_75KodxCg,3368
239
- akshare/stock/stock_board_concept_em.py,sha256=-ZzrpRCpoiTdOy_yeLtkGEHP_wjKBmKiR5l_EfDhLzg,18554
239
+ akshare/stock/stock_board_concept_em.py,sha256=9gf-hhb9-s-iOnPD7mlBSAf8_XYbyB-ly1Z8eg5CBGc,18116
240
240
  akshare/stock/stock_board_industry_em.py,sha256=Whqgve1JrghcKuaC2F80Vt-z-9oSxQW66GIZwMM0QG8,19170
241
241
  akshare/stock/stock_cg_equity_mortgage.py,sha256=Pui5aWKKPwGuKjF_GNpejDzsMGNPrxiaJviLz3x2e9I,3426
242
242
  akshare/stock/stock_cg_guarantee.py,sha256=ts7qcQhhyN1PHB7Q4XlMn38HhfVvubOvky9RZfmUP94,3844
@@ -263,7 +263,7 @@ akshare/stock/stock_industry_pe_cninfo.py,sha256=0OjjsFGG90zJRZEBqaCsjKSpSAgrp3P
263
263
  akshare/stock/stock_industry_sw.py,sha256=C0FjDg976EA0EksRS3sChbmJOZmOPEOzKCrHVs2YqTg,1441
264
264
  akshare/stock/stock_info.py,sha256=AqzLzsTlYTSExBtyrZZBjI-D-VROj9e7Sq37WKHJ7XQ,16314
265
265
  akshare/stock/stock_info_em.py,sha256=9dxvIeRmvfN-1blwivCT5gGWBsOyLQljHEW5TAG0qsU,2559
266
- akshare/stock/stock_intraday_em.py,sha256=s3gAzG0-6gYj407WePpoNXVyKUZB-siOOw1xZbBYIF4,4538
266
+ akshare/stock/stock_intraday_em.py,sha256=lKa33VVH9OPisYvUnfib-lmaGzl_iM12uyKUwRERDZE,2391
267
267
  akshare/stock/stock_intraday_sina.py,sha256=7LzXRwjdPo-BHwvs8244-MFiGriPUCFBJqRW-r9iVB4,2359
268
268
  akshare/stock/stock_ipo_summary_cninfo.py,sha256=Ma-54GsOOhRWxilLH-Qmm0VVbpJQGf2XWKaJ8NBSgAY,3847
269
269
  akshare/stock/stock_new_cninfo.py,sha256=EOuZowDLQSSHyPAwXcuPXbQkqhbz2nRBZsM7o2ZWILE,5725
@@ -318,7 +318,7 @@ akshare/stock_feature/stock_gdhs.py,sha256=Z6ZMy1A03BqMu9TghcIu2Sd_wwEtpIH7qawHu
318
318
  akshare/stock_feature/stock_gdzjc_em.py,sha256=SHJH5iS3_NhvjTqRXF0vPooZl0s_ASeyZmNCC50ZYqs,4426
319
319
  akshare/stock_feature/stock_gpzy_em.py,sha256=FgyjVgdoxrtMM7WwxdQJxK0mYGJklIHaT9KmMCFmEPM,17869
320
320
  akshare/stock_feature/stock_gxl_lg.py,sha256=I8TpDEpFzadZSSyZisyIk6163mJlRxup91dmlBH4t4U,2641
321
- akshare/stock_feature/stock_hist_em.py,sha256=8tR__dts03shNuxBGmEYmotOuVfAQpvUnzT2-m6shA4,67558
321
+ akshare/stock_feature/stock_hist_em.py,sha256=vC3gWA1hTgWdwk4VFfk6HOwfWuzlYO2xa5vZg5hi088,64241
322
322
  akshare/stock_feature/stock_hist_tx.py,sha256=WpLsbkG2didSx7lYNkSbTWNTrLhUKbcopfD18WO2Rlc,3397
323
323
  akshare/stock_feature/stock_hk_valuation_baidu.py,sha256=_sErx4UhNsSXJgXyPfrL0aPxkW53Mg1zH9gEKoziaCA,1968
324
324
  akshare/stock_feature/stock_hot_xq.py,sha256=NmoH4x-0hiDztj-YwzMFVIyOICQ2wUUBbhjt91q-tq4,9112
@@ -383,13 +383,13 @@ akshare/utils/__init__.py,sha256=HbKUP2vZApbeK2PTZVO_m-6kAUymfDwm2yv3Kr4R_1A,81
383
383
  akshare/utils/cons.py,sha256=PFZndkG3lMW1Qhg-wqcZmSowFXwQUsYYCLZT4s1Xkwc,225
384
384
  akshare/utils/context.py,sha256=Hl4kPUzQ1CecRzu5JvTKpTpiMLfzAzYzG7F5hktlsCQ,934
385
385
  akshare/utils/demjson.py,sha256=xW2z0UGS2zzyH_dzhd765ZveuXRbfjkM7KBiI8H5fJA,241609
386
- akshare/utils/func.py,sha256=PDkwpyCjZCbCLSAG9wBQt-sYNtb1XlpUBvhAfuSLf3s,586
386
+ akshare/utils/func.py,sha256=4cwmXFztU86yJNONJ40KJLvsIEQHBbct4iMm3zT2v30,2315
387
387
  akshare/utils/token_process.py,sha256=K4rGXjh_tgugbRcyOK2h2x0jP3PT65IIK7nxhUKhOeQ,666
388
388
  akshare/utils/tqdm.py,sha256=MuPNwcswkOGjwWQOMWXi9ZvQ_RmW4obCWRj2i7HM7FE,847
389
389
  tests/__init__.py,sha256=gNzhlO0UPjFq6Ieb38kaVIODXv4cTDByrdohAZnDYt4,82
390
390
  tests/test_func.py,sha256=j1MGYbZI2if2j_LY1S4FLsf4qfq4NwVqD5wmRlv5Log,832
391
- akshare-1.16.35.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
392
- akshare-1.16.35.dist-info/METADATA,sha256=9e0Iq61KfT8dieIOQTPKWjvnebu4fnngqBOcEK__FDQ,13653
393
- akshare-1.16.35.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
394
- akshare-1.16.35.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
395
- akshare-1.16.35.dist-info/RECORD,,
391
+ akshare-1.16.37.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
392
+ akshare-1.16.37.dist-info/METADATA,sha256=_VOPPo7anGG8O2U16g8i4mcT9gly7TNG_TY5z9D9h2E,13653
393
+ akshare-1.16.37.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
394
+ akshare-1.16.37.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
395
+ akshare-1.16.37.dist-info/RECORD,,