ys_base
YS 统一 SDK:契约模型(contracts)、auth 客户端与差量同步(auth)、WebSocket RPC 基类(ws)、
Mongo 存储(store,随基础安装)、子系统服务骨架(server,extra)。
交易网关已独立为 ys_trade_sdk,网关改动不再升本包。
pip install ys_base # 契约 + auth 客户端 + Mongo 存储
pip install ys_base[server] # + FastAPI 子系统骨架
使用 uv 添加依赖:
uv add ys_base # 契约 + auth 客户端 + Mongo 存储
uv add "ys_base[server]" # + FastAPI 子系统骨架
uv add ys_trade_sdk # 交易网关,独立版本
本仓库开发与全量测试需要安装全部 extras:
uv python install 3.13
uv sync --all-extras --frozen
uv run pytest
列表搜索(0.1.98 起)
服务端过滤的列表用 ys_base.search,规则与前端 @ysgroup/core 的 ysSearchText / ysMatch 完全相同
(全角转半角、不分大小写、空格分隔多关键词全部命中、拼音首字母/全拼/zh ch sh/最后一字半个全拼/多音字、
数字两边去千分位、数字原值自动加两位小数)。拼音数据与前端同源,由 tools/pinyin/build.py 生成,无第三方依赖。
from ys_base.search import ys_filter, ys_match, ys_matcher, ys_search_text
def text_of(row: dict) -> str:
# 传页面上显示的文字(含格式化后的数字),数字字段再传一次原值
return ys_search_text(row["name"], row["status_label"], f"{row['amount']:,.2f}", row["amount"])
ys_match(text_of(row), "zhs 1,377") # 单行判断
rows = ys_filter(rows, keyword, text_of) # 逐行过滤,关键词只处理一次
match = ys_matcher(keyword) # 或自己循环:match(text) -> bool
Decimal、bson.Decimal128 按数字处理;bool 写成 true/false,list/tuple 展开,None、空串跳过。
快速发布到 PyPI
先在 ys_base/__init__.py 中更新 __version__。PyPI 不允许覆盖已经发布的同版本文件,因此每次发布必须使用新版本号。
使用 project-scoped PyPI token,并将其保存在 macOS 钥匙串,不在项目目录、环境文件或 Shell 配置中保存明文 Token。
必须使用经典的“钥匙串访问”应用手动添加:文件 -> 新建密码项,不要使用新版“密码”App。新版“密码”App 管理的是网站密码,会强制要求填写网站,凭据类型不适合 PyPI 发布 Token。
在“钥匙串访问”中选择“登录”钥匙串,手动添加密码项目并填写:
- 钥匙串项目名称:
pypi:__token__ - 账户名称:当前 macOS 用户名
- 密码:完整的 PyPI project-scoped Token
保存后不要使用会直接输出密码内容的命令检查 Token。发布脚本会从钥匙串读取该通用密码,并只注入单次 uv publish 进程,不会打印、写入项目文件或长期导出为环境变量。
在 ys_platform 仓库根目录执行:
cd ys_base
./publish-pypi.sh
脚本会自动运行测试、构建、审计 wheel/sdist、上传,并校验 PyPI 文件哈希。发布成功后等清华镜像可下载该版本,再在消费仓升锁:
uv cache clean ys-base
version=$(sed -n 's/__version__ = "\([^"]*\)"/\1/p' ys_base/ys_base/__init__.py)
# 确认清华镜像已有该版本后再执行
uv add "ys_base==$version"
交易客户端、行情、静态信息和收益数据服务在 ys_trade_sdk。每个 TradeManager 独占一个 TradeRuntime。
业务系统使用 ys_base 0.1.29 后,Auth 协议逻辑表名继续保持 users、owners、accounts、brokers;Mongo 物理镜像统一为 _auth_*,同步状态为 _auth_sync_state,本地身份集合为 _local_users、_local_user_roles。MongoStore 启动时只对历史集合执行预检后的原地 rename,检测到新旧集合或同步状态键并存会拒绝启动。
from ys_trade_sdk import (
Account,
TradeManager,
TradeRuntimeConfig,
)
manager = TradeManager(
accounts=[
Account(
account="A001",
password="...",
trade_source="xt",
trade_uri="ws://trade.example.com",
profit_enabled=True,
)
],
runtime_config=TradeRuntimeConfig(
quote_data_base_url="http://quote.example.com",
symbol_data_base_url="http://symbol.example.com",
symbol_data_username="symbol-user",
symbol_data_password="symbol-password",
trade_data_base_url="http://trade-data.example.com",
trade_data_username="trade-user",
trade_data_password="trade-password",
),
)
quotes = await manager.query_snapshots({"600000.SH", "300750.SZ"})
refreshed = await manager.query_snapshots_with_refresh({"600000.SH"}, {"f43", "f58", "f60"})
statics = await manager.query_static_infos({"600000.SH"}, {"name", "pre_close"})
alive = await manager.check_snapshot_service_alive()
DefaultSnapshotFields == "f43,f58,f60",返回原始 f* 字段,并固定映射
f43 -> close、f60 -> pre_close、f58 -> name。不提供 last_price 或 pre_price 兼容字段;
可通过字符串或字段集合指定其他 fields。
query_snapshots()是无缓存单次查询,不登记后台刷新标的。query_snapshots_with_refresh()登记当日标的和字段,并在09:00:00-15:30:00每 2 秒持续刷新; 当日标的和字段只增不减。- Snapshot 和 StaticInfo 缓存在上海自然日变化时会同时清空日期、标的、字段和记录。
- 只有账号
profit_enabled=True(Trade 本地字段,缺省为 True)时,才要求 Snapshot、StaticInfo 和 TradeData 三类服务地址齐全。
刚发布的新版本若已在 PyPI 页面可见,但 uv 仍提示该版本不存在,通常是清华镜像尚未同步,或本地缓存的 Simple Index 尚未更新。生产锁文件必须继续走清华镜像,禁止 --default-index https://pypi.org/simple。
先确认镜像:
curl -fsS "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/ys-base/" | grep "ys_base-$version"
镜像已有该版本后,清理单包缓存再升锁:
uv cache clean ys-base
uv add "ys_base==$version" --refresh
如果仍无法解析,再清理完整缓存后重试同一条 uv add,不要改官方源。镜像长时间没有该版本时停止升锁并等待同步。
当前四仓边界、公共包依赖和配置规则见仓库根 docs/业务系统架构方案.md;开发与发版见 docs/业务系统开发规范.md。
Metadata
Release files for ys_base 0.1.98
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ys_base-0.1.98.tar.gz | 184.0 kB | Without provenance | Details for ys_base-0.1.98.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ys_base-0.1.98-py3-none-any.whl | Python 3 | none | any | Details for ys_base-0.1.98-py3-none-any.whl |
Total release size: 298.5 kB
Release files / ys_base-0.1.98.tar.gz
| Download URL | ys_base-0.1.98.tar.gz |
|---|---|
| Size | 184.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d69698287a8f2f04362a6c0cb0a0151dc71ce96a8bd26d1ed06f028d6df358dc
|
|
BLAKE2b-256 checksum How to use checksums |
dfed1dcabfb418ada3b6deaf3010c5bb3473a3c673c21c42e9564aa981150011
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / ys_base-0.1.98-py3-none-any.whl
| Download URL | ys_base-0.1.98-py3-none-any.whl |
|---|---|
| Size | 114.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
106cc9053cd8a8a56526e1f2bb6122cffa76f5a87d5837755f03556897d5c550
|
|
BLAKE2b-256 checksum How to use checksums |
ecb5eb69b738aaa64826673ed022fbecef78d0dcd8d093dd3cacfa1e9eef09d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for ys_base 0.1.98
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.