Metadata-Version: 2.1
Name: ys_base
Version: 0.1.6
Summary: YS 统一 SDK：契约模型 / auth 客户端与差量同步 / 应用服务骨架 / 交易网关
Author-email: ys <popsars@gmail.com>
Requires-Python: >=3.12
Description-Content-Type: text/markdown
Requires-Dist: pydantic>=2.7,<3
Requires-Dist: websockets>=13,<16
Requires-Dist: loguru>=0.7,<1
Requires-Dist: aiosqlite>=0.20,<1
Requires-Dist: motor>=3.5,<4 ; extra == "mongo"
Requires-Dist: fastapi>=0.115,<1 ; extra == "server"
Requires-Dist: uvicorn[standard]>=0.30,<1 ; extra == "server"
Requires-Dist: pyjwt[crypto]>=2.9,<3 ; extra == "server"
Requires-Dist: aiohttp>=3.10,<4 ; extra == "trade"
Requires-Dist: certifi ; extra == "trade"
Requires-Dist: exchange-calendars>=4.5 ; extra == "trade"
Requires-Dist: pandas>=2.2 ; extra == "trade"
Requires-Dist: motor>=3.5,<4 ; extra == "trade"
Provides-Extra: mongo
Provides-Extra: server
Provides-Extra: trade

# ys_base

YS 统一 SDK：契约模型（contracts）、auth 客户端与差量同步（auth）、WebSocket RPC 基类（ws）、
本地存储（store，默认 SQLite）、子系统服务骨架（server，extra）、交易网关（trade，extra，P4 收编）。

```bash
pip install ys_base            # 契约 + auth 客户端 + SQLite 存储
pip install ys_base[server]    # + FastAPI 子系统骨架
pip install ys_base[trade]     # + 交易网关（纯策略系统只装这个）
```

使用 uv 添加依赖：

```bash
uv add ys_base             # 契约 + auth 客户端 + SQLite 存储
uv add "ys_base[server]"   # + FastAPI 子系统骨架
uv add "ys_base[trade]"    # + 交易网关（纯策略系统只装这个）
```

`trade` extra 提供统一行情查询、健康检查与高可用快照缓存：

```python
from ys_base.trade import (
	DefaultSnapshotFields,
	SnapshotCache,
	check_quote_service_alive,
	get_quote_by_symbol_id,
	get_quote_by_symbol_ids,
	get_statics_by_symbol_ids,
)

quotes = await get_quote_by_symbol_ids({"600000.SH", "300750.SZ"})
names = await get_quote_by_symbol_ids(["600000.SH"], fields="f57,f58")
statics = await get_statics_by_symbol_ids({"600000.SH"})
alive = await check_quote_service_alive()

cache = SnapshotCache(
	fetcher=get_quote_by_symbol_ids,
	ttl_seconds=30,
	stale_ttl_seconds=300,
)
snapshots = await cache.get(slot_key="2026-07-24T09:30:00", symbol_ids={"600000.SH"})
```

`DefaultSnapshotFields == "f43,f58,f60"`，返回原始 `f*` 字段，并固定映射
`f43 -> close`、`f60 -> pre_close`、`f58 -> name`。不提供 `last_price` 或 `pre_price` 兼容字段；
可通过字符串或字段集合指定其他 `fields`。`SnapshotCache` 会合并同一时间片的并发回源，
并在短暂回源失败时使用 `stale_ttl_seconds` 范围内的最近快照。

刚发布的新版本若已在 PyPI 页面可见，但 uv 仍提示该版本不存在，通常是本地缓存的 PyPI Simple Index 元数据尚未更新。先清理单包缓存并从官方源重试：
uv cache clean ys-base：优先清理单包缓存。
uv cache clean：单包清理无效时清理完整缓存。
使用 --default-index https://pypi.org/simple 从官方 PyPI 重新安装。
使用 --refresh 强制刷新解析。
```bash
uv cache clean ys-base
uv add "ys_base[trade]" --default-index https://pypi.org/simple --refresh
```

如果仍无法解析，再清理完整缓存：
```bash
uv cache clean
uv add "ys_base[trade]" --default-index https://pypi.org/simple --refresh
```

设计文档：ys_auth/docs/架构方案.md（v6 终版）、契约初稿.md。

