akshare 1.14.96__py3-none-any.whl → 1.14.98__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
@@ -2907,9 +2907,11 @@ amac_manager_cancelled_info # 中国证券投资基金业协会-信息公示-诚
2907
2907
  1.14.94 fix: fix stock_zt_pool_strong_em interface
2908
2908
  1.14.95 fix: fix stock_zt_pool_sub_new_em interface
2909
2909
  1.14.96 fix: fix stock_zt_pool_sub_new_em interface
2910
+ 1.14.97 fix: fix stock_profile_cninfo interface
2911
+ 1.14.98 fix: fix futures_hold_pos_sina interface
2910
2912
  """
2911
2913
 
2912
- __version__ = "1.14.96"
2914
+ __version__ = "1.14.98"
2913
2915
  __author__ = "AKFamily"
2914
2916
 
2915
2917
  import sys
@@ -3457,17 +3459,6 @@ from akshare.stock_feature.stock_hot_xq import (
3457
3459
  stock_hot_tweet_xq,
3458
3460
  )
3459
3461
 
3460
- """
3461
- 南华期货-板块指数涨跌
3462
- 南华期货-品种指数涨跌
3463
- 南华期货-相关系数矩阵
3464
- """
3465
- from akshare.futures_derivative.futures_other_index_nh import (
3466
- futures_correlation_nh,
3467
- futures_board_index_nh,
3468
- futures_variety_index_nh,
3469
- )
3470
-
3471
3462
  """
3472
3463
  东方财富-股票数据-龙虎榜
3473
3464
  """
@@ -4964,20 +4955,6 @@ from akshare.index.index_sw import (
4964
4955
  """
4965
4956
  from akshare.article.epu_index import article_epu_index
4966
4957
 
4967
- """
4968
- 南华期货-南华指数
4969
- """
4970
- from akshare.futures_derivative.futures_index_return_nh import (
4971
- futures_return_index_nh,
4972
- )
4973
- from akshare.futures_derivative.futures_index_price_nh import (
4974
- futures_price_index_nh,
4975
- futures_index_symbol_table_nh,
4976
- )
4977
- from akshare.futures_derivative.futures_index_volatility_nh import (
4978
- futures_volatility_index_nh,
4979
- )
4980
-
4981
4958
  """
4982
4959
  空气-河北
4983
4960
  """
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2024/6/3 15:30
4
+ Date: 2024/10/16 21:30
5
5
  Desc: 新浪财经-期货-成交持仓
6
6
  https://vip.stock.finance.sina.com.cn/q/view/vFutures_Positions_cjcc.php
7
7
  """
@@ -29,7 +29,7 @@ def futures_hold_pos_sina(
29
29
  """
30
30
  date = "-".join([date[:4], date[4:6], date[6:]])
31
31
  url = "https://vip.stock.finance.sina.com.cn/q/view/vFutures_Positions_cjcc.php"
32
- params = {"symbol": contract, "date": date}
32
+ params = {"t_breed": contract, "t_date": date}
33
33
  r = requests.get(url, params=params)
34
34
  if symbol == "成交量":
35
35
  temp_df = pd.read_html(StringIO(r.text))[2].iloc[:-1, :]
@@ -59,16 +59,16 @@ def futures_hold_pos_sina(
59
59
 
60
60
  if __name__ == "__main__":
61
61
  futures_hold_pos_sina_df = futures_hold_pos_sina(
62
- symbol="成交量", contract="PTA2407", date="20240531"
62
+ symbol="成交量", contract="OI2501", date="20241016"
63
63
  )
64
64
  print(futures_hold_pos_sina_df)
65
65
 
66
66
  futures_hold_pos_sina_df = futures_hold_pos_sina(
67
- symbol="多单持仓", contract="IC2403", date="20240223"
67
+ symbol="多单持仓", contract="OI2501", date="20241016"
68
68
  )
69
69
  print(futures_hold_pos_sina_df)
70
70
 
71
71
  futures_hold_pos_sina_df = futures_hold_pos_sina(
72
- symbol="空单持仓", contract="IC2403", date="20240223"
72
+ symbol="空单持仓", contract="OI2501", date="20241016"
73
73
  )
74
74
  print(futures_hold_pos_sina_df)
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2024/6/5 15:00
4
+ Date: 2024/10/14 22:00
5
5
  Desc: 巨潮资讯-个股-公司概况
6
- http://webapi.cninfo.com.cn/#/company
6
+ https://webapi.cninfo.com.cn/#/company
7
7
  """
8
8
 
9
9
  import pandas as pd
10
- import requests
11
10
  import py_mini_racer
11
+ import requests
12
12
 
13
13
  from akshare.datasets import get_ths_js
14
14
 
@@ -30,14 +30,14 @@ def _get_file_content_ths(file: str = "cninfo.js") -> str:
30
30
  def stock_profile_cninfo(symbol: str = "600030") -> pd.DataFrame:
31
31
  """
32
32
  巨潮资讯-个股-公司概况
33
- http://webapi.cninfo.com.cn/#/company
33
+ https://webapi.cninfo.com.cn/#/company
34
34
  :param symbol: 股票代码
35
35
  :type symbol: str
36
36
  :return: 公司概况
37
37
  :rtype: pandas.DataFrame
38
38
  :raise: Exception,如果服务器返回的数据无法被解析
39
39
  """
40
- url = "http://webapi.cninfo.com.cn/api/sysapi/p_sysapi1133"
40
+ url = "https://webapi.cninfo.com.cn/api/sysapi/p_sysapi1133"
41
41
  params = {
42
42
  "scode": symbol,
43
43
  }
@@ -53,10 +53,10 @@ def stock_profile_cninfo(symbol: str = "600030") -> pd.DataFrame:
53
53
  "Content-Length": "0",
54
54
  "Host": "webapi.cninfo.com.cn",
55
55
  "Accept-Enckey": mcode,
56
- "Origin": "http://webapi.cninfo.com.cn",
56
+ "Origin": "https://webapi.cninfo.com.cn",
57
57
  "Pragma": "no-cache",
58
58
  "Proxy-Connection": "keep-alive",
59
- "Referer": "http://webapi.cninfo.com.cn/",
59
+ "Referer": "https://webapi.cninfo.com.cn/",
60
60
  "X-Requested-With": "XMLHttpRequest",
61
61
  }
62
62
  r = requests.post(url, params=params, headers=headers)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: akshare
3
- Version: 1.14.96
3
+ Version: 1.14.98
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=KnCf23BWYZ5SUYeJT1wRUQmiUmVjqBKKQqxupNoJFGs,182744
1
+ akshare/__init__.py,sha256=FTCz4boPcVSLOLKonwe3nTsyLXG1JwApfBriwQSOXq0,182220
2
2
  akshare/datasets.py,sha256=-qdwaQjgBlftX84uM74KJqCYJYkQ50PV416_neA4uls,995
3
3
  akshare/air/__init__.py,sha256=RMTf1bT5EOE3ttWpn3hGu1LtUmsVxDoa0W7W0gXHOy8,81
4
4
  akshare/air/air_hebei.py,sha256=xIXNGLK7IGYqrkteM9fxnHAwWqk6PCQs6D9-ggZ7byY,4442
@@ -137,13 +137,9 @@ akshare/futures_derivative/futures_contract_info_dce.py,sha256=pzSy8w280imjla3x8
137
137
  akshare/futures_derivative/futures_contract_info_gfex.py,sha256=uaAMVFeK9O1-BI7pYu94PHhkEX0FnakkvqjgEc5MVQE,2162
138
138
  akshare/futures_derivative/futures_contract_info_ine.py,sha256=DTG8S5ZaovlXpcQ5ARwduaap4wnKqdqJUdjYJeNpvv8,2295
139
139
  akshare/futures_derivative/futures_contract_info_shfe.py,sha256=2LtmACu_PcVlM9k5bEfMM44Vz5yDHXA7mE9alEZepgA,2462
140
- akshare/futures_derivative/futures_cot_sina.py,sha256=jWvy20Budu0ZtJw9-O2pXWJX80kp6zK5fe8s9KCqEyk,2742
140
+ akshare/futures_derivative/futures_cot_sina.py,sha256=1W8Q2AyYbxSxsAa7vzSwvRny_tAaYU59ozh_XlZE-1Y,2746
141
141
  akshare/futures_derivative/futures_hog.py,sha256=8VVd7w5LCUZWFdkffV7-dqihGcqdJlR1ks1evpcU9O0,11613
142
- akshare/futures_derivative/futures_index_price_nh.py,sha256=TzrGGHvyz93UPdPGMokQb16plE1CMSaJaDq4vHdE-2g,2275
143
- akshare/futures_derivative/futures_index_return_nh.py,sha256=56V3Mic8a-bKlkv4bUm_vTUC1u5qdDzrlZwsbUTCTPM,1734
144
142
  akshare/futures_derivative/futures_index_sina.py,sha256=G1dPeQcsHwMG81J4MqVjkHqFBM363ktzJmNI-EBsi3A,5902
145
- akshare/futures_derivative/futures_index_volatility_nh.py,sha256=IInn3yf2RqBStFcS8dHtqr3YW8myBD71v_04KA5JAy0,1824
146
- akshare/futures_derivative/futures_other_index_nh.py,sha256=b2oUWSuUIEL-lr2tUK6bIVxIhFNXbp7y2IaVXWqkcz0,4414
147
143
  akshare/futures_derivative/futures_spot_sys.py,sha256=Ufqh7S7UAeW_zkASap_DZGqwyW_Vgrf2UOhedYhe-BU,3351
148
144
  akshare/fx/__init__.py,sha256=fvH_pVxTFPnzXvnPvJZDD_vv0IBJusHkJxZ3dJ8ogl8,82
149
145
  akshare/fx/cons.py,sha256=6xxySOGmJ-sd4mygg0dT48oz-vcyOQcqWY4T2h3wjQQ,585
@@ -266,7 +262,7 @@ akshare/stock/stock_intraday_sina.py,sha256=HMuAAO2Teu4NUrOcBvyJdxYgWx-51qJCdtcq
266
262
  akshare/stock/stock_ipo_summary_cninfo.py,sha256=Ma-54GsOOhRWxilLH-Qmm0VVbpJQGf2XWKaJ8NBSgAY,3847
267
263
  akshare/stock/stock_new_cninfo.py,sha256=EOuZowDLQSSHyPAwXcuPXbQkqhbz2nRBZsM7o2ZWILE,5725
268
264
  akshare/stock/stock_news_cx.py,sha256=IuNo67ToW6SNT9aZVTDqQMnlLFw4QV-_FWSw-9vgfB4,1055
269
- akshare/stock/stock_profile_cninfo.py,sha256=tiEPnoH7IGp9DV1kMQNGIXuVOWpQFl_BS_RX_ijM4BI,3163
265
+ akshare/stock/stock_profile_cninfo.py,sha256=UgUH3GK52Xl25s3WIXlFmVTlKzDd6QGiTTjj0l-GKsk,3170
270
266
  akshare/stock/stock_rank_forecast.py,sha256=5U0fa4tzhqKrw5kDRahUCFSrbrEx_aRtlqZq2mpeJaU,3199
271
267
  akshare/stock/stock_repurchase_em.py,sha256=XVAUD_yd48wqxbMbfU0Ne2SNFOSG9NBklUhf3pl6cKc,5000
272
268
  akshare/stock/stock_share_changes_cninfo.py,sha256=zg-1KHPbxdMRMr4wYY8LA30D-u47YesbEDt_MgCMk_k,4846
@@ -382,8 +378,8 @@ akshare/utils/token_process.py,sha256=K4rGXjh_tgugbRcyOK2h2x0jP3PT65IIK7nxhUKhOe
382
378
  akshare/utils/tqdm.py,sha256=MuPNwcswkOGjwWQOMWXi9ZvQ_RmW4obCWRj2i7HM7FE,847
383
379
  tests/__init__.py,sha256=gNzhlO0UPjFq6Ieb38kaVIODXv4cTDByrdohAZnDYt4,82
384
380
  tests/test_func.py,sha256=j1MGYbZI2if2j_LY1S4FLsf4qfq4NwVqD5wmRlv5Log,832
385
- akshare-1.14.96.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
386
- akshare-1.14.96.dist-info/METADATA,sha256=ppYCML2cAOHC3S1KfDJknL9VEJ1HxxAwDrAQ9KNvTS8,14163
387
- akshare-1.14.96.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
388
- akshare-1.14.96.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
389
- akshare-1.14.96.dist-info/RECORD,,
381
+ akshare-1.14.98.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
382
+ akshare-1.14.98.dist-info/METADATA,sha256=VPbmVwalElmBQxFc1wGbdfmEP3RxxNdR53dkv9Xznx0,14163
383
+ akshare-1.14.98.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
384
+ akshare-1.14.98.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
385
+ akshare-1.14.98.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.1.0)
2
+ Generator: setuptools (75.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,61 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding:utf-8 -*-
3
- """
4
- Date: 2023/11/17 18:20
5
- Desc: 南华期货-商品指数历史走势-价格指数-数值
6
- https://www.nanhua.net/nhzc/varietytrend.html
7
- 1000 点开始, 用收益率累计
8
- https://www.nanhua.net/ianalysis/varietyindex/price/A.json?t=1574932974280
9
- """
10
- import time
11
-
12
- import pandas as pd
13
- import requests
14
-
15
-
16
- def futures_index_symbol_table_nh() -> pd.DataFrame:
17
- """
18
- 南华期货-南华指数所有品种一览表
19
- https://www.nanhua.net/ianalysis/varietyindex/price/A.json?t=1574932974280
20
- :return: 南华指数所有品种一览表
21
- :rtype: pandas.DataFrame
22
- """
23
- url = "https://www.nanhua.net/ianalysis/plate-variety.json"
24
- r = requests.get(url)
25
- data_json = r.json()
26
- temp_df = pd.DataFrame(data_json)
27
- temp_df["firstday"] = pd.to_datetime(temp_df["firstday"], errors="coerce").dt.date
28
- return temp_df
29
-
30
-
31
- def futures_price_index_nh(symbol: str = "A") -> pd.DataFrame:
32
- """
33
- 南华期货-南华指数单品种-价格-所有历史数据
34
- https://www.nanhua.net/ianalysis/varietyindex/price/A.json?t=1574932974280
35
- :param symbol: 通过 ak.futures_index_symbol_table_nh() 获取
36
- :type symbol: str
37
- :return: 南华期货-南华指数单品种-价格-所有历史数据
38
- :rtype: pandas.Series
39
- """
40
- symbol_df = futures_index_symbol_table_nh()
41
- symbol_list = symbol_df["code"].tolist()
42
- if symbol in symbol_list:
43
- t = time.time()
44
- url = f"https://www.nanhua.net/ianalysis/varietyindex/price/{symbol}.json?t={int(round(t * 1000))}"
45
- r = requests.get(url)
46
- data_json = r.json()
47
- temp_df = pd.DataFrame(data_json)
48
- temp_df.columns = ["date", "value"]
49
- temp_df["date"] = pd.to_datetime(temp_df["date"], unit="ms", errors="coerce")
50
- temp_df["date"] = temp_df["date"].dt.tz_localize("UTC")
51
- temp_df["date"] = temp_df["date"].dt.tz_convert("Asia/Shanghai").dt.date
52
- temp_df["value"] = pd.to_numeric(temp_df["value"], errors="coerce")
53
- return temp_df
54
-
55
-
56
- if __name__ == "__main__":
57
- futures_index_symbol_table_nh_df = futures_index_symbol_table_nh()
58
- print(futures_index_symbol_table_nh_df)
59
-
60
- futures_price_index_nh_df = futures_price_index_nh(symbol="A")
61
- print(futures_price_index_nh_df)
@@ -1,47 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding:utf-8 -*-
3
- """
4
- Date: 2023/11/17 18:20
5
- Desc: 南华期货-商品指数历史走势-收益率指数-数值
6
- https://www.nanhua.net/nhzc/varietytrend.html
7
- 1000 点开始, 用收益率累计
8
- https://www.nanhua.net/ianalysis/varietyindex/index/NHCI.json?t=1574932290494
9
- """
10
- import time
11
-
12
- import pandas as pd
13
- import requests
14
-
15
- from akshare.futures_derivative.futures_index_price_nh import (
16
- futures_index_symbol_table_nh,
17
- )
18
-
19
-
20
- def futures_return_index_nh(symbol: str = "Y") -> pd.DataFrame:
21
- """
22
- 南华期货-南华指数单品种-收益率-所有历史数据
23
- https://www.nanhua.net/ianalysis/varietyindex/index/NHCI.json?t=1574932290494
24
- :param symbol: 通过 ak.futures_index_symbol_table_nh() 获取
25
- :type symbol: str
26
- :return: 南华指数单品种-收益率-所有历史数据
27
- :rtype: pandas.Series
28
- """
29
- symbol_df = futures_index_symbol_table_nh()
30
- symbol_list = symbol_df["code"].tolist()
31
- if symbol in symbol_list:
32
- t = time.time()
33
- url = f"https://www.nanhua.net/ianalysis/varietyindex/index/{symbol}.json?t={int(round(t * 1000))}"
34
- r = requests.get(url)
35
- data_json = r.json()
36
- temp_df = pd.DataFrame(data_json)
37
- temp_df.columns = ["date", "value"]
38
- temp_df["date"] = pd.to_datetime(temp_df["date"], unit="ms", errors="coerce")
39
- temp_df["date"] = temp_df["date"].dt.tz_localize("UTC")
40
- temp_df["date"] = temp_df["date"].dt.tz_convert("Asia/Shanghai").dt.date
41
- temp_df["value"] = pd.to_numeric(temp_df["value"], errors="coerce")
42
- return temp_df
43
-
44
-
45
- if __name__ == "__main__":
46
- futures_return_index_nh_df = futures_return_index_nh(symbol="NHCI")
47
- print(futures_return_index_nh_df)
@@ -1,53 +0,0 @@
1
- #!/usr/bin/env python
2
- # -*- coding:utf-8 -*-
3
- """
4
- Date: 2024/5/19 15:30
5
- Desc: 南华期货-商品指数历史走势-收益率指数-波动率
6
- https://www.nanhua.net/nhzc/varietytrend.html
7
- 1000 点开始, 用收益率累计
8
- 目标地址: https://www.nanhua.net/ianalysis/volatility/20/NHCI.json?t=1574932291399
9
- """
10
-
11
- import time
12
-
13
- import pandas as pd
14
- import requests
15
-
16
- from akshare.futures_derivative.futures_index_price_nh import (
17
- futures_index_symbol_table_nh,
18
- )
19
-
20
-
21
- def futures_volatility_index_nh(
22
- symbol: str = "NHCI", period: str = "20"
23
- ) -> pd.DataFrame:
24
- """
25
- 南华期货-南华指数单品种-波动率-所有历史数据
26
- https://www.nanhua.net/nhzc/varietytrend.html
27
- :param symbol: 通过 ak.futures_index_symbol_table_nh() 获取
28
- :type symbol: str
29
- :param period: 波动周期 choice of {'5', '20', '60', '120'}
30
- :type period: str
31
- :return: 波动率-所有历史数据
32
- :rtype: pandas.DataFrame
33
- """
34
- symbol_df = futures_index_symbol_table_nh()
35
- if symbol in symbol_df["code"].tolist():
36
- t = time.time()
37
- url = f"https://www.nanhua.net/ianalysis/volatility/{period}/{symbol}.json?t={int(round(t * 1000))}"
38
- r = requests.get(url)
39
- data_json = r.json()
40
- temp_df = pd.DataFrame(data_json)
41
- temp_df.columns = ["date", "value"]
42
- temp_df["date"] = pd.to_datetime(temp_df["date"], unit="ms", errors="coerce")
43
- temp_df["date"] = temp_df["date"].dt.tz_localize("UTC")
44
- temp_df["date"] = temp_df["date"].dt.tz_convert("Asia/Shanghai").dt.date
45
- temp_df["value"] = pd.to_numeric(temp_df["value"], errors="coerce")
46
- return temp_df
47
-
48
-
49
- if __name__ == "__main__":
50
- futures_volatility_index_nh_df = futures_volatility_index_nh(
51
- symbol="SA", period="5"
52
- )
53
- print(futures_volatility_index_nh_df)
@@ -1,144 +0,0 @@
1
- # -*- coding:utf-8 -*-
2
- # !/usr/bin/env python
3
- """
4
- Date: 2023/12/2 19:00
5
- Desc: 板块指数、品种指数和相关系数矩阵
6
- 南华期货-板块指数涨跌
7
- https://www.nanhua.net/nhzc/platechange.html
8
- 南华期货-品种指数涨跌
9
- https://www.nanhua.net/nhzc/varietychange.html
10
- 南华期货-相关系数矩阵
11
- https://www.nanhua.net/nhzc/correltable.html
12
- """
13
-
14
- import pandas as pd
15
- import requests
16
-
17
-
18
- def futures_board_index_nh(
19
- start_date: str = "20231110", end_date: str = "20231116"
20
- ) -> pd.DataFrame:
21
- """
22
- 南华期货-市场涨跌-板块指数涨跌
23
- https://www.nanhua.net/nhzc/platechange.html
24
- :param start_date: 开始时间
25
- :type start_date: str
26
- :param end_date: 结束时间
27
- :type end_date: str
28
- :return: 板块指数涨跌
29
- :rtype: pandas.DataFrame
30
- """
31
- # 获取 start_date 的数据
32
- url = f"https://www.nanhua.net/ianalysis/plate/{start_date[:4]}/{start_date[4:6]}/{start_date}.json"
33
- params = {"t": "1649920913503"}
34
- r = requests.get(url, params=params)
35
- start_df = pd.DataFrame(r.json())
36
- start_df.columns = [
37
- "name",
38
- "code",
39
- start_date,
40
- ]
41
-
42
- # 获取 end_date 的数据
43
- url = f"https://www.nanhua.net/ianalysis/plate/{end_date[:4]}/{end_date[4:6]}/{end_date}.json"
44
- params = {"t": "1649920913503"}
45
- r = requests.get(url, params=params)
46
- end_df = pd.DataFrame(r.json())
47
- end_df.columns = [
48
- "name",
49
- "code",
50
- end_date,
51
- ]
52
- end_df.reset_index(inplace=True, drop=True)
53
-
54
- # 计算数据
55
- start_df = start_df.merge(end_df, on=["name", "code"], how="inner")
56
- # 去除异常数据 IF
57
- start_df = start_df[start_df["code"] != "IF"]
58
- start_df["return"] = start_df[end_date] / start_df[start_date] - 1
59
- temp_df = start_df[["name", "return"]]
60
-
61
- return temp_df
62
-
63
-
64
- def futures_variety_index_nh(
65
- start_date: str = "20231110", end_date: str = "20231116"
66
- ) -> pd.DataFrame:
67
- """
68
- 南华期货-市场涨跌-品种指数涨跌
69
- https://www.nanhua.net/nhzc/varietychange.html
70
- :param start_date: 开始时间
71
- :type start_date: str
72
- :param end_date: 结束时间
73
- :type end_date: str
74
- :return: 品种指数涨跌
75
- :rtype: pandas.DataFrame
76
- """
77
- url = f"https://www.nanhua.net/ianalysis/variety/{start_date[:4]}/{start_date[4:6]}/{start_date}.json"
78
- params = {"t": "1649920913503"}
79
- r = requests.get(url, params=params)
80
- start_df = pd.DataFrame(r.json())
81
- start_df.columns = [
82
- "name",
83
- "code",
84
- start_date,
85
- ]
86
-
87
- url = f"http://www.nanhua.net/ianalysis/variety/{end_date[:4]}/{end_date[4:6]}/{end_date}.json"
88
- params = {"t": "1649920913503"}
89
- r = requests.get(url, params=params)
90
- end_df = pd.DataFrame(r.json())
91
- end_df.columns = [
92
- "name",
93
- "code",
94
- "end_date",
95
- ]
96
- start_df[end_date] = end_df["end_date"]
97
-
98
- start_df["gap"] = start_df[end_date] - start_df[start_date]
99
- start_df["return"] = start_df["gap"] / start_df[start_date]
100
-
101
- temp_df = start_df
102
- temp_df = temp_df[["name", "return"]]
103
- return temp_df
104
-
105
-
106
- def futures_correlation_nh(date: str = "20231110", period: str = "20") -> pd.DataFrame:
107
- """
108
- 南华期货-统计监控-相关系数矩阵
109
- https://www.nanhua.net/nhzc/correltable.html
110
- :param date: 开始时间
111
- :type date: str
112
- :param period: 周期; choice of {"5", "20", "60", "120"}
113
- :type period: str
114
- :return: 相关系数矩阵
115
- :rtype: pandas.DataFrame
116
- """
117
- url = f"https://www.nanhua.net/ianalysis/correl/{period}/{date[:4]}/{date[4:6]}/{date}.json"
118
- params = {"t": "1649920913503"}
119
- r = requests.get(url, params=params)
120
- temp_df = pd.DataFrame(r.json())
121
- temp_df.columns = [
122
- "品种代码1",
123
- "品种名称1",
124
- "品种代码2",
125
- "品种名称2",
126
- "相关系数",
127
- ]
128
- temp_df["相关系数"] = pd.to_numeric(temp_df["相关系数"], errors="coerce")
129
- return temp_df
130
-
131
-
132
- if __name__ == "__main__":
133
- futures_board_index_nh_df = futures_board_index_nh(
134
- start_date="20230103", end_date="20231201"
135
- )
136
- print(futures_board_index_nh_df)
137
-
138
- futures_variety_index_nh_df = futures_variety_index_nh(
139
- start_date="20231110", end_date="20231116"
140
- )
141
- print(futures_variety_index_nh_df)
142
-
143
- futures_correlation_nh_df = futures_correlation_nh(date="20240816", period="20")
144
- print(futures_correlation_nh_df)