akshare-one 0.3.6__py3-none-any.whl → 0.3.8__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.
- akshare_one/__init__.py +214 -214
- akshare_one/eastmoney/client.py +80 -80
- akshare_one/eastmoney/utils.py +102 -102
- akshare_one/indicators.py +395 -395
- akshare_one/modules/cache.py +27 -27
- akshare_one/modules/financial/base.py +27 -27
- akshare_one/modules/financial/eastmoney_direct.py +183 -183
- akshare_one/modules/financial/factory.py +46 -46
- akshare_one/modules/financial/sina.py +292 -292
- akshare_one/modules/historical/base.py +47 -47
- akshare_one/modules/historical/eastmoney.py +236 -236
- akshare_one/modules/historical/eastmoney_direct.py +78 -78
- akshare_one/modules/historical/factory.py +48 -48
- akshare_one/modules/historical/sina.py +250 -250
- akshare_one/modules/indicators/base.py +158 -158
- akshare_one/modules/indicators/factory.py +33 -33
- akshare_one/modules/indicators/simple.py +384 -230
- akshare_one/modules/indicators/talib.py +263 -263
- akshare_one/modules/info/base.py +25 -25
- akshare_one/modules/info/eastmoney.py +51 -51
- akshare_one/modules/info/factory.py +44 -44
- akshare_one/modules/insider/base.py +28 -28
- akshare_one/modules/insider/factory.py +44 -44
- akshare_one/modules/insider/xueqiu.py +110 -110
- akshare_one/modules/news/base.py +22 -22
- akshare_one/modules/news/eastmoney.py +43 -43
- akshare_one/modules/news/factory.py +44 -44
- akshare_one/modules/realtime/base.py +27 -27
- akshare_one/modules/realtime/eastmoney.py +53 -53
- akshare_one/modules/realtime/eastmoney_direct.py +36 -36
- akshare_one/modules/realtime/factory.py +48 -48
- akshare_one/modules/realtime/xueqiu.py +57 -57
- akshare_one/modules/utils.py +10 -10
- {akshare_one-0.3.6.dist-info → akshare_one-0.3.8.dist-info}/METADATA +74 -74
- akshare_one-0.3.8.dist-info/RECORD +39 -0
- {akshare_one-0.3.6.dist-info → akshare_one-0.3.8.dist-info}/licenses/LICENSE +21 -21
- akshare_one-0.3.6.dist-info/RECORD +0 -39
- {akshare_one-0.3.6.dist-info → akshare_one-0.3.8.dist-info}/WHEEL +0 -0
- {akshare_one-0.3.6.dist-info → akshare_one-0.3.8.dist-info}/top_level.txt +0 -0
@@ -1,78 +1,78 @@
|
|
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 .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,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:
|
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
|