lixinger-python 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.
- lixinger/__init__.py +20 -1
- lixinger/api/cn/company/fs/__init__.py +44 -3
- lixinger/api/cn/company/fs/bank.py +132 -0
- lixinger/api/cn/company/fs/insurance.py +132 -0
- lixinger/api/cn/company/fs/non_financial.py +8 -2
- lixinger/api/cn/company/fs/other_financial.py +131 -0
- lixinger/api/cn/company/fs/security.py +132 -0
- lixinger/api/cn/company/namespace.py +46 -4
- lixinger/api/cn/index/__init__.py +19 -0
- lixinger/api/cn/index/fs/__init__.py +38 -0
- lixinger/api/cn/index/fs/bank.py +130 -0
- lixinger/api/cn/index/fs/hybrid.py +130 -0
- lixinger/api/cn/index/fs/non_financial.py +130 -0
- lixinger/api/cn/index/fs/security.py +130 -0
- lixinger/api/cn/index/namespace.py +57 -0
- lixinger/client.py +32 -0
- lixinger/models/cn/company/fs/__init__.py +11 -1
- lixinger/models/cn/company/fs/bank.py +20 -0
- lixinger/models/cn/company/fs/insurance.py +20 -0
- lixinger/models/cn/company/fs/other_financial.py +20 -0
- lixinger/models/cn/company/fs/security.py +20 -0
- lixinger/models/cn/index/__init__.py +11 -0
- lixinger/models/cn/index/fs/__init__.py +13 -0
- lixinger/models/cn/index/fs/bank.py +20 -0
- lixinger/models/cn/index/fs/hybrid.py +20 -0
- lixinger/models/cn/index/fs/non_financial.py +20 -0
- lixinger/models/cn/index/fs/security.py +20 -0
- {lixinger_python-0.3.6.dist-info → lixinger_python-0.3.8.dist-info}/METADATA +1 -1
- {lixinger_python-0.3.6.dist-info → lixinger_python-0.3.8.dist-info}/RECORD +31 -13
- {lixinger_python-0.3.6.dist-info → lixinger_python-0.3.8.dist-info}/WHEEL +0 -0
- {lixinger_python-0.3.6.dist-info → lixinger_python-0.3.8.dist-info}/licenses/LICENSE +0 -0
lixinger/__init__.py
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
from lixinger.api.cn.company import get_company, get_equity_change, get_profile
|
|
2
2
|
from lixinger.api.cn.company.candlestick import get_candlestick
|
|
3
|
-
from lixinger.api.cn.company.fs
|
|
3
|
+
from lixinger.api.cn.company.fs import (
|
|
4
|
+
get_bank_statements,
|
|
5
|
+
get_insurance_statements,
|
|
6
|
+
get_non_financial_statements,
|
|
7
|
+
get_other_financial_statements,
|
|
8
|
+
get_security_statements,
|
|
9
|
+
)
|
|
4
10
|
from lixinger.api.cn.company.fundamental import (
|
|
5
11
|
get_bank_fundamental,
|
|
6
12
|
get_insurance_fundamental,
|
|
@@ -25,7 +31,11 @@ from lixinger.api.cn.index import (
|
|
|
25
31
|
get_constituent_weightings,
|
|
26
32
|
get_constituents,
|
|
27
33
|
get_index,
|
|
34
|
+
get_index_bank_statements,
|
|
28
35
|
get_index_fundamental,
|
|
36
|
+
get_index_hybrid_statements,
|
|
37
|
+
get_index_non_financial_statements,
|
|
38
|
+
get_index_security_statements,
|
|
29
39
|
get_tracking_fund,
|
|
30
40
|
)
|
|
31
41
|
from lixinger.api.cn.index import (
|
|
@@ -69,9 +79,18 @@ __all__ = [
|
|
|
69
79
|
"get_index_candlestick",
|
|
70
80
|
"get_index_drawdown",
|
|
71
81
|
"get_non_financial_statements",
|
|
82
|
+
"get_bank_statements",
|
|
83
|
+
"get_insurance_statements",
|
|
84
|
+
"get_security_statements",
|
|
85
|
+
"get_other_financial_statements",
|
|
72
86
|
"get_non_financial_fundamental",
|
|
73
87
|
"get_bank_fundamental",
|
|
74
88
|
"get_insurance_fundamental",
|
|
75
89
|
"get_security_fundamental",
|
|
76
90
|
"get_other_financial_fundamental",
|
|
91
|
+
# Index financial statements
|
|
92
|
+
"get_index_non_financial_statements",
|
|
93
|
+
"get_index_bank_statements",
|
|
94
|
+
"get_index_security_statements",
|
|
95
|
+
"get_index_hybrid_statements",
|
|
77
96
|
]
|
|
@@ -1,5 +1,46 @@
|
|
|
1
|
-
"""Financial statement APIs.
|
|
1
|
+
"""Financial statement APIs.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This module provides access to company financial statement APIs by company type:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- non_financial: Non-financial companies (非金融企业)
|
|
6
|
+
- bank: Banks (银行)
|
|
7
|
+
- insurance: Insurance companies (保险)
|
|
8
|
+
- security: Securities companies (证券)
|
|
9
|
+
- other_financial: Other financial companies (租赁、消费金融等)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from lixinger.api.cn.company.fs.bank import (
|
|
13
|
+
BankStatementAPI,
|
|
14
|
+
get_bank_statements,
|
|
15
|
+
)
|
|
16
|
+
from lixinger.api.cn.company.fs.insurance import (
|
|
17
|
+
InsuranceStatementAPI,
|
|
18
|
+
get_insurance_statements,
|
|
19
|
+
)
|
|
20
|
+
from lixinger.api.cn.company.fs.non_financial import (
|
|
21
|
+
NonFinancialStatementAPI,
|
|
22
|
+
get_non_financial_statements,
|
|
23
|
+
)
|
|
24
|
+
from lixinger.api.cn.company.fs.other_financial import (
|
|
25
|
+
OtherFinancialStatementAPI,
|
|
26
|
+
get_other_financial_statements,
|
|
27
|
+
)
|
|
28
|
+
from lixinger.api.cn.company.fs.security import (
|
|
29
|
+
SecurityStatementAPI,
|
|
30
|
+
get_security_statements,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
__all__ = [
|
|
34
|
+
# API Classes
|
|
35
|
+
"BankStatementAPI",
|
|
36
|
+
"InsuranceStatementAPI",
|
|
37
|
+
"NonFinancialStatementAPI",
|
|
38
|
+
"OtherFinancialStatementAPI",
|
|
39
|
+
"SecurityStatementAPI",
|
|
40
|
+
# Functional APIs
|
|
41
|
+
"get_bank_statements",
|
|
42
|
+
"get_insurance_statements",
|
|
43
|
+
"get_non_financial_statements",
|
|
44
|
+
"get_other_financial_statements",
|
|
45
|
+
"get_security_statements",
|
|
46
|
+
]
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""Bank financial statement 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.company.fs.bank import BankStatementSchema
|
|
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 BankStatementAPI(BaseAPI):
|
|
15
|
+
"""Bank financial statement APIs."""
|
|
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
|
+
"""获取A股上市银行的财务报表数据.
|
|
27
|
+
|
|
28
|
+
API Endpoint: /cn/company/fs/bank
|
|
29
|
+
API Method: POST
|
|
30
|
+
API Doc: https://www.lixinger.com/open/api/doc?api-key=cn/company/fs/bank
|
|
31
|
+
|
|
32
|
+
获取A股上市银行的财务报表数据,包括利润表、资产负债表、现金流量表、
|
|
33
|
+
正常财务指标以及银行特有财务指标(净息差、净利差、资本充足率、
|
|
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
|
+
end_date: 结束日期 (YYYY-MM-DD),可选,默认上周一。
|
|
46
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
包含A股银行财务报表数据的 DataFrame。
|
|
50
|
+
|
|
51
|
+
Example:
|
|
52
|
+
获取民生银行和工商银行的营业收入::
|
|
53
|
+
|
|
54
|
+
from lixinger import AsyncLixingerClient
|
|
55
|
+
|
|
56
|
+
async with AsyncLixingerClient() as client:
|
|
57
|
+
df = await client.cn_company.fs.bank.get_bank_statements(
|
|
58
|
+
stock_codes=["600016", "601398"],
|
|
59
|
+
metrics=["q.ps.oi.t"],
|
|
60
|
+
date="2026-03-31",
|
|
61
|
+
)
|
|
62
|
+
print(df)
|
|
63
|
+
|
|
64
|
+
"""
|
|
65
|
+
payload: dict[str, Any] = {
|
|
66
|
+
"stockCodes": stock_codes,
|
|
67
|
+
"metricsList": metrics,
|
|
68
|
+
}
|
|
69
|
+
if date is not None:
|
|
70
|
+
payload["date"] = date
|
|
71
|
+
if start_date is not None:
|
|
72
|
+
payload["startDate"] = start_date
|
|
73
|
+
if end_date is not None:
|
|
74
|
+
payload["endDate"] = end_date
|
|
75
|
+
if limit is not None:
|
|
76
|
+
payload["limit"] = limit
|
|
77
|
+
|
|
78
|
+
data = await self._request("POST", "/cn/company/fs/bank", json=payload)
|
|
79
|
+
|
|
80
|
+
# Flatten nested metrics (e.g. {"q": {"ps": {"oi": {"t": ...}}}})
|
|
81
|
+
flattened_data = [flatten_dict(item) for item in data]
|
|
82
|
+
|
|
83
|
+
return get_response_df(flattened_data, BankStatementSchema)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# Functional API instance
|
|
87
|
+
_api_instance = BankStatementAPI()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@api
|
|
91
|
+
async def get_bank_statements( # noqa: PLR0913
|
|
92
|
+
stock_codes: list[str],
|
|
93
|
+
metrics: list[str],
|
|
94
|
+
date: str | None = None,
|
|
95
|
+
start_date: str | None = None,
|
|
96
|
+
end_date: str | None = None,
|
|
97
|
+
limit: int | None = None,
|
|
98
|
+
) -> pd.DataFrame:
|
|
99
|
+
"""获取A股上市银行的财务报表数据.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
stock_codes: 股票代码列表。
|
|
103
|
+
metrics: 指标列表。
|
|
104
|
+
date: 日期 (YYYY-MM-DD),与 start_date 二选一。
|
|
105
|
+
start_date: 开始日期 (YYYY-MM-DD),与 date 二选一。
|
|
106
|
+
end_date: 结束日期 (YYYY-MM-DD),可选。
|
|
107
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
包含A股银行财务报表数据的 DataFrame。
|
|
111
|
+
|
|
112
|
+
Example:
|
|
113
|
+
获取民生银行的营业收入::
|
|
114
|
+
|
|
115
|
+
from lixinger import get_bank_statements
|
|
116
|
+
|
|
117
|
+
df = await get_bank_statements(
|
|
118
|
+
stock_codes=["600016"],
|
|
119
|
+
metrics=["q.ps.oi.t"],
|
|
120
|
+
date="2026-03-31",
|
|
121
|
+
)
|
|
122
|
+
print(df)
|
|
123
|
+
|
|
124
|
+
"""
|
|
125
|
+
return await _api_instance.get_bank_statements(
|
|
126
|
+
stock_codes=stock_codes,
|
|
127
|
+
metrics=metrics,
|
|
128
|
+
date=date,
|
|
129
|
+
start_date=start_date,
|
|
130
|
+
end_date=end_date,
|
|
131
|
+
limit=limit,
|
|
132
|
+
)
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""Insurance financial statement 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.company.fs.insurance import InsuranceStatementSchema
|
|
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 InsuranceStatementAPI(BaseAPI):
|
|
15
|
+
"""Insurance financial statement APIs."""
|
|
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
|
+
"""获取A股保险公司的财务报表数据.
|
|
27
|
+
|
|
28
|
+
API Endpoint: /cn/company/fs/insurance
|
|
29
|
+
API Method: POST
|
|
30
|
+
API Doc: https://www.lixinger.com/open/api/doc?api-key=cn/company/fs/insurance
|
|
31
|
+
|
|
32
|
+
获取A股保险公司的财务报表数据,包括利润表、资产负债表、现金流量表、
|
|
33
|
+
正常财务指标以及保险公司特有财务指标(内含价值、新业务价值、
|
|
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
|
+
end_date: 结束日期 (YYYY-MM-DD),可选,默认上周一。
|
|
46
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
包含A股保险公司财务报表数据的 DataFrame。
|
|
50
|
+
|
|
51
|
+
Example:
|
|
52
|
+
获取中国平安的营业总收入::
|
|
53
|
+
|
|
54
|
+
from lixinger import AsyncLixingerClient
|
|
55
|
+
|
|
56
|
+
async with AsyncLixingerClient() as client:
|
|
57
|
+
df = await client.cn_company.fs.insurance.get_insurance_statements(
|
|
58
|
+
stock_codes=["601318"],
|
|
59
|
+
metrics=["q.ps.toi.t"],
|
|
60
|
+
date="2026-03-31",
|
|
61
|
+
)
|
|
62
|
+
print(df)
|
|
63
|
+
|
|
64
|
+
"""
|
|
65
|
+
payload: dict[str, Any] = {
|
|
66
|
+
"stockCodes": stock_codes,
|
|
67
|
+
"metricsList": metrics,
|
|
68
|
+
}
|
|
69
|
+
if date is not None:
|
|
70
|
+
payload["date"] = date
|
|
71
|
+
if start_date is not None:
|
|
72
|
+
payload["startDate"] = start_date
|
|
73
|
+
if end_date is not None:
|
|
74
|
+
payload["endDate"] = end_date
|
|
75
|
+
if limit is not None:
|
|
76
|
+
payload["limit"] = limit
|
|
77
|
+
|
|
78
|
+
data = await self._request("POST", "/cn/company/fs/insurance", json=payload)
|
|
79
|
+
|
|
80
|
+
# Flatten nested metrics (e.g. {"q": {"ps": {"toi": {"t": ...}}}})
|
|
81
|
+
flattened_data = [flatten_dict(item) for item in data]
|
|
82
|
+
|
|
83
|
+
return get_response_df(flattened_data, InsuranceStatementSchema)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# Functional API instance
|
|
87
|
+
_api_instance = InsuranceStatementAPI()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@api
|
|
91
|
+
async def get_insurance_statements( # noqa: PLR0913
|
|
92
|
+
stock_codes: list[str],
|
|
93
|
+
metrics: list[str],
|
|
94
|
+
date: str | None = None,
|
|
95
|
+
start_date: str | None = None,
|
|
96
|
+
end_date: str | None = None,
|
|
97
|
+
limit: int | None = None,
|
|
98
|
+
) -> pd.DataFrame:
|
|
99
|
+
"""获取A股保险公司的财务报表数据.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
stock_codes: 股票代码列表。
|
|
103
|
+
metrics: 指标列表。
|
|
104
|
+
date: 日期 (YYYY-MM-DD),与 start_date 二选一。
|
|
105
|
+
start_date: 开始日期 (YYYY-MM-DD),与 date 二选一。
|
|
106
|
+
end_date: 结束日期 (YYYY-MM-DD),可选。
|
|
107
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
包含A股保险公司财务报表数据的 DataFrame。
|
|
111
|
+
|
|
112
|
+
Example:
|
|
113
|
+
获取中国平安的营业总收入::
|
|
114
|
+
|
|
115
|
+
from lixinger import get_insurance_statements
|
|
116
|
+
|
|
117
|
+
df = await get_insurance_statements(
|
|
118
|
+
stock_codes=["601318"],
|
|
119
|
+
metrics=["q.ps.toi.t"],
|
|
120
|
+
date="2026-03-31",
|
|
121
|
+
)
|
|
122
|
+
print(df)
|
|
123
|
+
|
|
124
|
+
"""
|
|
125
|
+
return await _api_instance.get_insurance_statements(
|
|
126
|
+
stock_codes=stock_codes,
|
|
127
|
+
metrics=metrics,
|
|
128
|
+
date=date,
|
|
129
|
+
start_date=start_date,
|
|
130
|
+
end_date=end_date,
|
|
131
|
+
limit=limit,
|
|
132
|
+
)
|
|
@@ -14,13 +14,14 @@ from lixinger.utils.dict import flatten_dict
|
|
|
14
14
|
class NonFinancialStatementAPI(BaseAPI):
|
|
15
15
|
"""Non-financial statement APIs."""
|
|
16
16
|
|
|
17
|
-
async def get_non_financial_statements(
|
|
17
|
+
async def get_non_financial_statements( # noqa: PLR0913
|
|
18
18
|
self,
|
|
19
19
|
stock_codes: list[str],
|
|
20
20
|
metrics: list[str],
|
|
21
21
|
date: str | None = None,
|
|
22
22
|
start_date: str | None = None,
|
|
23
23
|
end_date: str | None = None,
|
|
24
|
+
limit: int | None = None,
|
|
24
25
|
) -> pd.DataFrame:
|
|
25
26
|
"""获取非金融企业财务报表数据.
|
|
26
27
|
|
|
@@ -34,6 +35,7 @@ class NonFinancialStatementAPI(BaseAPI):
|
|
|
34
35
|
date: 日期 (YYYY-MM-DD), 与 startDate 二选一
|
|
35
36
|
start_date: 开始日期 (YYYY-MM-DD), 与 date 二选一
|
|
36
37
|
end_date: 结束日期 (YYYY-MM-DD), 可选
|
|
38
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效
|
|
37
39
|
|
|
38
40
|
"""
|
|
39
41
|
payload: dict[str, Any] = {
|
|
@@ -46,6 +48,8 @@ class NonFinancialStatementAPI(BaseAPI):
|
|
|
46
48
|
payload["startDate"] = start_date
|
|
47
49
|
if end_date is not None:
|
|
48
50
|
payload["endDate"] = end_date
|
|
51
|
+
if limit is not None:
|
|
52
|
+
payload["limit"] = limit
|
|
49
53
|
|
|
50
54
|
data = await self._request("POST", "/cn/company/fs/non_financial", json=payload)
|
|
51
55
|
|
|
@@ -60,12 +64,13 @@ _api_instance = NonFinancialStatementAPI()
|
|
|
60
64
|
|
|
61
65
|
|
|
62
66
|
@api
|
|
63
|
-
async def get_non_financial_statements(
|
|
67
|
+
async def get_non_financial_statements( # noqa: PLR0913
|
|
64
68
|
stock_codes: list[str],
|
|
65
69
|
metrics: list[str],
|
|
66
70
|
date: str | None = None,
|
|
67
71
|
start_date: str | None = None,
|
|
68
72
|
end_date: str | None = None,
|
|
73
|
+
limit: int | None = None,
|
|
69
74
|
) -> pd.DataFrame:
|
|
70
75
|
"""获取非金融企业财务报表数据."""
|
|
71
76
|
return await _api_instance.get_non_financial_statements(
|
|
@@ -74,4 +79,5 @@ async def get_non_financial_statements(
|
|
|
74
79
|
date=date,
|
|
75
80
|
start_date=start_date,
|
|
76
81
|
end_date=end_date,
|
|
82
|
+
limit=limit,
|
|
77
83
|
)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Other financial company financial statement 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.company.fs.other_financial import OtherFinancialStatementSchema
|
|
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 OtherFinancialStatementAPI(BaseAPI):
|
|
15
|
+
"""Other financial company financial statement APIs."""
|
|
16
|
+
|
|
17
|
+
async def get_other_financial_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
|
+
"""获取A股其他金融公司(租赁、消费金融等)的财务报表数据.
|
|
27
|
+
|
|
28
|
+
API Endpoint: /cn/company/fs/other_financial
|
|
29
|
+
API Method: POST
|
|
30
|
+
API Doc: https://www.lixinger.com/open/api/doc?api-key=cn/company/fs/other_financial
|
|
31
|
+
|
|
32
|
+
获取A股其他金融公司(租赁、消费金融等)的财务报表数据,包括利润表、
|
|
33
|
+
资产负债表、现金流量表以及各类财务指标。
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
stock_codes: 股票代码列表,长度 >=1 且 <=100。当传入 start_date
|
|
37
|
+
时只能传入一个股票代码。
|
|
38
|
+
metrics: 指标列表,格式为
|
|
39
|
+
``[granularity].[tableName].[fieldName].[expressionCalculateType]``,
|
|
40
|
+
例如 ``"q.ps.toi.t"``。当 stock_codes 长度大于 1 时最多 48 个
|
|
41
|
+
指标;等于 1 时最多 128 个指标。
|
|
42
|
+
date: 日期 (YYYY-MM-DD),与 start_date 二选一。支持 ``"latest"``。
|
|
43
|
+
start_date: 开始日期 (YYYY-MM-DD),与 date 二选一。
|
|
44
|
+
end_date: 结束日期 (YYYY-MM-DD),可选,默认上周一。
|
|
45
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
包含A股其他金融公司财务报表数据的 DataFrame。
|
|
49
|
+
|
|
50
|
+
Example:
|
|
51
|
+
获取江苏租赁的营业总收入::
|
|
52
|
+
|
|
53
|
+
from lixinger import AsyncLixingerClient
|
|
54
|
+
|
|
55
|
+
async with AsyncLixingerClient() as client:
|
|
56
|
+
df = await client.cn_company.fs.other_financial.get_other_financial_statements(
|
|
57
|
+
stock_codes=["600901"],
|
|
58
|
+
metrics=["q.ps.toi.t"],
|
|
59
|
+
date="2026-03-31",
|
|
60
|
+
)
|
|
61
|
+
print(df)
|
|
62
|
+
|
|
63
|
+
"""
|
|
64
|
+
payload: dict[str, Any] = {
|
|
65
|
+
"stockCodes": stock_codes,
|
|
66
|
+
"metricsList": metrics,
|
|
67
|
+
}
|
|
68
|
+
if date is not None:
|
|
69
|
+
payload["date"] = date
|
|
70
|
+
if start_date is not None:
|
|
71
|
+
payload["startDate"] = start_date
|
|
72
|
+
if end_date is not None:
|
|
73
|
+
payload["endDate"] = end_date
|
|
74
|
+
if limit is not None:
|
|
75
|
+
payload["limit"] = limit
|
|
76
|
+
|
|
77
|
+
data = await self._request("POST", "/cn/company/fs/other_financial", json=payload)
|
|
78
|
+
|
|
79
|
+
# Flatten nested metrics (e.g. {"q": {"ps": {"toi": {"t": ...}}}})
|
|
80
|
+
flattened_data = [flatten_dict(item) for item in data]
|
|
81
|
+
|
|
82
|
+
return get_response_df(flattened_data, OtherFinancialStatementSchema)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# Functional API instance
|
|
86
|
+
_api_instance = OtherFinancialStatementAPI()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@api
|
|
90
|
+
async def get_other_financial_statements( # noqa: PLR0913
|
|
91
|
+
stock_codes: list[str],
|
|
92
|
+
metrics: list[str],
|
|
93
|
+
date: str | None = None,
|
|
94
|
+
start_date: str | None = None,
|
|
95
|
+
end_date: str | None = None,
|
|
96
|
+
limit: int | None = None,
|
|
97
|
+
) -> pd.DataFrame:
|
|
98
|
+
"""获取A股其他金融公司(租赁、消费金融等)的财务报表数据.
|
|
99
|
+
|
|
100
|
+
Args:
|
|
101
|
+
stock_codes: 股票代码列表。
|
|
102
|
+
metrics: 指标列表。
|
|
103
|
+
date: 日期 (YYYY-MM-DD),与 start_date 二选一。
|
|
104
|
+
start_date: 开始日期 (YYYY-MM-DD),与 date 二选一。
|
|
105
|
+
end_date: 结束日期 (YYYY-MM-DD),可选。
|
|
106
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
包含A股其他金融公司财务报表数据的 DataFrame。
|
|
110
|
+
|
|
111
|
+
Example:
|
|
112
|
+
获取江苏租赁的营业总收入::
|
|
113
|
+
|
|
114
|
+
from lixinger import get_other_financial_statements
|
|
115
|
+
|
|
116
|
+
df = await get_other_financial_statements(
|
|
117
|
+
stock_codes=["600901"],
|
|
118
|
+
metrics=["q.ps.toi.t"],
|
|
119
|
+
date="2026-03-31",
|
|
120
|
+
)
|
|
121
|
+
print(df)
|
|
122
|
+
|
|
123
|
+
"""
|
|
124
|
+
return await _api_instance.get_other_financial_statements(
|
|
125
|
+
stock_codes=stock_codes,
|
|
126
|
+
metrics=metrics,
|
|
127
|
+
date=date,
|
|
128
|
+
start_date=start_date,
|
|
129
|
+
end_date=end_date,
|
|
130
|
+
limit=limit,
|
|
131
|
+
)
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""Security (securities firm) financial statement 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.company.fs.security import SecurityStatementSchema
|
|
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 SecurityStatementAPI(BaseAPI):
|
|
15
|
+
"""Security (securities firm) financial statement APIs."""
|
|
16
|
+
|
|
17
|
+
async def get_security_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
|
+
"""获取A股证券公司的财务报表数据.
|
|
27
|
+
|
|
28
|
+
API Endpoint: /cn/company/fs/security
|
|
29
|
+
API Method: POST
|
|
30
|
+
API Doc: https://www.lixinger.com/open/api/doc?api-key=cn/company/fs/security
|
|
31
|
+
|
|
32
|
+
获取A股证券公司的财务报表数据,包括利润表、资产负债表、现金流量表、
|
|
33
|
+
正常财务指标以及证券公司特有财务指标(净资本、风险覆盖率、
|
|
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
|
+
end_date: 结束日期 (YYYY-MM-DD),可选,默认上周一。
|
|
46
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
包含A股证券公司财务报表数据的 DataFrame。
|
|
50
|
+
|
|
51
|
+
Example:
|
|
52
|
+
获取中信证券的营业总收入::
|
|
53
|
+
|
|
54
|
+
from lixinger import AsyncLixingerClient
|
|
55
|
+
|
|
56
|
+
async with AsyncLixingerClient() as client:
|
|
57
|
+
df = await client.cn_company.fs.security.get_security_statements(
|
|
58
|
+
stock_codes=["600030"],
|
|
59
|
+
metrics=["q.ps.toi.t"],
|
|
60
|
+
date="2026-03-31",
|
|
61
|
+
)
|
|
62
|
+
print(df)
|
|
63
|
+
|
|
64
|
+
"""
|
|
65
|
+
payload: dict[str, Any] = {
|
|
66
|
+
"stockCodes": stock_codes,
|
|
67
|
+
"metricsList": metrics,
|
|
68
|
+
}
|
|
69
|
+
if date is not None:
|
|
70
|
+
payload["date"] = date
|
|
71
|
+
if start_date is not None:
|
|
72
|
+
payload["startDate"] = start_date
|
|
73
|
+
if end_date is not None:
|
|
74
|
+
payload["endDate"] = end_date
|
|
75
|
+
if limit is not None:
|
|
76
|
+
payload["limit"] = limit
|
|
77
|
+
|
|
78
|
+
data = await self._request("POST", "/cn/company/fs/security", json=payload)
|
|
79
|
+
|
|
80
|
+
# Flatten nested metrics (e.g. {"q": {"ps": {"toi": {"t": ...}}}})
|
|
81
|
+
flattened_data = [flatten_dict(item) for item in data]
|
|
82
|
+
|
|
83
|
+
return get_response_df(flattened_data, SecurityStatementSchema)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# Functional API instance
|
|
87
|
+
_api_instance = SecurityStatementAPI()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@api
|
|
91
|
+
async def get_security_statements( # noqa: PLR0913
|
|
92
|
+
stock_codes: list[str],
|
|
93
|
+
metrics: list[str],
|
|
94
|
+
date: str | None = None,
|
|
95
|
+
start_date: str | None = None,
|
|
96
|
+
end_date: str | None = None,
|
|
97
|
+
limit: int | None = None,
|
|
98
|
+
) -> pd.DataFrame:
|
|
99
|
+
"""获取A股证券公司的财务报表数据.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
stock_codes: 股票代码列表。
|
|
103
|
+
metrics: 指标列表。
|
|
104
|
+
date: 日期 (YYYY-MM-DD),与 start_date 二选一。
|
|
105
|
+
start_date: 开始日期 (YYYY-MM-DD),与 date 二选一。
|
|
106
|
+
end_date: 结束日期 (YYYY-MM-DD),可选。
|
|
107
|
+
limit: 返回最近数据的数量,仅在 date range 请求下生效。
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
包含A股证券公司财务报表数据的 DataFrame。
|
|
111
|
+
|
|
112
|
+
Example:
|
|
113
|
+
获取中信证券的营业总收入::
|
|
114
|
+
|
|
115
|
+
from lixinger import get_security_statements
|
|
116
|
+
|
|
117
|
+
df = await get_security_statements(
|
|
118
|
+
stock_codes=["600030"],
|
|
119
|
+
metrics=["q.ps.toi.t"],
|
|
120
|
+
date="2026-03-31",
|
|
121
|
+
)
|
|
122
|
+
print(df)
|
|
123
|
+
|
|
124
|
+
"""
|
|
125
|
+
return await _api_instance.get_security_statements(
|
|
126
|
+
stock_codes=stock_codes,
|
|
127
|
+
metrics=metrics,
|
|
128
|
+
date=date,
|
|
129
|
+
start_date=start_date,
|
|
130
|
+
end_date=end_date,
|
|
131
|
+
limit=limit,
|
|
132
|
+
)
|