akshare-one 0.3.2__py3-none-any.whl → 0.3.4__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.
@@ -1,9 +1,8 @@
1
1
  import pandas as pd
2
- from cachetools import cached
3
2
  from .base import HistoricalDataProvider
4
- from ..cache import CACHE_CONFIG
5
- from ..eastmoney.client import EastMoneyClient
6
- from ..eastmoney.utils import parse_kline_data, resample_historical_data
3
+ from ..cache import cache
4
+ from akshare_one.eastmoney.client import EastMoneyClient
5
+ from akshare_one.eastmoney.utils import parse_kline_data, resample_historical_data
7
6
 
8
7
 
9
8
  class EastMoneyDirectHistorical(HistoricalDataProvider):
@@ -13,8 +12,8 @@ class EastMoneyDirectHistorical(HistoricalDataProvider):
13
12
  super().__init__(*args, **kwargs)
14
13
  self.client = EastMoneyClient()
15
14
 
16
- @cached(
17
- cache=CACHE_CONFIG["hist_data_cache"],
15
+ @cache(
16
+ "hist_data_cache",
18
17
  key=lambda self: f"eastmoney_direct_hist_{self.symbol}_{self.interval}_{self.interval_multiplier}_{self.adjust}",
19
18
  )
20
19
  def get_hist_data(self) -> pd.DataFrame:
@@ -195,7 +195,7 @@ class SinaHistorical(HistoricalDataProvider):
195
195
  return resampled.reset_index()
196
196
 
197
197
  def _clean_minute_data(self, raw_df: pd.DataFrame) -> pd.DataFrame:
198
- """Cleans and standardizes minute/hour level data, converting timestamps to UTC"""
198
+ """Cleans and standardizes minute/hour level data"""
199
199
  column_map = {
200
200
  "date": "timestamp",
201
201
  "open": "open",
@@ -208,16 +208,14 @@ class SinaHistorical(HistoricalDataProvider):
208
208
  df = raw_df.rename(columns=column_map)
209
209
 
210
210
  if "timestamp" in df.columns:
211
- df["timestamp"] = (
212
- pd.to_datetime(df["timestamp"])
213
- .dt.tz_localize("Asia/Shanghai")
214
- .dt.tz_convert("UTC")
211
+ df["timestamp"] = pd.to_datetime(df["timestamp"]).dt.tz_localize(
212
+ "Asia/Shanghai"
215
213
  )
216
214
 
217
215
  return self._select_standard_columns(df)
218
216
 
219
217
  def _clean_data(self, raw_df: pd.DataFrame) -> pd.DataFrame:
220
- """Cleans and standardizes daily and higher-level data, converting timestamps to UTC"""
218
+ """Cleans and standardizes daily and higher-level data"""
221
219
  column_map = {
222
220
  "date": "timestamp",
223
221
  "open": "open",
@@ -230,10 +228,8 @@ class SinaHistorical(HistoricalDataProvider):
230
228
  df = raw_df.rename(columns=column_map)
231
229
 
232
230
  if "timestamp" in df.columns:
233
- df["timestamp"] = (
234
- pd.to_datetime(df["timestamp"])
235
- .dt.tz_localize("Asia/Shanghai")
236
- .dt.tz_convert("UTC")
231
+ df["timestamp"] = pd.to_datetime(df["timestamp"]).dt.tz_localize(
232
+ "Asia/Shanghai"
237
233
  )
238
234
 
239
235
  if "volume" in df.columns:
@@ -0,0 +1,25 @@
1
+ from abc import ABC, abstractmethod
2
+ import pandas as pd
3
+
4
+
5
+ class InfoDataProvider(ABC):
6
+ def __init__(self, symbol: str) -> None:
7
+ self.symbol = symbol
8
+
9
+ @abstractmethod
10
+ def get_basic_info(self) -> pd.DataFrame:
11
+ """Fetches stock basic info data
12
+
13
+ Returns:
14
+ pd.DataFrame:
15
+ - price: 最新价
16
+ - symbol: 股票代码
17
+ - name: 股票简称
18
+ - total_shares: 总股本
19
+ - float_shares: 流通股
20
+ - total_market_cap: 总市值
21
+ - float_market_cap: 流通市值
22
+ - industry: 行业
23
+ - listing_date: 上市时间
24
+ """
25
+ pass
@@ -0,0 +1,51 @@
1
+ import pandas as pd
2
+ import akshare as ak
3
+
4
+ from ..cache import cache
5
+ from .base import InfoDataProvider
6
+
7
+
8
+ class EastmoneyInfo(InfoDataProvider):
9
+ _basic_info_rename_map = {
10
+ "最新": "price",
11
+ "股票代码": "symbol",
12
+ "股票简称": "name",
13
+ "总股本": "total_shares",
14
+ "流通股": "float_shares",
15
+ "总市值": "total_market_cap",
16
+ "流通市值": "float_market_cap",
17
+ "行业": "industry",
18
+ "上市时间": "listing_date",
19
+ }
20
+
21
+ @cache(
22
+ "info_cache",
23
+ key=lambda self, symbol=None: f"eastmoney_{symbol}",
24
+ )
25
+ def get_basic_info(self) -> pd.DataFrame:
26
+ """获取东方财富个股信息"""
27
+ info_df = ak.stock_individual_info_em(symbol=self.symbol)
28
+ info_df = info_df.set_index("item").T
29
+ info_df.reset_index(drop=True, inplace=True)
30
+ info_df.rename(columns=self._basic_info_rename_map, inplace=True)
31
+
32
+ if "symbol" in info_df.columns:
33
+ info_df["symbol"] = info_df["symbol"].astype(str)
34
+
35
+ if "listing_date" in info_df.columns:
36
+ info_df["listing_date"] = pd.to_datetime(
37
+ info_df["listing_date"], format="%Y%m%d"
38
+ )
39
+
40
+ numeric_cols = [
41
+ "price",
42
+ "total_shares",
43
+ "float_shares",
44
+ "total_market_cap",
45
+ "float_market_cap",
46
+ ]
47
+ for col in numeric_cols:
48
+ if col in info_df.columns:
49
+ info_df[col] = pd.to_numeric(info_df[col], errors="coerce")
50
+
51
+ return info_df
@@ -0,0 +1,44 @@
1
+ from .eastmoney import EastmoneyInfo
2
+ from .base import InfoDataProvider
3
+
4
+
5
+ class InfoDataFactory:
6
+ """
7
+ Factory class for creating info data providers
8
+ """
9
+
10
+ _providers = {
11
+ "eastmoney": EastmoneyInfo,
12
+ }
13
+
14
+ @classmethod
15
+ def get_provider(cls, provider_name: str, **kwargs) -> InfoDataProvider:
16
+ """
17
+ Get a info data provider by name
18
+
19
+ Args:
20
+ provider_name: Name of the provider (e.g., 'eastmoney')
21
+ **kwargs: Additional arguments to pass to the provider's constructor
22
+
23
+ Returns:
24
+ InfoDataProvider: An instance of the requested provider
25
+
26
+ Raises:
27
+ ValueError: If the requested provider is not found
28
+ """
29
+ provider_class = cls._providers.get(provider_name.lower())
30
+ if not provider_class:
31
+ raise ValueError(f"Unknown info data provider: {provider_name}")
32
+
33
+ return provider_class(**kwargs)
34
+
35
+ @classmethod
36
+ def register_provider(cls, name: str, provider_class: type):
37
+ """
38
+ Register a new info data provider
39
+
40
+ Args:
41
+ name: Name to associate with this provider
42
+ provider_class: The provider class to register
43
+ """
44
+ cls._providers[name.lower()] = provider_class
@@ -16,7 +16,7 @@ class InsiderDataProvider(ABC):
16
16
  - issuer: 股票名称
17
17
  - name: 变动人
18
18
  - title: 董监高职务
19
- - transaction_date: 变动日期(UTC时区)
19
+ - transaction_date: 变动日期
20
20
  - transaction_shares: 变动股数
21
21
  - transaction_price_per_share: 成交均价
22
22
  - shares_owned_after_transaction: 变动后持股数
@@ -1,16 +1,15 @@
1
- from cachetools import cached
2
1
  import pandas as pd
3
2
  import akshare as ak
4
3
  from .base import InsiderDataProvider
5
4
  from ..utils import convert_xieqiu_symbol
6
- from ..cache import CACHE_CONFIG
5
+ from ..cache import cache
7
6
 
8
7
 
9
8
  class XueQiuInsider(InsiderDataProvider):
10
9
  """Provider for XueQiu insider trading data"""
11
10
 
12
- @cached(
13
- cache=CACHE_CONFIG["financial_cache"],
11
+ @cache(
12
+ "financial_cache",
14
13
  key=lambda self, symbol=None: f"xueqiu_insider_{symbol if symbol else 'all'}",
15
14
  )
16
15
  def get_inner_trade_data(self) -> pd.DataFrame:
@@ -87,17 +86,13 @@ class XueQiuInsider(InsiderDataProvider):
87
86
 
88
87
  # Convert date format
89
88
  if "transaction_date" in df.columns:
90
- df["transaction_date"] = (
91
- pd.to_datetime(df["transaction_date"])
92
- .dt.tz_localize("Asia/Shanghai")
93
- .dt.tz_convert("UTC")
94
- )
89
+ df["transaction_date"] = pd.to_datetime(
90
+ df["transaction_date"]
91
+ ).dt.tz_localize("Asia/Shanghai")
95
92
 
96
93
  if "filing_date" in df.columns:
97
- df["filing_date"] = (
98
- pd.to_datetime(df["filing_date"])
99
- .dt.tz_localize("Asia/Shanghai")
100
- .dt.tz_convert("UTC")
94
+ df["filing_date"] = pd.to_datetime(df["filing_date"]).dt.tz_localize(
95
+ "Asia/Shanghai"
101
96
  )
102
97
 
103
98
  # Convert numeric columns
@@ -15,7 +15,7 @@ class NewsDataProvider(ABC):
15
15
  - keyword: 关键词
16
16
  - title: 新闻标题
17
17
  - content: 新闻内容
18
- - publish_time: 发布时间 (UTC)
18
+ - publish_time: 发布时间
19
19
  - source: 文章来源
20
20
  - url: 新闻链接
21
21
  """
@@ -1,14 +1,13 @@
1
- from cachetools import cached
2
1
  import pandas as pd
3
2
  import akshare as ak
4
3
 
5
- from ..cache import CACHE_CONFIG
4
+ from ..cache import cache
6
5
  from .base import NewsDataProvider
7
6
 
8
7
 
9
8
  class EastMoneyNews(NewsDataProvider):
10
- @cached(
11
- CACHE_CONFIG["news_cache"],
9
+ @cache(
10
+ "news_cache",
12
11
  key=lambda self: f"eastmoney_news_{self.symbol}",
13
12
  )
14
13
  def get_news_data(self) -> pd.DataFrame:
@@ -29,11 +28,8 @@ class EastMoneyNews(NewsDataProvider):
29
28
 
30
29
  df = raw_df.rename(columns=column_mapping)
31
30
 
32
- # Convert time to UTC
33
- df["publish_time"] = (
34
- pd.to_datetime(df["publish_time"])
35
- .dt.tz_localize("Asia/Shanghai")
36
- .dt.tz_convert("UTC")
31
+ df["publish_time"] = pd.to_datetime(df["publish_time"]).dt.tz_localize(
32
+ "Asia/Shanghai"
37
33
  )
38
34
 
39
35
  required_columns = [
@@ -1,14 +1,13 @@
1
- from cachetools import cached
2
1
  import pandas as pd
3
2
  import akshare as ak
4
3
 
5
- from ..cache import CACHE_CONFIG
4
+ from ..cache import cache
6
5
  from .base import RealtimeDataProvider
7
6
 
8
7
 
9
8
  class EastmoneyRealtime(RealtimeDataProvider):
10
- @cached(
11
- CACHE_CONFIG["realtime_cache"],
9
+ @cache(
10
+ "realtime_cache",
12
11
  key=lambda self, symbol=None: f"eastmoney_{symbol if symbol else 'all'}",
13
12
  )
14
13
  def get_current_data(self) -> pd.DataFrame:
@@ -36,10 +35,7 @@ class EastmoneyRealtime(RealtimeDataProvider):
36
35
 
37
36
  df = raw_df.rename(columns=column_mapping)
38
37
 
39
- # Change time to UTC
40
- df = df.assign(
41
- timestamp=lambda x: pd.Timestamp.now(tz="Asia/Shanghai").tz_convert("UTC")
42
- )
38
+ df = df.assign(timestamp=lambda x: pd.Timestamp.now(tz="Asia/Shanghai"))
43
39
 
44
40
  required_columns = [
45
41
  "symbol",
@@ -1,9 +1,8 @@
1
1
  import pandas as pd
2
- from cachetools import cached
3
2
  from .base import RealtimeDataProvider
4
- from ..cache import CACHE_CONFIG
5
- from ..eastmoney.client import EastMoneyClient
6
- from ..eastmoney.utils import parse_realtime_data
3
+ from ..cache import cache
4
+ from akshare_one.eastmoney.client import EastMoneyClient
5
+ from akshare_one.eastmoney.utils import parse_realtime_data
7
6
 
8
7
 
9
8
  class EastMoneyDirectRealtime(RealtimeDataProvider):
@@ -13,8 +12,8 @@ class EastMoneyDirectRealtime(RealtimeDataProvider):
13
12
  super().__init__(symbol)
14
13
  self.client = EastMoneyClient()
15
14
 
16
- @cached(
17
- cache=CACHE_CONFIG["realtime_cache"],
15
+ @cache(
16
+ "realtime_cache",
18
17
  key=lambda self: f"eastmoney_direct_realtime_{self.symbol}",
19
18
  )
20
19
  def get_current_data(self) -> pd.DataFrame:
@@ -1,14 +1,13 @@
1
- from cachetools import cached
2
1
  import pandas as pd
3
2
  import akshare as ak
4
3
  from ..utils import convert_xieqiu_symbol
5
- from ..cache import CACHE_CONFIG
4
+ from ..cache import cache
6
5
  from .base import RealtimeDataProvider
7
6
 
8
7
 
9
8
  class XueQiuRealtime(RealtimeDataProvider):
10
- @cached(
11
- cache=CACHE_CONFIG["realtime_cache"],
9
+ @cache(
10
+ "realtime_cache",
12
11
  key=lambda self, symbol=None: f"xueqiu_{symbol}",
13
12
  )
14
13
  def get_current_data(self) -> pd.DataFrame:
@@ -43,9 +42,7 @@ class XueQiuRealtime(RealtimeDataProvider):
43
42
  ),
44
43
  "timestamp": pd.to_datetime(
45
44
  raw_df.loc[raw_df["item"] == "时间", "value"].values[0]
46
- )
47
- .tz_localize("Asia/Shanghai")
48
- .tz_convert("UTC"),
45
+ ).tz_localize("Asia/Shanghai"),
49
46
  "volume": int(raw_df.loc[raw_df["item"] == "成交量", "value"].values[0])
50
47
  / 100,
51
48
  "amount": float(raw_df.loc[raw_df["item"] == "成交额", "value"].values[0]),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: akshare-one
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: Standardized interface for Chinese financial market data, built on AKShare with unified data formats and simplified APIs
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://github.com/zwldarren/akshare-one
@@ -9,8 +9,8 @@ Keywords: akshare,financial-data,stock-data,quant
9
9
  Requires-Python: >=3.10
10
10
  Description-Content-Type: text/markdown
11
11
  License-File: LICENSE
12
- Requires-Dist: akshare>=1.17.15
13
- Requires-Dist: cachetools>=6.1.0
12
+ Requires-Dist: akshare>=1.17.20
13
+ Requires-Dist: cachetools>=5.5.2
14
14
  Provides-Extra: talib
15
15
  Requires-Dist: ta-lib>=0.6.4; extra == "talib"
16
16
  Dynamic: license-file
@@ -40,7 +40,9 @@ Dynamic: license-file
40
40
  | Stock news | `get_news_data` |
41
41
  | Financial data | `get_balance_sheet`/`get_income_statement`/`get_cash_flow` |
42
42
  | Internal transactions | `get_inner_trade_data` |
43
- | Technical indicators | See [indicators.py](akshare_one/indicators.py) |
43
+ | Basic stock info | `get_basic_info` |
44
+ | Financial metrics | `get_financial_metrics` |
45
+ | Technical indicators | See [indicators.py](akshare-one/indicators.py) |
44
46
 
45
47
  ## 📦 Quick Installation
46
48
 
@@ -67,4 +69,6 @@ df_sma = get_sma(df, window=20)
67
69
 
68
70
  ## 📚 Documentation
69
71
 
70
- Detailed API reference: [docs/api.md](docs/api.md)
72
+ Full API documentation is now available on GitHub Pages:
73
+
74
+ https://zwldarren.github.io/akshare-one/
@@ -0,0 +1,36 @@
1
+ akshare_one/__init__.py,sha256=iqMgeNlNfxGURekZdNOopLl1L1oufkyw3s48cRqNFxo,6514
2
+ akshare_one/indicators.py,sha256=x3Amff9CG_GvQpA-sqGfFwEAIvaaXlBxDfzTxD05taQ,12533
3
+ akshare_one/modules/cache.py,sha256=_3n35rt9xJfQzZSV6JZ6bGzf2VnqTmLfe49WXk4c9K8,867
4
+ akshare_one/modules/utils.py,sha256=msHqsjWSRULbX-3Bnit1p26a4a7MOEuNfkPSaECXr4k,333
5
+ akshare_one/modules/financial/base.py,sha256=TG3ncf3rXfgWCk4qUORN01uxT1SgLWiyjkt5Jb9eoxo,688
6
+ akshare_one/modules/financial/factory.py,sha256=9xR_uKt7n8dndYUxEGDDL65LXnbm-edtTLdhF0Bfyro,1468
7
+ akshare_one/modules/financial/sina.py,sha256=c6rSxCVNU6h-7XWSiqPHDN_XAhRdGHdqI9Haruy3mDs,12801
8
+ akshare_one/modules/historical/base.py,sha256=kDy76OJUp-LIddsC23YAQdf4Q_YGCrnZ8AvU4xRzQsI,1286
9
+ akshare_one/modules/historical/eastmoney.py,sha256=B1H67o1bj8RjaKhfRu0xSA0MoQTEXz_6gRUNg138gJU,8252
10
+ akshare_one/modules/historical/eastmoney_direct.py,sha256=cBT5_tz6a4qEV5KMiyFBdOfEVTLlJfT2o4uNBIu137Y,2854
11
+ akshare_one/modules/historical/factory.py,sha256=qfMod5HSV-itE-i1ludIp0w8Zq7Vjp2LPomajVd5Kjc,1548
12
+ akshare_one/modules/historical/sina.py,sha256=sQoUnQlkxyI4i7Cuw5YwKT3IoNM8-K5wleusVM_tKJA,8761
13
+ akshare_one/modules/indicators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ akshare_one/modules/indicators/base.py,sha256=DhFivpVIUIkdIv24U2WoOy1GCDySxsw0tD0-rBRe5Lc,4376
15
+ akshare_one/modules/indicators/factory.py,sha256=pKx57oej_L0Lz3kkXwzVievKpOYph0T_Y7fzSwO3Zd4,1021
16
+ akshare_one/modules/indicators/simple.py,sha256=vAqE3v9HYpW-Sy6KsG9oV5fppWchQTxtz1M_508sQtY,9342
17
+ akshare_one/modules/indicators/talib.py,sha256=w0KpV-BXVxU0LmWs_EbXJUFgo9dbMeUQijjJMkjtWtU,10773
18
+ akshare_one/modules/info/base.py,sha256=Kof-e1I2usx1VOc1d05kyL-8B_QEDOsbry4R3dV0zZE,697
19
+ akshare_one/modules/info/eastmoney.py,sha256=pvWLcVoVWwgZS_4Bg-OtHQW5SPCZ9I1PAFbN4yqluq0,1610
20
+ akshare_one/modules/info/factory.py,sha256=xvwPrgce0p9U4qAQBJM7FFw3zJks6m2hLHwHf0t1rfU,1308
21
+ akshare_one/modules/insider/base.py,sha256=bJoyNSoa0o8py6GqjlMRIEV6DbOoc2OEOyE0vmjT_n4,966
22
+ akshare_one/modules/insider/factory.py,sha256=32bueJA3E8yCZc0v5EAen_48RZ23yojYzpzaZyQ6WnA,1324
23
+ akshare_one/modules/insider/xueqiu.py,sha256=7PfyRioZ6KHW82sbXYcc1yNF6QGPS-kPG7i91YoxNfU,3932
24
+ akshare_one/modules/news/base.py,sha256=t8b_RBRDQ_HyqGHQWVzojbonNJmwp2p1ckpyYPaSmdY,575
25
+ akshare_one/modules/news/eastmoney.py,sha256=kKNBmd-PRzMJVDauL_QIrFduB_E0vp96pLCuVsE3L-k,1245
26
+ akshare_one/modules/news/factory.py,sha256=3FMkNBpYF7l-v2NHHR5TzbvklQNzJ-R_XzG8AlRjJcg,1308
27
+ akshare_one/modules/realtime/base.py,sha256=eYicSs7E4qmcpQ-8TnbfmJvsK0VQoezVK7Zobqh5xPk,729
28
+ akshare_one/modules/realtime/eastmoney.py,sha256=6acJeIdrvkW4ZqM9CALithlx85QSogrlPLSo-yKhQ8w,1582
29
+ akshare_one/modules/realtime/eastmoney_direct.py,sha256=A2ScBRfIP6n_BxQ6muB26AEykIvTG7Mt3BDAZMyugkg,1236
30
+ akshare_one/modules/realtime/factory.py,sha256=_7jBDgqWqkt5xTTT1SpZoUHM9IpMRpcUQeyyCglM5z0,1528
31
+ akshare_one/modules/realtime/xueqiu.py,sha256=CHTN5VUwo24H-2EGKQkN8oqr3MWjDi-7DpvQEDyPlls,2196
32
+ akshare_one-0.3.4.dist-info/licenses/LICENSE,sha256=3bqxoD7aU4QS7kpNtQmRd4MikxXe6Gtm_DrojyFHGAc,1087
33
+ akshare_one-0.3.4.dist-info/METADATA,sha256=ShCNaVjkVQJa41srBtN-6gKBDCfHWompMxXBSzEdO5I,2272
34
+ akshare_one-0.3.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
35
+ akshare_one-0.3.4.dist-info/top_level.txt,sha256=kNiucyLVAGa89wmUSpXbBLWD7pF_RuahuiaOfLHZSyw,12
36
+ akshare_one-0.3.4.dist-info/RECORD,,
akshare_one/financial.py DELETED
@@ -1,46 +0,0 @@
1
- """财务报表数据模块
2
-
3
- 包含资产负债表、利润表和现金流量表相关功能
4
- """
5
-
6
- import pandas as pd
7
- from akshare_one.modules.financial.factory import FinancialDataFactory
8
-
9
-
10
- def get_balance_sheet(symbol: str, source: str = "sina") -> "pd.DataFrame":
11
- """获取资产负债表数据
12
-
13
- Args:
14
- symbol: 股票代码 (如 "600600")
15
- source: 数据源 ("sina")
16
- """
17
- if source == "sina":
18
- provider = FinancialDataFactory.get_provider(source, symbol=symbol)
19
- return provider.get_balance_sheet()
20
- raise ValueError(f"Unsupported data source: {source}")
21
-
22
-
23
- def get_income_statement(symbol: str, source: str = "sina") -> "pd.DataFrame":
24
- """获取利润表数据
25
-
26
- Args:
27
- symbol: 股票代码 (如 "600600")
28
- source: 数据源 ("sina")
29
- """
30
- if source == "sina":
31
- provider = FinancialDataFactory.get_provider(source, symbol=symbol)
32
- return provider.get_income_statement()
33
- raise ValueError(f"Unsupported data source: {source}")
34
-
35
-
36
- def get_cash_flow(symbol: str, source: str = "sina") -> "pd.DataFrame":
37
- """获取现金流量表数据
38
-
39
- Args:
40
- symbol: 股票代码 (如 "600600")
41
- source: 数据源 ("sina")
42
- """
43
- if source == "sina":
44
- provider = FinancialDataFactory.get_provider(source, symbol=symbol)
45
- return provider.get_cash_flow()
46
- raise ValueError(f"Unsupported data source: {source}")
akshare_one/insider.py DELETED
@@ -1,33 +0,0 @@
1
- """内部交易数据模块
2
-
3
- 包含上市公司内部交易相关功能
4
- """
5
-
6
- import pandas as pd
7
- from .modules.insider.factory import InsiderDataFactory
8
-
9
-
10
- def get_inner_trade_data(symbol: str, source: str = "xueqiu") -> "pd.DataFrame":
11
- """获取雪球内部交易数据
12
-
13
- Args:
14
- source: 数据源 (目前支持 "xueqiu")
15
- symbol: 股票代码,如"600000"
16
-
17
- Returns:
18
- pd.DataFrame:
19
- - symbol: 股票代码
20
- - issuer: 股票名称
21
- - name: 变动人
22
- - title: 董监高职务
23
- - transaction_date: 变动日期(UTC时区)
24
- - transaction_shares: 变动股数
25
- - transaction_price_per_share: 成交均价
26
- - shares_owned_after_transaction: 变动后持股数
27
- - relationship: 与董监高关系
28
- - is_board_director: 是否为董事会成员
29
- - transaction_value: 交易金额(变动股数*成交均价)
30
- - shares_owned_before_transaction: 变动前持股数
31
- """
32
- provider = InsiderDataFactory.get_provider(source, symbol=symbol)
33
- return provider.get_inner_trade_data()
@@ -1,88 +0,0 @@
1
- import requests
2
- from typing import Dict, Any
3
-
4
-
5
- class EastMoneyClient:
6
- """
7
- A client for interacting directly with EastMoney's data APIs.
8
- This class handles session management, request signing, and API calls.
9
- """
10
-
11
- def __init__(self):
12
- self.session = requests.Session()
13
- self.session.headers.update(
14
- {
15
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36",
16
- "Referer": "https://quote.eastmoney.com/",
17
- "Accept": "application/json, text/plain, */*",
18
- "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
19
- }
20
- )
21
-
22
- def _get_security_id(self, symbol: str) -> str:
23
- """
24
- Converts a stock symbol to EastMoney's internal secid format.
25
- e.g., '600519' -> '1.600519', '000001' -> '0.000001'
26
- """
27
- symbol = symbol.upper()
28
- if symbol.startswith("SZ"):
29
- market = "0"
30
- code = symbol[2:]
31
- elif symbol.startswith("SH"):
32
- market = "1"
33
- code = symbol[2:]
34
- elif symbol.startswith("HK"):
35
- market = "116"
36
- code = symbol[2:]
37
- elif len(symbol) == 6:
38
- if symbol.startswith(("000", "001", "002", "003", "300", "200")):
39
- market = "0"
40
- elif symbol.startswith(("600", "601", "603", "605", "688", "900")):
41
- market = "1"
42
- else:
43
- market = "0" # Default to SZ for ambiguity
44
- code = symbol
45
- elif len(symbol) == 5: # HK Market
46
- market = "116"
47
- code = symbol
48
- else:
49
- market = "0"
50
- code = symbol
51
- return f"{market}.{code}"
52
-
53
- def fetch_historical_klines(
54
- self, symbol: str, klt: str, fqt: str, start_date: str, end_date: str
55
- ) -> Dict[str, Any]:
56
- """
57
- Fetches historical K-line (candlestick) data.
58
- """
59
- url = "https://push2his.eastmoney.com/api/qt/stock/kline/get"
60
- secid = self._get_security_id(symbol)
61
- params = {
62
- "fields1": "f1,f2,f3,f4,f5,f6",
63
- "fields2": "f51,f52,f53,f54,f55,f56,f57,f58,f59,f60,f61",
64
- "klt": klt,
65
- "fqt": fqt,
66
- "secid": secid,
67
- "beg": start_date,
68
- "end": end_date,
69
- }
70
- response = self.session.get(url, params=params)
71
- response.raise_for_status()
72
- return response.json()
73
-
74
- def fetch_realtime_quote(self, symbol: str) -> Dict[str, Any]:
75
- """
76
- Fetches real-time quote data for a single stock.
77
- """
78
- url = "https://push2.eastmoney.com/api/qt/stock/get"
79
- secid = self._get_security_id(symbol)
80
- params = {
81
- "invt": "2",
82
- "fltt": "2",
83
- "fields": "f43,f57,f58,f169,f170,f46,f60,f44,f51,f168,f47,f164,f163,f116,f60,f45,f52,f50,f48,f167,f117,f71,f161,f49,f530",
84
- "secid": secid,
85
- }
86
- response = self.session.get(url, params=params)
87
- response.raise_for_status()
88
- return response.json()