English | 中文
Tianji Symbols
面向中国证券的代码识别、标准化与多格式转换工具。
Tianji Symbols 是 Tianji 开源市场研究工具生态的组成部分。它可以在 Tushare、新浪、东方财富、聚宽、BaoStock 与 Tianji 自身常用的代码格式之间转换。
特性
- 自动识别常见的中国证券代码格式
- 转换为指定的目标格式
- Tianji 标准格式:
600519.SH - 支持沪深北(SSE、SZSE、BSE)规则
- 可编程查询的格式注册表
- 输出大小写控制(
is_lower) - 离线优先,零外部数据依赖
安装
pip install tj-symbols
快速开始
from tj_symbols import convert, normalize, parse_symbol
convert("SH600519", to="tianji")
# "600519.SH"
convert("600519.SH", to="sina")
# "sh600519"
convert("000001.SZ", to="eastmoney")
# "0.000001"
normalize("sh600519")
# "600519.SH"
parse_symbol("600519.SH")
# ParseResult(symbol=Symbol(code='600519', exchange=<Exchange.SSE: 'SSE'>, ...), source_format='tianji')
CLI
tjsym convert SH600519 --to tianji
# 600519.SH
tjsym convert 600519.SH --to sina
# sh600519
tjsym convert 000001 --to tianji --exchange SSE
# 000001.SH
tjsym parse 600519.SH --json
{
"code": "600519",
"exchange": "SSE",
"suffix": "SH",
"market": "CN_A_SHARE",
"asset_type": "stock",
"source_format": "tianji",
"normalized": "600519.SH"
}
支持的格式
tjsym formats
Name Example Input Output Exchanges Notes
tianji 600519.SH yes yes SSE,SZSE,BSE
tushare 600519.SH yes yes SSE,SZSE,BSE Currently equivalent to Tianji for supported markets.
prefix SH600519 yes yes SSE,SZSE,BSE
sina sh600519 yes yes SSE,SZSE BSE support is not guaranteed in MVP.
eastmoney 1.600519 yes yes SSE,SZSE BSE support varies by endpoint and is not guaranteed in MVP.
jqdata 600519.XSHG yes yes SSE,SZSE BSE mapping is reserved but not guaranteed in MVP.
baostock sh.600519 yes yes SSE,SZSE BSE support is not guaranteed in MVP.
plain 600519 yes yes SSE,SZSE,BSE lossy, ambiguous
plain 是有损格式:转换成它会丢失交易所信息。将裸 600519 转回来时按代码前缀推断交易所,可能存在歧义(见下文)。
歧义处理
裸 6 位代码可能存在歧义。000001 既可以是 000001.SZ(平安银行),也可以是 000001.SH(上证指数)。裸代码默认按股票 / 深市解释;传入 exchange 或 asset_type 可消除歧义。
normalize("000001")
# "000001.SZ"
normalize("000001", exchange="SSE")
# "000001.SH"
normalize("000001", asset_type="index")
# "000001.SH"
CLI 参考
tjsym convert <symbol> --to <format> [--from <fmt>] [--exchange <ex>] [--lower|--upper]
tjsym normalize <symbol>
tjsym parse <symbol> [--json]
tjsym detect-format <symbol>
tjsym detect-exchange <symbol>
tjsym validate <symbol>
tjsym formats [--json]
tjsym format-info <format> [--json]
开发
uv sync --group dev
uv run ruff check .
uv run ruff format --check .
uv run pyright
uv run pytest -q
Tianji 生态
Tianji 是一套面向市场研究的可组合开源工具生态。每个子项目都可以独立使用,也可以组合成完整的市场研究工作流。
- tj-calendar: 离线优先的交易日历
- tj-symbols: 证券代码标准化与格式转换
- tj-data: 市场数据适配与本地缓存
- tj-factors: 技术指标与因子
- tj-metrics: 绩效指标
- tj-backtest: 轻量回测
- tj-research: AI 辅助研究
- tj-terminal: 综合研究工作台
Notes / 说明
格式合法不代表证券真实存在。 本包不提供市场数据、投资建议或交易信号。
Disclaimer / 免责声明
This project is for research and educational purposes only. It does not provide investment advice, trading signals, or financial recommendations.
本项目仅用于研究和教育目的,不构成投资建议、交易信号或金融建议。
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tj_symbols-0.1.0.tar.gz.
File metadata
- Download URL: tj_symbols-0.1.0.tar.gz
- Upload date:
- Size: 31.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85c657563f94d54095311cf55073bc50c575a72de0427211457f7de5ba8ac5a3
|
|
| MD5 |
385c2d5b9a2b2c7e16c1670270b02130
|
|
| BLAKE2b-256 |
6ad7863713c910be3b45afd0ffd1407babdce7537f6b9752f1104bc28a659e3f
|
Provenance
The following attestation bundles were made for tj_symbols-0.1.0.tar.gz:
Publisher:
release.yml on Angryshark128/tj-symbols
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tj_symbols-0.1.0.tar.gz -
Subject digest:
85c657563f94d54095311cf55073bc50c575a72de0427211457f7de5ba8ac5a3 - Sigstore transparency entry: 2346850276
- Sigstore integration time:
-
Permalink:
Angryshark128/tj-symbols@ccc4797903039ddfd62aaf4774fc85095dfcbc09 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Angryshark128
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ccc4797903039ddfd62aaf4774fc85095dfcbc09 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tj_symbols-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tj_symbols-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
203bd47bb8bf36133a48b62c5dc9c8b03d1966411c3c16afa65295c9a98bfed4
|
|
| MD5 |
99d9a7c298da7ce3b91b7df2e6bd19f7
|
|
| BLAKE2b-256 |
1c3769d57a67b2e57dde9076b0c9f119397079a6d243b35c603c12df9279ca77
|
Provenance
The following attestation bundles were made for tj_symbols-0.1.0-py3-none-any.whl:
Publisher:
release.yml on Angryshark128/tj-symbols
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tj_symbols-0.1.0-py3-none-any.whl -
Subject digest:
203bd47bb8bf36133a48b62c5dc9c8b03d1966411c3c16afa65295c9a98bfed4 - Sigstore transparency entry: 2346850694
- Sigstore integration time:
-
Permalink:
Angryshark128/tj-symbols@ccc4797903039ddfd62aaf4774fc85095dfcbc09 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Angryshark128
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ccc4797903039ddfd62aaf4774fc85095dfcbc09 -
Trigger Event:
push
-
Statement type: