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,102 +1,102 @@
1
- import pandas as pd
2
- from typing import Dict, Any
3
-
4
-
5
- def parse_kline_data(data: Dict[str, Any]) -> pd.DataFrame:
6
- """
7
- Parses K-line data from the API response into a pandas DataFrame.
8
- """
9
- klines = data.get("data", {}).get("klines", [])
10
- if not klines:
11
- return pd.DataFrame(
12
- columns=["timestamp", "open", "high", "low", "close", "volume"]
13
- )
14
-
15
- records = []
16
- for kline in klines:
17
- parts = kline.split(",")
18
- if len(parts) >= 6:
19
- records.append(
20
- {
21
- "timestamp": parts[0],
22
- "open": float(parts[1]),
23
- "close": float(parts[2]),
24
- "high": float(parts[3]),
25
- "low": float(parts[4]),
26
- "volume": int(parts[5]),
27
- }
28
- )
29
-
30
- df = pd.DataFrame(records)
31
- if not df.empty:
32
- df["timestamp"] = pd.to_datetime(df["timestamp"])
33
- df["timestamp"] = df["timestamp"].dt.tz_localize("Asia/Shanghai")
34
- df = df[["timestamp", "open", "high", "low", "close", "volume"]]
35
- return df
36
-
37
-
38
- def parse_realtime_data(data: Dict[str, Any]) -> pd.DataFrame:
39
- """
40
- Parses real-time quote data from the API response into a pandas DataFrame.
41
- """
42
- stock_data = data.get("data")
43
- if not stock_data:
44
- return pd.DataFrame()
45
-
46
- df = pd.DataFrame(
47
- [
48
- {
49
- "symbol": stock_data.get("f57"),
50
- "price": stock_data.get("f43"),
51
- "change": stock_data.get("f169"),
52
- "pct_change": stock_data.get("f170"),
53
- "volume": stock_data.get("f47"),
54
- "amount": stock_data.get("f48"),
55
- "open": stock_data.get("f46"),
56
- "high": stock_data.get("f44"),
57
- "low": stock_data.get("f45"),
58
- "prev_close": stock_data.get("f60"),
59
- }
60
- ]
61
- )
62
- df["timestamp"] = pd.Timestamp.now(tz="Asia/Shanghai")
63
- return df
64
-
65
-
66
- def resample_historical_data(
67
- df: pd.DataFrame, interval: str, multiplier: int
68
- ) -> pd.DataFrame:
69
- """
70
- Resamples historical data to a specified frequency.
71
- """
72
- if df.empty or multiplier <= 1:
73
- return df
74
-
75
- df = df.set_index("timestamp")
76
-
77
- freq_map = {
78
- "day": f"{multiplier}D",
79
- "week": f"{multiplier}W-MON",
80
- "month": f"{multiplier}MS",
81
- "year": f"{multiplier * 12}MS",
82
- }
83
- freq = freq_map.get(interval)
84
-
85
- if not freq:
86
- return df.reset_index()
87
-
88
- resampled = (
89
- df.resample(freq)
90
- .agg(
91
- {
92
- "open": "first",
93
- "high": "max",
94
- "low": "min",
95
- "close": "last",
96
- "volume": "sum",
97
- }
98
- )
99
- .dropna()
100
- )
101
-
102
- return resampled.reset_index()
1
+ import pandas as pd
2
+ from typing import Dict, Any
3
+
4
+
5
+ def parse_kline_data(data: Dict[str, Any]) -> pd.DataFrame:
6
+ """
7
+ Parses K-line data from the API response into a pandas DataFrame.
8
+ """
9
+ klines = data.get("data", {}).get("klines", [])
10
+ if not klines:
11
+ return pd.DataFrame(
12
+ columns=["timestamp", "open", "high", "low", "close", "volume"]
13
+ )
14
+
15
+ records = []
16
+ for kline in klines:
17
+ parts = kline.split(",")
18
+ if len(parts) >= 6:
19
+ records.append(
20
+ {
21
+ "timestamp": parts[0],
22
+ "open": float(parts[1]),
23
+ "close": float(parts[2]),
24
+ "high": float(parts[3]),
25
+ "low": float(parts[4]),
26
+ "volume": int(parts[5]),
27
+ }
28
+ )
29
+
30
+ df = pd.DataFrame(records)
31
+ if not df.empty:
32
+ df["timestamp"] = pd.to_datetime(df["timestamp"])
33
+ df["timestamp"] = df["timestamp"].dt.tz_localize("Asia/Shanghai")
34
+ df = df[["timestamp", "open", "high", "low", "close", "volume"]]
35
+ return df
36
+
37
+
38
+ def parse_realtime_data(data: Dict[str, Any]) -> pd.DataFrame:
39
+ """
40
+ Parses real-time quote data from the API response into a pandas DataFrame.
41
+ """
42
+ stock_data = data.get("data")
43
+ if not stock_data:
44
+ return pd.DataFrame()
45
+
46
+ df = pd.DataFrame(
47
+ [
48
+ {
49
+ "symbol": stock_data.get("f57"),
50
+ "price": stock_data.get("f43"),
51
+ "change": stock_data.get("f169"),
52
+ "pct_change": stock_data.get("f170"),
53
+ "volume": stock_data.get("f47"),
54
+ "amount": stock_data.get("f48"),
55
+ "open": stock_data.get("f46"),
56
+ "high": stock_data.get("f44"),
57
+ "low": stock_data.get("f45"),
58
+ "prev_close": stock_data.get("f60"),
59
+ }
60
+ ]
61
+ )
62
+ df["timestamp"] = pd.Timestamp.now(tz="Asia/Shanghai")
63
+ return df
64
+
65
+
66
+ def resample_historical_data(
67
+ df: pd.DataFrame, interval: str, multiplier: int
68
+ ) -> pd.DataFrame:
69
+ """
70
+ Resamples historical data to a specified frequency.
71
+ """
72
+ if df.empty or multiplier <= 1:
73
+ return df
74
+
75
+ df = df.set_index("timestamp")
76
+
77
+ freq_map = {
78
+ "day": f"{multiplier}D",
79
+ "week": f"{multiplier}W-MON",
80
+ "month": f"{multiplier}MS",
81
+ "year": f"{multiplier * 12}MS",
82
+ }
83
+ freq = freq_map.get(interval)
84
+
85
+ if not freq:
86
+ return df.reset_index()
87
+
88
+ resampled = (
89
+ df.resample(freq)
90
+ .agg(
91
+ {
92
+ "open": "first",
93
+ "high": "max",
94
+ "low": "min",
95
+ "close": "last",
96
+ "volume": "sum",
97
+ }
98
+ )
99
+ .dropna()
100
+ )
101
+
102
+ return resampled.reset_index()