lixinger-python 0.3.23__py3-none-any.whl → 0.3.25__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 +14 -0
- lixinger/api/macro/__init__.py +34 -0
- lixinger/api/macro/crude_oil.py +119 -0
- lixinger/api/macro/gold_price.py +119 -0
- lixinger/api/macro/namespace.py +64 -1
- lixinger/api/macro/natural_gas.py +119 -0
- lixinger/api/macro/non_ferrous_metals.py +121 -0
- lixinger/api/macro/official_reserve_assets.py +132 -0
- lixinger/api/macro/platinum_price.py +119 -0
- lixinger/api/macro/silver_price.py +119 -0
- lixinger/client.py +28 -0
- lixinger/models/macro/__init__.py +12 -0
- lixinger/models/macro/crude_oil.py +20 -0
- lixinger/models/macro/gold_price.py +20 -0
- lixinger/models/macro/natural_gas.py +20 -0
- lixinger/models/macro/non_ferrous_metals.py +21 -0
- lixinger/models/macro/official_reserve_assets.py +20 -0
- lixinger/models/macro/platinum_price.py +20 -0
- lixinger/models/macro/silver_price.py +20 -0
- {lixinger_python-0.3.23.dist-info → lixinger_python-0.3.25.dist-info}/METADATA +1 -1
- {lixinger_python-0.3.23.dist-info → lixinger_python-0.3.25.dist-info}/RECORD +23 -9
- {lixinger_python-0.3.23.dist-info → lixinger_python-0.3.25.dist-info}/WHEEL +0 -0
- {lixinger_python-0.3.23.dist-info → lixinger_python-0.3.25.dist-info}/licenses/LICENSE +0 -0
lixinger/__init__.py
CHANGED
|
@@ -56,9 +56,16 @@ from lixinger.api.cn.industry import (
|
|
|
56
56
|
get_industry_sw_margin_trading,
|
|
57
57
|
)
|
|
58
58
|
from lixinger.api.macro import (
|
|
59
|
+
get_crude_oil,
|
|
60
|
+
get_gold_price,
|
|
59
61
|
get_national_debt,
|
|
62
|
+
get_natural_gas,
|
|
63
|
+
get_non_ferrous_metals,
|
|
64
|
+
get_official_reserve_assets,
|
|
65
|
+
get_platinum_price,
|
|
60
66
|
get_rmb_deposits,
|
|
61
67
|
get_rmb_loans,
|
|
68
|
+
get_silver_price,
|
|
62
69
|
get_social_financing,
|
|
63
70
|
)
|
|
64
71
|
from lixinger.client import AsyncLixingerClient
|
|
@@ -135,4 +142,11 @@ __all__ = [
|
|
|
135
142
|
"get_rmb_deposits",
|
|
136
143
|
"get_rmb_loans",
|
|
137
144
|
"get_social_financing",
|
|
145
|
+
"get_gold_price",
|
|
146
|
+
"get_silver_price",
|
|
147
|
+
"get_platinum_price",
|
|
148
|
+
"get_crude_oil",
|
|
149
|
+
"get_natural_gas",
|
|
150
|
+
"get_non_ferrous_metals",
|
|
151
|
+
"get_official_reserve_assets",
|
|
138
152
|
]
|
lixinger/api/macro/__init__.py
CHANGED
|
@@ -3,14 +3,34 @@
|
|
|
3
3
|
This module provides access to macroeconomic data APIs:
|
|
4
4
|
|
|
5
5
|
- national_debt: 国债收益率 (/macro/national-debt)
|
|
6
|
+
- official_reserve_assets: 官方储备资产 (/macro/official-reserve-assets)
|
|
6
7
|
- rmb_deposits: 人民币存款 (/macro/rmb-deposits)
|
|
7
8
|
- rmb_loans: 人民币贷款 (/macro/rmb-loans)
|
|
8
9
|
- social_financing: 社会融资规模 (/macro/social-financing)
|
|
10
|
+
- gold_price: 黄金 (/macro/gold-price)
|
|
11
|
+
- silver_price: 白银 (/macro/silver-price)
|
|
12
|
+
- platinum_price: 铂金 (/macro/platinum-price)
|
|
13
|
+
- crude_oil: 原油 (/macro/crude-oil)
|
|
14
|
+
- natural_gas: 天然气 (/macro/natural-gas)
|
|
15
|
+
- non_ferrous_metals: 有色金属 (/macro/non-ferrous-metals)
|
|
9
16
|
"""
|
|
10
17
|
|
|
18
|
+
from lixinger.api.macro.crude_oil import CrudeOilAPI, get_crude_oil
|
|
19
|
+
from lixinger.api.macro.gold_price import GoldPriceAPI, get_gold_price
|
|
11
20
|
from lixinger.api.macro.national_debt import NationalDebtAPI, get_national_debt
|
|
21
|
+
from lixinger.api.macro.natural_gas import NaturalGasAPI, get_natural_gas
|
|
22
|
+
from lixinger.api.macro.non_ferrous_metals import (
|
|
23
|
+
NonFerrousMetalsAPI,
|
|
24
|
+
get_non_ferrous_metals,
|
|
25
|
+
)
|
|
26
|
+
from lixinger.api.macro.official_reserve_assets import (
|
|
27
|
+
OfficialReserveAssetsAPI,
|
|
28
|
+
get_official_reserve_assets,
|
|
29
|
+
)
|
|
30
|
+
from lixinger.api.macro.platinum_price import PlatinumPriceAPI, get_platinum_price
|
|
12
31
|
from lixinger.api.macro.rmb_deposits import RmbDepositsAPI, get_rmb_deposits
|
|
13
32
|
from lixinger.api.macro.rmb_loans import RmbLoansAPI, get_rmb_loans
|
|
33
|
+
from lixinger.api.macro.silver_price import SilverPriceAPI, get_silver_price
|
|
14
34
|
from lixinger.api.macro.social_financing import (
|
|
15
35
|
SocialFinancingAPI,
|
|
16
36
|
get_social_financing,
|
|
@@ -18,13 +38,27 @@ from lixinger.api.macro.social_financing import (
|
|
|
18
38
|
|
|
19
39
|
__all__ = [
|
|
20
40
|
# API Classes
|
|
41
|
+
"CrudeOilAPI",
|
|
42
|
+
"GoldPriceAPI",
|
|
21
43
|
"NationalDebtAPI",
|
|
44
|
+
"NaturalGasAPI",
|
|
45
|
+
"NonFerrousMetalsAPI",
|
|
46
|
+
"OfficialReserveAssetsAPI",
|
|
47
|
+
"PlatinumPriceAPI",
|
|
22
48
|
"RmbDepositsAPI",
|
|
23
49
|
"RmbLoansAPI",
|
|
50
|
+
"SilverPriceAPI",
|
|
24
51
|
"SocialFinancingAPI",
|
|
25
52
|
# Functional APIs
|
|
53
|
+
"get_crude_oil",
|
|
54
|
+
"get_gold_price",
|
|
26
55
|
"get_national_debt",
|
|
56
|
+
"get_natural_gas",
|
|
57
|
+
"get_non_ferrous_metals",
|
|
58
|
+
"get_official_reserve_assets",
|
|
59
|
+
"get_platinum_price",
|
|
27
60
|
"get_rmb_deposits",
|
|
28
61
|
"get_rmb_loans",
|
|
62
|
+
"get_silver_price",
|
|
29
63
|
"get_social_financing",
|
|
30
64
|
]
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""原油 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.macro.crude_oil import CrudeOil
|
|
9
|
+
from lixinger.utils.api import api
|
|
10
|
+
from lixinger.utils.dataframe import get_response_df
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CrudeOilAPI(BaseAPI):
|
|
14
|
+
"""原油 API."""
|
|
15
|
+
|
|
16
|
+
async def get_crude_oil(
|
|
17
|
+
self,
|
|
18
|
+
area_code: str,
|
|
19
|
+
start_date: str,
|
|
20
|
+
end_date: str,
|
|
21
|
+
metrics_list: list[str],
|
|
22
|
+
limit: int | None = None,
|
|
23
|
+
) -> pd.DataFrame:
|
|
24
|
+
"""获取原油数据.
|
|
25
|
+
|
|
26
|
+
获取国际原油现货价格数据. 可按时间范围获取WTI原油和布伦特原油现货价格数据.
|
|
27
|
+
|
|
28
|
+
API Endpoint: /macro/crude-oil
|
|
29
|
+
API Method: POST
|
|
30
|
+
API Doc: https://www.lixinger.com/open/api/doc?api-key=macro/crude-oil
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
area_code: 地区代码, 目前支持 ``us``.
|
|
34
|
+
start_date: 信息起始时间 (YYYY-MM-DD, 北京时间), 开始和结束的时间间隔不超过10年.
|
|
35
|
+
end_date: 信息结束时间 (YYYY-MM-DD, 北京时间).
|
|
36
|
+
metrics_list: 指标列表, 例如 ``["wti_co_sp"]``.
|
|
37
|
+
支持的指标: ``wti_co_sp`` (WTI原油现货价格), ``brent_co_sp`` (布伦特原油现货价格).
|
|
38
|
+
limit: 返回最近数据的数量.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
DataFrame 包含以下列:
|
|
42
|
+
|
|
43
|
+
- date: 数据时间
|
|
44
|
+
- area_code: 地区代码
|
|
45
|
+
- 各请求指标 (如 wti_co_sp, brent_co_sp 等)
|
|
46
|
+
|
|
47
|
+
Example:
|
|
48
|
+
获取WTI原油现货价格::
|
|
49
|
+
|
|
50
|
+
from lixinger import AsyncLixingerClient
|
|
51
|
+
|
|
52
|
+
async with AsyncLixingerClient() as client:
|
|
53
|
+
df = await client.macro.crude_oil.get_crude_oil(
|
|
54
|
+
area_code="us",
|
|
55
|
+
start_date="2025-06-13",
|
|
56
|
+
end_date="2026-06-13",
|
|
57
|
+
metrics_list=["wti_co_sp"],
|
|
58
|
+
)
|
|
59
|
+
print(df)
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
payload: dict[str, Any] = {
|
|
63
|
+
"areaCode": area_code,
|
|
64
|
+
"startDate": start_date,
|
|
65
|
+
"endDate": end_date,
|
|
66
|
+
"metricsList": metrics_list,
|
|
67
|
+
}
|
|
68
|
+
if limit is not None:
|
|
69
|
+
payload["limit"] = limit
|
|
70
|
+
|
|
71
|
+
data = await self._request("POST", "/macro/crude-oil", json=payload)
|
|
72
|
+
return get_response_df(data, CrudeOil)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# Functional API instance
|
|
76
|
+
_api_instance = CrudeOilAPI()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@api
|
|
80
|
+
async def get_crude_oil(
|
|
81
|
+
area_code: str,
|
|
82
|
+
start_date: str,
|
|
83
|
+
end_date: str,
|
|
84
|
+
metrics_list: list[str],
|
|
85
|
+
limit: int | None = None,
|
|
86
|
+
) -> pd.DataFrame:
|
|
87
|
+
"""获取原油数据.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
area_code: 地区代码, 目前支持 ``us``.
|
|
91
|
+
start_date: 信息起始时间 (YYYY-MM-DD).
|
|
92
|
+
end_date: 信息结束时间 (YYYY-MM-DD).
|
|
93
|
+
metrics_list: 指标列表, 例如 ``["wti_co_sp"]``.
|
|
94
|
+
limit: 返回最近数据的数量.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
DataFrame 包含原油价格数据.
|
|
98
|
+
|
|
99
|
+
Example:
|
|
100
|
+
获取WTI原油现货价格::
|
|
101
|
+
|
|
102
|
+
from lixinger import get_crude_oil
|
|
103
|
+
|
|
104
|
+
df = await get_crude_oil(
|
|
105
|
+
area_code="us",
|
|
106
|
+
start_date="2025-06-13",
|
|
107
|
+
end_date="2026-06-13",
|
|
108
|
+
metrics_list=["wti_co_sp"],
|
|
109
|
+
)
|
|
110
|
+
print(df)
|
|
111
|
+
|
|
112
|
+
"""
|
|
113
|
+
return await _api_instance.get_crude_oil(
|
|
114
|
+
area_code=area_code,
|
|
115
|
+
start_date=start_date,
|
|
116
|
+
end_date=end_date,
|
|
117
|
+
metrics_list=metrics_list,
|
|
118
|
+
limit=limit,
|
|
119
|
+
)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""黄金 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.macro.gold_price import GoldPrice
|
|
9
|
+
from lixinger.utils.api import api
|
|
10
|
+
from lixinger.utils.dataframe import get_response_df
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class GoldPriceAPI(BaseAPI):
|
|
14
|
+
"""黄金 API."""
|
|
15
|
+
|
|
16
|
+
async def get_gold_price(
|
|
17
|
+
self,
|
|
18
|
+
area_code: str,
|
|
19
|
+
start_date: str,
|
|
20
|
+
end_date: str,
|
|
21
|
+
metrics_list: list[str],
|
|
22
|
+
limit: int | None = None,
|
|
23
|
+
) -> pd.DataFrame:
|
|
24
|
+
"""获取黄金数据.
|
|
25
|
+
|
|
26
|
+
获取国际黄金现货价格数据. 可按时间范围获取伦敦金价格、上海金价格等数据.
|
|
27
|
+
|
|
28
|
+
API Endpoint: /macro/gold-price
|
|
29
|
+
API Method: POST
|
|
30
|
+
API Doc: https://www.lixinger.com/open/api/doc?api-key=macro/gold-price
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
area_code: 地区代码, 目前支持 ``us``.
|
|
34
|
+
start_date: 信息起始时间 (YYYY-MM-DD, 北京时间), 开始和结束的时间间隔不超过10年.
|
|
35
|
+
end_date: 信息结束时间 (YYYY-MM-DD, 北京时间).
|
|
36
|
+
metrics_list: 指标列表, 例如 ``["lbma_pm_usd"]``.
|
|
37
|
+
支持的指标: ``lbma_pm_usd`` (伦敦金价格), ``sge_pm_cny`` (上海金价格).
|
|
38
|
+
limit: 返回最近数据的数量.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
DataFrame 包含以下列:
|
|
42
|
+
|
|
43
|
+
- date: 数据时间
|
|
44
|
+
- area_code: 地区代码
|
|
45
|
+
- 各请求指标 (如 lbma_pm_usd, sge_pm_cny 等)
|
|
46
|
+
|
|
47
|
+
Example:
|
|
48
|
+
获取伦敦金价格::
|
|
49
|
+
|
|
50
|
+
from lixinger import AsyncLixingerClient
|
|
51
|
+
|
|
52
|
+
async with AsyncLixingerClient() as client:
|
|
53
|
+
df = await client.macro.gold_price.get_gold_price(
|
|
54
|
+
area_code="us",
|
|
55
|
+
start_date="2025-06-13",
|
|
56
|
+
end_date="2026-06-13",
|
|
57
|
+
metrics_list=["lbma_pm_usd"],
|
|
58
|
+
)
|
|
59
|
+
print(df)
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
payload: dict[str, Any] = {
|
|
63
|
+
"areaCode": area_code,
|
|
64
|
+
"startDate": start_date,
|
|
65
|
+
"endDate": end_date,
|
|
66
|
+
"metricsList": metrics_list,
|
|
67
|
+
}
|
|
68
|
+
if limit is not None:
|
|
69
|
+
payload["limit"] = limit
|
|
70
|
+
|
|
71
|
+
data = await self._request("POST", "/macro/gold-price", json=payload)
|
|
72
|
+
return get_response_df(data, GoldPrice)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# Functional API instance
|
|
76
|
+
_api_instance = GoldPriceAPI()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@api
|
|
80
|
+
async def get_gold_price(
|
|
81
|
+
area_code: str,
|
|
82
|
+
start_date: str,
|
|
83
|
+
end_date: str,
|
|
84
|
+
metrics_list: list[str],
|
|
85
|
+
limit: int | None = None,
|
|
86
|
+
) -> pd.DataFrame:
|
|
87
|
+
"""获取黄金数据.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
area_code: 地区代码, 目前支持 ``us``.
|
|
91
|
+
start_date: 信息起始时间 (YYYY-MM-DD).
|
|
92
|
+
end_date: 信息结束时间 (YYYY-MM-DD).
|
|
93
|
+
metrics_list: 指标列表, 例如 ``["lbma_pm_usd"]``.
|
|
94
|
+
limit: 返回最近数据的数量.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
DataFrame 包含黄金价格数据.
|
|
98
|
+
|
|
99
|
+
Example:
|
|
100
|
+
获取伦敦金价格::
|
|
101
|
+
|
|
102
|
+
from lixinger import get_gold_price
|
|
103
|
+
|
|
104
|
+
df = await get_gold_price(
|
|
105
|
+
area_code="us",
|
|
106
|
+
start_date="2025-06-13",
|
|
107
|
+
end_date="2026-06-13",
|
|
108
|
+
metrics_list=["lbma_pm_usd"],
|
|
109
|
+
)
|
|
110
|
+
print(df)
|
|
111
|
+
|
|
112
|
+
"""
|
|
113
|
+
return await _api_instance.get_gold_price(
|
|
114
|
+
area_code=area_code,
|
|
115
|
+
start_date=start_date,
|
|
116
|
+
end_date=end_date,
|
|
117
|
+
metrics_list=metrics_list,
|
|
118
|
+
limit=limit,
|
|
119
|
+
)
|
lixinger/api/macro/namespace.py
CHANGED
|
@@ -4,9 +4,16 @@ from typing import Any
|
|
|
4
4
|
|
|
5
5
|
import pandas as pd
|
|
6
6
|
|
|
7
|
+
from lixinger.api.macro.crude_oil import CrudeOilAPI
|
|
8
|
+
from lixinger.api.macro.gold_price import GoldPriceAPI
|
|
7
9
|
from lixinger.api.macro.national_debt import NationalDebtAPI
|
|
10
|
+
from lixinger.api.macro.natural_gas import NaturalGasAPI
|
|
11
|
+
from lixinger.api.macro.non_ferrous_metals import NonFerrousMetalsAPI
|
|
12
|
+
from lixinger.api.macro.official_reserve_assets import OfficialReserveAssetsAPI
|
|
13
|
+
from lixinger.api.macro.platinum_price import PlatinumPriceAPI
|
|
8
14
|
from lixinger.api.macro.rmb_deposits import RmbDepositsAPI
|
|
9
15
|
from lixinger.api.macro.rmb_loans import RmbLoansAPI
|
|
16
|
+
from lixinger.api.macro.silver_price import SilverPriceAPI
|
|
10
17
|
from lixinger.api.macro.social_financing import SocialFinancingAPI
|
|
11
18
|
|
|
12
19
|
|
|
@@ -20,15 +27,29 @@ class MacroNamespace:
|
|
|
20
27
|
- rmb_deposits: 人民币存款 API
|
|
21
28
|
- rmb_loans: 人民币贷款 API
|
|
22
29
|
- social_financing: 社会融资 API
|
|
30
|
+
- gold_price: 黄金 API
|
|
31
|
+
- silver_price: 白银 API
|
|
32
|
+
- platinum_price: 铂金 API
|
|
33
|
+
- crude_oil: 原油 API
|
|
34
|
+
- natural_gas: 天然气 API
|
|
35
|
+
- non_ferrous_metals: 有色金属 API
|
|
36
|
+
- official_reserve_assets: 官方储备资产 API
|
|
23
37
|
|
|
24
38
|
"""
|
|
25
39
|
|
|
26
|
-
def __init__(
|
|
40
|
+
def __init__( # noqa: PLR0913
|
|
27
41
|
self,
|
|
28
42
|
national_debt: NationalDebtAPI,
|
|
29
43
|
rmb_deposits: RmbDepositsAPI,
|
|
30
44
|
rmb_loans: RmbLoansAPI,
|
|
31
45
|
social_financing: SocialFinancingAPI,
|
|
46
|
+
gold_price: GoldPriceAPI,
|
|
47
|
+
silver_price: SilverPriceAPI,
|
|
48
|
+
platinum_price: PlatinumPriceAPI,
|
|
49
|
+
crude_oil: CrudeOilAPI,
|
|
50
|
+
natural_gas: NaturalGasAPI,
|
|
51
|
+
non_ferrous_metals: NonFerrousMetalsAPI,
|
|
52
|
+
official_reserve_assets: OfficialReserveAssetsAPI,
|
|
32
53
|
) -> None:
|
|
33
54
|
"""Initialize the macro namespace.
|
|
34
55
|
|
|
@@ -37,12 +58,26 @@ class MacroNamespace:
|
|
|
37
58
|
rmb_deposits: 人民币存款 API
|
|
38
59
|
rmb_loans: 人民币贷款 API
|
|
39
60
|
social_financing: 社会融资 API
|
|
61
|
+
gold_price: 黄金 API
|
|
62
|
+
silver_price: 白银 API
|
|
63
|
+
platinum_price: 铂金 API
|
|
64
|
+
crude_oil: 原油 API
|
|
65
|
+
natural_gas: 天然气 API
|
|
66
|
+
non_ferrous_metals: 有色金属 API
|
|
67
|
+
official_reserve_assets: 官方储备资产 API
|
|
40
68
|
|
|
41
69
|
"""
|
|
42
70
|
self.national_debt = national_debt
|
|
43
71
|
self.rmb_deposits = rmb_deposits
|
|
44
72
|
self.rmb_loans = rmb_loans
|
|
45
73
|
self.social_financing = social_financing
|
|
74
|
+
self.gold_price = gold_price
|
|
75
|
+
self.silver_price = silver_price
|
|
76
|
+
self.platinum_price = platinum_price
|
|
77
|
+
self.crude_oil = crude_oil
|
|
78
|
+
self.natural_gas = natural_gas
|
|
79
|
+
self.non_ferrous_metals = non_ferrous_metals
|
|
80
|
+
self.official_reserve_assets = official_reserve_assets
|
|
46
81
|
|
|
47
82
|
# Convenience aliases for shorter access
|
|
48
83
|
async def get_national_debt(self, *args: Any, **kwargs: Any) -> pd.DataFrame:
|
|
@@ -60,3 +95,31 @@ class MacroNamespace:
|
|
|
60
95
|
async def get_social_financing(self, *args: Any, **kwargs: Any) -> pd.DataFrame:
|
|
61
96
|
"""Alias for social_financing.get_social_financing."""
|
|
62
97
|
return await self.social_financing.get_social_financing(*args, **kwargs)
|
|
98
|
+
|
|
99
|
+
async def get_gold_price(self, *args: Any, **kwargs: Any) -> pd.DataFrame:
|
|
100
|
+
"""Alias for gold_price.get_gold_price."""
|
|
101
|
+
return await self.gold_price.get_gold_price(*args, **kwargs)
|
|
102
|
+
|
|
103
|
+
async def get_silver_price(self, *args: Any, **kwargs: Any) -> pd.DataFrame:
|
|
104
|
+
"""Alias for silver_price.get_silver_price."""
|
|
105
|
+
return await self.silver_price.get_silver_price(*args, **kwargs)
|
|
106
|
+
|
|
107
|
+
async def get_platinum_price(self, *args: Any, **kwargs: Any) -> pd.DataFrame:
|
|
108
|
+
"""Alias for platinum_price.get_platinum_price."""
|
|
109
|
+
return await self.platinum_price.get_platinum_price(*args, **kwargs)
|
|
110
|
+
|
|
111
|
+
async def get_crude_oil(self, *args: Any, **kwargs: Any) -> pd.DataFrame:
|
|
112
|
+
"""Alias for crude_oil.get_crude_oil."""
|
|
113
|
+
return await self.crude_oil.get_crude_oil(*args, **kwargs)
|
|
114
|
+
|
|
115
|
+
async def get_natural_gas(self, *args: Any, **kwargs: Any) -> pd.DataFrame:
|
|
116
|
+
"""Alias for natural_gas.get_natural_gas."""
|
|
117
|
+
return await self.natural_gas.get_natural_gas(*args, **kwargs)
|
|
118
|
+
|
|
119
|
+
async def get_non_ferrous_metals(self, *args: Any, **kwargs: Any) -> pd.DataFrame:
|
|
120
|
+
"""Alias for non_ferrous_metals.get_non_ferrous_metals."""
|
|
121
|
+
return await self.non_ferrous_metals.get_non_ferrous_metals(*args, **kwargs)
|
|
122
|
+
|
|
123
|
+
async def get_official_reserve_assets(self, *args: Any, **kwargs: Any) -> pd.DataFrame:
|
|
124
|
+
"""Alias for official_reserve_assets.get_official_reserve_assets."""
|
|
125
|
+
return await self.official_reserve_assets.get_official_reserve_assets(*args, **kwargs)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""天然气 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.macro.natural_gas import NaturalGas
|
|
9
|
+
from lixinger.utils.api import api
|
|
10
|
+
from lixinger.utils.dataframe import get_response_df
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class NaturalGasAPI(BaseAPI):
|
|
14
|
+
"""天然气 API."""
|
|
15
|
+
|
|
16
|
+
async def get_natural_gas(
|
|
17
|
+
self,
|
|
18
|
+
area_code: str,
|
|
19
|
+
start_date: str,
|
|
20
|
+
end_date: str,
|
|
21
|
+
metrics_list: list[str],
|
|
22
|
+
limit: int | None = None,
|
|
23
|
+
) -> pd.DataFrame:
|
|
24
|
+
"""获取天然气数据.
|
|
25
|
+
|
|
26
|
+
获取国际天然气现货价格数据. 可按时间范围获取亨利港天然气现货价格数据.
|
|
27
|
+
|
|
28
|
+
API Endpoint: /macro/natural-gas
|
|
29
|
+
API Method: POST
|
|
30
|
+
API Doc: https://www.lixinger.com/open/api/doc?api-key=macro/natural-gas
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
area_code: 地区代码, 目前支持 ``us``.
|
|
34
|
+
start_date: 信息起始时间 (YYYY-MM-DD, 北京时间), 开始和结束的时间间隔不超过10年.
|
|
35
|
+
end_date: 信息结束时间 (YYYY-MM-DD, 北京时间).
|
|
36
|
+
metrics_list: 指标列表, 例如 ``["hh_ng_sp"]``.
|
|
37
|
+
支持的指标: ``hh_ng_sp`` (亨利港天然气现货价格).
|
|
38
|
+
limit: 返回最近数据的数量.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
DataFrame 包含以下列:
|
|
42
|
+
|
|
43
|
+
- date: 数据时间
|
|
44
|
+
- area_code: 地区代码
|
|
45
|
+
- 各请求指标 (如 hh_ng_sp 等)
|
|
46
|
+
|
|
47
|
+
Example:
|
|
48
|
+
获取亨利港天然气现货价格::
|
|
49
|
+
|
|
50
|
+
from lixinger import AsyncLixingerClient
|
|
51
|
+
|
|
52
|
+
async with AsyncLixingerClient() as client:
|
|
53
|
+
df = await client.macro.natural_gas.get_natural_gas(
|
|
54
|
+
area_code="us",
|
|
55
|
+
start_date="2025-06-13",
|
|
56
|
+
end_date="2026-06-13",
|
|
57
|
+
metrics_list=["hh_ng_sp"],
|
|
58
|
+
)
|
|
59
|
+
print(df)
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
payload: dict[str, Any] = {
|
|
63
|
+
"areaCode": area_code,
|
|
64
|
+
"startDate": start_date,
|
|
65
|
+
"endDate": end_date,
|
|
66
|
+
"metricsList": metrics_list,
|
|
67
|
+
}
|
|
68
|
+
if limit is not None:
|
|
69
|
+
payload["limit"] = limit
|
|
70
|
+
|
|
71
|
+
data = await self._request("POST", "/macro/natural-gas", json=payload)
|
|
72
|
+
return get_response_df(data, NaturalGas)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# Functional API instance
|
|
76
|
+
_api_instance = NaturalGasAPI()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@api
|
|
80
|
+
async def get_natural_gas(
|
|
81
|
+
area_code: str,
|
|
82
|
+
start_date: str,
|
|
83
|
+
end_date: str,
|
|
84
|
+
metrics_list: list[str],
|
|
85
|
+
limit: int | None = None,
|
|
86
|
+
) -> pd.DataFrame:
|
|
87
|
+
"""获取天然气数据.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
area_code: 地区代码, 目前支持 ``us``.
|
|
91
|
+
start_date: 信息起始时间 (YYYY-MM-DD).
|
|
92
|
+
end_date: 信息结束时间 (YYYY-MM-DD).
|
|
93
|
+
metrics_list: 指标列表, 例如 ``["hh_ng_sp"]``.
|
|
94
|
+
limit: 返回最近数据的数量.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
DataFrame 包含天然气价格数据.
|
|
98
|
+
|
|
99
|
+
Example:
|
|
100
|
+
获取亨利港天然气现货价格::
|
|
101
|
+
|
|
102
|
+
from lixinger import get_natural_gas
|
|
103
|
+
|
|
104
|
+
df = await get_natural_gas(
|
|
105
|
+
area_code="us",
|
|
106
|
+
start_date="2025-06-13",
|
|
107
|
+
end_date="2026-06-13",
|
|
108
|
+
metrics_list=["hh_ng_sp"],
|
|
109
|
+
)
|
|
110
|
+
print(df)
|
|
111
|
+
|
|
112
|
+
"""
|
|
113
|
+
return await _api_instance.get_natural_gas(
|
|
114
|
+
area_code=area_code,
|
|
115
|
+
start_date=start_date,
|
|
116
|
+
end_date=end_date,
|
|
117
|
+
metrics_list=metrics_list,
|
|
118
|
+
limit=limit,
|
|
119
|
+
)
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""有色金属 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.macro.non_ferrous_metals import NonFerrousMetals
|
|
9
|
+
from lixinger.utils.api import api
|
|
10
|
+
from lixinger.utils.dataframe import get_response_df
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class NonFerrousMetalsAPI(BaseAPI):
|
|
14
|
+
"""有色金属 API."""
|
|
15
|
+
|
|
16
|
+
async def get_non_ferrous_metals(
|
|
17
|
+
self,
|
|
18
|
+
area_code: str,
|
|
19
|
+
start_date: str,
|
|
20
|
+
end_date: str,
|
|
21
|
+
metrics_list: list[str],
|
|
22
|
+
limit: int | None = None,
|
|
23
|
+
) -> pd.DataFrame:
|
|
24
|
+
"""获取有色金属数据.
|
|
25
|
+
|
|
26
|
+
获取有色金属数据. 可按时间范围获取伦敦铜、锌、铅、铝、镍、锡等有色金属现货价格数据.
|
|
27
|
+
|
|
28
|
+
API Endpoint: /macro/non-ferrous-metals
|
|
29
|
+
API Method: POST
|
|
30
|
+
API Doc: https://www.lixinger.com/open/api/doc?api-key=macro/non-ferrous-metals
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
area_code: 地区代码, 目前支持 ``us``.
|
|
34
|
+
start_date: 信息起始时间 (YYYY-MM-DD, 北京时间), 开始和结束的时间间隔不超过10年.
|
|
35
|
+
end_date: 信息结束时间 (YYYY-MM-DD, 北京时间).
|
|
36
|
+
metrics_list: 指标列表, 例如 ``["l_cu_p"]``.
|
|
37
|
+
支持的指标: ``l_cu_p`` (伦敦铜价格), ``l_zn_p`` (伦敦锌价格),
|
|
38
|
+
``l_pb_p`` (伦敦铅价格), ``l_al_p`` (伦敦铝价格),
|
|
39
|
+
``l_ni_p`` (伦敦镍价格), ``l_sn_p`` (伦敦锡价格).
|
|
40
|
+
limit: 返回最近数据的数量.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
DataFrame 包含以下列:
|
|
44
|
+
|
|
45
|
+
- date: 数据时间
|
|
46
|
+
- area_code: 地区代码
|
|
47
|
+
- 各请求指标 (如 l_cu_p, l_zn_p 等)
|
|
48
|
+
|
|
49
|
+
Example:
|
|
50
|
+
获取伦敦铜价格::
|
|
51
|
+
|
|
52
|
+
from lixinger import AsyncLixingerClient
|
|
53
|
+
|
|
54
|
+
async with AsyncLixingerClient() as client:
|
|
55
|
+
df = await client.macro.non_ferrous_metals.get_non_ferrous_metals(
|
|
56
|
+
area_code="us",
|
|
57
|
+
start_date="2025-06-13",
|
|
58
|
+
end_date="2026-06-13",
|
|
59
|
+
metrics_list=["l_cu_p"],
|
|
60
|
+
)
|
|
61
|
+
print(df)
|
|
62
|
+
|
|
63
|
+
"""
|
|
64
|
+
payload: dict[str, Any] = {
|
|
65
|
+
"areaCode": area_code,
|
|
66
|
+
"startDate": start_date,
|
|
67
|
+
"endDate": end_date,
|
|
68
|
+
"metricsList": metrics_list,
|
|
69
|
+
}
|
|
70
|
+
if limit is not None:
|
|
71
|
+
payload["limit"] = limit
|
|
72
|
+
|
|
73
|
+
data = await self._request("POST", "/macro/non-ferrous-metals", json=payload)
|
|
74
|
+
return get_response_df(data, NonFerrousMetals)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# Functional API instance
|
|
78
|
+
_api_instance = NonFerrousMetalsAPI()
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@api
|
|
82
|
+
async def get_non_ferrous_metals(
|
|
83
|
+
area_code: str,
|
|
84
|
+
start_date: str,
|
|
85
|
+
end_date: str,
|
|
86
|
+
metrics_list: list[str],
|
|
87
|
+
limit: int | None = None,
|
|
88
|
+
) -> pd.DataFrame:
|
|
89
|
+
"""获取有色金属数据.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
area_code: 地区代码, 目前支持 ``us``.
|
|
93
|
+
start_date: 信息起始时间 (YYYY-MM-DD).
|
|
94
|
+
end_date: 信息结束时间 (YYYY-MM-DD).
|
|
95
|
+
metrics_list: 指标列表, 例如 ``["l_cu_p"]``.
|
|
96
|
+
limit: 返回最近数据的数量.
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
DataFrame 包含有色金属价格数据.
|
|
100
|
+
|
|
101
|
+
Example:
|
|
102
|
+
获取伦敦铜价格::
|
|
103
|
+
|
|
104
|
+
from lixinger import get_non_ferrous_metals
|
|
105
|
+
|
|
106
|
+
df = await get_non_ferrous_metals(
|
|
107
|
+
area_code="us",
|
|
108
|
+
start_date="2025-06-13",
|
|
109
|
+
end_date="2026-06-13",
|
|
110
|
+
metrics_list=["l_cu_p"],
|
|
111
|
+
)
|
|
112
|
+
print(df)
|
|
113
|
+
|
|
114
|
+
"""
|
|
115
|
+
return await _api_instance.get_non_ferrous_metals(
|
|
116
|
+
area_code=area_code,
|
|
117
|
+
start_date=start_date,
|
|
118
|
+
end_date=end_date,
|
|
119
|
+
metrics_list=metrics_list,
|
|
120
|
+
limit=limit,
|
|
121
|
+
)
|