akshare 1.16.36__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
@@ -3045,9 +3045,10 @@ amac_manager_cancelled_info # 中国证券投资基金业协会-信息公示-诚
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
3047
  1.16.36 fix: fix stock_intraday_em interface
3048
+ 1.16.37 fix: fix stock_board_concept_hist_em interface
3048
3049
  """
3049
3050
 
3050
- __version__ = "1.16.36"
3051
+ __version__ = "1.16.37"
3051
3052
  __author__ = "AKFamily"
3052
3053
 
3053
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,7 +28,7 @@ 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
@@ -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:
@@ -35,24 +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
- per_page_num = len(data_json["data"]["diff"])
41
- total_page = math.ceil(data_json["data"]["total"] / per_page_num)
42
- temp_list = []
43
- tqdm = get_tqdm()
44
- for page in tqdm(range(1, total_page + 1), leave=False):
45
- params.update(
46
- {
47
- "pn": page,
48
- }
49
- )
50
- r = requests.get(url, params=params, timeout=15)
51
- data_json = r.json()
52
- inner_temp_df = pd.DataFrame(data_json["data"]["diff"])
53
- temp_list.append(inner_temp_df)
54
- temp_df = pd.concat(temp_list, ignore_index=True)
37
+ temp_df = fetch_paginated_data(url, params)
55
38
  temp_df.columns = [
39
+ "index",
56
40
  "_",
57
41
  "最新价",
58
42
  "涨跌幅",
@@ -85,8 +69,6 @@ def stock_zh_a_spot_em() -> pd.DataFrame:
85
69
  "-",
86
70
  "-",
87
71
  ]
88
- temp_df.reset_index(inplace=True)
89
- temp_df["index"] = temp_df.index + 1
90
72
  temp_df.rename(columns={"index": "序号"}, inplace=True)
91
73
  temp_df = temp_df[
92
74
  [
@@ -150,24 +132,21 @@ def stock_sh_a_spot_em() -> pd.DataFrame:
150
132
  url = "https://82.push2.eastmoney.com/api/qt/clist/get"
151
133
  params = {
152
134
  "pn": "1",
153
- "pz": "50000",
135
+ "pz": "100",
154
136
  "po": "1",
155
- "np": "2",
137
+ "np": "1",
156
138
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
157
139
  "fltt": "2",
158
140
  "invt": "2",
159
- "fid": "f3",
141
+ "fid": "f12",
160
142
  "fs": "m:1 t:2,m:1 t:23",
161
143
  "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,"
162
144
  "f24,f25,f22,f11,f62,f128,f136,f115,f152",
163
145
  "_": "1623833739532",
164
146
  }
165
- r = requests.get(url, timeout=15, params=params)
166
- data_json = r.json()
167
- if not data_json["data"]["diff"]:
168
- return pd.DataFrame()
169
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
147
+ temp_df = fetch_paginated_data(url, params)
170
148
  temp_df.columns = [
149
+ "序号",
171
150
  "_",
172
151
  "最新价",
173
152
  "涨跌幅",
@@ -200,9 +179,6 @@ def stock_sh_a_spot_em() -> pd.DataFrame:
200
179
  "-",
201
180
  "-",
202
181
  ]
203
- temp_df.reset_index(inplace=True)
204
- temp_df["index"] = temp_df.index + 1
205
- temp_df.rename(columns={"index": "序号"}, inplace=True)
206
182
  temp_df = temp_df[
207
183
  [
208
184
  "序号",
@@ -265,9 +241,9 @@ def stock_sz_a_spot_em() -> pd.DataFrame:
265
241
  url = "https://82.push2.eastmoney.com/api/qt/clist/get"
266
242
  params = {
267
243
  "pn": "1",
268
- "pz": "50000",
244
+ "pz": "100",
269
245
  "po": "1",
270
- "np": "2",
246
+ "np": "1",
271
247
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
272
248
  "fltt": "2",
273
249
  "invt": "2",
@@ -277,12 +253,9 @@ def stock_sz_a_spot_em() -> pd.DataFrame:
277
253
  "f25,f22,f11,f62,f128,f136,f115,f152",
278
254
  "_": "1623833739532",
279
255
  }
280
- r = requests.get(url, timeout=15, params=params)
281
- data_json = r.json()
282
- if not data_json["data"]["diff"]:
283
- return pd.DataFrame()
284
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
256
+ temp_df = fetch_paginated_data(url, params)
285
257
  temp_df.columns = [
258
+ "序号",
286
259
  "_",
287
260
  "最新价",
288
261
  "涨跌幅",
@@ -315,9 +288,6 @@ def stock_sz_a_spot_em() -> pd.DataFrame:
315
288
  "-",
316
289
  "-",
317
290
  ]
318
- temp_df.reset_index(inplace=True)
319
- temp_df["index"] = temp_df.index + 1
320
- temp_df.rename(columns={"index": "序号"}, inplace=True)
321
291
  temp_df = temp_df[
322
292
  [
323
293
  "序号",
@@ -380,9 +350,9 @@ def stock_bj_a_spot_em() -> pd.DataFrame:
380
350
  url = "https://82.push2.eastmoney.com/api/qt/clist/get"
381
351
  params = {
382
352
  "pn": "1",
383
- "pz": "50000",
353
+ "pz": "100",
384
354
  "po": "1",
385
- "np": "2",
355
+ "np": "1",
386
356
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
387
357
  "fltt": "2",
388
358
  "invt": "2",
@@ -392,12 +362,9 @@ def stock_bj_a_spot_em() -> pd.DataFrame:
392
362
  ",f25,f22,f11,f62,f128,f136,f115,f152",
393
363
  "_": "1623833739532",
394
364
  }
395
- r = requests.get(url, params=params, timeout=15)
396
- data_json = r.json()
397
- if not data_json["data"]["diff"]:
398
- return pd.DataFrame()
399
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
365
+ temp_df = fetch_paginated_data(url, params)
400
366
  temp_df.columns = [
367
+ "序号",
401
368
  "_",
402
369
  "最新价",
403
370
  "涨跌幅",
@@ -430,9 +397,6 @@ def stock_bj_a_spot_em() -> pd.DataFrame:
430
397
  "-",
431
398
  "-",
432
399
  ]
433
- temp_df.reset_index(inplace=True)
434
- temp_df["index"] = temp_df.index + 1
435
- temp_df.rename(columns={"index": "序号"}, inplace=True)
436
400
  temp_df = temp_df[
437
401
  [
438
402
  "序号",
@@ -495,9 +459,9 @@ def stock_new_a_spot_em() -> pd.DataFrame:
495
459
  url = "https://82.push2.eastmoney.com/api/qt/clist/get"
496
460
  params = {
497
461
  "pn": "1",
498
- "pz": "50000",
462
+ "pz": "100",
499
463
  "po": "1",
500
- "np": "2",
464
+ "np": "1",
501
465
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
502
466
  "fltt": "2",
503
467
  "invt": "2",
@@ -508,12 +472,9 @@ def stock_new_a_spot_em() -> pd.DataFrame:
508
472
  "f25,f26,f22,f11,f62,f128,f136,f115,f152",
509
473
  "_": "1623833739532",
510
474
  }
511
- r = requests.get(url, timeout=15, params=params)
512
- data_json = r.json()
513
- if not data_json["data"]["diff"]:
514
- return pd.DataFrame()
515
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
475
+ temp_df = fetch_paginated_data(url, params)
516
476
  temp_df.columns = [
477
+ "序号",
517
478
  "_",
518
479
  "最新价",
519
480
  "涨跌幅",
@@ -547,9 +508,6 @@ def stock_new_a_spot_em() -> pd.DataFrame:
547
508
  "-",
548
509
  "-",
549
510
  ]
550
- temp_df.reset_index(inplace=True)
551
- temp_df["index"] = temp_df.index + 1
552
- temp_df.rename(columns={"index": "序号"}, inplace=True)
553
511
  temp_df = temp_df[
554
512
  [
555
513
  "序号",
@@ -615,9 +573,9 @@ def stock_cy_a_spot_em() -> pd.DataFrame:
615
573
  url = "https://7.push2.eastmoney.com/api/qt/clist/get"
616
574
  params = {
617
575
  "pn": "1",
618
- "pz": "50000",
576
+ "pz": "100",
619
577
  "po": "1",
620
- "np": "2",
578
+ "np": "1",
621
579
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
622
580
  "fltt": "2",
623
581
  "invt": "2",
@@ -628,12 +586,9 @@ def stock_cy_a_spot_em() -> pd.DataFrame:
628
586
  "f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
629
587
  "_": "1623833739532",
630
588
  }
631
- r = requests.get(url, timeout=15, params=params)
632
- data_json = r.json()
633
- if not data_json["data"]["diff"]:
634
- return pd.DataFrame()
635
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
589
+ temp_df = fetch_paginated_data(url, params)
636
590
  temp_df.columns = [
591
+ "序号",
637
592
  "_",
638
593
  "最新价",
639
594
  "涨跌幅",
@@ -666,9 +621,6 @@ def stock_cy_a_spot_em() -> pd.DataFrame:
666
621
  "-",
667
622
  "-",
668
623
  ]
669
- temp_df.reset_index(inplace=True)
670
- temp_df["index"] = temp_df.index + 1
671
- temp_df.rename(columns={"index": "序号"}, inplace=True)
672
624
  temp_df = temp_df[
673
625
  [
674
626
  "序号",
@@ -731,9 +683,9 @@ def stock_kc_a_spot_em() -> pd.DataFrame:
731
683
  url = "https://7.push2.eastmoney.com/api/qt/clist/get"
732
684
  params = {
733
685
  "pn": "1",
734
- "pz": "50000",
686
+ "pz": "100",
735
687
  "po": "1",
736
- "np": "2",
688
+ "np": "1",
737
689
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
738
690
  "fltt": "2",
739
691
  "invt": "2",
@@ -744,12 +696,9 @@ def stock_kc_a_spot_em() -> pd.DataFrame:
744
696
  "f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
745
697
  "_": "1623833739532",
746
698
  }
747
- r = requests.get(url, params=params, timeout=15)
748
- data_json = r.json()
749
- if not data_json["data"]["diff"]:
750
- return pd.DataFrame()
751
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
699
+ temp_df = fetch_paginated_data(url, params)
752
700
  temp_df.columns = [
701
+ "序号",
753
702
  "_",
754
703
  "最新价",
755
704
  "涨跌幅",
@@ -782,9 +731,6 @@ def stock_kc_a_spot_em() -> pd.DataFrame:
782
731
  "-",
783
732
  "-",
784
733
  ]
785
- temp_df.reset_index(inplace=True)
786
- temp_df["index"] = temp_df.index + 1
787
- temp_df.rename(columns={"index": "序号"}, inplace=True)
788
734
  temp_df = temp_df[
789
735
  [
790
736
  "序号",
@@ -847,9 +793,9 @@ def stock_zh_b_spot_em() -> pd.DataFrame:
847
793
  url = "https://28.push2.eastmoney.com/api/qt/clist/get"
848
794
  params = {
849
795
  "pn": "1",
850
- "pz": "50000",
796
+ "pz": "100",
851
797
  "po": "1",
852
- "np": "2",
798
+ "np": "1",
853
799
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
854
800
  "fltt": "2",
855
801
  "invt": "2",
@@ -859,12 +805,9 @@ def stock_zh_b_spot_em() -> pd.DataFrame:
859
805
  ",f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
860
806
  "_": "1623833739532",
861
807
  }
862
- r = requests.get(url, params=params, timeout=15)
863
- data_json = r.json()
864
- if not data_json["data"]["diff"]:
865
- return pd.DataFrame()
866
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
808
+ temp_df = fetch_paginated_data(url, params)
867
809
  temp_df.columns = [
810
+ "序号",
868
811
  "_",
869
812
  "最新价",
870
813
  "涨跌幅",
@@ -897,9 +840,6 @@ def stock_zh_b_spot_em() -> pd.DataFrame:
897
840
  "-",
898
841
  "-",
899
842
  ]
900
- temp_df.reset_index(inplace=True)
901
- temp_df["index"] = temp_df.index + 1
902
- temp_df.rename(columns={"index": "序号"}, inplace=True)
903
843
  temp_df = temp_df[
904
844
  [
905
845
  "序号",
@@ -1240,9 +1180,9 @@ def stock_hk_spot_em() -> pd.DataFrame:
1240
1180
  url = "https://72.push2.eastmoney.com/api/qt/clist/get"
1241
1181
  params = {
1242
1182
  "pn": "1",
1243
- "pz": "50000",
1183
+ "pz": "100",
1244
1184
  "po": "1",
1245
- "np": "2",
1185
+ "np": "1",
1246
1186
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
1247
1187
  "fltt": "2",
1248
1188
  "invt": "2",
@@ -1252,12 +1192,9 @@ def stock_hk_spot_em() -> pd.DataFrame:
1252
1192
  "f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
1253
1193
  "_": "1624010056945",
1254
1194
  }
1255
- r = requests.get(url, timeout=15, params=params)
1256
- data_json = r.json()
1257
- if not data_json["data"]["diff"]:
1258
- return pd.DataFrame()
1259
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
1195
+ temp_df = fetch_paginated_data(url, params)
1260
1196
  temp_df.columns = [
1197
+ "序号",
1261
1198
  "_",
1262
1199
  "最新价",
1263
1200
  "涨跌幅",
@@ -1290,9 +1227,6 @@ def stock_hk_spot_em() -> pd.DataFrame:
1290
1227
  "_",
1291
1228
  "_",
1292
1229
  ]
1293
- temp_df.reset_index(inplace=True)
1294
- temp_df["index"] = temp_df.index + 1
1295
- temp_df.rename(columns={"index": "序号"}, inplace=True)
1296
1230
  temp_df = temp_df[
1297
1231
  [
1298
1232
  "序号",
@@ -1332,9 +1266,9 @@ def stock_hk_main_board_spot_em() -> pd.DataFrame:
1332
1266
  url = "https://81.push2.eastmoney.com/api/qt/clist/get"
1333
1267
  params = {
1334
1268
  "pn": "1",
1335
- "pz": "50000",
1269
+ "pz": "100",
1336
1270
  "po": "1",
1337
- "np": "2",
1271
+ "np": "1",
1338
1272
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
1339
1273
  "fltt": "2",
1340
1274
  "invt": "2",
@@ -1344,10 +1278,9 @@ def stock_hk_main_board_spot_em() -> pd.DataFrame:
1344
1278
  "f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152",
1345
1279
  "_": "1624010056945",
1346
1280
  }
1347
- r = requests.get(url, params=params, timeout=15)
1348
- data_json = r.json()
1349
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
1281
+ temp_df = fetch_paginated_data(url, params)
1350
1282
  temp_df.columns = [
1283
+ "序号",
1351
1284
  "_",
1352
1285
  "最新价",
1353
1286
  "涨跌幅",
@@ -1380,9 +1313,6 @@ def stock_hk_main_board_spot_em() -> pd.DataFrame:
1380
1313
  "_",
1381
1314
  "_",
1382
1315
  ]
1383
- temp_df.reset_index(inplace=True)
1384
- temp_df["index"] = temp_df.index + 1
1385
- temp_df.rename(columns={"index": "序号"}, inplace=True)
1386
1316
  temp_df = temp_df[
1387
1317
  [
1388
1318
  "序号",
@@ -1625,9 +1555,9 @@ def stock_us_spot_em() -> pd.DataFrame:
1625
1555
  url = "https://72.push2.eastmoney.com/api/qt/clist/get"
1626
1556
  params = {
1627
1557
  "pn": "1",
1628
- "pz": "50000",
1558
+ "pz": "100",
1629
1559
  "po": "1",
1630
- "np": "2",
1560
+ "np": "1",
1631
1561
  "ut": "bd1d9ddb04089700cf9c27f6f7426281",
1632
1562
  "fltt": "2",
1633
1563
  "invt": "2",
@@ -1637,12 +1567,9 @@ def stock_us_spot_em() -> pd.DataFrame:
1637
1567
  "f21,f23,f24,f25,f26,f22,f33,f11,f62,f128,f136,f115,f152",
1638
1568
  "_": "1624010056945",
1639
1569
  }
1640
- r = requests.get(url, params=params, timeout=15)
1641
- data_json = r.json()
1642
- if not data_json["data"]["diff"]:
1643
- return pd.DataFrame()
1644
- temp_df = pd.DataFrame(data_json["data"]["diff"]).T
1570
+ temp_df = fetch_paginated_data(url, params)
1645
1571
  temp_df.columns = [
1572
+ "序号",
1646
1573
  "_",
1647
1574
  "最新价",
1648
1575
  "涨跌幅",
@@ -1677,9 +1604,6 @@ def stock_us_spot_em() -> pd.DataFrame:
1677
1604
  "_",
1678
1605
  "_",
1679
1606
  ]
1680
- temp_df.reset_index(inplace=True)
1681
- temp_df["index"] = range(1, len(temp_df) + 1)
1682
- temp_df.rename(columns={"index": "序号"}, inplace=True)
1683
1607
  temp_df["代码"] = temp_df["编码"].astype(str) + "." + temp_df["简称"]
1684
1608
  temp_df = temp_df[
1685
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.36
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=BEyF7znXUR1G0SYE6hnt_FLL5y57W-0aN-S7yBLKmxg,190387
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=DOjBDUGkFYHmrCPiAWYR5EgErN8yhuSBngVLreE5hT0,4530
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=cs4Ib6YYG-E1QDftOu6ZGink_Mcg6YbmyiFJKuzQ5VA,67617
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.36.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
392
- akshare-1.16.36.dist-info/METADATA,sha256=OXCWYNvHif2CpLEg-elgARcE74xjv7x8I14CUshdb_U,13653
393
- akshare-1.16.36.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
394
- akshare-1.16.36.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
395
- akshare-1.16.36.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,,