akshare 1.15.32__py3-none-any.whl → 1.15.34__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 +8 -9
- akshare/fund/fund_rank_em.py +1 -1
- akshare/stock_feature/stock_value_em.py +83 -0
- {akshare-1.15.32.dist-info → akshare-1.15.34.dist-info}/METADATA +1 -1
- {akshare-1.15.32.dist-info → akshare-1.15.34.dist-info}/RECORD +8 -8
- akshare/crypto/crypto_hist_investing.py +0 -249
- {akshare-1.15.32.dist-info → akshare-1.15.34.dist-info}/LICENSE +0 -0
- {akshare-1.15.32.dist-info → akshare-1.15.34.dist-info}/WHEEL +0 -0
- {akshare-1.15.32.dist-info → akshare-1.15.34.dist-info}/top_level.txt +0 -0
akshare/__init__.py
CHANGED
|
@@ -2942,9 +2942,11 @@ amac_manager_cancelled_info # 中国证券投资基金业协会-信息公示-诚
|
|
|
2942
2942
|
1.15.30 fix: fix fund_etf_category_sina interface
|
|
2943
2943
|
1.15.31 fix: fix stock_zt_pool_strong_em interface
|
|
2944
2944
|
1.15.32 fix: fix stock_info_global_cls interface
|
|
2945
|
+
1.15.33 add: add stock_value_em interface
|
|
2946
|
+
1.15.34 fix: fix fund_open_fund_rank_em interface
|
|
2945
2947
|
"""
|
|
2946
2948
|
|
|
2947
|
-
__version__ = "1.15.
|
|
2949
|
+
__version__ = "1.15.34"
|
|
2948
2950
|
__author__ = "AKFamily"
|
|
2949
2951
|
|
|
2950
2952
|
import sys
|
|
@@ -2966,6 +2968,11 @@ if sys.version_info < (3, 9):
|
|
|
2966
2968
|
|
|
2967
2969
|
del sys
|
|
2968
2970
|
|
|
2971
|
+
"""
|
|
2972
|
+
东方财富网-数据中心-估值分析-每日互动-每日互动-估值分析
|
|
2973
|
+
"""
|
|
2974
|
+
from akshare.stock_feature.stock_value_em import stock_value_em
|
|
2975
|
+
|
|
2969
2976
|
"""
|
|
2970
2977
|
已实现波动率
|
|
2971
2978
|
"""
|
|
@@ -4339,14 +4346,6 @@ from akshare.fund.fund_rank_em import (
|
|
|
4339
4346
|
fund_lcx_rank_em,
|
|
4340
4347
|
)
|
|
4341
4348
|
|
|
4342
|
-
"""
|
|
4343
|
-
英为财情-加密货币
|
|
4344
|
-
"""
|
|
4345
|
-
from akshare.crypto.crypto_hist_investing import (
|
|
4346
|
-
crypto_hist,
|
|
4347
|
-
crypto_name_url_table,
|
|
4348
|
-
)
|
|
4349
|
-
|
|
4350
4349
|
"""
|
|
4351
4350
|
电影票房
|
|
4352
4351
|
"""
|
akshare/fund/fund_rank_em.py
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding:utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Date: 2024/11/26 18:00
|
|
5
|
+
Desc: 东方财富网-数据中心-估值分析-每日互动-每日互动-估值分析
|
|
6
|
+
https://data.eastmoney.com/gzfx/detail/300766.html
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import pandas as pd
|
|
10
|
+
|
|
11
|
+
from akshare.request import make_request_with_retry_json
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def stock_value_em(symbol: str = "300766") -> pd.DataFrame:
|
|
15
|
+
"""
|
|
16
|
+
东方财富网-数据中心-估值分析-每日互动-每日互动-估值分析
|
|
17
|
+
https://data.eastmoney.com/gzfx/detail/300766.html
|
|
18
|
+
:param symbol: 股票代码
|
|
19
|
+
:type symbol: str
|
|
20
|
+
:return: 估值分析
|
|
21
|
+
:rtype: pandas.DataFrame
|
|
22
|
+
"""
|
|
23
|
+
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
|
|
24
|
+
params = {
|
|
25
|
+
"sortColumns": "TRADE_DATE",
|
|
26
|
+
"sortTypes": "-1",
|
|
27
|
+
"pageSize": "5000",
|
|
28
|
+
"pageNumber": "1",
|
|
29
|
+
"reportName": "RPT_VALUEANALYSIS_DET",
|
|
30
|
+
"columns": "ALL",
|
|
31
|
+
"quoteColumns": "",
|
|
32
|
+
"source": "WEB",
|
|
33
|
+
"client": "WEB",
|
|
34
|
+
"filter": f'(SECURITY_CODE="{symbol}")',
|
|
35
|
+
}
|
|
36
|
+
data_json = make_request_with_retry_json(url, params=params)
|
|
37
|
+
temp_json = data_json["result"]["data"]
|
|
38
|
+
temp_df = pd.DataFrame(temp_json)
|
|
39
|
+
temp_df.rename(
|
|
40
|
+
columns={
|
|
41
|
+
"TRADE_DATE": "数据日期",
|
|
42
|
+
"CLOSE_PRICE": "当日收盘价",
|
|
43
|
+
"CHANGE_RATE": "当日涨跌幅",
|
|
44
|
+
"TOTAL_MARKET_CAP": "总市值",
|
|
45
|
+
"NOTLIMITED_MARKETCAP_A": "流通市值",
|
|
46
|
+
"TOTAL_SHARES": "总股本",
|
|
47
|
+
"FREE_SHARES_A": "流通股本",
|
|
48
|
+
"PE_TTM": "PE(TTM)",
|
|
49
|
+
"PE_LAR": "PE(静)",
|
|
50
|
+
"PB_MRQ": "市净率",
|
|
51
|
+
"PEG_CAR": "PEG值",
|
|
52
|
+
"PCF_OCF_TTM": "市现率",
|
|
53
|
+
"PS_TTM": "市销率",
|
|
54
|
+
},
|
|
55
|
+
inplace=True,
|
|
56
|
+
)
|
|
57
|
+
temp_df = temp_df[
|
|
58
|
+
[
|
|
59
|
+
"数据日期",
|
|
60
|
+
"当日收盘价",
|
|
61
|
+
"当日涨跌幅",
|
|
62
|
+
"总市值",
|
|
63
|
+
"流通市值",
|
|
64
|
+
"总股本",
|
|
65
|
+
"流通股本",
|
|
66
|
+
"PE(TTM)",
|
|
67
|
+
"PE(静)",
|
|
68
|
+
"市净率",
|
|
69
|
+
"PEG值",
|
|
70
|
+
"市现率",
|
|
71
|
+
"市销率",
|
|
72
|
+
]
|
|
73
|
+
]
|
|
74
|
+
temp_df["数据日期"] = pd.to_datetime(temp_df["数据日期"], errors="coerce").dt.date
|
|
75
|
+
for item in temp_df.columns[1:]:
|
|
76
|
+
temp_df[item] = pd.to_numeric(temp_df[item], errors="coerce")
|
|
77
|
+
temp_df.sort_values(by="数据日期", ignore_index=True, inplace=True)
|
|
78
|
+
return temp_df
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
if __name__ == "__main__":
|
|
82
|
+
stock_value_em_df = stock_value_em(symbol="300766")
|
|
83
|
+
print(stock_value_em_df)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
akshare/__init__.py,sha256=
|
|
1
|
+
akshare/__init__.py,sha256=TIvsy-58dhzMEmUrg3Fiip7I8pzQehul6K5Ruq6Ho9M,184396
|
|
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
|
|
@@ -40,7 +40,6 @@ akshare/cost/__init__.py,sha256=x1R9hH6E0M7C86XhHFzbPiipUWz9IknuhVZrk4gZus4,82
|
|
|
40
40
|
akshare/cost/cost_living.py,sha256=_yoGEW4jBfpjhgMxCXvMtBbrCx2PEuOngV3laEoEOvk,2078
|
|
41
41
|
akshare/crypto/__init__.py,sha256=lbmNMPPLGkW9AgGL4ZnCwoQvPjOFPDNUz6P3arSkNI0,83
|
|
42
42
|
akshare/crypto/crypto_bitcoin_cme.py,sha256=IO4dxPj-kwtJXo9F_h5tH64__yeDQXs2cavCkgxxp1I,2436
|
|
43
|
-
akshare/crypto/crypto_hist_investing.py,sha256=tIeEkFur-u-E2_-R4I_Zy0s_VFnR03CCl4GpgJkLYJw,9748
|
|
44
43
|
akshare/crypto/crypto_hold.py,sha256=029V9l8FI4Ewyq2Zg9HTLYX33BdF9nz4EUxtltKtKV8,2405
|
|
45
44
|
akshare/currency/__init__.py,sha256=d8yOOiPqY7_A0AuIpCI71-qxxwyUyCaax5jhE54CeMo,80
|
|
46
45
|
akshare/currency/currency.py,sha256=NwtfLAWVRoMb8BQ-E92XobydGTOcV_D5zKAZmf3rT6Q,6397
|
|
@@ -97,7 +96,7 @@ akshare/fund/fund_lof_em.py,sha256=eWpIlHzUYbscyxvz8awiDERxd7gTucHcGcrBPTCCFno,1
|
|
|
97
96
|
akshare/fund/fund_manager.py,sha256=yhpXp_WKradzSc0dMfGKJibNCksts2L2Bg_gvUU4_VQ,2801
|
|
98
97
|
akshare/fund/fund_portfolio_em.py,sha256=8kk7a8hA22ANfnlnK1j4f5qXepfkgJOiEMpuazP2Xlk,10785
|
|
99
98
|
akshare/fund/fund_position_lg.py,sha256=dxwGvfc8SXlRziWBWHIcaqOOltsKlxHgHL0Cxr7cCeM,3857
|
|
100
|
-
akshare/fund/fund_rank_em.py,sha256=
|
|
99
|
+
akshare/fund/fund_rank_em.py,sha256=e39e11YoctRRYX46mzoOCZQGSA6ZtImoEsuY3ElNjG4,17874
|
|
101
100
|
akshare/fund/fund_rating.py,sha256=oBZTOBaiC9RMfTK2XGKIMY58sPxc7M6GlMJ3_M3i0lQ,11680
|
|
102
101
|
akshare/fund/fund_report_cninfo.py,sha256=rhztaa3J48VdnCEXFAl8wMg-P7MI2iQa0HculkvL8CI,8785
|
|
103
102
|
akshare/fund/fund_scale_em.py,sha256=8XLZpz9DzsAnJCo1moBmzf3u7mfZNZHsb3cPKJ-gCJM,4237
|
|
@@ -343,6 +342,7 @@ akshare/stock_feature/stock_technology_ths.py,sha256=4u9z7H6MYEutOYAQvYfzgc_FxG6
|
|
|
343
342
|
akshare/stock_feature/stock_tfp_em.py,sha256=nN4gcK6hOe4tIA-nOoY_lMNC7qY7o9Ga35_-VvxS3fA,2474
|
|
344
343
|
akshare/stock_feature/stock_three_report_em.py,sha256=riIE9YwMKn279GAAdBFATTfK4_ui4X30Ew1LNcIwwsk,23675
|
|
345
344
|
akshare/stock_feature/stock_ttm_lyr.py,sha256=RwKMgI_A3rDRIITd_idmvlFSkn4DTUPNVfPjISSTZYw,1110
|
|
345
|
+
akshare/stock_feature/stock_value_em.py,sha256=RA842dkeChSEoS3yN9fiGxS3eDzYjeUdrpXbnteyzZY,2576
|
|
346
346
|
akshare/stock_feature/stock_wencai.py,sha256=KPwt72SOnK4dHh2vpWOHYynkj8Vrbv3AW-EXK7d3NZY,4343
|
|
347
347
|
akshare/stock_feature/stock_yjbb_em.py,sha256=J-JFnRy4M1DlM46J2ccJTdnkUrI3M2lTYj4CpzqgADo,4275
|
|
348
348
|
akshare/stock_feature/stock_yjyg_cninfo.py,sha256=DveTsc-DhLzRDBJZQ7yv8KogzG-vo3Pmr2oRgCzaH1E,2870
|
|
@@ -383,8 +383,8 @@ akshare/utils/token_process.py,sha256=K4rGXjh_tgugbRcyOK2h2x0jP3PT65IIK7nxhUKhOe
|
|
|
383
383
|
akshare/utils/tqdm.py,sha256=MuPNwcswkOGjwWQOMWXi9ZvQ_RmW4obCWRj2i7HM7FE,847
|
|
384
384
|
tests/__init__.py,sha256=gNzhlO0UPjFq6Ieb38kaVIODXv4cTDByrdohAZnDYt4,82
|
|
385
385
|
tests/test_func.py,sha256=j1MGYbZI2if2j_LY1S4FLsf4qfq4NwVqD5wmRlv5Log,832
|
|
386
|
-
akshare-1.15.
|
|
387
|
-
akshare-1.15.
|
|
388
|
-
akshare-1.15.
|
|
389
|
-
akshare-1.15.
|
|
390
|
-
akshare-1.15.
|
|
386
|
+
akshare-1.15.34.dist-info/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
|
|
387
|
+
akshare-1.15.34.dist-info/METADATA,sha256=l0ykGsvmO36Z0SFp4KJzemkml4Vk40I0A7fYrYTwXbc,13423
|
|
388
|
+
akshare-1.15.34.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
389
|
+
akshare-1.15.34.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
|
|
390
|
+
akshare-1.15.34.dist-info/RECORD,,
|
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding:utf-8 -*-
|
|
3
|
-
"""
|
|
4
|
-
Date: 2022/5/11 17:52
|
|
5
|
-
Desc: 加密货币
|
|
6
|
-
https://cn.investing.com/crypto/currencies
|
|
7
|
-
高频数据
|
|
8
|
-
https://bitcoincharts.com/about/markets-api/
|
|
9
|
-
"""
|
|
10
|
-
import math
|
|
11
|
-
|
|
12
|
-
import pandas as pd
|
|
13
|
-
import requests
|
|
14
|
-
from tqdm import tqdm
|
|
15
|
-
|
|
16
|
-
from akshare.datasets import get_crypto_info_csv
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def crypto_name_url_table(symbol: str = "web") -> pd.DataFrame:
|
|
20
|
-
"""
|
|
21
|
-
加密货币名称、代码和 ID,每次更新较慢
|
|
22
|
-
https://cn.investing.com/crypto/ethereum/historical-data
|
|
23
|
-
:param symbol: choice of {"web", "local"}; web 表示从网页获取最新,local 表示利用本地本文件
|
|
24
|
-
:type symbol: str
|
|
25
|
-
:return: 加密货币名称、代码和 ID
|
|
26
|
-
:rtype: pandas.DataFrame
|
|
27
|
-
"""
|
|
28
|
-
if symbol == "web":
|
|
29
|
-
headers = {
|
|
30
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",
|
|
31
|
-
"X-Requested-With": "XMLHttpRequest",
|
|
32
|
-
}
|
|
33
|
-
url = "https://cn.investing.com/crypto/Service/LoadCryptoCurrencies"
|
|
34
|
-
payload = {
|
|
35
|
-
'draw': '14',
|
|
36
|
-
'columns[0][data]': 'currencies_order',
|
|
37
|
-
'columns[0][name]': 'currencies_order',
|
|
38
|
-
'columns[0][searchable]': 'true',
|
|
39
|
-
'columns[0][orderable]': 'true',
|
|
40
|
-
'columns[0][search][value]': '',
|
|
41
|
-
'columns[0][search][regex]': 'false',
|
|
42
|
-
'columns[1][data]': 'function',
|
|
43
|
-
'columns[1][name]': 'crypto_id',
|
|
44
|
-
'columns[1][searchable]': 'true',
|
|
45
|
-
'columns[1][orderable]': 'false',
|
|
46
|
-
'columns[1][search][value]': '',
|
|
47
|
-
'columns[1][search][regex]': 'false',
|
|
48
|
-
'columns[2][data]': 'function',
|
|
49
|
-
'columns[2][name]': 'name',
|
|
50
|
-
'columns[2][searchable]': 'true',
|
|
51
|
-
'columns[2][orderable]': 'true',
|
|
52
|
-
'columns[2][search][value]': '',
|
|
53
|
-
'columns[2][search][regex]': 'false',
|
|
54
|
-
'columns[3][data]': 'symbol',
|
|
55
|
-
'columns[3][name]': 'symbol',
|
|
56
|
-
'columns[3][searchable]': 'true',
|
|
57
|
-
'columns[3][orderable]': 'true',
|
|
58
|
-
'columns[3][search][value]': '',
|
|
59
|
-
'columns[3][search][regex]': 'false',
|
|
60
|
-
'columns[4][data]': 'function',
|
|
61
|
-
'columns[4][name]': 'price_usd',
|
|
62
|
-
'columns[4][searchable]': 'true',
|
|
63
|
-
'columns[4][orderable]': 'true',
|
|
64
|
-
'columns[4][search][value]': '',
|
|
65
|
-
'columns[4][search][regex]': 'false',
|
|
66
|
-
'columns[5][data]': 'market_cap_formatted',
|
|
67
|
-
'columns[5][name]': 'market_cap_usd',
|
|
68
|
-
'columns[5][searchable]': 'true',
|
|
69
|
-
'columns[5][orderable]': 'true',
|
|
70
|
-
'columns[5][search][value]': '',
|
|
71
|
-
'columns[5][search][regex]': 'false',
|
|
72
|
-
'columns[6][data]': '24h_volume_formatted',
|
|
73
|
-
'columns[6][name]': '24h_volume_usd',
|
|
74
|
-
'columns[6][searchable]': 'true',
|
|
75
|
-
'columns[6][orderable]': 'true',
|
|
76
|
-
'columns[6][search][value]': '',
|
|
77
|
-
'columns[6][search][regex]': 'false',
|
|
78
|
-
'columns[7][data]': 'total_volume',
|
|
79
|
-
'columns[7][name]': 'total_volume',
|
|
80
|
-
'columns[7][searchable]': 'true',
|
|
81
|
-
'columns[7][orderable]': 'true',
|
|
82
|
-
'columns[7][search][value]': '',
|
|
83
|
-
'columns[7][search][regex]': 'false',
|
|
84
|
-
'columns[8][data]': 'change_percent_formatted',
|
|
85
|
-
'columns[8][name]': 'change_percent',
|
|
86
|
-
'columns[8][searchable]': 'true',
|
|
87
|
-
'columns[8][orderable]': 'true',
|
|
88
|
-
'columns[8][search][value]': '',
|
|
89
|
-
'columns[8][search][regex]': 'false',
|
|
90
|
-
'columns[9][data]': 'percent_change_7d_formatted',
|
|
91
|
-
'columns[9][name]': 'percent_change_7d',
|
|
92
|
-
'columns[9][searchable]': 'true',
|
|
93
|
-
'columns[9][orderable]': 'true',
|
|
94
|
-
'columns[9][search][value]': '',
|
|
95
|
-
'columns[9][search][regex]': 'false',
|
|
96
|
-
'order[0][column]': 'currencies_order',
|
|
97
|
-
'order[0][dir]': 'asc',
|
|
98
|
-
'start': '0',
|
|
99
|
-
'length': '100',
|
|
100
|
-
'search[value]': '',
|
|
101
|
-
'search[regex]': 'false',
|
|
102
|
-
'currencyId': '12',
|
|
103
|
-
}
|
|
104
|
-
r = requests.post(url, data=payload, headers=headers)
|
|
105
|
-
data_json = r.json()
|
|
106
|
-
total_page = math.ceil(int(data_json['recordsTotal']) / 100)
|
|
107
|
-
big_df = pd.DataFrame()
|
|
108
|
-
for page in tqdm(range(1, total_page+1), leave=False):
|
|
109
|
-
payload.update({
|
|
110
|
-
"start": (page-1)*100,
|
|
111
|
-
'length': 100
|
|
112
|
-
})
|
|
113
|
-
r = requests.post(url, data=payload, headers=headers)
|
|
114
|
-
data_json = r.json()
|
|
115
|
-
temp_df = pd.DataFrame(data_json['data'])
|
|
116
|
-
big_df = pd.concat([big_df, temp_df], ignore_index=True)
|
|
117
|
-
big_df = big_df[[
|
|
118
|
-
'symbol',
|
|
119
|
-
'name',
|
|
120
|
-
'name_trans',
|
|
121
|
-
'sml_id',
|
|
122
|
-
'related_pair_ID',
|
|
123
|
-
]]
|
|
124
|
-
return big_df
|
|
125
|
-
else:
|
|
126
|
-
get_crypto_info_csv_path = get_crypto_info_csv()
|
|
127
|
-
name_url_df = pd.read_csv(get_crypto_info_csv_path)
|
|
128
|
-
return name_url_df
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
def crypto_hist(
|
|
132
|
-
symbol: str = "BTC",
|
|
133
|
-
period: str = "每日",
|
|
134
|
-
start_date: str = "20191020",
|
|
135
|
-
end_date: str = "20201020",
|
|
136
|
-
):
|
|
137
|
-
"""
|
|
138
|
-
加密货币历史数据
|
|
139
|
-
https://cn.investing.com/crypto/ethereum/historical-data
|
|
140
|
-
:param symbol: 货币名称
|
|
141
|
-
:type symbol: str
|
|
142
|
-
:param period: choice of {"每日", "每周", "每月"}
|
|
143
|
-
:type period: str
|
|
144
|
-
:param start_date: '20151020', 注意格式
|
|
145
|
-
:type start_date: str
|
|
146
|
-
:param end_date: '20201020', 注意格式
|
|
147
|
-
:type end_date: str
|
|
148
|
-
:return: 加密货币历史数据获取
|
|
149
|
-
:rtype: pandas.DataFrame
|
|
150
|
-
"""
|
|
151
|
-
import warnings
|
|
152
|
-
warnings.filterwarnings('ignore')
|
|
153
|
-
headers = {
|
|
154
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",
|
|
155
|
-
"X-Requested-With": "XMLHttpRequest",
|
|
156
|
-
}
|
|
157
|
-
period_map = {"每日": "Daily", "每周": "Weekly", "每月": "Monthly"}
|
|
158
|
-
start_date = "/".join([start_date[:4], start_date[4:6], start_date[6:]])
|
|
159
|
-
end_date = "/".join([end_date[:4], end_date[4:6], end_date[6:]])
|
|
160
|
-
name_url_df = crypto_name_url_table(symbol='local')
|
|
161
|
-
curr_id = name_url_df[name_url_df["symbol"] == symbol]["related_pair_ID"].values[0]
|
|
162
|
-
sml_id = name_url_df[name_url_df["symbol"] == symbol]["sml_id"].values[0]
|
|
163
|
-
url = "https://cn.investing.com/instruments/HistoricalDataAjax"
|
|
164
|
-
payload = {
|
|
165
|
-
"curr_id": curr_id,
|
|
166
|
-
"smlID": sml_id,
|
|
167
|
-
"header": "null",
|
|
168
|
-
"st_date": start_date,
|
|
169
|
-
"end_date": end_date,
|
|
170
|
-
"interval_sec": period_map[period],
|
|
171
|
-
"sort_col": "date",
|
|
172
|
-
"sort_ord": "DESC",
|
|
173
|
-
"action": "historical_data",
|
|
174
|
-
}
|
|
175
|
-
r = requests.post(url, data=payload, headers=headers)
|
|
176
|
-
|
|
177
|
-
temp_df = pd.read_html(r.text)[0]
|
|
178
|
-
df_data = temp_df.copy()
|
|
179
|
-
if period == "每月":
|
|
180
|
-
df_data.index = pd.to_datetime(df_data["日期"], format="%Y年%m月")
|
|
181
|
-
else:
|
|
182
|
-
df_data.index = pd.to_datetime(df_data["日期"], format="%Y年%m月%d日")
|
|
183
|
-
if any(df_data["交易量"].astype(str).str.contains("-")):
|
|
184
|
-
df_data["交易量"][df_data["交易量"].str.contains("-")] = df_data["交易量"][
|
|
185
|
-
df_data["交易量"].str.contains("-")
|
|
186
|
-
].replace("-", 0)
|
|
187
|
-
if any(df_data["交易量"].astype(str).str.contains("B")):
|
|
188
|
-
df_data["交易量"][df_data["交易量"].str.contains("B").fillna(False)] = (
|
|
189
|
-
df_data["交易量"][df_data["交易量"].str.contains("B").fillna(False)]
|
|
190
|
-
.str.replace("B", "")
|
|
191
|
-
.str.replace(",", "")
|
|
192
|
-
.astype(float)
|
|
193
|
-
* 1000000000
|
|
194
|
-
)
|
|
195
|
-
if any(df_data["交易量"].astype(str).str.contains("M")):
|
|
196
|
-
df_data["交易量"][df_data["交易量"].str.contains("M").fillna(False)] = (
|
|
197
|
-
df_data["交易量"][df_data["交易量"].str.contains("M").fillna(False)]
|
|
198
|
-
.str.replace("M", "")
|
|
199
|
-
.str.replace(",", "")
|
|
200
|
-
.astype(float)
|
|
201
|
-
* 1000000
|
|
202
|
-
)
|
|
203
|
-
if any(df_data["交易量"].astype(str).str.contains("K")):
|
|
204
|
-
df_data["交易量"][df_data["交易量"].str.contains("K").fillna(False)] = (
|
|
205
|
-
df_data["交易量"][df_data["交易量"].str.contains("K").fillna(False)]
|
|
206
|
-
.str.replace("K", "")
|
|
207
|
-
.str.replace(",", "")
|
|
208
|
-
.astype(float)
|
|
209
|
-
* 1000
|
|
210
|
-
)
|
|
211
|
-
df_data["交易量"] = df_data["交易量"].astype(float)
|
|
212
|
-
df_data["涨跌幅"] = pd.DataFrame(
|
|
213
|
-
round(
|
|
214
|
-
df_data["涨跌幅"].str.replace(",", "").str.replace("%", "").astype(float)
|
|
215
|
-
/ 100,
|
|
216
|
-
6,
|
|
217
|
-
)
|
|
218
|
-
)
|
|
219
|
-
del df_data["日期"]
|
|
220
|
-
df_data.reset_index(inplace=True)
|
|
221
|
-
df_data = df_data[[
|
|
222
|
-
"日期",
|
|
223
|
-
"收盘",
|
|
224
|
-
"开盘",
|
|
225
|
-
"高",
|
|
226
|
-
"低",
|
|
227
|
-
"交易量",
|
|
228
|
-
"涨跌幅",
|
|
229
|
-
]]
|
|
230
|
-
df_data['日期'] = pd.to_datetime(df_data['日期']).dt.date
|
|
231
|
-
df_data['收盘'] = pd.to_numeric(df_data['收盘'])
|
|
232
|
-
df_data['开盘'] = pd.to_numeric(df_data['开盘'])
|
|
233
|
-
df_data['高'] = pd.to_numeric(df_data['高'])
|
|
234
|
-
df_data['低'] = pd.to_numeric(df_data['低'])
|
|
235
|
-
df_data['交易量'] = pd.to_numeric(df_data['交易量'])
|
|
236
|
-
df_data['涨跌幅'] = pd.to_numeric(df_data['涨跌幅'])
|
|
237
|
-
df_data.sort_values('日期', inplace=True)
|
|
238
|
-
df_data.reset_index(inplace=True, drop=True)
|
|
239
|
-
return df_data
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if __name__ == "__main__":
|
|
243
|
-
crypto_name_url_table_df = crypto_name_url_table(symbol="local")
|
|
244
|
-
print(crypto_name_url_table_df)
|
|
245
|
-
|
|
246
|
-
crypto_hist_df = crypto_hist(
|
|
247
|
-
symbol="BTC", period="每日", start_date="20201020", end_date="20220511"
|
|
248
|
-
)
|
|
249
|
-
print(crypto_hist_df)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|