lixinger-python 0.3.13__py3-none-any.whl → 0.3.15__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.
- lixinger/__init__.py +11 -0
- lixinger/api/base.py +20 -2
- lixinger/api/cn/industry/__init__.py +22 -0
- lixinger/api/cn/industry/fs/__init__.py +35 -0
- lixinger/api/cn/industry/fs/sw_2021/__init__.py +47 -0
- lixinger/api/cn/industry/fs/sw_2021/bank.py +133 -0
- lixinger/api/cn/industry/fs/sw_2021/hybrid.py +133 -0
- lixinger/api/cn/industry/fs/sw_2021/insurance.py +134 -0
- lixinger/api/cn/industry/fs/sw_2021/non_financial.py +133 -0
- lixinger/api/cn/industry/fs/sw_2021/security.py +134 -0
- lixinger/api/cn/industry/namespace.py +111 -1
- lixinger/client.py +28 -0
- lixinger/models/cn/industry/__init__.py +12 -0
- lixinger/models/cn/industry/fs/__init__.py +17 -0
- lixinger/models/cn/industry/fs/sw_2021/__init__.py +15 -0
- lixinger/models/cn/industry/fs/sw_2021/bank.py +20 -0
- lixinger/models/cn/industry/fs/sw_2021/hybrid.py +20 -0
- lixinger/models/cn/industry/fs/sw_2021/insurance.py +20 -0
- lixinger/models/cn/industry/fs/sw_2021/non_financial.py +20 -0
- lixinger/models/cn/industry/fs/sw_2021/security.py +20 -0
- lixinger/utils/retry.py +15 -4
- {lixinger_python-0.3.13.dist-info → lixinger_python-0.3.15.dist-info}/METADATA +1 -1
- {lixinger_python-0.3.13.dist-info → lixinger_python-0.3.15.dist-info}/RECORD +25 -11
- {lixinger_python-0.3.13.dist-info → lixinger_python-0.3.15.dist-info}/WHEEL +0 -0
- {lixinger_python-0.3.13.dist-info → lixinger_python-0.3.15.dist-info}/licenses/LICENSE +0 -0
lixinger/__init__.py
CHANGED
|
@@ -44,7 +44,12 @@ from lixinger.api.cn.index import (
|
|
|
44
44
|
)
|
|
45
45
|
from lixinger.api.cn.industry import (
|
|
46
46
|
get_industry_cni_margin_trading,
|
|
47
|
+
get_industry_sw_2021_bank_statements,
|
|
48
|
+
get_industry_sw_2021_hybrid_statements,
|
|
49
|
+
get_industry_sw_2021_insurance_statements,
|
|
47
50
|
get_industry_sw_2021_margin_trading,
|
|
51
|
+
get_industry_sw_2021_non_financial_statements,
|
|
52
|
+
get_industry_sw_2021_security_statements,
|
|
48
53
|
get_industry_sw_margin_trading,
|
|
49
54
|
)
|
|
50
55
|
from lixinger.api.macro import (
|
|
@@ -110,6 +115,12 @@ __all__ = [
|
|
|
110
115
|
"get_industry_sw_margin_trading",
|
|
111
116
|
"get_industry_sw_2021_margin_trading",
|
|
112
117
|
"get_industry_cni_margin_trading",
|
|
118
|
+
# Industry financial statements (申万2021版)
|
|
119
|
+
"get_industry_sw_2021_bank_statements",
|
|
120
|
+
"get_industry_sw_2021_hybrid_statements",
|
|
121
|
+
"get_industry_sw_2021_insurance_statements",
|
|
122
|
+
"get_industry_sw_2021_non_financial_statements",
|
|
123
|
+
"get_industry_sw_2021_security_statements",
|
|
113
124
|
# Macro
|
|
114
125
|
"get_national_debt",
|
|
115
126
|
"get_rmb_deposits",
|
lixinger/api/base.py
CHANGED
|
@@ -15,6 +15,12 @@ _global_rate_limiter = AsyncRateLimiter(max_requests=1000)
|
|
|
15
15
|
# Lazy initialization of global http client to avoid issues with proxy/config changes
|
|
16
16
|
_global_http_client: httpx.AsyncClient | None = None
|
|
17
17
|
|
|
18
|
+
# Fallback delay in seconds when a 429 response omits Retry-After. The Lixinger
|
|
19
|
+
# rate-limit window is 60s, so short exponential backoff (1/2/4s) almost always
|
|
20
|
+
# fires inside the same window and gets 429ed again. 15s gives the window room
|
|
21
|
+
# to age and burns fewer retry attempts on doomed requests.
|
|
22
|
+
DEFAULT_RATE_LIMIT_RETRY_AFTER = 15.0
|
|
23
|
+
|
|
18
24
|
|
|
19
25
|
def get_global_client() -> httpx.AsyncClient:
|
|
20
26
|
"""Get or create the global HTTP client."""
|
|
@@ -113,6 +119,10 @@ class BaseAPI:
|
|
|
113
119
|
|
|
114
120
|
if response.status_code == 429:
|
|
115
121
|
retry_after = _parse_retry_after(response.headers.get("Retry-After"))
|
|
122
|
+
# Server didn't tell us how long to wait — pick a delay long enough
|
|
123
|
+
# for the 60s rate-limit window to actually age.
|
|
124
|
+
if retry_after is None:
|
|
125
|
+
retry_after = DEFAULT_RATE_LIMIT_RETRY_AFTER
|
|
116
126
|
raise RateLimitError(
|
|
117
127
|
"Rate limit exceeded",
|
|
118
128
|
status_code=429,
|
|
@@ -133,7 +143,15 @@ class BaseAPI:
|
|
|
133
143
|
code = data.get("code")
|
|
134
144
|
message = data.get("message")
|
|
135
145
|
|
|
136
|
-
|
|
146
|
+
# code is the machine-readable success signal; message is human text.
|
|
147
|
+
# Lixinger returns code=1 for success even when there's no data
|
|
148
|
+
# (e.g. message="no data" on non-trading days or empty ranges) —
|
|
149
|
+
# treat any code=1 as success and normalize a missing/null payload
|
|
150
|
+
# to [] so downstream iteration and get_response_df both work.
|
|
151
|
+
if code != 1:
|
|
137
152
|
raise APIError(f"API returned error code {code}: {message}")
|
|
138
153
|
|
|
139
|
-
|
|
154
|
+
payload = data.get("data")
|
|
155
|
+
if payload is None:
|
|
156
|
+
return []
|
|
157
|
+
return payload
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
"""Industry-related APIs."""
|
|
2
2
|
|
|
3
|
+
from lixinger.api.cn.industry.fs import (
|
|
4
|
+
IndustrySw2021BankStatementAPI,
|
|
5
|
+
IndustrySw2021HybridStatementAPI,
|
|
6
|
+
IndustrySw2021InsuranceStatementAPI,
|
|
7
|
+
IndustrySw2021NonFinancialStatementAPI,
|
|
8
|
+
IndustrySw2021SecurityStatementAPI,
|
|
9
|
+
get_industry_sw_2021_bank_statements,
|
|
10
|
+
get_industry_sw_2021_hybrid_statements,
|
|
11
|
+
get_industry_sw_2021_insurance_statements,
|
|
12
|
+
get_industry_sw_2021_non_financial_statements,
|
|
13
|
+
get_industry_sw_2021_security_statements,
|
|
14
|
+
)
|
|
3
15
|
from lixinger.api.cn.industry.margin_trading import (
|
|
4
16
|
IndustryCniMarginTradingAPI,
|
|
5
17
|
IndustrySw2021MarginTradingAPI,
|
|
@@ -12,10 +24,20 @@ from lixinger.api.cn.industry.margin_trading import (
|
|
|
12
24
|
__all__ = [
|
|
13
25
|
# API Classes
|
|
14
26
|
"IndustryCniMarginTradingAPI",
|
|
27
|
+
"IndustrySw2021BankStatementAPI",
|
|
28
|
+
"IndustrySw2021HybridStatementAPI",
|
|
29
|
+
"IndustrySw2021InsuranceStatementAPI",
|
|
15
30
|
"IndustrySw2021MarginTradingAPI",
|
|
31
|
+
"IndustrySw2021NonFinancialStatementAPI",
|
|
32
|
+
"IndustrySw2021SecurityStatementAPI",
|
|
16
33
|
"IndustrySwMarginTradingAPI",
|
|
17
34
|
# Functional APIs
|
|
18
35
|
"get_industry_cni_margin_trading",
|
|
36
|
+
"get_industry_sw_2021_bank_statements",
|
|
37
|
+
"get_industry_sw_2021_hybrid_statements",
|
|
38
|
+
"get_industry_sw_2021_insurance_statements",
|
|
19
39
|
"get_industry_sw_2021_margin_trading",
|
|
40
|
+
"get_industry_sw_2021_non_financial_statements",
|
|
41
|
+
"get_industry_sw_2021_security_statements",
|
|
20
42
|
"get_industry_sw_margin_trading",
|
|
21
43
|
]
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Industry financial statement APIs.
|
|
2
|
+
|
|
3
|
+
This module provides access to industry financial statement APIs by
|
|
4
|
+
industry classification system:
|
|
5
|
+
|
|
6
|
+
- sw_2021: 申万2021版行业财报数据
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from lixinger.api.cn.industry.fs.sw_2021 import (
|
|
10
|
+
IndustrySw2021BankStatementAPI,
|
|
11
|
+
IndustrySw2021HybridStatementAPI,
|
|
12
|
+
IndustrySw2021InsuranceStatementAPI,
|
|
13
|
+
IndustrySw2021NonFinancialStatementAPI,
|
|
14
|
+
IndustrySw2021SecurityStatementAPI,
|
|
15
|
+
get_industry_sw_2021_bank_statements,
|
|
16
|
+
get_industry_sw_2021_hybrid_statements,
|
|
17
|
+
get_industry_sw_2021_insurance_statements,
|
|
18
|
+
get_industry_sw_2021_non_financial_statements,
|
|
19
|
+
get_industry_sw_2021_security_statements,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
# API Classes
|
|
24
|
+
"IndustrySw2021BankStatementAPI",
|
|
25
|
+
"IndustrySw2021HybridStatementAPI",
|
|
26
|
+
"IndustrySw2021InsuranceStatementAPI",
|
|
27
|
+
"IndustrySw2021NonFinancialStatementAPI",
|
|
28
|
+
"IndustrySw2021SecurityStatementAPI",
|
|
29
|
+
# Functional APIs
|
|
30
|
+
"get_industry_sw_2021_bank_statements",
|
|
31
|
+
"get_industry_sw_2021_hybrid_statements",
|
|
32
|
+
"get_industry_sw_2021_insurance_statements",
|
|
33
|
+
"get_industry_sw_2021_non_financial_statements",
|
|
34
|
+
"get_industry_sw_2021_security_statements",
|
|
35
|
+
]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""申万2021版行业财报数据 API.
|
|
2
|
+
|
|
3
|
+
This module provides access to industry financial statement APIs for the
|
|
4
|
+
Shenwan 2021 classification, grouped by industry sample type:
|
|
5
|
+
|
|
6
|
+
- bank: 银行类行业财报
|
|
7
|
+
- hybrid: 混合型行业财报(同时包含金融和非金融公司)
|
|
8
|
+
- insurance: 保险类行业财报
|
|
9
|
+
- non_financial: 非金融类行业财报
|
|
10
|
+
- security: 证券类行业财报
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from lixinger.api.cn.industry.fs.sw_2021.bank import (
|
|
14
|
+
IndustrySw2021BankStatementAPI,
|
|
15
|
+
get_industry_sw_2021_bank_statements,
|
|
16
|
+
)
|
|
17
|
+
from lixinger.api.cn.industry.fs.sw_2021.hybrid import (
|
|
18
|
+
IndustrySw2021HybridStatementAPI,
|
|
19
|
+
get_industry_sw_2021_hybrid_statements,
|
|
20
|
+
)
|
|
21
|
+
from lixinger.api.cn.industry.fs.sw_2021.insurance import (
|
|
22
|
+
IndustrySw2021InsuranceStatementAPI,
|
|
23
|
+
get_industry_sw_2021_insurance_statements,
|
|
24
|
+
)
|
|
25
|
+
from lixinger.api.cn.industry.fs.sw_2021.non_financial import (
|
|
26
|
+
IndustrySw2021NonFinancialStatementAPI,
|
|
27
|
+
get_industry_sw_2021_non_financial_statements,
|
|
28
|
+
)
|
|
29
|
+
from lixinger.api.cn.industry.fs.sw_2021.security import (
|
|
30
|
+
IndustrySw2021SecurityStatementAPI,
|
|
31
|
+
get_industry_sw_2021_security_statements,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
__all__ = [
|
|
35
|
+
# API Classes
|
|
36
|
+
"IndustrySw2021BankStatementAPI",
|
|
37
|
+
"IndustrySw2021HybridStatementAPI",
|
|
38
|
+
"IndustrySw2021InsuranceStatementAPI",
|
|
39
|
+
"IndustrySw2021NonFinancialStatementAPI",
|
|
40
|
+
"IndustrySw2021SecurityStatementAPI",
|
|
41
|
+
# Functional APIs
|
|
42
|
+
"get_industry_sw_2021_bank_statements",
|
|
43
|
+
"get_industry_sw_2021_hybrid_statements",
|
|
44
|
+
"get_industry_sw_2021_insurance_statements",
|
|
45
|
+
"get_industry_sw_2021_non_financial_statements",
|
|
46
|
+
"get_industry_sw_2021_security_statements",
|
|
47
|
+
]
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""申万2021版行业 - 银行类财报数据 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.industry.fs.sw_2021.bank import IndustrySw2021BankStatementSchema
|
|
9
|
+
from lixinger.utils.api import api
|
|
10
|
+
from lixinger.utils.dataframe import get_response_df
|
|
11
|
+
from lixinger.utils.dict import flatten_dict
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class IndustrySw2021BankStatementAPI(BaseAPI):
|
|
15
|
+
"""申万2021版银行类行业财报数据 API."""
|
|
16
|
+
|
|
17
|
+
async def get_bank_statements( # noqa: PLR0913
|
|
18
|
+
self,
|
|
19
|
+
stock_codes: list[str],
|
|
20
|
+
metrics: list[str],
|
|
21
|
+
date: str | None = None,
|
|
22
|
+
start_date: str | None = None,
|
|
23
|
+
end_date: str | None = None,
|
|
24
|
+
limit: int | None = None,
|
|
25
|
+
) -> pd.DataFrame:
|
|
26
|
+
"""获取申万2021版银行类行业的财报数据.
|
|
27
|
+
|
|
28
|
+
API Endpoint: /cn/industry/fs/sw_2021/bank
|
|
29
|
+
API Method: POST
|
|
30
|
+
API Doc: https://www.lixinger.com/open/api/doc?api-key=cn/industry/fs/sw_2021/bank
|
|
31
|
+
|
|
32
|
+
获取申万2021年版银行类大陆行业(样本仅包含银行)的财务数据,包括利润表、
|
|
33
|
+
资产负债表、现金流量表、财务指标。注意该行业划分多从2021年开始,
|
|
34
|
+
更早的时间可能没有数据。
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
stock_codes: 行业代码列表,长度 >=1 且 <=100。当传入 start_date
|
|
38
|
+
时只能传入一个行业代码。
|
|
39
|
+
metrics: 指标列表,格式为
|
|
40
|
+
``[granularity].[tableName].[fieldName].[expressionCalculateType]``,
|
|
41
|
+
例如 ``"q.ps.oi.t"``。当 stock_codes 长度大于 1 时最多 48 个
|
|
42
|
+
指标;等于 1 时最多 128 个指标。
|
|
43
|
+
date: 日期 (YYYY-MM-DD),与 start_date 二选一。支持 ``"latest"``。
|
|
44
|
+
start_date: 开始日期 (YYYY-MM-DD),与 date 二选一。开始和结束的时间
|
|
45
|
+
间隔不超过 10 年。
|
|
46
|
+
end_date: 结束日期 (YYYY-MM-DD),可选,默认上周一。
|
|
47
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
包含申万2021版银行类行业财报数据的 DataFrame。
|
|
51
|
+
|
|
52
|
+
Example:
|
|
53
|
+
获取申万2021版银行行业的营业收入::
|
|
54
|
+
|
|
55
|
+
from lixinger import AsyncLixingerClient
|
|
56
|
+
|
|
57
|
+
async with AsyncLixingerClient() as client:
|
|
58
|
+
df = await client.industry.fs.sw_2021.bank.get_bank_statements(
|
|
59
|
+
stock_codes=["480000"],
|
|
60
|
+
metrics=["q.ps.oi.t"],
|
|
61
|
+
date="2026-03-31",
|
|
62
|
+
)
|
|
63
|
+
print(df)
|
|
64
|
+
|
|
65
|
+
"""
|
|
66
|
+
payload: dict[str, Any] = {
|
|
67
|
+
"stockCodes": stock_codes,
|
|
68
|
+
"metricsList": metrics,
|
|
69
|
+
}
|
|
70
|
+
if date is not None:
|
|
71
|
+
payload["date"] = date
|
|
72
|
+
if start_date is not None:
|
|
73
|
+
payload["startDate"] = start_date
|
|
74
|
+
if end_date is not None:
|
|
75
|
+
payload["endDate"] = end_date
|
|
76
|
+
if limit is not None:
|
|
77
|
+
payload["limit"] = limit
|
|
78
|
+
|
|
79
|
+
data = await self._request("POST", "/cn/industry/fs/sw_2021/bank", json=payload)
|
|
80
|
+
|
|
81
|
+
# Flatten nested metrics (e.g. {"q": {"ps": {"oi": {"t": ...}}}})
|
|
82
|
+
flattened_data = [flatten_dict(item) for item in data]
|
|
83
|
+
|
|
84
|
+
return get_response_df(flattened_data, IndustrySw2021BankStatementSchema)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# Functional API instance
|
|
88
|
+
_api_instance = IndustrySw2021BankStatementAPI()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@api
|
|
92
|
+
async def get_industry_sw_2021_bank_statements( # noqa: PLR0913
|
|
93
|
+
stock_codes: list[str],
|
|
94
|
+
metrics: list[str],
|
|
95
|
+
date: str | None = None,
|
|
96
|
+
start_date: str | None = None,
|
|
97
|
+
end_date: str | None = None,
|
|
98
|
+
limit: int | None = None,
|
|
99
|
+
) -> pd.DataFrame:
|
|
100
|
+
"""获取申万2021版银行类行业的财报数据.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
stock_codes: 行业代码列表。
|
|
104
|
+
metrics: 指标列表。
|
|
105
|
+
date: 日期 (YYYY-MM-DD),与 start_date 二选一。
|
|
106
|
+
start_date: 开始日期 (YYYY-MM-DD),与 date 二选一。
|
|
107
|
+
end_date: 结束日期 (YYYY-MM-DD),可选。
|
|
108
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
包含申万2021版银行类行业财报数据的 DataFrame。
|
|
112
|
+
|
|
113
|
+
Example:
|
|
114
|
+
获取申万2021版银行行业的营业收入::
|
|
115
|
+
|
|
116
|
+
from lixinger import get_industry_sw_2021_bank_statements
|
|
117
|
+
|
|
118
|
+
df = await get_industry_sw_2021_bank_statements(
|
|
119
|
+
stock_codes=["480000"],
|
|
120
|
+
metrics=["q.ps.oi.t"],
|
|
121
|
+
date="2026-03-31",
|
|
122
|
+
)
|
|
123
|
+
print(df)
|
|
124
|
+
|
|
125
|
+
"""
|
|
126
|
+
return await _api_instance.get_bank_statements(
|
|
127
|
+
stock_codes=stock_codes,
|
|
128
|
+
metrics=metrics,
|
|
129
|
+
date=date,
|
|
130
|
+
start_date=start_date,
|
|
131
|
+
end_date=end_date,
|
|
132
|
+
limit=limit,
|
|
133
|
+
)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""申万2021版行业 - 混合型财报数据 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.industry.fs.sw_2021.hybrid import IndustrySw2021HybridStatementSchema
|
|
9
|
+
from lixinger.utils.api import api
|
|
10
|
+
from lixinger.utils.dataframe import get_response_df
|
|
11
|
+
from lixinger.utils.dict import flatten_dict
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class IndustrySw2021HybridStatementAPI(BaseAPI):
|
|
15
|
+
"""申万2021版混合型行业财报数据 API."""
|
|
16
|
+
|
|
17
|
+
async def get_hybrid_statements( # noqa: PLR0913
|
|
18
|
+
self,
|
|
19
|
+
stock_codes: list[str],
|
|
20
|
+
metrics: list[str],
|
|
21
|
+
date: str | None = None,
|
|
22
|
+
start_date: str | None = None,
|
|
23
|
+
end_date: str | None = None,
|
|
24
|
+
limit: int | None = None,
|
|
25
|
+
) -> pd.DataFrame:
|
|
26
|
+
"""获取申万2021版混合型行业的财报数据.
|
|
27
|
+
|
|
28
|
+
API Endpoint: /cn/industry/fs/sw_2021/hybrid
|
|
29
|
+
API Method: POST
|
|
30
|
+
API Doc: https://www.lixinger.com/open/api/doc?api-key=cn/industry/fs/sw_2021/hybrid
|
|
31
|
+
|
|
32
|
+
获取申万2021年版混合型行业(样本同时包含金融公司和非金融公司)的财务数据,
|
|
33
|
+
包括利润表、资产负债表、现金流量表、财务指标。注意该行业划分多从2021年
|
|
34
|
+
开始,更早的时间可能没有数据。
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
stock_codes: 行业代码列表,长度 >=1 且 <=100。当传入 start_date
|
|
38
|
+
时只能传入一个行业代码。
|
|
39
|
+
metrics: 指标列表,格式为
|
|
40
|
+
``[granularity].[tableName].[fieldName].[expressionCalculateType]``,
|
|
41
|
+
例如 ``"q.ps.toi.t"``。当 stock_codes 长度大于 1 时最多 48 个
|
|
42
|
+
指标;等于 1 时最多 128 个指标。
|
|
43
|
+
date: 日期 (YYYY-MM-DD),与 start_date 二选一。支持 ``"latest"``。
|
|
44
|
+
start_date: 开始日期 (YYYY-MM-DD),与 date 二选一。开始和结束的时间
|
|
45
|
+
间隔不超过 10 年。
|
|
46
|
+
end_date: 结束日期 (YYYY-MM-DD),可选,默认上周一。
|
|
47
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
包含申万2021版混合型行业财报数据的 DataFrame。
|
|
51
|
+
|
|
52
|
+
Example:
|
|
53
|
+
获取申万2021版非银金融行业的营业总收入::
|
|
54
|
+
|
|
55
|
+
from lixinger import AsyncLixingerClient
|
|
56
|
+
|
|
57
|
+
async with AsyncLixingerClient() as client:
|
|
58
|
+
df = await client.industry.fs.sw_2021.hybrid.get_hybrid_statements(
|
|
59
|
+
stock_codes=["490000"],
|
|
60
|
+
metrics=["q.ps.toi.t"],
|
|
61
|
+
date="2026-03-31",
|
|
62
|
+
)
|
|
63
|
+
print(df)
|
|
64
|
+
|
|
65
|
+
"""
|
|
66
|
+
payload: dict[str, Any] = {
|
|
67
|
+
"stockCodes": stock_codes,
|
|
68
|
+
"metricsList": metrics,
|
|
69
|
+
}
|
|
70
|
+
if date is not None:
|
|
71
|
+
payload["date"] = date
|
|
72
|
+
if start_date is not None:
|
|
73
|
+
payload["startDate"] = start_date
|
|
74
|
+
if end_date is not None:
|
|
75
|
+
payload["endDate"] = end_date
|
|
76
|
+
if limit is not None:
|
|
77
|
+
payload["limit"] = limit
|
|
78
|
+
|
|
79
|
+
data = await self._request("POST", "/cn/industry/fs/sw_2021/hybrid", json=payload)
|
|
80
|
+
|
|
81
|
+
# Flatten nested metrics (e.g. {"q": {"ps": {"toi": {"t": ...}}}})
|
|
82
|
+
flattened_data = [flatten_dict(item) for item in data]
|
|
83
|
+
|
|
84
|
+
return get_response_df(flattened_data, IndustrySw2021HybridStatementSchema)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# Functional API instance
|
|
88
|
+
_api_instance = IndustrySw2021HybridStatementAPI()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@api
|
|
92
|
+
async def get_industry_sw_2021_hybrid_statements( # noqa: PLR0913
|
|
93
|
+
stock_codes: list[str],
|
|
94
|
+
metrics: list[str],
|
|
95
|
+
date: str | None = None,
|
|
96
|
+
start_date: str | None = None,
|
|
97
|
+
end_date: str | None = None,
|
|
98
|
+
limit: int | None = None,
|
|
99
|
+
) -> pd.DataFrame:
|
|
100
|
+
"""获取申万2021版混合型行业的财报数据.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
stock_codes: 行业代码列表。
|
|
104
|
+
metrics: 指标列表。
|
|
105
|
+
date: 日期 (YYYY-MM-DD),与 start_date 二选一。
|
|
106
|
+
start_date: 开始日期 (YYYY-MM-DD),与 date 二选一。
|
|
107
|
+
end_date: 结束日期 (YYYY-MM-DD),可选。
|
|
108
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
包含申万2021版混合型行业财报数据的 DataFrame。
|
|
112
|
+
|
|
113
|
+
Example:
|
|
114
|
+
获取申万2021版非银金融行业的营业总收入::
|
|
115
|
+
|
|
116
|
+
from lixinger import get_industry_sw_2021_hybrid_statements
|
|
117
|
+
|
|
118
|
+
df = await get_industry_sw_2021_hybrid_statements(
|
|
119
|
+
stock_codes=["490000"],
|
|
120
|
+
metrics=["q.ps.toi.t"],
|
|
121
|
+
date="2026-03-31",
|
|
122
|
+
)
|
|
123
|
+
print(df)
|
|
124
|
+
|
|
125
|
+
"""
|
|
126
|
+
return await _api_instance.get_hybrid_statements(
|
|
127
|
+
stock_codes=stock_codes,
|
|
128
|
+
metrics=metrics,
|
|
129
|
+
date=date,
|
|
130
|
+
start_date=start_date,
|
|
131
|
+
end_date=end_date,
|
|
132
|
+
limit=limit,
|
|
133
|
+
)
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""申万2021版行业 - 保险类财报数据 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.industry.fs.sw_2021.insurance import IndustrySw2021InsuranceStatementSchema
|
|
9
|
+
from lixinger.utils.api import api
|
|
10
|
+
from lixinger.utils.dataframe import get_response_df
|
|
11
|
+
from lixinger.utils.dict import flatten_dict
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class IndustrySw2021InsuranceStatementAPI(BaseAPI):
|
|
15
|
+
"""申万2021版保险类行业财报数据 API."""
|
|
16
|
+
|
|
17
|
+
async def get_insurance_statements( # noqa: PLR0913
|
|
18
|
+
self,
|
|
19
|
+
stock_codes: list[str],
|
|
20
|
+
metrics: list[str],
|
|
21
|
+
date: str | None = None,
|
|
22
|
+
start_date: str | None = None,
|
|
23
|
+
end_date: str | None = None,
|
|
24
|
+
limit: int | None = None,
|
|
25
|
+
) -> pd.DataFrame:
|
|
26
|
+
"""获取申万2021版保险类行业的财报数据.
|
|
27
|
+
|
|
28
|
+
API Endpoint: /cn/industry/fs/sw_2021/insurance
|
|
29
|
+
API Method: POST
|
|
30
|
+
API Doc: https://www.lixinger.com/open/api/doc?api-key=cn/industry/fs/sw_2021/insurance
|
|
31
|
+
|
|
32
|
+
获取申万2021年版保险类行业(样本仅包含保险公司)的财务数据,包括利润表、
|
|
33
|
+
资产负债表、现金流量表、财务指标(含内含价值、寿险及健康险业务内含价值、
|
|
34
|
+
新业务价值等保险行业特有指标)。注意该行业划分多从2021年开始,
|
|
35
|
+
更早的时间可能没有数据。
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
stock_codes: 行业代码列表,长度 >=1 且 <=100。当传入 start_date
|
|
39
|
+
时只能传入一个行业代码。
|
|
40
|
+
metrics: 指标列表,格式为
|
|
41
|
+
``[granularity].[tableName].[fieldName].[expressionCalculateType]``,
|
|
42
|
+
例如 ``"q.ps.oi.t"``。当 stock_codes 长度大于 1 时最多 48 个
|
|
43
|
+
指标;等于 1 时最多 128 个指标。
|
|
44
|
+
date: 日期 (YYYY-MM-DD),与 start_date 二选一。支持 ``"latest"``。
|
|
45
|
+
start_date: 开始日期 (YYYY-MM-DD),与 date 二选一。开始和结束的时间
|
|
46
|
+
间隔不超过 10 年。
|
|
47
|
+
end_date: 结束日期 (YYYY-MM-DD),可选,默认上周一。
|
|
48
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
包含申万2021版保险类行业财报数据的 DataFrame。
|
|
52
|
+
|
|
53
|
+
Example:
|
|
54
|
+
获取申万2021版保险行业的营业收入::
|
|
55
|
+
|
|
56
|
+
from lixinger import AsyncLixingerClient
|
|
57
|
+
|
|
58
|
+
async with AsyncLixingerClient() as client:
|
|
59
|
+
df = await client.industry.fs.sw_2021.insurance.get_insurance_statements(
|
|
60
|
+
stock_codes=["490200"],
|
|
61
|
+
metrics=["q.ps.oi.t"],
|
|
62
|
+
date="2026-03-31",
|
|
63
|
+
)
|
|
64
|
+
print(df)
|
|
65
|
+
|
|
66
|
+
"""
|
|
67
|
+
payload: dict[str, Any] = {
|
|
68
|
+
"stockCodes": stock_codes,
|
|
69
|
+
"metricsList": metrics,
|
|
70
|
+
}
|
|
71
|
+
if date is not None:
|
|
72
|
+
payload["date"] = date
|
|
73
|
+
if start_date is not None:
|
|
74
|
+
payload["startDate"] = start_date
|
|
75
|
+
if end_date is not None:
|
|
76
|
+
payload["endDate"] = end_date
|
|
77
|
+
if limit is not None:
|
|
78
|
+
payload["limit"] = limit
|
|
79
|
+
|
|
80
|
+
data = await self._request("POST", "/cn/industry/fs/sw_2021/insurance", json=payload)
|
|
81
|
+
|
|
82
|
+
# Flatten nested metrics
|
|
83
|
+
flattened_data = [flatten_dict(item) for item in data]
|
|
84
|
+
|
|
85
|
+
return get_response_df(flattened_data, IndustrySw2021InsuranceStatementSchema)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# Functional API instance
|
|
89
|
+
_api_instance = IndustrySw2021InsuranceStatementAPI()
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@api
|
|
93
|
+
async def get_industry_sw_2021_insurance_statements( # noqa: PLR0913
|
|
94
|
+
stock_codes: list[str],
|
|
95
|
+
metrics: list[str],
|
|
96
|
+
date: str | None = None,
|
|
97
|
+
start_date: str | None = None,
|
|
98
|
+
end_date: str | None = None,
|
|
99
|
+
limit: int | None = None,
|
|
100
|
+
) -> pd.DataFrame:
|
|
101
|
+
"""获取申万2021版保险类行业的财报数据.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
stock_codes: 行业代码列表。
|
|
105
|
+
metrics: 指标列表。
|
|
106
|
+
date: 日期 (YYYY-MM-DD),与 start_date 二选一。
|
|
107
|
+
start_date: 开始日期 (YYYY-MM-DD),与 date 二选一。
|
|
108
|
+
end_date: 结束日期 (YYYY-MM-DD),可选。
|
|
109
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
包含申万2021版保险类行业财报数据的 DataFrame。
|
|
113
|
+
|
|
114
|
+
Example:
|
|
115
|
+
获取申万2021版保险行业的营业收入::
|
|
116
|
+
|
|
117
|
+
from lixinger import get_industry_sw_2021_insurance_statements
|
|
118
|
+
|
|
119
|
+
df = await get_industry_sw_2021_insurance_statements(
|
|
120
|
+
stock_codes=["490200"],
|
|
121
|
+
metrics=["q.ps.oi.t"],
|
|
122
|
+
date="2026-03-31",
|
|
123
|
+
)
|
|
124
|
+
print(df)
|
|
125
|
+
|
|
126
|
+
"""
|
|
127
|
+
return await _api_instance.get_insurance_statements(
|
|
128
|
+
stock_codes=stock_codes,
|
|
129
|
+
metrics=metrics,
|
|
130
|
+
date=date,
|
|
131
|
+
start_date=start_date,
|
|
132
|
+
end_date=end_date,
|
|
133
|
+
limit=limit,
|
|
134
|
+
)
|