openbb-akshare 0.3.1__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 openbb-akshare might be problematic. Click here for more details.

@@ -0,0 +1,189 @@
1
+ Ticker,Description,Exchange,Category
2
+ YI,"1,000 oz Mini Silver Futures",NYB,metals
3
+ ALI,Aluminum Futures,CMX,metals
4
+ BLK,Block Cheese Futures,CME,agriculture
5
+ AW,Bloomberg Commodity Index Futures,CBT,index
6
+ BZ,Brent Crude Oil Last Day Finance Futures,NYM,hydrocarbon
7
+ BZT,Brent Crude Oil Last Day TAS Futures,NYM,hydrocarbon
8
+ CB,Cash-Settled Butter Futures,CME,agriculture
9
+ CSC,Cash-Settled Cheese Futures,CME,agriculture
10
+ GEO,CBL Global Emissions Offset Futures,NYM,hydrocarbon
11
+ ZW,Chicago SRW Wheat Futures,CBT,agriculture
12
+ ZWT,Chicago SRW Wheat TAS Futures,CBT,agriculture
13
+ DC,Class III Milk Futures,CME,agriculture
14
+ GDK,Class IV Milk Futures,CME,agriculture
15
+ HG0,Copper Spot TAS Futures,CMX,metals
16
+ HGT,Copper TAS Futures,CMX,metals
17
+ ZC,Corn Futures,CBT,agriculture
18
+ ZCT,Corn TAS Futures,CBT,agriculture
19
+ CLT,Crude Oil TAS Futures,NYM,hydrocarbon
20
+ DY,Dry Whey Futures,CME,agriculture
21
+ QC,E-mini Copper Futures,CMX,metals
22
+ QM,E-mini Crude Oil Futures,NYM,hydrocarbon
23
+ XAE,E-mini Energy Select Sector Futures,CME,index
24
+ QO,E-mini Gold Futures,CMX,metals
25
+ GC,CME Gold Futures,CMX,metals
26
+ SGU,Shanghai Gold (USD) Futures,CMX,metals
27
+ QG,E-mini Natural Gas Futures,NYM,hydrocarbon
28
+ QH,E-mini NY Harbor ULSD Futures,NYM,hydrocarbon
29
+ QU,E-mini RBOB Gasoline Futures,NYM,hydrocarbon
30
+ QI,E-mini Silver Futures,CMX,metals
31
+ GF,Feeder Cattle Futures,CME,agriculture
32
+ GFT,Feeder Cattle TAS Futures,CME,agriculture
33
+ GCT,Gold TAS Futures Futures,CMX,metals
34
+ KE,KC HRW Wheat Futures,CBT,agriculture
35
+ KET,KC HRW Wheat TAS Futures,CBT,agriculture
36
+ HE,Lean Hogs Futures,CME,agriculture
37
+ HET,Lean Hogs TAS Futures,CME,agriculture
38
+ LE,Live Cattle Futures,CME,agriculture
39
+ LET,Live Cattle TAS Futures,CME,agriculture
40
+ HG,Copper Futures,CMX,metals
41
+ MHG,E-mini Micro Copper Futures,CMX,metals
42
+ MGC,E-mini Micro Gold Futures,CMX,metals
43
+ SIL,E-mini Micro Silver Futures ,CMX,metals
44
+ MCL,Micro WTI Crude Oil Futures,NYM,hydrocarbon
45
+ YG,E-mini Gold Futures,NYB,metals
46
+ XK,Mini Soybean Futures,CBT,agriculture
47
+ XC,Mini Corn Futures,CBT,agriculture
48
+ XW,Mini Chicago SRW Wheat Futures,CBT,agriculture
49
+ GNF,Nonfat Dry Milk Futures,CME,agriculture
50
+ ZO,Oats Futures,CBT,agriculture
51
+ PRK,Pork Cutout Futures,CME,agriculture
52
+ RBT,RBOB Gasoline TAS Futures,NYM,hydrocarbon
53
+ ZR,Rough Rice Futures,CBT,agriculture
54
+ GD,S&P GSCI Commodity Index Futures,CME,index
55
+ SIT,Silver TAS Futures,CMX,metals
56
+ ZS,Soybean Futures,CBT,agriculture
57
+ ZM,Soybean Meal Futures,CBT,agriculture
58
+ ZMT,Soybean Meal TAS Futures,CBT,agriculture
59
+ ZL,Soybean Oil Futures,CBT,agriculture
60
+ ZLT,Soybean Oil TAS Futures,CBT,agriculture
61
+ SBT,Soybean TAS Futures,CBT,agriculture
62
+ ZN,10-Year T-Note Futures,CBT,bonds
63
+ N1U,10-Year USD MAC Swap Futures,CBT,bonds
64
+ TWE,20-Year U.S. Treasury Bond Futures,CBT,bonds
65
+ ZT,2-Year T-Note Futures,CBT,bonds
66
+ F1U,5-Year USD MAC Swap Futures,CBT,bonds
67
+ RX,Dow Jones Real Estate Index Futures,CBT,index
68
+ GE,Eurodollar Futures,CME,currency
69
+ GLB,One-Month Eurodollar Futures,CME,currency
70
+ ZF,Five-Year US Treasury Note Futures,CBT,bonds
71
+ 10Y,Micro 10-Year Yield Futures,CBT,bonds
72
+ 2YY,Micro 2-Year Yield Futures,CBT,bonds
73
+ 30Y,Micro 30-Year Yield Futures,CBT,bonds
74
+ 5YY,Micro 5-Year Yield Futures,CBT,bonds
75
+ SR1,One-Month SOFR Futures,CME,bonds
76
+ ZFT,TAS on 5-Year Treasury Note Futures,CBT,bonds
77
+ ZQ,Thirty-Day Fed Fund Futures,CBT,bonds
78
+ Z3N,Three Year Treasury Note Futures,CBT,bonds
79
+ SR3,Three-Month SOFR Futures,CME,bonds
80
+ ZB,U.S. Treasury Bond Futures,CBT,bonds
81
+ UB,Ultra U.S. Treasury Bond Futures,CBT,bonds
82
+ BTM,Bakkt BTC (USD) Monthly Futures,NYB,currency
83
+ BTC,Bitcoin Futures,CME,currency
84
+ ETH,Ether Futures,CME,currency
85
+ MBT,E-mini Micro Bitcoin Futures,CME,currency
86
+ MET,E-mini Micro Ether Futures,CME,currency
87
+ 6A,Australian Dollar Futures,CME,currency
88
+ 6L,Brazilian Real Futures,CME,currency
89
+ 6B,British Pound Futures,CME,currency
90
+ PJY,British Pound/Japanese Yen Futures,CME,currency
91
+ PSF,British Pound/Swiss Franc Futures,CME,currency
92
+ 6C,Canadian Dollar Futures,CME,currency
93
+ E7,E-mini Euro FX Futures,CME,currency
94
+ J7,E-mini Japanese Yen Futures,CME,currency
95
+ 6E,Euro FX Futures,CME,currency
96
+ EAD,Euro/Australian Dollar Futures,CME,currency
97
+ RP,Euro/British Pound Futures,CME,currency
98
+ ECD,Euro/Canadian Dollar Futures,CME,currency
99
+ RY,Euro/Japanese Yen Futures,CME,currency
100
+ ENK,Euro/Norwegian Krone Futures,CME,currency
101
+ ESK,Euro/Swedish Krona Futures,CME,currency
102
+ RF,Euro/Swiss Franc Futures,CME,currency
103
+ SIR,Indian Rupee/USD Futures,CME,currency
104
+ 6J,Japanese Yen Futures,CME,currency
105
+ KRW,Korean Won Futures,CME,currency
106
+ 6M,Mexican Peso Futures,CME,currency
107
+ M6A,Micro AUD/USD Futures,CME,currency
108
+ MCD,Micro CAD/USD Futures,CME,currency
109
+ MSF,Micro CHF/USD Futures,CME,currency
110
+ M6E,Micro EUR/USD Futures,CME,currency
111
+ M6B,Micro GBP/USD Futures,CME,currency
112
+ MIR,Micro INR/USD Futures,CME,currency
113
+ M6C,Micro USD/CAD Futures,CME,currency
114
+ M6J,Micro USD/JPY Futures,CME,currency
115
+ 6N,New Zealand Dollar Futures,CME,currency
116
+ NKD,Nikkei Index (USD) Futures,CME,index
117
+ NIY,Nikkei Index (YEN) Futures,CME,index
118
+ NOK,Norwegian Krone Futures,CME,currency
119
+ 6R,Russian Ruble Futures,CME,currency
120
+ 6Z,South African Rand Futures,CME,currency
121
+ SEK,Swedish Krona Futures,CME,currency
122
+ 6S,Swiss Franc Futures,CME,currency
123
+ SJY,Swiss Franc/Japanese Yen Futures,CME,currency
124
+ TPY,Yen Denominated TOPIX Futures,CME,index
125
+ YMT,E-mini DJIA Index BTIC Futures,CBT,index
126
+ NQT,E-mini Nasdaq 100 BTIC Futures,CME,index
127
+ EST,E-mini S&P 500 BTIC Futures,CME,index
128
+ XAF,E-mini S&P 500 Financial Select Sector Index Futures,CME,index
129
+ RS1,E-mini Russell 1000 Index Futures,CME,index
130
+ RSG,E-mini Russell 1000 Growth Index Futures,CME,index
131
+ RSV,E-mini Russell 1000 Value Index Futures,CME,index
132
+ RTY,E-mini Russell 2000 Index Futures,CME,index
133
+ M2K,E-mini Micro Russell 2000 Index Futures,CME,index
134
+ ESG,E-mini S&P 500 ESG Index Futures,CME,index
135
+ EMT,E-mini S&P MidCap 400 Index BTIC Futures,CME,index
136
+ EMD,E-mini S&P MidCap 400 Index Futures,CME,index
137
+ MNQ,E-mini Micro Nasdaq 100 Index Futures,CME,index
138
+ MES,E-mini Micro S&P 500 Index Futures,CME,index
139
+ ES,E-Mini S&P 500 Index Futures,CME,index
140
+ FNG,ICE Micro FANG+ Index Futures,NYB,index
141
+ MMW,ICE MSCI ACWI NTR Index Futures,NYB,index
142
+ CHH,ICE MSCI China NTR Futures,NYB,index
143
+ MFS,ICE MSCI EAFE Index Futures,NYB,index
144
+ ASN,ICE MSCI EM Asia NTR Index Futures,NYB,index
145
+ LFM,ICE MSCI EM ESG Leaders NTR Index Futures,NYB,index
146
+ MML,ICE MSCI EM Latin America NTR Index Futures,NYB,index
147
+ MME,ICE MSCI Emerging Markets Index Futures,NYB,index
148
+ MIN,ICE MSCI India NTR Index Futures,NYB,index
149
+ USS,ICE MSCI USA GTR Index Futures,NYB,index
150
+ MWL,ICE MSCI World Index Futures,NYB,index
151
+ MWS,ICE MSCI World NTR Index Futures,NYB,index
152
+ VLQ,Nasdaq 100 Volatility Index Futures,CME,index
153
+ SDA,S&P 500 Annual Dividend Index Futures,CME,index
154
+ SED,SED (SOFR-Eurodollar) Spread Futures,CME,bonds
155
+ PL,Platinum Futures,NYM,metals
156
+ PA,Palladium Futures,NYM,metals
157
+ BUS,US Midwest Busheling Ferrous Futures,CMX,metals
158
+ AUP,Aluminum MW U.S. Transaction,CMX,metals
159
+ GLI,European Low Sulphur Gasoil Futures,NYM,hydrocarbon
160
+ DX,ICE U.S. Dollar Index Futures,NYB,index
161
+ FT5,E-mini FTSE China 50 Index Futures,CME,index
162
+ MMM,ICE MSCI Emerging Markets EMEA NTR Index Futures,NYB,index
163
+ MMN,ICE MSCI Emerging Markets NTR Index Futures,NYB,index
164
+ MLE,ICE MSCI Latin America Index Futures,NYB,index
165
+ YM,E-mini DJ $5 Index Futures,CBT,index
166
+ XAI,E-mini S&P 500 Industrial Select Sector Futures,CME,index
167
+ XAB,E-mini S&P 500 Materials Select Sector Futures,CME,index
168
+ XAK,E-mini S&P 500 Technology Select Sector Futures,CME,index
169
+ XAP,E-mini S&P 500 Consumer Staples Select Sector Futures,CME,index
170
+ XAR,E-mini S&P 500 Real Estate Select Sector Futures,CME,index
171
+ XAU,E-mini S&P 500 Utilities Select Sector Futures,CME,index
172
+ XAV,E-mini S&P 500 Health Care Select Sector Futures,CME,index
173
+ XAY,E-mini S&P 500 Consumer Discretionary Select Sector Futures,CME,index
174
+ XAZ,E-mini S&P 500 Communication Services Select Sector Futures,CME,index
175
+ BIO,E-mini Nasdaq Biotech Industry Futures,CME,index
176
+ NQ,CME Nasdaq 100 Index Futures,CME,index
177
+ NQQ,TACO on E-mini Nasdaq 100 Index Futures,CME,index
178
+ UFV,Urea (Granular) FOB US Gulf Futures,CBT,agriculture
179
+ CC,Cocoa Futures,NYB,agriculture
180
+ KC,Coffee Futures,NYB,agriculture
181
+ CT,Cotton Futures,NYB,agriculture
182
+ SF,Sugar No. 16 Futures,NYB,agriculture
183
+ SB,Sugar No. 11 Futures,NYB,agriculture
184
+ OJ,Orange Juice Futures,NYB,agriculture
185
+ NG,Natural Gas Futures,NYM,hydrocarbon
186
+ HO,Heating Oil Futures,NYM,hydrocarbon
187
+ RB,RBOB Gasoline Futures,NYM,hydrocarbon
188
+ CL,WTI Crude Oil Futures,NYM,hydrocarbon
189
+ TRM,ICE TRY/USD Futures,NYB,currency
@@ -0,0 +1,206 @@
1
+ """AKShare helpers module."""
2
+
3
+ # pylint: disable=unused-argument,too-many-arguments,too-many-branches,too-many-locals,too-many-statements
4
+ import re
5
+ from typing import Dict, Any, List, Optional, Union
6
+
7
+ from openbb_core.provider.utils.errors import EmptyDataError
8
+ from openbb_yfinance.utils.references import INTERVALS, MONTHS, PERIODS
9
+ from pandas import DataFrame
10
+ from datetime import datetime, timedelta
11
+ from .tools import normalize_date, normalize_symbol
12
+
13
+ import logging
14
+ from openbb_akshare.utils.tools import setup_logger, normalize_symbol
15
+
16
+ #setup_logger()
17
+ logger = logging.getLogger(__name__)
18
+
19
+ def ak_download( # pylint: disable=too-many-positional-arguments
20
+ symbol: str,
21
+ start_date: Optional[Union[str, "date"]] = None,
22
+ end_date: Optional[Union[str, "date"]] = None,
23
+ interval: INTERVALS = "1d",
24
+ period: Optional[PERIODS] = None,
25
+ **kwargs: Any,
26
+ ) -> DataFrame:
27
+ import akshare as ak
28
+
29
+ start = start_date.strftime("%Y%m%d")
30
+ end = end_date.strftime("%Y%m%d")
31
+
32
+ symbol_b, symbol_f, market = normalize_symbol(symbol)
33
+ if market == "HK":
34
+ stock_zh_a_hist_df = ak.stock_hk_hist(symbol_b, period, start, end, adjust="")
35
+ else:
36
+ stock_zh_a_hist_df = ak.stock_zh_a_hist(symbol_b, period, start, end, adjust="")
37
+
38
+ stock_zh_a_hist_df.rename(columns={"日期": "date", "股票代码": "symbol", "开盘": "open", "收盘": "close", "最高": "high", "最低": "low", "成交量": "volume", "成交额": "amount", "涨跌幅":"change_percent", "涨跌额": "change"}, inplace=True)
39
+ stock_zh_a_hist_df = stock_zh_a_hist_df.drop(columns=["振幅"])
40
+ stock_zh_a_hist_df = stock_zh_a_hist_df.drop(columns=["换手率"])
41
+ return stock_zh_a_hist_df
42
+
43
+
44
+ import re
45
+
46
+ def get_post_tax_dividend_per_share(dividend_str: str) -> float:
47
+ """
48
+ Parses Chinese dividend descriptions and returns post-tax dividend per share.
49
+
50
+ Handles:
51
+ - Non-dividend cases (return 0)
52
+ - Per-share direct values (e.g., "每股0.38港元")
53
+ - Base-share values (e.g., "10派1元")
54
+ - Complex combinations (e.g., "每股派发现金股利0.088332港元,每10股派送股票股利3股")
55
+
56
+ Parameters:
57
+ dividend_str (str): Dividend description string
58
+
59
+ Returns:
60
+ float: Post-tax dividend amount per share, rounded to 4 decimal places
61
+ """
62
+ # Case 1: Non-dividend cases
63
+ if re.search(r'不分红|不分配不转增|转增.*不分配', dividend_str):
64
+ return 0.0
65
+
66
+ # If A股 is present, extract only that part
67
+ a_share_match = re.search(r'(A股[^,]*)', dividend_str)
68
+ if a_share_match:
69
+ dividend_str = a_share_match.group(1)
70
+ # Remove 'A股' prefix if present
71
+ dividend_str = dividend_str.replace('A股', '')
72
+
73
+ # Extract base shares
74
+ base_match = re.match(r'(\d+(?:\.\d+)?)', dividend_str)
75
+ base = float(base_match.group(1)) if base_match else 0.0
76
+
77
+ # Extract bonus shares (送)
78
+ bonus_match = re.search(r'送(\d+(?:\.\d+)?)股', dividend_str)
79
+ bonus = float(bonus_match.group(1)) if bonus_match else 0.0
80
+
81
+ # Extract conversion shares (转)
82
+ conversion_match = re.search(r'转(\d+(?:\.\d+)?)股', dividend_str)
83
+ conversion = float(conversion_match.group(1)) if conversion_match else 0.0
84
+
85
+ # Extract cash dividend (派)
86
+ cash_match = re.search(r'派(\d+(?:\.\d+)?)元', dividend_str)
87
+ cash = float(cash_match.group(1)) if cash_match else 0.0
88
+
89
+ if base != 0 and cash != 0:
90
+ return round(cash / base, 4)
91
+
92
+ # Case 2: Direct per-share values (e.g., "每股0.38港元", "每股人民币0.25元")
93
+ direct_match = re.search(r'每股[\u4e00-\u9fa5]*([\d\.]+)[^\d]*(?:港元|人民币|元)', dividend_str)
94
+ if direct_match:
95
+ return round(float(direct_match.group(1)), 4)
96
+
97
+ # Case 3: Base-share values (e.g., "10派1元", "10转10股派1元")
98
+ # Match "10转10股派1元" or similar
99
+ match = re.match(r'(\d+)转(\d+)股派([\d\.]+)元', dividend_str)
100
+ if match:
101
+ base = int(match.group(1))
102
+ bonus = int(match.group(2))
103
+ cash = float(match.group(3))
104
+ total_shares = base
105
+ return round(cash / total_shares, 4)
106
+ # Handle "10派1元" or "10.00派2.00元"
107
+ match = re.match(r'(\d+(?:\.\d+)?)派([\d\.]+)元', dividend_str)
108
+ if match:
109
+ base = int(float(match.group(1)))
110
+ cash = float(match.group(2))
111
+ return round(cash / base, 4)
112
+
113
+ base_match = re.search(r'(\d+)(?:[转股]+[\d\.]+)*(?:派|现金股利)([\d\.]+)', dividend_str)
114
+ if base_match:
115
+ base_shares = int(float(base_match.group(1))) # Handle '10.00' cases
116
+ dividend_amount = float(base_match.group(2))
117
+ return round(dividend_amount / base_shares, 4)
118
+
119
+ # Case 4: Complex mixed formats (e.g., "每股派发现金股利0.088332港元,每10股派送股票股利3股")
120
+ complex_match = re.search(r'每股[\u4e00-\u9fa5]*([\d\.]+)[^\d]*(?:港元|人民币|元)', dividend_str)
121
+ if complex_match:
122
+ return round(float(complex_match.group(1)), 4)
123
+
124
+ # Default: Return 0 for unrecognized formats
125
+ return 0.0
126
+ def get_a_dividends(
127
+ symbol: str,
128
+ start_date: Optional[Union[str, "date"]] = None,
129
+ end_date: Optional[Union[str, "date"]] = None,
130
+ ) -> List[Dict]:
131
+ """
132
+ Fetches historical dividends for a Shanghai/Shenzhen/Beijing stock symbol.
133
+
134
+ Parameters:
135
+ symbol (str): Stock symbol to fetch dividends for.
136
+ start_date (Optional[Union[str, date]]): Start date for fetching dividends.
137
+ end_date (Optional[Union[str, date]]): End date for fetching dividends.
138
+
139
+ Returns:
140
+ DataFrame: DataFrame containing dividend information.
141
+ """
142
+ import akshare as ak
143
+
144
+ if not symbol:
145
+ raise EmptyDataError("Symbol cannot be empty.")
146
+
147
+ div_df = ak.stock_fhps_detail_ths(symbol)
148
+ div_df.dropna(inplace=True)
149
+ ticker = div_df[['实施公告日',
150
+ '分红方案说明',
151
+ 'A股股权登记日',
152
+ 'A股除权除息日']]
153
+ ticker['amount'] = div_df['分红方案说明'].apply(
154
+ lambda x: get_post_tax_dividend_per_share(x) if isinstance(x, str) else None
155
+ )
156
+ ticker.rename(columns={'实施公告日': "report_date",
157
+ '分红方案说明': "description",
158
+ 'A股股权登记日': "record_date",
159
+ 'A股除权除息日': "ex_dividend_date"}, inplace=True)
160
+ dividends = ticker.to_dict("records") # type: ignore
161
+
162
+ if not dividends:
163
+ raise EmptyDataError(f"No dividend data found for {symbol}.")
164
+
165
+ return dividends
166
+
167
+ def get_hk_dividends(
168
+ symbol: str,
169
+ start_date: Optional[Union[str, "date"]] = None,
170
+ end_date: Optional[Union[str, "date"]] = None,
171
+ ) -> List[Dict]:
172
+ """
173
+ Fetches historical dividends for a Hong Kong stock symbol.
174
+
175
+ Parameters:
176
+ symbol (str): Stock symbol to fetch dividends for.
177
+ start_date (Optional[Union[str, date]]): Start date for fetching dividends.
178
+ end_date (Optional[Union[str, date]]): End date for fetching dividends.
179
+
180
+ Returns:
181
+ DataFrame: DataFrame containing dividend information.
182
+ """
183
+ import akshare as ak
184
+
185
+ if not symbol:
186
+ raise EmptyDataError("Symbol cannot be empty.")
187
+
188
+ div_df = ak.stock_hk_fhpx_detail_ths(symbol[1:])
189
+ div_df.dropna(inplace=True)
190
+ ticker = div_df[['公告日期',
191
+ '方案',
192
+ '除净日',
193
+ '派息日']]
194
+ ticker['amount'] = div_df['方案'].apply(
195
+ lambda x: get_post_tax_dividend_per_share(x) if isinstance(x, str) else None
196
+ )
197
+ ticker.rename(columns={'公告日期': "report_date",
198
+ '方案': "description",
199
+ '除净日': "record_date",
200
+ '派息日': "ex_dividend_date"}, inplace=True)
201
+ dividends = ticker.to_dict("records") # type: ignore
202
+
203
+ if not dividends:
204
+ raise EmptyDataError(f"No dividend data found for {symbol}.")
205
+
206
+ return dividends