akshare-one 0.3.7__py3-none-any.whl → 0.3.9__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.
Files changed (41) hide show
  1. akshare_one/__init__.py +214 -214
  2. akshare_one/eastmoney/client.py +80 -80
  3. akshare_one/eastmoney/utils.py +102 -102
  4. akshare_one/indicators.py +395 -395
  5. akshare_one/modules/cache.py +30 -27
  6. akshare_one/modules/financial/base.py +27 -27
  7. akshare_one/modules/financial/eastmoney_direct.py +183 -183
  8. akshare_one/modules/financial/factory.py +46 -46
  9. akshare_one/modules/financial/sina.py +292 -292
  10. akshare_one/modules/historical/base.py +47 -47
  11. akshare_one/modules/historical/eastmoney.py +236 -236
  12. akshare_one/modules/historical/eastmoney_direct.py +79 -78
  13. akshare_one/modules/historical/factory.py +48 -48
  14. akshare_one/modules/historical/sina.py +250 -250
  15. akshare_one/modules/indicators/base.py +158 -158
  16. akshare_one/modules/indicators/factory.py +33 -33
  17. akshare_one/modules/indicators/simple.py +9 -8
  18. akshare_one/modules/indicators/talib.py +263 -263
  19. akshare_one/modules/info/base.py +25 -25
  20. akshare_one/modules/info/eastmoney.py +51 -51
  21. akshare_one/modules/info/factory.py +44 -44
  22. akshare_one/modules/insider/base.py +28 -28
  23. akshare_one/modules/insider/factory.py +44 -44
  24. akshare_one/modules/insider/xueqiu.py +110 -110
  25. akshare_one/modules/news/base.py +22 -22
  26. akshare_one/modules/news/eastmoney.py +43 -43
  27. akshare_one/modules/news/factory.py +44 -44
  28. akshare_one/modules/realtime/base.py +27 -27
  29. akshare_one/modules/realtime/eastmoney.py +53 -53
  30. akshare_one/modules/realtime/eastmoney_direct.py +36 -36
  31. akshare_one/modules/realtime/factory.py +71 -48
  32. akshare_one/modules/realtime/xueqiu.py +57 -57
  33. akshare_one/modules/utils.py +10 -10
  34. akshare_one/py.typed +0 -0
  35. {akshare_one-0.3.7.dist-info → akshare_one-0.3.9.dist-info}/METADATA +72 -74
  36. akshare_one-0.3.9.dist-info/RECORD +38 -0
  37. akshare_one-0.3.9.dist-info/WHEEL +4 -0
  38. akshare_one-0.3.7.dist-info/RECORD +0 -39
  39. akshare_one-0.3.7.dist-info/WHEEL +0 -5
  40. akshare_one-0.3.7.dist-info/licenses/LICENSE +0 -21
  41. akshare_one-0.3.7.dist-info/top_level.txt +0 -1
@@ -1,78 +1,79 @@
1
- import pandas as pd
2
- from .base import HistoricalDataProvider
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
6
-
7
-
8
- class EastMoneyDirectHistorical(HistoricalDataProvider):
9
- """Direct implementation for EastMoney historical stock data API"""
10
-
11
- def __init__(self, *args, **kwargs):
12
- super().__init__(*args, **kwargs)
13
- self.client = EastMoneyClient()
14
-
15
- @cache(
16
- "hist_data_cache",
17
- key=lambda self: f"eastmoney_direct_hist_{self.symbol}_{self.interval}_{self.interval_multiplier}_{self.adjust}",
18
- )
19
- def get_hist_data(self) -> pd.DataFrame:
20
- """Fetches EastMoney historical market data directly from API"""
21
- self.interval = self.interval.lower()
22
- self._validate_interval_params()
23
-
24
- try:
25
- klt = self._get_kline_type()
26
- fqt = self._get_adjust_type()
27
- start_date = self.start_date.replace("-", "")
28
- end_date = self.end_date.replace("-", "")
29
-
30
- raw_data = self.client.fetch_historical_klines(
31
- symbol=self.symbol,
32
- klt=klt,
33
- fqt=fqt,
34
- start_date=start_date,
35
- end_date=end_date,
36
- )
37
-
38
- if raw_data.get("rc") != 0:
39
- raise ValueError(f"API returned error: {raw_data.get('msg')}")
40
-
41
- df = parse_kline_data(raw_data)
42
-
43
- df = resample_historical_data(df, self.interval, self.interval_multiplier)
44
-
45
- return df
46
-
47
- except Exception as e:
48
- raise ValueError(f"Failed to fetch historical data for {self.symbol}: {e}")
49
-
50
- def _get_kline_type(self) -> str:
51
- """Get K-line type based on interval."""
52
- kline_map = {
53
- "minute": "1",
54
- "hour": "60",
55
- "day": "101",
56
- "week": "102",
57
- "month": "103",
58
- "year": "103",
59
- }
60
-
61
- base_klt = kline_map.get(self.interval, "101")
62
-
63
- if self.interval == "minute" and self.interval_multiplier in [5, 15, 30, 60]:
64
- return str(self.interval_multiplier)
65
-
66
- return base_klt
67
-
68
- def _get_adjust_type(self) -> str:
69
- """Get adjustment type."""
70
- adjust_map = {"none": "0", "qfq": "1", "hfq": "2"}
71
- return adjust_map.get(self.adjust, "0")
72
-
73
- def _validate_interval_params(self) -> None:
74
- """Validates the interval and multiplier."""
75
- if self.interval not in self.get_supported_intervals():
76
- raise ValueError(f"Unsupported interval: {self.interval}")
77
- if self.interval in ["minute", "hour"] and self.interval_multiplier < 1:
78
- raise ValueError("Interval multiplier must be >= 1 for minute/hour.")
1
+ import pandas as pd
2
+ from typing import Any
3
+ from .base import HistoricalDataProvider
4
+ from ..cache import cache
5
+ from akshare_one.eastmoney.client import EastMoneyClient
6
+ from akshare_one.eastmoney.utils import parse_kline_data, resample_historical_data
7
+
8
+
9
+ class EastMoneyDirectHistorical(HistoricalDataProvider):
10
+ """Direct implementation for EastMoney historical stock data API"""
11
+
12
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
13
+ super().__init__(*args, **kwargs)
14
+ self.client = EastMoneyClient()
15
+
16
+ @cache(
17
+ "hist_data_cache",
18
+ key=lambda self: f"eastmoney_direct_hist_{self.symbol}_{self.interval}_{self.interval_multiplier}_{self.adjust}",
19
+ )
20
+ def get_hist_data(self) -> pd.DataFrame:
21
+ """Fetches EastMoney historical market data directly from API"""
22
+ self.interval = self.interval.lower()
23
+ self._validate_interval_params()
24
+
25
+ try:
26
+ klt = self._get_kline_type()
27
+ fqt = self._get_adjust_type()
28
+ start_date = self.start_date.replace("-", "")
29
+ end_date = self.end_date.replace("-", "")
30
+
31
+ raw_data = self.client.fetch_historical_klines(
32
+ symbol=self.symbol,
33
+ klt=klt,
34
+ fqt=fqt,
35
+ start_date=start_date,
36
+ end_date=end_date,
37
+ )
38
+
39
+ if raw_data.get("rc") != 0:
40
+ raise ValueError(f"API returned error: {raw_data.get('msg')}")
41
+
42
+ df = parse_kline_data(raw_data)
43
+
44
+ df = resample_historical_data(df, self.interval, self.interval_multiplier)
45
+
46
+ return df
47
+
48
+ except Exception as e:
49
+ raise ValueError(f"Failed to fetch historical data for {self.symbol}: {e}")
50
+
51
+ def _get_kline_type(self) -> str:
52
+ """Get K-line type based on interval."""
53
+ kline_map = {
54
+ "minute": "1",
55
+ "hour": "60",
56
+ "day": "101",
57
+ "week": "102",
58
+ "month": "103",
59
+ "year": "103",
60
+ }
61
+
62
+ base_klt = kline_map.get(self.interval, "101")
63
+
64
+ if self.interval == "minute" and self.interval_multiplier in [5, 15, 30, 60]:
65
+ return str(self.interval_multiplier)
66
+
67
+ return base_klt
68
+
69
+ def _get_adjust_type(self) -> str:
70
+ """Get adjustment type."""
71
+ adjust_map = {"none": "0", "qfq": "1", "hfq": "2"}
72
+ return adjust_map.get(self.adjust, "0")
73
+
74
+ def _validate_interval_params(self) -> None:
75
+ """Validates the interval and multiplier."""
76
+ if self.interval not in self.get_supported_intervals():
77
+ raise ValueError(f"Unsupported interval: {self.interval}")
78
+ if self.interval in ["minute", "hour"] and self.interval_multiplier < 1:
79
+ raise ValueError("Interval multiplier must be >= 1 for minute/hour.")
@@ -1,48 +1,48 @@
1
- from .base import HistoricalDataProvider
2
- from .eastmoney import EastMoneyHistorical
3
- from .eastmoney_direct import EastMoneyDirectHistorical
4
- from .sina import SinaHistorical
5
-
6
-
7
- class HistoricalDataFactory:
8
- """
9
- Factory class for creating historical data providers
10
- """
11
-
12
- _providers = {
13
- "eastmoney": EastMoneyHistorical,
14
- "eastmoney_direct": EastMoneyDirectHistorical,
15
- "sina": SinaHistorical,
16
- }
17
-
18
- @classmethod
19
- def get_provider(cls, provider_name: str, **kwargs) -> HistoricalDataProvider:
20
- """
21
- Get a historical data provider by name
22
-
23
- Args:
24
- provider_name: Name of the provider (e.g., 'eastmoney')
25
- **kwargs: Additional arguments to pass to the provider's constructor
26
-
27
- Returns:
28
- HistoricalDataProvider: An instance of the requested provider
29
-
30
- Raises:
31
- ValueError: If the requested provider is not found
32
- """
33
- provider_class = cls._providers.get(provider_name.lower())
34
- if not provider_class:
35
- raise ValueError(f"Unknown historical data provider: {provider_name}")
36
-
37
- return provider_class(**kwargs)
38
-
39
- @classmethod
40
- def register_provider(cls, name: str, provider_class: type):
41
- """
42
- Register a new historical data provider
43
-
44
- Args:
45
- name: Name to associate with this provider
46
- provider_class: The provider class to register
47
- """
48
- cls._providers[name.lower()] = provider_class
1
+ from .base import HistoricalDataProvider
2
+ from .eastmoney import EastMoneyHistorical
3
+ from .eastmoney_direct import EastMoneyDirectHistorical
4
+ from .sina import SinaHistorical
5
+
6
+
7
+ class HistoricalDataFactory:
8
+ """
9
+ Factory class for creating historical data providers
10
+ """
11
+
12
+ _providers = {
13
+ "eastmoney": EastMoneyHistorical,
14
+ "eastmoney_direct": EastMoneyDirectHistorical,
15
+ "sina": SinaHistorical,
16
+ }
17
+
18
+ @classmethod
19
+ def get_provider(cls, provider_name: str, **kwargs) -> HistoricalDataProvider: # type: ignore
20
+ """
21
+ Get a historical data provider by name
22
+
23
+ Args:
24
+ provider_name: Name of the provider (e.g., 'eastmoney')
25
+ **kwargs: Additional arguments to pass to the provider's constructor
26
+
27
+ Returns:
28
+ HistoricalDataProvider: An instance of the requested provider
29
+
30
+ Raises:
31
+ ValueError: If the requested provider is not found
32
+ """
33
+ provider_class = cls._providers.get(provider_name.lower())
34
+ if not provider_class:
35
+ raise ValueError(f"Unknown historical data provider: {provider_name}")
36
+
37
+ return provider_class(**kwargs) # type: ignore
38
+
39
+ @classmethod
40
+ def register_provider(cls, name: str, provider_class: type) -> None:
41
+ """
42
+ Register a new historical data provider
43
+
44
+ Args:
45
+ name: Name to associate with this provider
46
+ provider_class: The provider class to register
47
+ """
48
+ cls._providers[name.lower()] = provider_class # type: ignore