yjdata 0.2.3__tar.gz → 0.2.5__tar.gz

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 (42) hide show
  1. yjdata-0.2.5/PKG-INFO +49 -0
  2. yjdata-0.2.5/README.md +38 -0
  3. {yjdata-0.2.3 → yjdata-0.2.5}/pyproject.toml +1 -1
  4. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/web/calendar.py +3 -3
  5. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/web/client.py +24 -0
  6. yjdata-0.2.5/src/yjdata/web/cn_fund.py +116 -0
  7. yjdata-0.2.5/src/yjdata/web/cn_future.py +179 -0
  8. yjdata-0.2.5/src/yjdata/web/cn_stock.py +202 -0
  9. yjdata-0.2.5/src/yjdata/web/md.py +78 -0
  10. yjdata-0.2.5/src/yjdata.egg-info/PKG-INFO +49 -0
  11. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata.egg-info/SOURCES.txt +6 -1
  12. yjdata-0.2.5/tests/test_web_market_data.py +185 -0
  13. yjdata-0.2.3/PKG-INFO +0 -130
  14. yjdata-0.2.3/README.md +0 -119
  15. yjdata-0.2.3/src/yjdata.egg-info/PKG-INFO +0 -130
  16. {yjdata-0.2.3 → yjdata-0.2.5}/setup.cfg +0 -0
  17. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/__init__.py +0 -0
  18. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/_optional.py +0 -0
  19. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/dataset/__init__.py +0 -0
  20. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/dataset/common.py +0 -0
  21. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/dataset/quote.py +0 -0
  22. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/dataset/snapshot.py +0 -0
  23. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/dataset/trade.py +0 -0
  24. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/db/__init__.py +0 -0
  25. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/db/adapter.py +0 -0
  26. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/db/expression.py +0 -0
  27. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/db/mysql.py +0 -0
  28. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/db/postgres.py +0 -0
  29. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/db/sql.py +0 -0
  30. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/dtype.py +0 -0
  31. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/utlity/__init__.py +0 -0
  32. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/utlity/s3.py +0 -0
  33. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/web/__init__.py +0 -0
  34. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/web/_context.py +0 -0
  35. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/web/_input.py +0 -0
  36. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata/web/time_util.py +0 -0
  37. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata.egg-info/dependency_links.txt +0 -0
  38. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata.egg-info/requires.txt +0 -0
  39. {yjdata-0.2.3 → yjdata-0.2.5}/src/yjdata.egg-info/top_level.txt +0 -0
  40. {yjdata-0.2.3 → yjdata-0.2.5}/tests/test_batch_writes.py +0 -0
  41. {yjdata-0.2.3 → yjdata-0.2.5}/tests/test_last_of_group.py +0 -0
  42. {yjdata-0.2.3 → yjdata-0.2.5}/tests/test_mysql_batch_updates.py +0 -0
yjdata-0.2.5/PKG-INFO ADDED
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.4
2
+ Name: yjdata
3
+ Version: 0.2.5
4
+ Summary: yjdata SDK for Python
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: httpx>=0.25
8
+ Requires-Dist: polars>=1.30
9
+ Requires-Dist: pyarrow>=18
10
+ Requires-Dist: pydantic>=2.11
11
+
12
+ # yjdata
13
+
14
+ Python SDK,提供 yjdata WebAPI client、MySQL/PostgreSQL adapter 和 Parquet 工具。
15
+ [更新日志](doc/updates/v0.2.x.md)
16
+
17
+ ## 安装与配置
18
+
19
+ 需要 Python 3.10+:
20
+
21
+ ```bash
22
+ pip install yjdata
23
+ ```
24
+
25
+ 默认访问内网 `yjdata-api.yaojingriver.internal`,可通过
26
+ `YJDATA_WEB_BASE_URL` 环境变量或 client 的 `host` 参数指定地址。
27
+
28
+ ## 使用
29
+
30
+ ```python
31
+ from yjdata import WebDataClient
32
+
33
+ client = WebDataClient()
34
+ prices = client.cn_stock.stk_eod_md("2026-11-06", ids="000001.XSHE")
35
+ for price in prices:
36
+ print(price.id, price.close)
37
+
38
+ for snapshot in client.md.latest_brief(["000001.XSHE"]):
39
+ print(snapshot.id, snapshot.last, snapshot.bid1, snapshot.ask1)
40
+ ```
41
+
42
+ - WebAPI:`calendar`、`md`、`cn_stock`、`cn_future`、`cn_fund`;异步使用 `AsyncWebDataClient`。
43
+ - ETF/LOF:`cn_fund.etf_eod_md` 和 `cn_fund.etf_sod_ref` 按交易日查询收盘行情和盘前参考数据。对应的 `_id` 方法按单只基金查询闭区间内的数据。
44
+ - 最新行情:`md.latest_brief` 获取买卖一档,`md.latest_full` 获取完整快照。两者均接受显示 ID 列表或逗号分隔的字符串。
45
+ - 数据库:`yjdata.db.MysqlAdapter`、`yjdata.db.PostgresAdapter`。
46
+ - Parquet:`yjdata.dataset`。
47
+
48
+ 接口与字段见 [OpenAPI](https://yjdata-api.yaojingriver.internal/openapi.json),
49
+ Python 参数见对应模块的 docstring。
yjdata-0.2.5/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # yjdata
2
+
3
+ Python SDK,提供 yjdata WebAPI client、MySQL/PostgreSQL adapter 和 Parquet 工具。
4
+ [更新日志](doc/updates/v0.2.x.md)
5
+
6
+ ## 安装与配置
7
+
8
+ 需要 Python 3.10+:
9
+
10
+ ```bash
11
+ pip install yjdata
12
+ ```
13
+
14
+ 默认访问内网 `yjdata-api.yaojingriver.internal`,可通过
15
+ `YJDATA_WEB_BASE_URL` 环境变量或 client 的 `host` 参数指定地址。
16
+
17
+ ## 使用
18
+
19
+ ```python
20
+ from yjdata import WebDataClient
21
+
22
+ client = WebDataClient()
23
+ prices = client.cn_stock.stk_eod_md("2026-11-06", ids="000001.XSHE")
24
+ for price in prices:
25
+ print(price.id, price.close)
26
+
27
+ for snapshot in client.md.latest_brief(["000001.XSHE"]):
28
+ print(snapshot.id, snapshot.last, snapshot.bid1, snapshot.ask1)
29
+ ```
30
+
31
+ - WebAPI:`calendar`、`md`、`cn_stock`、`cn_future`、`cn_fund`;异步使用 `AsyncWebDataClient`。
32
+ - ETF/LOF:`cn_fund.etf_eod_md` 和 `cn_fund.etf_sod_ref` 按交易日查询收盘行情和盘前参考数据。对应的 `_id` 方法按单只基金查询闭区间内的数据。
33
+ - 最新行情:`md.latest_brief` 获取买卖一档,`md.latest_full` 获取完整快照。两者均接受显示 ID 列表或逗号分隔的字符串。
34
+ - 数据库:`yjdata.db.MysqlAdapter`、`yjdata.db.PostgresAdapter`。
35
+ - Parquet:`yjdata.dataset`。
36
+
37
+ 接口与字段见 [OpenAPI](https://yjdata-api.yaojingriver.internal/openapi.json),
38
+ Python 参数见对应模块的 docstring。
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "yjdata"
7
- version = "0.2.3"
7
+ version = "0.2.5"
8
8
  description = "yjdata SDK for Python"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -49,7 +49,7 @@ class CalendarWebClient:
49
49
  return self._context.post(f'{self._api_root}/next-n', payload={
50
50
  'start': parse_date_str_arg(start, False),
51
51
  'n': n,
52
- 'calendar': calendar
52
+ 'exchange': calendar
53
53
  })
54
54
 
55
55
  def last_n(
@@ -83,7 +83,7 @@ class CalendarWebClient:
83
83
  return self._context.post(f'{self._api_root}/last-n', payload={
84
84
  'end': parse_date_str_arg(end, False),
85
85
  'n': n,
86
- 'calendar': calendar
86
+ 'exchange': calendar
87
87
  })
88
88
 
89
89
  def range(
@@ -118,7 +118,7 @@ class CalendarWebClient:
118
118
  return self._context.post(f'{self._api_root}/range', payload={
119
119
  'start': parse_date_str_arg(start, False),
120
120
  'end': parse_date_str_arg(end, False),
121
- 'calendar': calendar
121
+ 'exchange': calendar
122
122
  })
123
123
 
124
124
  @abstractmethod
@@ -1,6 +1,10 @@
1
1
  import os
2
2
 
3
3
  from .calendar import SyncCalenderWebClient, AsyncCalendarWebClient
4
+ from .cn_fund import CnFundWebClient
5
+ from .cn_future import CnFutureWebClient
6
+ from .cn_stock import CnStockWebClient
7
+ from .md import MdWebClient
4
8
  from ._context import RequestContext, SyncRequestContext, AsyncRequestContext
5
9
 
6
10
 
@@ -23,6 +27,26 @@ class _WebClient:
23
27
  self._host = host
24
28
  self._context = context
25
29
 
30
+ @property
31
+ def md(self) -> MdWebClient:
32
+ """API set for latest market snapshots."""
33
+ return MdWebClient(self._host, self._context)
34
+
35
+ @property
36
+ def cn_stock(self) -> CnStockWebClient:
37
+ """API set for domestic stock market data."""
38
+ return CnStockWebClient(self._host, self._context)
39
+
40
+ @property
41
+ def cn_fund(self) -> CnFundWebClient:
42
+ """API set for domestic ETF and LOF data."""
43
+ return CnFundWebClient(self._host, self._context)
44
+
45
+ @property
46
+ def cn_future(self) -> CnFutureWebClient:
47
+ """API set for domestic futures market data."""
48
+ return CnFutureWebClient(self._host, self._context)
49
+
26
50
 
27
51
  class WebDataClient(_WebClient):
28
52
  """Client for accessing YJData web API."""
@@ -0,0 +1,116 @@
1
+ from typing import Awaitable
2
+
3
+ from pydantic import BaseModel, ConfigDict, Field
4
+
5
+ from ._context import RequestContext
6
+ from ._input import DateStrArgType, StrListArgType, parse_date_str_arg, parse_str_list_arg
7
+
8
+
9
+ __all__ = ['CnFundWebClient', 'EtfEodMd', 'EtfSodRef']
10
+
11
+
12
+ class EtfEodMd(BaseModel):
13
+ """ETF/LOF end-of-day prices, volume and turnover."""
14
+
15
+ model_config = ConfigDict(validate_by_name=True)
16
+
17
+ id: str
18
+ time: str = Field(alias='date')
19
+ pre_close: float = Field(alias='pc')
20
+ open: float = Field(alias='o')
21
+ high: float = Field(alias='h')
22
+ low: float = Field(alias='l')
23
+ close: float = Field(alias='c')
24
+ volume: int = Field(alias='vol')
25
+ amount: float = Field(alias='amt')
26
+
27
+
28
+ class EtfSodRef(BaseModel):
29
+ """ETF/LOF pre-market reference data."""
30
+
31
+ model_config = ConfigDict(validate_by_name=True)
32
+
33
+ id: str
34
+ time: str = Field(alias='date')
35
+ name: str
36
+ ticker: str
37
+ display_id: str = Field(alias='dispId')
38
+ trading_status: str = Field(alias='status')
39
+ pre_close: float = Field(alias='pc')
40
+ prior_close: float = Field(alias='prc')
41
+ upper_limit: float = Field(alias='ul')
42
+ lower_limit: float = Field(alias='ll')
43
+ auct_hours: str = Field(alias='auct')
44
+ cont_hours: str = Field(alias='cont')
45
+
46
+
47
+ def _range_payload(id: str, start: DateStrArgType, end: DateStrArgType, stable_id: bool) -> dict:
48
+ return {
49
+ 'id': id,
50
+ 'start': parse_date_str_arg(start, False),
51
+ 'end': parse_date_str_arg(end, False),
52
+ 'stableId': stable_id,
53
+ }
54
+
55
+
56
+ class CnFundWebClient:
57
+ """Domestic ETF/LOF data by trading date or inclusive date range.
58
+
59
+ Dates accept date or datetime objects and YYYY-MM-DD or YYYYMMDD strings.
60
+ Daily queries accept a list of IDs or a comma-separated string. Omit ids
61
+ to request all funds, or pass an empty list to request none.
62
+ """
63
+
64
+ def __init__(self, host: str, context: RequestContext) -> None:
65
+ self._api_root = f'http://{host}/v1/cn-fund'
66
+ self._context = context
67
+
68
+ def etf_eod_md(
69
+ self, date: DateStrArgType, ids: StrListArgType = None, stable_id: bool = True,
70
+ ) -> list[EtfEodMd] | Awaitable[list[EtfEodMd]]:
71
+ """Get daily prices. Set stable_id=False to query and return current IDs."""
72
+ return self._context.post_model_list(
73
+ EtfEodMd, f'{self._api_root}/etf-eod-md',
74
+ payload={
75
+ 'date': parse_date_str_arg(date, False),
76
+ 'ids': None if ids is None else parse_str_list_arg(ids),
77
+ 'stableId': stable_id,
78
+ },
79
+ )
80
+
81
+ def etf_sod_ref(
82
+ self, date: DateStrArgType, ids: StrListArgType = None,
83
+ ) -> list[EtfSodRef] | Awaitable[list[EtfSodRef]]:
84
+ """Get pre-market reference data for a trading date using internal IDs."""
85
+ return self._context.post_model_list(
86
+ EtfSodRef, f'{self._api_root}/etf-sod-ref',
87
+ payload={
88
+ 'date': parse_date_str_arg(date, False),
89
+ 'ids': None if ids is None else parse_str_list_arg(ids),
90
+ },
91
+ )
92
+
93
+ def etf_eod_md_id(
94
+ self, id: str, start: DateStrArgType, end: DateStrArgType, stable_id: bool = True,
95
+ ) -> list[EtfEodMd] | Awaitable[list[EtfEodMd]]:
96
+ """Get one fund's prices from start through end, sorted by date.
97
+
98
+ Set stable_id=False to query by the current ID and return it on each record.
99
+ """
100
+ return self._context.post_model_list(
101
+ EtfEodMd, f'{self._api_root}/etf-eod-md-id',
102
+ payload=_range_payload(id, start, end, stable_id),
103
+ )
104
+
105
+ def etf_sod_ref_id(
106
+ self, id: str, start: DateStrArgType, end: DateStrArgType, stable_id: bool = True,
107
+ ) -> list[EtfSodRef] | Awaitable[list[EtfSodRef]]:
108
+ """Get one fund's pre-market data from start through end, sorted by date.
109
+
110
+ Set stable_id=False to query by the current ID. Each record contains the
111
+ internal id and the display_id in effect on its trading date.
112
+ """
113
+ return self._context.post_model_list(
114
+ EtfSodRef, f'{self._api_root}/etf-sod-ref-id',
115
+ payload=_range_payload(id, start, end, stable_id),
116
+ )
@@ -0,0 +1,179 @@
1
+ from pydantic import BaseModel, ConfigDict, Field
2
+ from typing import Awaitable, List, Union
3
+
4
+ from ._context import RequestContext
5
+ from ._input import DateStrArgType, StrListArgType, parse_date_str_arg, parse_str_list_arg
6
+
7
+
8
+ __all__ = ['CnFutureWebClient', 'FutEodMd', 'FutSodRef']
9
+
10
+
11
+ class FutEodMd(BaseModel):
12
+ """Futures end-of-day prices, volume, turnover and open interest."""
13
+
14
+ model_config = ConfigDict(validate_by_name=True)
15
+
16
+ id: str
17
+ time: str = Field(alias='date')
18
+ pre_settle: float = Field(alias='ps')
19
+ pre_close: float = Field(alias='pc')
20
+ open: float = Field(alias='o')
21
+ high: float = Field(alias='h')
22
+ low: float = Field(alias='l')
23
+ close: float = Field(alias='c')
24
+ settle: float = Field(alias='s')
25
+ volume: int = Field(alias='vol')
26
+ amount: float = Field(alias='amt')
27
+ open_interest: int = Field(alias='oi')
28
+
29
+
30
+ class FutSodRef(BaseModel):
31
+ """Futures pre-market reference data, including contract specifications."""
32
+
33
+ model_config = ConfigDict(validate_by_name=True)
34
+
35
+ id: str
36
+ time: str = Field(alias='date')
37
+ name: str
38
+ display_id: str = Field(alias='dispId')
39
+ ticker: str
40
+ trading_status: str = Field(alias='status')
41
+ underlying_id: Union[str, None] = Field(alias='ulId')
42
+ product: str = Field(alias='prod')
43
+ multiplier: float = Field(alias='mult')
44
+ tick: float
45
+ pre_close: float = Field(alias='pc')
46
+ pre_settle: float = Field(alias='ps')
47
+ auct_hours: str = Field(alias='auct')
48
+ cont_hours: str = Field(alias='cont')
49
+ upper_limit: float = Field(alias='ul')
50
+ lower_limit: float = Field(alias='ll')
51
+
52
+
53
+ class CnFutureWebClient:
54
+
55
+ def __init__(self, host: str, context: RequestContext) -> None:
56
+ self._api_root = f'http://{host}/v1/cn-future'
57
+ self._context = context
58
+
59
+ def fut_eod_md(
60
+ self,
61
+ date: DateStrArgType,
62
+ ids: StrListArgType = None
63
+ ) -> Union[List[FutEodMd], Awaitable[List[FutEodMd]]]:
64
+ """Get domestic futures end-of-day market data for a trading date.
65
+
66
+ Parameters
67
+ ----------
68
+ date : str, datetime.date or datetime.datetime
69
+ Trading date; strings accept YYYY-MM-DD or YYYYMMDD.
70
+ ids : str or list[str], optional
71
+ IDs as a list or comma-separated string. None returns all records;
72
+ an empty list or blank string returns no records.
73
+
74
+ Returns
75
+ -------
76
+ list[FutEodMd] or Awaitable[list[FutEodMd]]
77
+ Validated records; await the result with AsyncWebDataClient.
78
+ """
79
+ return self._context.post_model_list(
80
+ FutEodMd,
81
+ f'{self._api_root}/fut-eod-md',
82
+ payload={
83
+ 'date': parse_date_str_arg(date, False),
84
+ 'ids': None if ids is None else parse_str_list_arg(ids),
85
+ },
86
+ )
87
+
88
+ def fut_sod_ref(
89
+ self,
90
+ date: DateStrArgType,
91
+ ids: StrListArgType = None
92
+ ) -> Union[List[FutSodRef], Awaitable[List[FutSodRef]]]:
93
+ """Get domestic futures pre-market reference data for a trading date.
94
+
95
+ Parameters
96
+ ----------
97
+ date : str, datetime.date or datetime.datetime
98
+ Trading date; strings accept YYYY-MM-DD or YYYYMMDD.
99
+ ids : str or list[str], optional
100
+ IDs as a list or comma-separated string. None returns all records;
101
+ an empty list or blank string returns no records.
102
+
103
+ Returns
104
+ -------
105
+ list[FutSodRef] or Awaitable[list[FutSodRef]]
106
+ Validated records; await the result with AsyncWebDataClient.
107
+ API fields dispId and ulId use display_id and underlying_id.
108
+ underlying_id is None for contracts without an underlying index.
109
+ """
110
+ return self._context.post_model_list(
111
+ FutSodRef,
112
+ f'{self._api_root}/fut-sod-ref',
113
+ payload={
114
+ 'date': parse_date_str_arg(date, False),
115
+ 'ids': None if ids is None else parse_str_list_arg(ids),
116
+ },
117
+ )
118
+
119
+ def fut_eod_md_id(
120
+ self,
121
+ id: str,
122
+ start: DateStrArgType,
123
+ end: DateStrArgType,
124
+ ) -> Union[List[FutEodMd], Awaitable[List[FutEodMd]]]:
125
+ """Get one futures contract's end-of-day data for a date range.
126
+
127
+ Parameters
128
+ ----------
129
+ id : str
130
+ A single contract ID, preserving the contract code's case.
131
+ start, end : str, datetime.date or datetime.datetime
132
+ Inclusive dates; strings accept YYYY-MM-DD or YYYYMMDD.
133
+ end must not precede start.
134
+
135
+ Returns
136
+ -------
137
+ list[FutEodMd] or Awaitable[list[FutEodMd]]
138
+ Records sorted by date ascending; await with AsyncWebDataClient.
139
+ """
140
+ return self._context.post_model_list(
141
+ FutEodMd,
142
+ f'{self._api_root}/fut-eod-md-id',
143
+ payload={
144
+ 'id': id,
145
+ 'start': parse_date_str_arg(start, False),
146
+ 'end': parse_date_str_arg(end, False),
147
+ },
148
+ )
149
+
150
+ def fut_sod_ref_id(
151
+ self,
152
+ id: str,
153
+ start: DateStrArgType,
154
+ end: DateStrArgType,
155
+ ) -> Union[List[FutSodRef], Awaitable[List[FutSodRef]]]:
156
+ """Get one futures contract's pre-market data for a date range.
157
+
158
+ Parameters
159
+ ----------
160
+ id : str
161
+ A single contract ID, preserving the contract code's case.
162
+ start, end : str, datetime.date or datetime.datetime
163
+ Inclusive dates; strings accept YYYY-MM-DD or YYYYMMDD.
164
+ end must not precede start.
165
+
166
+ Returns
167
+ -------
168
+ list[FutSodRef] or Awaitable[list[FutSodRef]]
169
+ Records sorted by date ascending; await with AsyncWebDataClient.
170
+ """
171
+ return self._context.post_model_list(
172
+ FutSodRef,
173
+ f'{self._api_root}/fut-sod-ref-id',
174
+ payload={
175
+ 'id': id,
176
+ 'start': parse_date_str_arg(start, False),
177
+ 'end': parse_date_str_arg(end, False),
178
+ },
179
+ )
@@ -0,0 +1,202 @@
1
+ from pydantic import BaseModel, ConfigDict, Field
2
+ from typing import Awaitable, List, Union
3
+
4
+ from ._context import RequestContext
5
+ from ._input import DateStrArgType, StrListArgType, parse_date_str_arg, parse_str_list_arg
6
+
7
+
8
+ __all__ = ['CnStockWebClient', 'StkEodMd', 'StkSodRef']
9
+
10
+
11
+ class StkEodMd(BaseModel):
12
+ """Stock end-of-day prices, volume and turnover."""
13
+
14
+ model_config = ConfigDict(validate_by_name=True)
15
+
16
+ id: str
17
+ time: str = Field(alias='date')
18
+ pre_close: float = Field(alias='pc')
19
+ open: float = Field(alias='o')
20
+ high: float = Field(alias='h')
21
+ low: float = Field(alias='l')
22
+ close: float = Field(alias='c')
23
+ volume: int = Field(alias='vol')
24
+ amount: float = Field(alias='amt')
25
+
26
+
27
+ class StkSodRef(BaseModel):
28
+ """Stock pre-market reference data. IDs use the first listing ticker."""
29
+
30
+ model_config = ConfigDict(validate_by_name=True)
31
+
32
+ id: str
33
+ time: str = Field(alias='date')
34
+ name: str
35
+ display_id: str = Field(alias='dispId')
36
+ ticker: str
37
+ trading_status: str = Field(alias='status')
38
+ st_status: str = Field(alias='st')
39
+ pre_close: float = Field(alias='pc')
40
+ prior_close: float = Field(alias='prc')
41
+ upper_limit: float = Field(alias='ul')
42
+ lower_limit: float = Field(alias='ll')
43
+ auct_hours: str = Field(alias='auct')
44
+ cont_hours: str = Field(alias='cont')
45
+
46
+
47
+ class CnStockWebClient:
48
+
49
+ def __init__(self, host: str, context: RequestContext) -> None:
50
+ self._api_root = f'http://{host}/v1/cn-stock'
51
+ self._context = context
52
+
53
+ def stk_eod_md(
54
+ self,
55
+ date: DateStrArgType,
56
+ ids: StrListArgType = None,
57
+ stable_id: bool = True
58
+ ) -> Union[List[StkEodMd], Awaitable[List[StkEodMd]]]:
59
+ """Get stock end-of-day market data for a trading date.
60
+
61
+ Parameters
62
+ ----------
63
+ date : str, datetime.date or datetime.datetime
64
+ Trading date; strings accept YYYY-MM-DD or YYYYMMDD.
65
+ ids : str or list[str], optional
66
+ IDs as a list or comma-separated string. None returns all records;
67
+ an empty list or blank string returns no records.
68
+ stable_id : bool, default: True
69
+ True filters by stable (first-listing) IDs. False filters by
70
+ current latest IDs, independent of the requested date, and all
71
+ returned IDs use those latest IDs. If multiple listings match,
72
+ the server uses the last listing by start_time for each ID.
73
+
74
+ Returns
75
+ -------
76
+ list[StkEodMd] or Awaitable[list[StkEodMd]]
77
+ Validated records; await the result with AsyncWebDataClient.
78
+ """
79
+ return self._context.post_model_list(
80
+ StkEodMd,
81
+ f'{self._api_root}/stk-eod-md',
82
+ payload={
83
+ 'date': parse_date_str_arg(date, False),
84
+ 'ids': None if ids is None else parse_str_list_arg(ids),
85
+ 'stableId': stable_id,
86
+ },
87
+ )
88
+
89
+ def stk_sod_ref(
90
+ self,
91
+ date: DateStrArgType,
92
+ ids: StrListArgType = None,
93
+ stable_id: bool = True,
94
+ ) -> Union[List[StkSodRef], Awaitable[List[StkSodRef]]]:
95
+ """Get stock pre-market reference data for a trading date.
96
+
97
+ Parameters
98
+ ----------
99
+ date : str, datetime.date or datetime.datetime
100
+ Trading date; strings accept YYYY-MM-DD or YYYYMMDD.
101
+ ids : str or list[str], optional
102
+ IDs as a list or comma-separated string. None returns all records;
103
+ an empty list or blank string returns no records.
104
+ stable_id : bool, default: True
105
+ True filters by stable (first-listing) IDs. False filters by
106
+ current latest IDs, independent of the requested date. If multiple
107
+ listings match, the server uses the last listing by start_time
108
+ for each ID. Returned fields remain unchanged: id is stable and
109
+ display_id is the ticker plus exchange on each record's date.
110
+
111
+ Returns
112
+ -------
113
+ list[StkSodRef] or Awaitable[list[StkSodRef]]
114
+ Validated records; await the result with AsyncWebDataClient.
115
+ Fields use backend Python names, such as display_id for dispId.
116
+ """
117
+ return self._context.post_model_list(
118
+ StkSodRef,
119
+ f'{self._api_root}/stk-sod-ref',
120
+ payload={
121
+ 'date': parse_date_str_arg(date, False),
122
+ 'ids': None if ids is None else parse_str_list_arg(ids),
123
+ 'stableId': stable_id,
124
+ },
125
+ )
126
+
127
+ def stk_eod_md_id(
128
+ self,
129
+ id: str,
130
+ start: DateStrArgType,
131
+ end: DateStrArgType,
132
+ stable_id: bool = True,
133
+ ) -> Union[List[StkEodMd], Awaitable[List[StkEodMd]]]:
134
+ """Get one stock's end-of-day data within an inclusive date range.
135
+
136
+ Parameters
137
+ ----------
138
+ id : str
139
+ A single stock ID; its meaning is controlled by stable_id.
140
+ start, end : str, datetime.date or datetime.datetime
141
+ Inclusive dates; strings accept YYYY-MM-DD or YYYYMMDD.
142
+ end must not precede start.
143
+ stable_id : bool, default: True
144
+ True filters by stable (first-listing) ID. False uses the current
145
+ latest ID, independent of start/end, and replaces every returned
146
+ id with that latest ID. If multiple listings match, the server
147
+ uses the last listing by start_time.
148
+
149
+ Returns
150
+ -------
151
+ list[StkEodMd] or Awaitable[list[StkEodMd]]
152
+ Records sorted by date ascending; await with AsyncWebDataClient.
153
+ """
154
+ return self._context.post_model_list(
155
+ StkEodMd,
156
+ f'{self._api_root}/stk-eod-md-id',
157
+ payload={
158
+ 'id': id,
159
+ 'start': parse_date_str_arg(start, False),
160
+ 'end': parse_date_str_arg(end, False),
161
+ 'stableId': stable_id,
162
+ },
163
+ )
164
+
165
+ def stk_sod_ref_id(
166
+ self,
167
+ id: str,
168
+ start: DateStrArgType,
169
+ end: DateStrArgType,
170
+ stable_id: bool = True,
171
+ ) -> Union[List[StkSodRef], Awaitable[List[StkSodRef]]]:
172
+ """Get one stock's pre-market data within an inclusive date range.
173
+
174
+ Parameters
175
+ ----------
176
+ id : str
177
+ A single stock ID; its meaning is controlled by stable_id.
178
+ start, end : str, datetime.date or datetime.datetime
179
+ Inclusive dates; strings accept YYYY-MM-DD or YYYYMMDD.
180
+ end must not precede start.
181
+ stable_id : bool, default: True
182
+ True filters by stable (first-listing) ID. False uses the current
183
+ latest ID, independent of start/end. If multiple listings match,
184
+ the server uses the last listing by start_time. Returned fields
185
+ remain unchanged: id is stable and display_id is the ticker plus
186
+ exchange on each record's date.
187
+
188
+ Returns
189
+ -------
190
+ list[StkSodRef] or Awaitable[list[StkSodRef]]
191
+ Records sorted by date ascending; await with AsyncWebDataClient.
192
+ """
193
+ return self._context.post_model_list(
194
+ StkSodRef,
195
+ f'{self._api_root}/stk-sod-ref-id',
196
+ payload={
197
+ 'id': id,
198
+ 'start': parse_date_str_arg(start, False),
199
+ 'end': parse_date_str_arg(end, False),
200
+ 'stableId': stable_id,
201
+ },
202
+ )