lixinger-python 0.1.2__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 (74) hide show
  1. lixinger/__init__.py +79 -0
  2. lixinger/api/__init__.py +0 -0
  3. lixinger/api/base.py +94 -0
  4. lixinger/api/cn/__init__.py +0 -0
  5. lixinger/api/cn/company/__init__.py +34 -0
  6. lixinger/api/cn/company/announcement.py +74 -0
  7. lixinger/api/cn/company/candlestick.py +76 -0
  8. lixinger/api/cn/company/company.py +88 -0
  9. lixinger/api/cn/company/dividend.py +67 -0
  10. lixinger/api/cn/company/equity_change.py +84 -0
  11. lixinger/api/cn/company/fs/__init__.py +5 -0
  12. lixinger/api/cn/company/fs/non_financial.py +77 -0
  13. lixinger/api/cn/company/fundamental.py +228 -0
  14. lixinger/api/cn/company/indices.py +52 -0
  15. lixinger/api/cn/company/namespace.py +66 -0
  16. lixinger/api/cn/company/profile.py +66 -0
  17. lixinger/api/cn/fund/__init__.py +35 -0
  18. lixinger/api/cn/fund/announcement.py +89 -0
  19. lixinger/api/cn/fund/asset_combination.py +82 -0
  20. lixinger/api/cn/fund/asset_industry_combination.py +93 -0
  21. lixinger/api/cn/fund/candlestick.py +84 -0
  22. lixinger/api/cn/fund/fund.py +70 -0
  23. lixinger/api/cn/fund/profile.py +60 -0
  24. lixinger/api/cn/fund/shareholdings.py +86 -0
  25. lixinger/api/cn/index/__init__.py +32 -0
  26. lixinger/api/cn/index/candlestick.py +86 -0
  27. lixinger/api/cn/index/constituent_weightings.py +71 -0
  28. lixinger/api/cn/index/constituents.py +71 -0
  29. lixinger/api/cn/index/drawdown.py +87 -0
  30. lixinger/api/cn/index/fundamental.py +87 -0
  31. lixinger/api/cn/index/index.py +69 -0
  32. lixinger/api/cn/index/tracking_fund.py +71 -0
  33. lixinger/client.py +184 -0
  34. lixinger/config.py +72 -0
  35. lixinger/exceptions.py +22 -0
  36. lixinger/models/__init__.py +5 -0
  37. lixinger/models/cn/__init__.py +1 -0
  38. lixinger/models/cn/company/__init__.py +20 -0
  39. lixinger/models/cn/company/announcement.py +20 -0
  40. lixinger/models/cn/company/candlestick.py +24 -0
  41. lixinger/models/cn/company/company.py +33 -0
  42. lixinger/models/cn/company/dividend.py +25 -0
  43. lixinger/models/cn/company/equity_change.py +26 -0
  44. lixinger/models/cn/company/fs/__init__.py +5 -0
  45. lixinger/models/cn/company/fs/non_financial.py +20 -0
  46. lixinger/models/cn/company/fundamental.py +16 -0
  47. lixinger/models/cn/company/indices.py +17 -0
  48. lixinger/models/cn/fund/__init__.py +19 -0
  49. lixinger/models/cn/fund/announcement.py +21 -0
  50. lixinger/models/cn/fund/asset_combination.py +40 -0
  51. lixinger/models/cn/fund/asset_industry_combination.py +24 -0
  52. lixinger/models/cn/fund/candlestick.py +23 -0
  53. lixinger/models/cn/fund/fund.py +23 -0
  54. lixinger/models/cn/fund/profile.py +28 -0
  55. lixinger/models/cn/fund/shareholdings.py +21 -0
  56. lixinger/models/cn/index/__init__.py +19 -0
  57. lixinger/models/cn/index/candlestick.py +22 -0
  58. lixinger/models/cn/index/constituent_weightings.py +16 -0
  59. lixinger/models/cn/index/constituents.py +17 -0
  60. lixinger/models/cn/index/drawdown.py +16 -0
  61. lixinger/models/cn/index/fundamental.py +16 -0
  62. lixinger/models/cn/index/index.py +24 -0
  63. lixinger/models/cn/index/tracking_fund.py +19 -0
  64. lixinger/py.typed +0 -0
  65. lixinger/utils/__init__.py +0 -0
  66. lixinger/utils/api.py +15 -0
  67. lixinger/utils/dataframe.py +57 -0
  68. lixinger/utils/dict.py +22 -0
  69. lixinger/utils/rate_limiter.py +35 -0
  70. lixinger/utils/retry.py +31 -0
  71. lixinger_python-0.1.2.dist-info/METADATA +171 -0
  72. lixinger_python-0.1.2.dist-info/RECORD +74 -0
  73. lixinger_python-0.1.2.dist-info/WHEEL +4 -0
  74. lixinger_python-0.1.2.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,93 @@
1
+ """Fund asset industry combination API."""
2
+
3
+ from typing import Any
4
+
5
+ import pandas as pd
6
+
7
+ from lixinger.api.base import BaseAPI
8
+ from lixinger.models.cn.fund.asset_industry_combination import AssetIndustryCombination
9
+ from lixinger.utils.api import api
10
+ from lixinger.utils.dataframe import get_response_df
11
+
12
+
13
+ class FundAssetIndustryCombinationAPI(BaseAPI):
14
+ """Fund asset industry combination API."""
15
+
16
+ def get_asset_industry_combination(
17
+ self,
18
+ stock_code: str,
19
+ start_date: str,
20
+ end_date: str | None = None,
21
+ limit: int | None = None,
22
+ ) -> pd.DataFrame:
23
+ """获取按行业分类的股票投资组合数据.
24
+
25
+ API Endpoint: /cn/fund/asset-industry-combination
26
+ API Method: POST
27
+ Documentation: https://www.lixinger.com/open/api/doc?api-key=cn/fund/asset-industry-combination
28
+
29
+ Args:
30
+ stock_code: 基金代码
31
+ start_date: 开始日期 (YYYY-MM-DD)
32
+ end_date: 结束日期 (YYYY-MM-DD), 可选
33
+ limit: 限制返回的报告期数量, 可选
34
+
35
+ Returns:
36
+ DataFrame containing fund asset industry combination data
37
+
38
+ """
39
+ payload: dict[str, Any] = {
40
+ "stockCode": stock_code,
41
+ "startDate": start_date,
42
+ }
43
+ if end_date is not None:
44
+ payload["endDate"] = end_date
45
+ if limit is not None:
46
+ payload["limit"] = limit
47
+
48
+ data = self._request("POST", "/cn/fund/asset-industry-combination", json=payload)
49
+
50
+ # Flatten nested industry combination data
51
+ flattened_data = []
52
+ for item in data:
53
+ date = item["date"]
54
+ for aic in item.get("aic_cn", []):
55
+ record = {
56
+ "date": date,
57
+ "stock_code": stock_code,
58
+ **aic,
59
+ }
60
+ flattened_data.append(record)
61
+
62
+ return get_response_df(flattened_data, AssetIndustryCombination)
63
+
64
+
65
+ # Functional API instance
66
+ _api_instance = FundAssetIndustryCombinationAPI()
67
+
68
+
69
+ @api
70
+ def get_fund_asset_industry_combination(
71
+ stock_code: str,
72
+ start_date: str,
73
+ end_date: str | None = None,
74
+ limit: int | None = None,
75
+ ) -> pd.DataFrame:
76
+ """获取按行业分类的股票投资组合数据.
77
+
78
+ Args:
79
+ stock_code: 基金代码
80
+ start_date: 开始日期 (YYYY-MM-DD)
81
+ end_date: 结束日期 (YYYY-MM-DD), 可选
82
+ limit: 限制返回的报告期数量, 可选
83
+
84
+ Returns:
85
+ DataFrame containing fund asset industry combination data
86
+
87
+ """
88
+ return _api_instance.get_asset_industry_combination(
89
+ stock_code=stock_code,
90
+ start_date=start_date,
91
+ end_date=end_date,
92
+ limit=limit,
93
+ )
@@ -0,0 +1,84 @@
1
+ """Fund candlestick data APIs."""
2
+
3
+ from typing import Any, Literal
4
+
5
+ import pandas as pd
6
+
7
+ from lixinger.api.base import BaseAPI
8
+ from lixinger.models.cn.fund.candlestick import FundCandlestick
9
+ from lixinger.utils.api import api
10
+ from lixinger.utils.dataframe import get_response_df
11
+
12
+
13
+ class FundCandlestickAPI(BaseAPI):
14
+ """Fund candlestick data APIs."""
15
+
16
+ def get_candlestick(
17
+ self,
18
+ type: Literal["normal", "total_return"],
19
+ stock_code: str,
20
+ start_date: str,
21
+ end_date: str,
22
+ ) -> pd.DataFrame:
23
+ """获取基金K线数据.
24
+
25
+ API Endpoint: /cn/fund/candlestick
26
+ API Method: POST
27
+ Documentation: https://www.lixinger.com/open/api/doc?api-key=cn/fund/candlestick
28
+
29
+ Args:
30
+ type: K线类型 (normal, total_return)
31
+ stock_code: 基金代码
32
+ start_date: 开始日期 (YYYY-MM-DD)
33
+ end_date: 结束日期 (YYYY-MM-DD)
34
+
35
+ Returns:
36
+ DataFrame containing fund candlestick data
37
+
38
+ """
39
+ payload: dict[str, Any] = {
40
+ "type": type,
41
+ "stockCode": stock_code,
42
+ "startDate": start_date,
43
+ "endDate": end_date,
44
+ }
45
+
46
+ data = self._request("POST", "/cn/fund/candlestick", json=payload)
47
+ for item in data:
48
+ item["stockCode"] = stock_code
49
+ return get_response_df(data, FundCandlestick)
50
+
51
+
52
+ # Functional API instance
53
+ _api_instance = FundCandlestickAPI()
54
+
55
+
56
+ @api
57
+ def get_fund_candlestick(
58
+ type: Literal["normal", "total_return"],
59
+ stock_code: str,
60
+ start_date: str,
61
+ end_date: str,
62
+ ) -> pd.DataFrame:
63
+ """获取基金K线数据.
64
+
65
+ API Endpoint: /cn/fund/candlestick
66
+ API Method: POST
67
+ Documentation: https://www.lixinger.com/open/api/doc?api-key=cn/fund/candlestick
68
+
69
+ Args:
70
+ type: K线类型 (normal, total_return)
71
+ stock_code: 基金代码
72
+ start_date: 开始日期 (YYYY-MM-DD)
73
+ end_date: 结束日期 (YYYY-MM-DD)
74
+
75
+ Returns:
76
+ DataFrame containing fund candlestick data
77
+
78
+ """
79
+ return _api_instance.get_candlestick(
80
+ type=type,
81
+ stock_code=stock_code,
82
+ start_date=start_date,
83
+ end_date=end_date,
84
+ )
@@ -0,0 +1,70 @@
1
+ """Fund-related APIs.
2
+
3
+ This module provides APIs for querying fund information.
4
+ """
5
+
6
+ from typing import Any
7
+
8
+ import pandas as pd
9
+
10
+ from lixinger.api.base import BaseAPI
11
+ from lixinger.models.cn.fund import Fund
12
+ from lixinger.utils.api import api
13
+ from lixinger.utils.dataframe import get_response_df
14
+
15
+
16
+ class FundAPI(BaseAPI):
17
+ """Fund related APIs."""
18
+
19
+ def get_fund(
20
+ self,
21
+ stock_codes: list[str] | None = None,
22
+ page_index: int | None = None,
23
+ ) -> pd.DataFrame:
24
+ """获取基金信息.
25
+
26
+ API Endpoint: /cn/fund
27
+ API Method: POST
28
+ Documentation: https://www.lixinger.com/open/api/doc?api-key=cn/fund
29
+
30
+ Args:
31
+ stock_codes: 基金代码列表
32
+ page_index: 分页索引
33
+
34
+ Returns:
35
+ DataFrame containing fund information
36
+
37
+ """
38
+ payload: dict[str, Any] = {}
39
+ if stock_codes is not None:
40
+ payload["stockCodes"] = stock_codes
41
+ if page_index is not None:
42
+ payload["pageIndex"] = page_index
43
+
44
+ data = self._request("POST", "/cn/fund", json=payload)
45
+ return get_response_df(data, Fund)
46
+
47
+
48
+ # Functional API instance
49
+ _api_instance = FundAPI()
50
+
51
+
52
+ @api
53
+ def get_fund(
54
+ stock_codes: list[str] | None = None,
55
+ page_index: int | None = None,
56
+ ) -> pd.DataFrame:
57
+ """获取基金信息.
58
+
59
+ Args:
60
+ stock_codes: 基金代码列表
61
+ page_index: 分页索引
62
+
63
+ Returns:
64
+ DataFrame containing fund information
65
+
66
+ """
67
+ return _api_instance.get_fund(
68
+ stock_codes=stock_codes,
69
+ page_index=page_index,
70
+ )
@@ -0,0 +1,60 @@
1
+ """Fund profile APIs."""
2
+
3
+ from typing import Any
4
+
5
+ import pandas as pd
6
+
7
+ from lixinger.api.base import BaseAPI
8
+ from lixinger.models.cn.fund.profile import FundProfile
9
+ from lixinger.utils.api import api
10
+ from lixinger.utils.dataframe import get_response_df
11
+
12
+
13
+ class FundProfileAPI(BaseAPI):
14
+ """Fund profile APIs."""
15
+
16
+ def get_profile(
17
+ self,
18
+ stock_codes: list[str],
19
+ ) -> pd.DataFrame:
20
+ """获取基金基本概况.
21
+
22
+ API Endpoint: /cn/fund/profile
23
+ API Method: POST
24
+ Documentation: https://www.lixinger.com/open/api/doc?api-key=cn/fund/profile
25
+
26
+ Args:
27
+ stock_codes: 基金代码列表
28
+
29
+ Returns:
30
+ DataFrame containing fund profile information
31
+
32
+ """
33
+ payload: dict[str, Any] = {
34
+ "stockCodes": stock_codes,
35
+ }
36
+
37
+ data = self._request("POST", "/cn/fund/profile", json=payload)
38
+ return get_response_df(data, FundProfile)
39
+
40
+
41
+ # Functional API instance
42
+ _api_instance = FundProfileAPI()
43
+
44
+
45
+ @api
46
+ def get_fund_profile(
47
+ stock_codes: list[str],
48
+ ) -> pd.DataFrame:
49
+ """获取基金基本概况.
50
+
51
+ Args:
52
+ stock_codes: 基金代码列表
53
+
54
+ Returns:
55
+ DataFrame containing fund profile information
56
+
57
+ """
58
+ return _api_instance.get_profile(
59
+ stock_codes=stock_codes,
60
+ )
@@ -0,0 +1,86 @@
1
+ """Fund shareholdings API."""
2
+
3
+ from typing import Any
4
+
5
+ import pandas as pd
6
+
7
+ from lixinger.api.base import BaseAPI
8
+ from lixinger.models.cn.fund.shareholdings import Shareholding
9
+ from lixinger.utils.api import api
10
+ from lixinger.utils.dataframe import get_response_df
11
+
12
+
13
+ class FundShareholdingsAPI(BaseAPI):
14
+ """Fund shareholdings API."""
15
+
16
+ def get_shareholdings(
17
+ self,
18
+ stock_code: str,
19
+ start_date: str,
20
+ end_date: str | None = None,
21
+ limit: int | None = None,
22
+ ) -> pd.DataFrame:
23
+ """获取基金持仓数据.
24
+
25
+ API Endpoint: /cn/fund/shareholdings
26
+ API Method: POST
27
+ Documentation: https://www.lixinger.com/open/api/doc?api-key=cn/fund/shareholdings
28
+
29
+ Args:
30
+ stock_code: 基金代码
31
+ start_date: 开始日期 (YYYY-MM-DD)
32
+ end_date: 结束日期 (YYYY-MM-DD), 可选
33
+ limit: 限制返回的报告期数量, 可选
34
+
35
+ Returns:
36
+ DataFrame containing fund shareholdings data
37
+
38
+ """
39
+ payload: dict[str, Any] = {
40
+ "stockCode": stock_code,
41
+ "startDate": start_date,
42
+ }
43
+ if end_date is not None:
44
+ payload["endDate"] = end_date
45
+ if limit is not None:
46
+ payload["limit"] = limit
47
+
48
+ data = self._request("POST", "/cn/fund/shareholdings", json=payload)
49
+ for item in data:
50
+ item["fund_stock_code"] = stock_code
51
+ return get_response_df(data, Shareholding)
52
+
53
+
54
+ # Functional API instance
55
+ _api_instance = FundShareholdingsAPI()
56
+
57
+
58
+ @api
59
+ def get_fund_shareholdings(
60
+ stock_code: str,
61
+ start_date: str,
62
+ end_date: str | None = None,
63
+ limit: int | None = None,
64
+ ) -> pd.DataFrame:
65
+ """获取基金持仓数据.
66
+
67
+ API Endpoint: /cn/fund/shareholdings
68
+ API Method: POST
69
+ Documentation: https://www.lixinger.com/open/api/doc?api-key=cn/fund/shareholdings
70
+
71
+ Args:
72
+ stock_code: 基金代码
73
+ start_date: 开始日期 (YYYY-MM-DD)
74
+ end_date: 结束日期 (YYYY-MM-DD), 可选
75
+ limit: 限制返回的报告期数量, 可选
76
+
77
+ Returns:
78
+ DataFrame containing fund shareholdings data
79
+
80
+ """
81
+ return _api_instance.get_shareholdings(
82
+ stock_code=stock_code,
83
+ start_date=start_date,
84
+ end_date=end_date,
85
+ limit=limit,
86
+ )
@@ -0,0 +1,32 @@
1
+ """Index-related APIs."""
2
+
3
+ from lixinger.api.cn.index.candlestick import IndexCandlestickAPI, get_candlestick
4
+ from lixinger.api.cn.index.constituent_weightings import (
5
+ ConstituentWeightingsAPI,
6
+ get_constituent_weightings,
7
+ )
8
+ from lixinger.api.cn.index.constituents import ConstituentsAPI, get_constituents
9
+ from lixinger.api.cn.index.drawdown import DrawdownAPI, get_drawdown
10
+ from lixinger.api.cn.index.fundamental import (
11
+ IndexFundamentalAPI,
12
+ get_index_fundamental,
13
+ )
14
+ from lixinger.api.cn.index.index import IndexAPI, get_index
15
+ from lixinger.api.cn.index.tracking_fund import TrackingFundAPI, get_tracking_fund
16
+
17
+ __all__ = [
18
+ "IndexAPI",
19
+ "get_index",
20
+ "ConstituentsAPI",
21
+ "get_constituents",
22
+ "ConstituentWeightingsAPI",
23
+ "get_constituent_weightings",
24
+ "IndexCandlestickAPI",
25
+ "get_candlestick",
26
+ "DrawdownAPI",
27
+ "get_drawdown",
28
+ "IndexFundamentalAPI",
29
+ "get_index_fundamental",
30
+ "TrackingFundAPI",
31
+ "get_tracking_fund",
32
+ ]
@@ -0,0 +1,86 @@
1
+ """Index candlestick data APIs."""
2
+
3
+ from typing import Any, Literal
4
+
5
+ import pandas as pd
6
+
7
+ from lixinger.api.base import BaseAPI
8
+ from lixinger.models.cn.index.candlestick import IndexCandlestick
9
+ from lixinger.utils.api import api
10
+ from lixinger.utils.dataframe import get_response_df
11
+
12
+
13
+ class IndexCandlestickAPI(BaseAPI):
14
+ """Index candlestick data APIs."""
15
+
16
+ def get_candlestick(
17
+ self,
18
+ type: Literal["normal", "total_return"],
19
+ stock_code: str,
20
+ start_date: str,
21
+ end_date: str,
22
+ adjust_type: Literal["none", "qxw", "hxw"] | None = None,
23
+ ) -> pd.DataFrame:
24
+ """获取指数K线数据.
25
+
26
+ API Endpoint: /cn/index/candlestick
27
+ API Method: POST
28
+
29
+ Args:
30
+ type: K线类型 (normal, total_return)
31
+ stock_code: 指数代码
32
+ start_date: 开始日期 (YYYY-MM-DD)
33
+ end_date: 结束日期 (YYYY-MM-DD)
34
+ adjust_type: 复权类型 (none, qxw, hxw)
35
+
36
+ Returns:
37
+ DataFrame containing index candlestick data
38
+
39
+ """
40
+ payload: dict[str, Any] = {
41
+ "type": type,
42
+ "stockCode": stock_code,
43
+ "startDate": start_date,
44
+ "endDate": end_date,
45
+ }
46
+ if adjust_type is not None:
47
+ payload["adjustType"] = adjust_type
48
+
49
+ data = self._request("POST", "/cn/index/candlestick", json=payload)
50
+ for item in data:
51
+ item["stockCode"] = stock_code
52
+ return get_response_df(data, IndexCandlestick)
53
+
54
+
55
+ # Functional API instance
56
+ _api_instance = IndexCandlestickAPI()
57
+
58
+
59
+ @api
60
+ def get_candlestick(
61
+ type: Literal["normal", "total_return"],
62
+ stock_code: str,
63
+ start_date: str,
64
+ end_date: str,
65
+ adjust_type: Literal["none", "qxw", "hxw"] | None = None,
66
+ ) -> pd.DataFrame:
67
+ """获取指数K线数据.
68
+
69
+ Args:
70
+ type: K线类型 (normal, total_return)
71
+ stock_code: 指数代码
72
+ start_date: 开始日期 (YYYY-MM-DD)
73
+ end_date: 结束日期 (YYYY-MM-DD)
74
+ adjust_type: 复权类型 (none, qxw, hxw)
75
+
76
+ Returns:
77
+ DataFrame containing index candlestick data
78
+
79
+ """
80
+ return _api_instance.get_candlestick(
81
+ type=type,
82
+ stock_code=stock_code,
83
+ start_date=start_date,
84
+ end_date=end_date,
85
+ adjust_type=adjust_type,
86
+ )
@@ -0,0 +1,71 @@
1
+ """Index constituent weightings APIs."""
2
+
3
+ from typing import Any
4
+
5
+ import pandas as pd
6
+
7
+ from lixinger.api.base import BaseAPI
8
+ from lixinger.models.cn.index.constituent_weightings import ConstituentWeighting
9
+ from lixinger.utils.api import api
10
+ from lixinger.utils.dataframe import get_response_df
11
+
12
+
13
+ class ConstituentWeightingsAPI(BaseAPI):
14
+ """Index constituent weightings APIs."""
15
+
16
+ def get_constituent_weightings(
17
+ self,
18
+ stock_code: str,
19
+ start_date: str,
20
+ end_date: str,
21
+ ) -> pd.DataFrame:
22
+ """获取指数权重股及其权重.
23
+
24
+ API Endpoint: /cn/index/constituent-weightings
25
+ API Method: POST
26
+
27
+ Args:
28
+ stock_code: 指数代码
29
+ start_date: 开始日期 (YYYY-MM-DD)
30
+ end_date: 结束日期 (YYYY-MM-DD)
31
+
32
+ Returns:
33
+ DataFrame containing index constituent weightings information
34
+
35
+ """
36
+ payload: dict[str, Any] = {
37
+ "stockCode": stock_code,
38
+ "startDate": start_date,
39
+ "endDate": end_date,
40
+ }
41
+
42
+ data = self._request("POST", "/cn/index/constituent-weightings", json=payload)
43
+ return get_response_df(data, ConstituentWeighting)
44
+
45
+
46
+ # Functional API instance
47
+ _api_instance = ConstituentWeightingsAPI()
48
+
49
+
50
+ @api
51
+ def get_constituent_weightings(
52
+ stock_code: str,
53
+ start_date: str,
54
+ end_date: str,
55
+ ) -> pd.DataFrame:
56
+ """获取指数权重股及其权重.
57
+
58
+ Args:
59
+ stock_code: 指数代码
60
+ start_date: 开始日期 (YYYY-MM-DD)
61
+ end_date: 结束日期 (YYYY-MM-DD)
62
+
63
+ Returns:
64
+ DataFrame containing index constituent weightings information
65
+
66
+ """
67
+ return _api_instance.get_constituent_weightings(
68
+ stock_code=stock_code,
69
+ start_date=start_date,
70
+ end_date=end_date,
71
+ )
@@ -0,0 +1,71 @@
1
+ """Index constituents APIs."""
2
+
3
+ from typing import Any
4
+
5
+ import pandas as pd
6
+
7
+ from lixinger.api.base import BaseAPI
8
+ from lixinger.models.cn.index.constituents import Constituent
9
+ from lixinger.utils.api import api
10
+ from lixinger.utils.dataframe import get_response_df
11
+
12
+
13
+ class ConstituentsAPI(BaseAPI):
14
+ """Index constituents APIs."""
15
+
16
+ def get_constituents(
17
+ self,
18
+ stock_codes: list[str],
19
+ date: str,
20
+ ) -> pd.DataFrame:
21
+ """获取指数权重股.
22
+
23
+ API Endpoint: /cn/index/constituents
24
+ API Method: POST
25
+
26
+ Args:
27
+ stock_codes: 指数代码列表
28
+ date: 日期 (YYYY-MM-DD)
29
+
30
+ Returns:
31
+ DataFrame containing index constituents information
32
+
33
+ """
34
+ payload: dict[str, Any] = {
35
+ "stockCodes": stock_codes,
36
+ "date": date,
37
+ }
38
+
39
+ data = self._request("POST", "/cn/index/constituents", json=payload)
40
+ flattened_data = []
41
+ for item in data:
42
+ index_stock_code = item["stockCode"]
43
+ for constituent in item["constituents"]:
44
+ constituent["index_stock_code"] = index_stock_code
45
+ flattened_data.append(constituent)
46
+ return get_response_df(flattened_data, Constituent)
47
+
48
+
49
+ # Functional API instance
50
+ _api_instance = ConstituentsAPI()
51
+
52
+
53
+ @api
54
+ def get_constituents(
55
+ stock_codes: list[str],
56
+ date: str,
57
+ ) -> pd.DataFrame:
58
+ """获取指数权重股.
59
+
60
+ Args:
61
+ stock_codes: 指数代码列表
62
+ date: 日期 (YYYY-MM-DD)
63
+
64
+ Returns:
65
+ DataFrame containing index constituents information
66
+
67
+ """
68
+ return _api_instance.get_constituents(
69
+ stock_codes=stock_codes,
70
+ date=date,
71
+ )