akshare 1.15.42__py3-none-any.whl → 1.15.44__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.

Potentially problematic release.


This version of akshare might be problematic. Click here for more details.

akshare/__init__.py CHANGED
@@ -2952,9 +2952,11 @@ amac_manager_cancelled_info # 中国证券投资基金业协会-信息公示-诚
2952
2952
  1.15.40 fix: fix macro_china_fdi interface
2953
2953
  1.15.41 fix: fix macro_china_fdi interface
2954
2954
  1.15.42 fix: fix get_roll_yield_bar interface
2955
+ 1.15.43 fix: fix macro_china_urban_unemployment interface
2956
+ 1.15.44 fix: fix index_detail_hist_adjust_cni interface
2955
2957
  """
2956
2958
 
2957
- __version__ = "1.15.42"
2959
+ __version__ = "1.15.44"
2958
2960
  __author__ = "AKFamily"
2959
2961
 
2960
2962
  import sys
@@ -5273,14 +5275,6 @@ from akshare.economic.macro_china_nbs import (
5273
5275
  macro_china_nbs_region
5274
5276
  )
5275
5277
 
5276
- """
5277
- 全球期货
5278
- """
5279
- from akshare.futures.futures_international import (
5280
- futures_global_commodity_hist,
5281
- futures_global_commodity_name_url_map,
5282
- )
5283
-
5284
5278
  """
5285
5279
  外汇
5286
5280
  """
@@ -5306,23 +5300,6 @@ from akshare.option.option_commodity import (
5306
5300
  option_gfex_daily,
5307
5301
  )
5308
5302
 
5309
- """
5310
- 英为财情-债券
5311
- """
5312
- from akshare.bond.bond_investing import (
5313
- bond_investing_global,
5314
- bond_investing_global_country_name_url,
5315
- )
5316
-
5317
- """
5318
- 英为财情-指数
5319
- """
5320
- from akshare.index.index_investing import (
5321
- index_investing_global,
5322
- index_investing_global_area_index_name_code,
5323
- index_investing_global_area_index_name_url,
5324
- )
5325
-
5326
5303
  """
5327
5304
  99期货-期货库存数据
5328
5305
  """
@@ -327,6 +327,7 @@ def macro_china_urban_unemployment() -> pd.DataFrame:
327
327
  temp_df.columns = ["date", "item", "value"]
328
328
  temp_df["item"] = temp_df["item"].map(code_item_map)
329
329
  temp_df["value"] = pd.to_numeric(temp_df["value"], errors="coerce")
330
+ temp_df.sort_values(by=["date"], ignore_index=True, inplace=True)
330
331
  return temp_df
331
332
 
332
333
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: akshare
3
- Version: 1.15.42
3
+ Version: 1.15.44
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=AKrQXVbxBE0WBJwKdTU0eWBNw1TH4O_Rtkxnagldcdc,184785
1
+ akshare/__init__.py,sha256=k5Qws3U5exDAyMlcwsIfEoDHbeEaa-ET9AqYaXuH3ro,184401
2
2
  akshare/datasets.py,sha256=-qdwaQjgBlftX84uM74KJqCYJYkQ50PV416_neA4uls,995
3
3
  akshare/exceptions.py,sha256=WEJjIhSmJ_xXNW6grwV4nufE_cfmmyuhmueVGiN1VAg,878
4
4
  akshare/request.py,sha256=HtFFf9MhfEibR-ETWe-1Tts6ELU4VKSqA-ghaXjegQM,4252
@@ -27,7 +27,6 @@ akshare/bond/bond_china_money.py,sha256=IInePsQJDby5w0AYd84ipiJL_nbyVAaRC7SaHLWD
27
27
  akshare/bond/bond_convert.py,sha256=9w94nIdSN4BUL27sPbVEUouBaAm30WMBiokYr4yM0sI,12649
28
28
  akshare/bond/bond_em.py,sha256=Ck5hCloZ25I8updarLPzqHYYZPeOsjIFy4g2oaZvFMs,5318
29
29
  akshare/bond/bond_info_cm.py,sha256=VBu9UM9tUcGDRV07pndU9yttLDF_Nk3b0vU0n65qpHs,7890
30
- akshare/bond/bond_investing.py,sha256=nWONMggn-KV8XwUSs5CqIXKHX9F7W1tb4w8umH5rWho,4992
31
30
  akshare/bond/bond_issue_cninfo.py,sha256=tPoZhF-_sIX9ztCKB0K0-Z4Kd9b-389bP3_CdFK7Wb0,21672
32
31
  akshare/bond/bond_nafmii.py,sha256=cekcobyXKMG1zDuM8wHWOn__SuWELxYmUwfGVmLRP40,2155
33
32
  akshare/bond/bond_summary.py,sha256=ECwCRcs5YMIro4I1Yayf6SZ8nz1Hr97RhmKT6aGaQDg,3581
@@ -54,7 +53,7 @@ akshare/economic/cons.py,sha256=0JM61Eiro0xqXGnCaDSoLsw5iQWKAtqhRHcXmDfJgyw,1659
54
53
  akshare/economic/macro_australia.py,sha256=JKNaedN19Rw15dn8bPur1yrsQA5j6hfX4tjgh7OCBHY,10801
55
54
  akshare/economic/macro_bank.py,sha256=wG_u5w5YjeFRn1wr-Re7ty_s2CbQ0Qphxs_bIF_20UQ,11495
56
55
  akshare/economic/macro_canada.py,sha256=nNaZ3yZIvgTtRiQhwoEybMX6UpqszPKeixzYITv9ox0,15195
57
- akshare/economic/macro_china.py,sha256=vrlOrV0D88JPeJzL1yWzpLlVuoBoQL-UY_wVT6ooUMs,148785
56
+ akshare/economic/macro_china.py,sha256=O3pgTke7VbHMJKY3ZRU6hC_noOXnaQFPr0u2qJsebEY,148855
58
57
  akshare/economic/macro_china_hk.py,sha256=dIBc9gAYiHZUjXLF4c3yBK-2s3iLx46GcgJGlVJpv4c,5974
59
58
  akshare/economic/macro_china_nbs.py,sha256=nP6dI-fawch8dz7GMcfGVJsTri-FfIAkvTf3h7DT-kc,9679
60
59
  akshare/economic/macro_constitute.py,sha256=cCfWupKJ86uUzg_pULsg1C2FleHb25mYbfE4x29VnKA,8197
@@ -115,7 +114,6 @@ akshare/futures/futures_foreign.py,sha256=oSIoAg5oy-CIlPWHkQffcvZGu02Y2GWOrt-6aP
115
114
  akshare/futures/futures_hf_em.py,sha256=jne-wUYr2QTUkDq3qAxYKE0Hm90L3H8qUDu3JavKiUg,3338
116
115
  akshare/futures/futures_hq_sina.py,sha256=eK1gEan4DPvpYmln8-tNnzh_J_733s95DBr--NqNYVA,9576
117
116
  akshare/futures/futures_index_ccidx.py,sha256=9Rhk3ps-H69tU-NIV0W2NdLFUDTSUx0bwtePA6gLMZA,4566
118
- akshare/futures/futures_international.py,sha256=EE_JTjQKekx8_FU8M12wHSd1DSlfMXYFiBJ6_wmThfc,6946
119
117
  akshare/futures/futures_inventory_99.py,sha256=Nvw39obGGhgOkk_C4jOrV4gdq78dtHPOnits_B0Ljxk,8450
120
118
  akshare/futures/futures_inventory_em.py,sha256=C5nt4F51WB-oc8o3GrMvEGo0SO2mIq_H1vHVl42vzT0,2340
121
119
  akshare/futures/futures_news_baidu.py,sha256=uqXUgQa7_aNjj1g4IBt6Ic4DhlsuBvjEEYC3OTPeqmA,1544
@@ -161,7 +159,6 @@ akshare/index/index_drewry.py,sha256=BM7V6P8K4QUFQArsdaWRu5qJUZaCoyNz97_b8dmLeCw
161
159
  akshare/index/index_eri.py,sha256=7X0KNDBntEkE_qSb2jb6IBv-S8PsevLFdxGT8nKT3W0,2111
162
160
  akshare/index/index_fear_greed_funddb.py,sha256=7Z6GqYkKPJHNHMEN-uZNu2KnNNLTWvJcVlYpfAShJJc,2378
163
161
  akshare/index/index_hog.py,sha256=kb867BVagt70_ycZMn22ks5Z9jlVbMiuTsvq5ygjeig,1657
164
- akshare/index/index_investing.py,sha256=BPGIAD-_QNhpMivQi7bSGvBF2KWd8gfHsNf0hqHKrR0,8897
165
162
  akshare/index/index_kq_fz.py,sha256=Y-cbxWLpRyGcFcMSDxZZQXdAuD85IuQH5xC2rhtGbRc,3395
166
163
  akshare/index/index_kq_ss.py,sha256=m4hAMNnzHk8JNAnKjkYYVeyG4zUC5zR5i0-u-OxmaGU,3333
167
164
  akshare/index/index_option_qvix.py,sha256=sCx0iiIetkp5ELE9sDwesVFgJNfa_1tAEWVCJI-I2u4,3270
@@ -383,8 +380,8 @@ akshare/utils/token_process.py,sha256=K4rGXjh_tgugbRcyOK2h2x0jP3PT65IIK7nxhUKhOe
383
380
  akshare/utils/tqdm.py,sha256=MuPNwcswkOGjwWQOMWXi9ZvQ_RmW4obCWRj2i7HM7FE,847
384
381
  tests/__init__.py,sha256=gNzhlO0UPjFq6Ieb38kaVIODXv4cTDByrdohAZnDYt4,82
385
382
  tests/test_func.py,sha256=j1MGYbZI2if2j_LY1S4FLsf4qfq4NwVqD5wmRlv5Log,832
386
- akshare-1.15.42.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
387
- akshare-1.15.42.dist-info/METADATA,sha256=IsPcr7junkYm9ZTzrV9cHfUJhOXMEe471JfMpRCCc_8,13423
388
- akshare-1.15.42.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
389
- akshare-1.15.42.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
390
- akshare-1.15.42.dist-info/RECORD,,
383
+ akshare-1.15.44.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
384
+ akshare-1.15.44.dist-info/METADATA,sha256=Cwm3ThUj13hwU3jQddS0Dn7zjqwK_9N5hey9CNFO4jw,13423
385
+ akshare-1.15.44.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
386
+ akshare-1.15.44.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
387
+ akshare-1.15.44.dist-info/RECORD,,
@@ -1,139 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding:utf-8 -*-
3
- """
4
- Date: 2021/5/7 13:50
5
- Desc: 英为财情-利率国债-全球政府债券行情与收益率
6
- https://cn.investing.com/rates-bonds/
7
- """
8
- import re
9
-
10
- import pandas as pd
11
- import requests
12
- from bs4 import BeautifulSoup
13
-
14
- from akshare.index.cons import short_headers, long_headers
15
-
16
-
17
- def _get_global_country_name_url() -> dict:
18
- """
19
- 指数数据国家对应的 URL
20
- https://cn.investing.com/rates-bonds/
21
- :return: 指数数据国家对应的 URL
22
- :rtype: dict
23
- """
24
- url = "https://cn.investing.com/rates-bonds/"
25
- res = requests.get(url, headers=short_headers, timeout=30)
26
- soup = BeautifulSoup(res.text, "lxml")
27
- name_url_option_list = soup.find("select", attrs={"name": "country"}).find_all(
28
- "option"
29
- )[1:]
30
- url_list = [item["value"] for item in name_url_option_list]
31
- name_list = [item.get_text() for item in name_url_option_list]
32
- name_code_map_dict = {}
33
- name_code_map_dict.update(zip(name_list, url_list))
34
- return name_code_map_dict
35
-
36
-
37
- def bond_investing_global_country_name_url(country: str = "中国") -> dict:
38
- """
39
- 参考网页: https://cn.investing.com/rates-bonds/
40
- 获取选择国家对应的: 主要指数, 主要行业, 附加指数, 其他指数
41
- :param country: str 中文国家名称, 对应 get_global_country_name_url 函数返回的国家名称
42
- :return: dict
43
- """
44
- name_url_dict = _get_global_country_name_url()
45
- url = f"https://cn.investing.com{name_url_dict[country]}"
46
- res = requests.get(url, headers=short_headers, timeout=30)
47
- soup = BeautifulSoup(res.text, "lxml")
48
- url_list = [
49
- item.find("a")["href"] for item in soup.find_all(attrs={"class": "plusIconTd"})
50
- ]
51
- name_list = [
52
- item.find("a").get_text()
53
- for item in soup.find_all(attrs={"class": "plusIconTd"})
54
- ]
55
- name_code_map_dict = {}
56
- name_code_map_dict.update(zip(name_list, url_list))
57
- return name_code_map_dict
58
-
59
-
60
- def bond_investing_global(
61
- country: str = "中国",
62
- index_name: str = "中国1年期国债",
63
- period: str = "每日",
64
- start_date: str = "20000101",
65
- end_date: str = "20191017",
66
- ) -> pd.DataFrame:
67
- """
68
- 具体国家的具体指数的从 start_date 到 end_date 期间的数据
69
- https://cn.investing.com/rates-bonds/
70
- :param country: 对应函数中的国家名称
71
- :type country: str
72
- :param index_name: 对应函数中的指数名称
73
- :type index_name: str
74
- :param period: choice of {"每日", "每周", "每月"}
75
- :type period: str
76
- :param start_date: '2000-01-01', 注意格式
77
- :type start_date: str
78
- :param end_date: '2019-10-17', 注意格式
79
- :type end_date: str
80
- :return: 指定参数的数据
81
- :rtype: pandas.DataFrame
82
- """
83
- start_date = "/".join([start_date[:4], start_date[4:6], start_date[6:]])
84
- end_date = "/".join([end_date[:4], end_date[4:6], end_date[6:]])
85
- period_map = {"每日": "Daily", "每周": "Weekly", "每月": "Monthly"}
86
- name_code_dict = bond_investing_global_country_name_url(country)
87
- temp_url = f"https://cn.investing.com/{name_code_dict[index_name]}-historical-data"
88
- res = requests.get(temp_url, headers=short_headers, timeout=30)
89
- soup = BeautifulSoup(res.text, "lxml")
90
- title = soup.find("h2", attrs={"class": "float_lang_base_1"}).get_text()
91
- data = soup.find_all(text=re.compile("window.histDataExcessInfo"))[0].strip()
92
- para_data = re.findall(r"\d+", data)
93
- payload = {
94
- "curr_id": para_data[0],
95
- "smlID": para_data[1],
96
- "header": title,
97
- "st_date": start_date,
98
- "end_date": end_date,
99
- "interval_sec": period_map[period],
100
- "sort_col": "date",
101
- "sort_ord": "DESC",
102
- "action": "historical_data",
103
- }
104
- url = "https://cn.investing.com/instruments/HistoricalDataAjax"
105
- res = requests.post(url, data=payload, headers=long_headers, timeout=60)
106
- df_data = pd.read_html(res.text)[0]
107
- df_data.columns = [
108
- "日期",
109
- "收盘",
110
- "开盘",
111
- "高",
112
- "低",
113
- "涨跌幅",
114
- ]
115
- if period == "每月":
116
- df_data.index = pd.to_datetime(df_data["日期"], format="%Y年%m月")
117
- else:
118
- df_data.index = pd.to_datetime(df_data["日期"], format="%Y年%m月%d日")
119
- df_data = df_data[["收盘", "开盘", "高", "低", "涨跌幅"]]
120
- df_data["涨跌幅"] = df_data["涨跌幅"].str.replace("%", "")
121
- df_data["涨跌幅"] = df_data["涨跌幅"].str.replace(",", "")
122
- df_data = df_data.astype(float)
123
- return df_data
124
-
125
-
126
- if __name__ == "__main__":
127
- bond_investing_global_country_name_url_df = bond_investing_global_country_name_url(
128
- "中国"
129
- )
130
- print(bond_investing_global_country_name_url_df)
131
-
132
- bond_investing_global_df = bond_investing_global(
133
- country="中国",
134
- index_name="中国10年期国债",
135
- period="每日",
136
- start_date="20100101",
137
- end_date="20210318",
138
- )
139
- print(bond_investing_global_df)
@@ -1,170 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding:utf-8 -*-
3
- """
4
- Date: 2021/5/10 17:06
5
- Desc: 提供英为财情-国际大宗商品期货
6
- https://cn.investing.com/commodities/brent-oil-historical-data
7
- """
8
- import re
9
-
10
- import pandas as pd
11
- import requests
12
- from bs4 import BeautifulSoup
13
-
14
- from akshare.index.cons import short_headers, long_headers
15
-
16
-
17
- def get_sector_symbol_name_url() -> dict:
18
- """
19
- 期货所对应板块的 URL
20
- :return: dict
21
- {'能源': '/commodities/energy',
22
- '金属': '/commodities/metals',
23
- '农业': '/commodities/softs',
24
- '商品指数': '/indices/commodities-indices'}
25
- """
26
- url = "https://cn.investing.com/commodities/"
27
- res = requests.get(url, headers=short_headers)
28
- soup = BeautifulSoup(res.text, "lxml")
29
- name_url_option_list = soup.find_all(attrs={"class": "linkTitle"}) # 去掉-所有国家及地区
30
- url_list = [item.find("a")["href"] for item in name_url_option_list]
31
- name_list = [item.get_text() for item in name_url_option_list]
32
- name_code_map_dict = {}
33
- name_code_map_dict.update(zip(name_list, url_list))
34
- return name_code_map_dict
35
-
36
-
37
- def futures_global_commodity_name_url_map(sector: str = "能源") -> dict:
38
- """
39
- 参考网页: https://cn.investing.com/commodities/
40
- 获取选择板块对应的: 具体期货品种的 url 地址
41
- :param sector: 板块, 对应 get_global_country_name_url 品种名称
42
- :type sector: str
43
- :return: dict of name-url
44
- :rtype: dict
45
- {'伦敦布伦特原油': '/commodities/brent-oil',
46
- 'WTI原油': '/commodities/crude-oil',
47
- '伦敦汽油': '/commodities/london-gas-oil',
48
- '天然气': '/commodities/natural-gas?cid=49787',
49
- '燃料油': '/commodities/heating-oil',
50
- '碳排放': '/commodities/carbon-emissions',
51
- 'RBOB汽油': '/commodities/gasoline-rbob',
52
- '布伦特原油': '/commodities/brent-oil?cid=49769',
53
- '原油': '/commodities/crude-oil?cid=49774'}
54
- """
55
- name_url_dict = get_sector_symbol_name_url()
56
- url = f"https://cn.investing.com{name_url_dict[sector]}"
57
- res = requests.post(url, headers=short_headers)
58
- soup = BeautifulSoup(res.text, "lxml")
59
- url_list = [
60
- item.find("a")["href"].split("?")[0]
61
- for item in soup.find_all(attrs={"class": "plusIconTd"})
62
- ]
63
- name_list = [
64
- item.find("a").get_text()
65
- for item in soup.find_all(attrs={"class": "plusIconTd"})
66
- ]
67
- name_code_map_dict = {}
68
- name_code_map_dict.update(zip(name_list, url_list))
69
- return name_code_map_dict
70
-
71
-
72
- def futures_global_commodity_hist(
73
- sector: str = "能源",
74
- symbol: str = "伦敦布伦特原油",
75
- start_date: str = "20000101",
76
- end_date: str = "20191017",
77
- ) -> pd.DataFrame:
78
- """
79
- 国际大宗商品的历史量价数据
80
- https://cn.investing.com/commodities
81
- :param sector: 板块名称; 调用 futures_global_commodity_name_url_map 函数获取
82
- :type sector: str
83
- :param symbol: 品种名称; 通过访问网站查询
84
- :type symbol: str
85
- :param start_date: 开始日期
86
- :type start_date: str
87
- :param end_date: 结束日期
88
- :type end_date: str
89
- :return: 国际大宗商品的历史量价数据
90
- :rtype: pandas.DataFrame
91
- """
92
- start_date = "/".join([start_date[:4], start_date[4:6], start_date[6:]])
93
- end_date = "/".join([end_date[:4], end_date[4:6], end_date[6:]])
94
- name_code_dict = futures_global_commodity_name_url_map(sector)
95
- temp_url = f"https://cn.investing.com/{name_code_dict[symbol]}-historical-data"
96
- res = requests.post(temp_url, headers=short_headers)
97
- soup = BeautifulSoup(res.text, "lxml")
98
- title = soup.find("h2", attrs={"class": "float_lang_base_1"}).get_text()
99
- res = requests.post(temp_url, headers=short_headers)
100
- soup = BeautifulSoup(res.text, "lxml")
101
- data = soup.find_all(text=re.compile("window.histDataExcessInfo"))[0].strip()
102
- para_data = re.findall(r"\d+", data)
103
- payload = {
104
- "curr_id": para_data[0],
105
- "smlID": para_data[1],
106
- "header": title,
107
- "st_date": start_date,
108
- "end_date": end_date,
109
- "interval_sec": "Daily",
110
- "sort_col": "date",
111
- "sort_ord": "DESC",
112
- "action": "historical_data",
113
- }
114
- url = "https://cn.investing.com/instruments/HistoricalDataAjax"
115
- r = requests.post(url, data=payload, headers=long_headers)
116
- temp_df = pd.read_html(r.text)[0]
117
- temp_df["日期"] = pd.to_datetime(temp_df["日期"], format="%Y年%m月%d日")
118
- if any(temp_df["交易量"].astype(str).str.contains("-")):
119
- temp_df["交易量"][temp_df["交易量"].str.contains("-")] = temp_df["交易量"][
120
- temp_df["交易量"].str.contains("-")
121
- ].replace("-", 0)
122
- if any(temp_df["交易量"].astype(str).str.contains("B")):
123
- temp_df["交易量"][temp_df["交易量"].str.contains("B").fillna(False)] = (
124
- temp_df["交易量"][temp_df["交易量"].str.contains("B").fillna(False)]
125
- .str.replace("B", "")
126
- .astype(float)
127
- * 1000000000
128
- )
129
- if any(temp_df["交易量"].astype(str).str.contains("M")):
130
- temp_df["交易量"][temp_df["交易量"].str.contains("M").fillna(False)] = (
131
- temp_df["交易量"][temp_df["交易量"].str.contains("M").fillna(False)]
132
- .str.replace("M", "")
133
- .astype(float)
134
- * 1000000
135
- )
136
- if any(temp_df["交易量"].astype(str).str.contains("K")):
137
- temp_df["交易量"][temp_df["交易量"].str.contains("K").fillna(False)] = (
138
- temp_df["交易量"][temp_df["交易量"].str.contains("K").fillna(False)]
139
- .str.replace("K", "")
140
- .astype(float)
141
- * 1000
142
- )
143
- temp_df["交易量"] = temp_df["交易量"].astype(float)
144
- temp_df["涨跌幅"] = pd.DataFrame(
145
- round(temp_df["涨跌幅"].str.replace("%", "").astype(float) / 100, 6)
146
- )
147
- temp_df.name = title
148
- temp_df.columns.name = None
149
- temp_df.sort_values(["日期"], ascending=False, inplace=True)
150
- return temp_df
151
-
152
-
153
- if __name__ == "__main__":
154
- temp_dict = futures_global_commodity_name_url_map(sector="能源")
155
- print(temp_dict)
156
-
157
- futures_global_commodity_hist_df = futures_global_commodity_hist(
158
- sector="能源", symbol="伦敦布伦特原油", start_date="19700101", end_date="20210510"
159
- )
160
- print(futures_global_commodity_hist_df)
161
-
162
- # futures_global_commodity_hist_df = futures_global_commodity_hist(
163
- # sector="能源", symbol="伦敦布伦特原油", start_date="1970/01/01", end_date="2021/05/10"
164
- # )
165
- # print(futures_global_commodity_hist_df.to_csv("伦敦布伦特原油_19880627_20080319.csv", encoding="gb2312"))
166
- #
167
- # futures_global_commodity_hist_df = futures_global_commodity_hist(
168
- # sector="能源", symbol="伦敦布伦特原油", start_date="2008/03/19", end_date="2021/05/10"
169
- # )
170
- # print(futures_global_commodity_hist_df.to_csv("伦敦布伦特原油_20080319_20210510.csv", encoding="gb2312"))
@@ -1,232 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding:utf-8 -*-
3
- """
4
- Date: 2022/8/8 19:53
5
- Desc: 英为财情-股票指数-全球股指与期货指数数据接口
6
- https://cn.investing.com/indices/volatility-s-p-500-historical-data
7
- """
8
- import json
9
-
10
- import pandas as pd
11
- import requests
12
- from bs4 import BeautifulSoup
13
-
14
- from akshare.index.cons import short_headers
15
-
16
-
17
- def _get_global_index_area_name_code() -> dict:
18
- """
19
- 全球指数-各国的全球指数数据
20
- https://cn.investing.com/indices/global-indices?majorIndices=on&primarySectors=on&bonds=on&additionalIndices=on&otherIndices=on&c_id=37
21
- :return: 国家和代码
22
- :rtype: dict
23
- """
24
- url = "https://cn.investing.com/indices/global-indices"
25
- params = {
26
- "majorIndices": "on",
27
- "primarySectors": "on",
28
- "bonds": "on",
29
- "additionalIndices": "on",
30
- "otherIndices": "on",
31
- }
32
- r = requests.get(url, params=params, headers=short_headers)
33
- data_text = r.text
34
- soup = BeautifulSoup(data_text, "lxml")
35
- name_url_option_list = soup.find_all("option")[1:]
36
- url_list = [
37
- item["value"]
38
- for item in name_url_option_list
39
- if "c_id" in item["value"]
40
- ]
41
- url_list_code = [
42
- item["value"].split("?")[1].split("=")[1]
43
- for item in name_url_option_list
44
- if "c_id" in item["value"]
45
- ]
46
- name_list = [item.get_text() for item in name_url_option_list][
47
- : len(url_list)
48
- ]
49
- _temp_df = pd.DataFrame([name_list, url_list_code]).T
50
- name_code_list = dict(zip(_temp_df.iloc[:, 0], _temp_df.iloc[:, 1]))
51
- return name_code_list
52
-
53
-
54
- def _get_global_country_name_url() -> dict:
55
- """
56
- 可获得指数数据国家对应的 URL
57
- https://cn.investing.com/indices/
58
- :return: 国家和 URL
59
- :rtype: dict
60
- """
61
- url = "https://cn.investing.com/indices/"
62
- res = requests.post(url, headers=short_headers)
63
- soup = BeautifulSoup(res.text, "lxml")
64
- name_url_option_list = soup.find(
65
- "select", attrs={"name": "country"}
66
- ).find_all("option")[
67
- 1:
68
- ] # 去掉-所有国家及地区
69
- url_list = [item["value"] for item in name_url_option_list]
70
- name_list = [item.get_text() for item in name_url_option_list]
71
- name_code_map_dict = {}
72
- name_code_map_dict.update(zip(name_list, url_list))
73
- return name_code_map_dict
74
-
75
-
76
- def index_investing_global_area_index_name_code(area: str = "中国") -> dict:
77
- """
78
- 指定 area 的所有指数和代码
79
- https://cn.investing.com/indices/
80
- :param area: 指定的国家或地区;ak._get_global_country_name_url() 函数返回的国家或地区的名称
81
- :type area: str
82
- :return: 指定 area 的所有指数和代码
83
- :rtype: dict
84
- """
85
- pd.set_option("mode.chained_assignment", None)
86
- name_url_dict = _get_global_country_name_url()
87
- url = f"https://cn.investing.com{name_url_dict[area]}?&majorIndices=on&primarySectors=on&additionalIndices=on&otherIndices=on"
88
- r = requests.get(url)
89
- soup = BeautifulSoup(r.text, "lxml")
90
- code_list = [
91
- item["data-id"]
92
- for item in soup.find_all("table")[1].find_all(
93
- "span", attrs={"class": "alertBellGrayPlus"}
94
- )
95
- ]
96
- name_list = [
97
- item.find("a").text
98
- for item in soup.find_all("td", attrs={"class": "plusIconTd"})
99
- ]
100
- name_code_map_dict = {}
101
- name_code_map_dict.update(zip(name_list, code_list))
102
- return name_code_map_dict
103
-
104
-
105
- def index_investing_global_area_index_name_url(area: str = "中国") -> dict:
106
- """
107
- 指定 area 的所有指数和 URL 地址
108
- https://cn.investing.com/indices/
109
- :param area: 指定的国家或地区;ak._get_global_country_name_url() 函数返回的国家或地区的名称
110
- :type area: str
111
- :return: 指定 area 的所有指数和 URL 地址
112
- :rtype: dict
113
- """
114
- pd.set_option("mode.chained_assignment", None)
115
- name_url_dict = _get_global_country_name_url()
116
- url = f"https://cn.investing.com{name_url_dict[area]}?&majorIndices=on&primarySectors=on&additionalIndices=on&otherIndices=on"
117
- r = requests.get(url)
118
- soup = BeautifulSoup(r.text, "lxml")
119
- code_list = [
120
- item.find("a")["href"]
121
- for item in soup.find_all("td", attrs={"class": "plusIconTd"})
122
- ]
123
- name_list = [
124
- item.find("a").text
125
- for item in soup.find_all("td", attrs={"class": "plusIconTd"})
126
- ]
127
- name_code_map_dict = {}
128
- name_code_map_dict.update(zip(name_list, code_list))
129
- return name_code_map_dict
130
-
131
-
132
- def index_investing_global(
133
- area: str = "中国",
134
- symbol: str = "上证指数",
135
- period: str = "每日",
136
- start_date: str = "20100101",
137
- end_date: str = "20211031",
138
- ) -> pd.DataFrame:
139
- """
140
- 具体国家或地区的从 start_date 到 end_date 期间的数据
141
- https://cn.investing.com/indices/ftse-epra-nareit-hong-kong-historical-data
142
- :param area: 对应函数中的国家或地区名称
143
- :type area: str
144
- :param symbol: 对应函数中的指数名称
145
- :type symbol: str
146
- :param period: choice of {"每日", "每周", "每月"}
147
- :type period: str
148
- :param start_date: '20000101', 注意格式
149
- :type start_date: str
150
- :param end_date: '20191017', 注意格式
151
- :type end_date: str
152
- :return: 指定参数的数据
153
- :rtype: pandas.DataFrame
154
- """
155
- start_date = "-".join([start_date[:4], start_date[4:6], start_date[6:]])
156
- end_date = "-".join([end_date[:4], end_date[4:6], end_date[6:]])
157
- period_map = {"每日": "Daily", "每周": "Weekly", "每月": "Monthly"}
158
- name_code_dict = index_investing_global_area_index_name_code(area)
159
- url = f"https://api.investing.com/api/financialdata/historical/{name_code_dict[symbol]}"
160
- params = {
161
- "start-date": start_date,
162
- "end-date": end_date,
163
- "time-frame": period_map[period],
164
- "add-missing-rows": "false",
165
- }
166
- headers = {
167
- "accept": "application/json, text/plain, */*",
168
- "accept-encoding": "gzip, deflate, br",
169
- "accept-language": "zh-CN,zh;q=0.9,en;q=0.8",
170
- "cache-control": "no-cache",
171
- "domain-id": "cn",
172
- "origin": "https://cn.investing.com",
173
- "pragma": "no-cache",
174
- "referer": "https://cn.investing.com/",
175
- "sec-ch-ua": '"Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"',
176
- "sec-ch-ua-mobile": "?0",
177
- "sec-ch-ua-platform": '"Windows"',
178
- "sec-fetch-dest": "empty",
179
- "sec-fetch-mode": "cors",
180
- "sec-fetch-site": "same-site",
181
- "authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjM2NjQ1NzUsImp0aSI6IjIyODA4MDM5MSIsImlhdCI6MTY2MzY2MDk3NSwiaXNzIjoiaW52ZXN0aW5nLmNvbSIsInVzZXJfaWQiOjIyODA4MDM5MSwicHJpbWFyeV9kb21haW5faWQiOiIxIiwiQXV0aG5TeXN0ZW1Ub2tlbiI6IiIsIkF1dGhuU2Vzc2lvblRva2VuIjoiIiwiRGV2aWNlVG9rZW4iOiIiLCJVYXBpVG9rZW4iOiJObmclMkJmMlJyUHpjeWRtdHRaell5TW1JN1pUNWliV1prTURJMVB6czlNeVUySWpVN1lEYzNjV1ZxYWlSZ1kyVjVNamRsWWpRMFptWTFQMkk4TnpCdlBEWXlQbVJrWXo4M01tQnJaMmN3TW1aaU1HVm9ZbWRtWmpBNU5UWTdhRE0lMkJOalUxTW1Cdk56VmxPbW93WUR4bGJUSWdaWGswY0daM05XZGlNamQyYnlnMk9UNSUyRlpEUSUyRllESm1hMjluTURJeFlqRmxQV0l3Wmpjd1pUVXhPenN6S3paOSIsIkF1dGhuSWQiOiIiLCJJc0RvdWJsZUVuY3J5cHRlZCI6ZmFsc2UsIkRldmljZUlkIjoiIiwiUmVmcmVzaEV4cGlyZWRBdCI6MTY2NjE4MDk3NX0.uRLTP1IG3696uxHm3Qq0D8z4o3nfsD3CaIS9cZGjsV0",
182
- "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
183
- }
184
- r = requests.get(url, params=params, headers=headers)
185
- r.encoding = "utf-8"
186
- r = requests.get(url, params=params, headers=headers)
187
- data_json = r.json()
188
- df_data = pd.DataFrame(data_json["data"])
189
- df_data.columns = [
190
- "-",
191
- "-",
192
- "-",
193
- "日期",
194
- "-",
195
- "-",
196
- "-",
197
- "-",
198
- "-",
199
- "交易量",
200
- "-",
201
- "收盘",
202
- "开盘",
203
- "高",
204
- "低",
205
- "涨跌幅",
206
- ]
207
- df_data = df_data[["日期", "收盘", "开盘", "高", "低", "交易量", "涨跌幅"]]
208
- df_data["日期"] = pd.to_datetime(df_data["日期"]).dt.date
209
- df_data["收盘"] = pd.to_numeric(df_data["收盘"])
210
- df_data["开盘"] = pd.to_numeric(df_data["开盘"])
211
- df_data["高"] = pd.to_numeric(df_data["高"])
212
- df_data["低"] = pd.to_numeric(df_data["低"])
213
- df_data["交易量"] = pd.to_numeric(df_data["交易量"])
214
- df_data["涨跌幅"] = pd.to_numeric(df_data["涨跌幅"])
215
- df_data.sort_values("日期", inplace=True)
216
- df_data.reset_index(inplace=True, drop=True)
217
- return df_data
218
-
219
-
220
- if __name__ == "__main__":
221
- print(index_investing_global_area_index_name_url("香港"))
222
-
223
- print(index_investing_global_area_index_name_code("香港"))
224
-
225
- index_investing_global_df = index_investing_global(
226
- area="中国",
227
- symbol="富时中国A50指数",
228
- period="每日",
229
- start_date="20100101",
230
- end_date="20220808",
231
- )
232
- print(index_investing_global_df)