TickPlusSkill
TickPlus 股票数据 API Python SDK - 提供沪深京A股、ETF基金、沪深可转债、指数的实时行情和历史数据查询服务,支持 REST API 和 WebSocket 实时推送。
📋 项目简介
本项目是 TickPlus 平台的 Python SDK 实现,提供了完整的 API 接口调用封装,支持获取:
- 实时行情: A股、ETF、可转债、指数的实时报价数据
- K线数据: 日线、周线、月线、年线及 1m/5m/15m/30m/1h 分钟线
- 指标数据: 行情指标(量比、换手率、市盈率等)、核心财务指标、股本数据
- 高级数据: 逐笔交易、Tick数据、买卖五档、集合竞价、异动数据(涨停板股池)
- WebSocket 实时推送: 长连接实时数据推送,支持秒级更新
✨ 主要特性
- ✅ 支持 16 个 REST API 接口,覆盖基础、专业、专家三个等级
- ✅ 支持 WebSocket 实时推送,秒级数据更新
- ✅ 完整的数据类型支持:沪深京A股、ETF基金、沪深可转债、指数
- ✅ 清晰的权限分级:基础版、高级版、专业版
- ✅ 简洁的 API 设计,易于集成和使用
- ✅ 统一的错误处理和日志输出
📦 安装依赖
pip install tickplus
也可以从源码仓库安装:
pip install git+https://github.com/tickplusx/TickPlusSkill.git
依赖包:
requests: HTTP 请求库websocket-client: WebSocket 客户端库pandas: 数据处理(可选)
🚀 快速开始
1. 配置 Token
在 TickPlus官网 注册账号并获取 token,然后修改配置文件:
# tickplus/scripts/Config.py
class Config:
SERVER_URL = "http://api.tickplus.org"
TOKEN = "your_token_here" # 替换为你的token
2. 基本使用
REST API 使用
from tickplus.scripts.api import BasicApi, ProApi, ExpertApi
from tickplus.scripts.Config import Config
token = Config.TOKEN
# 获取股票列表(stock/etf/bond/index)
stocks = BasicApi.getStockList(symbol="stock", token=token)
print(f"共 {len(stocks)} 只股票")
# 获取实时行情
quotes = BasicApi.getFullQuotes(
symbol="stock",
code="000001,000002",
token=token
)
# 获取日K线数据
from datetime import datetime, timedelta
end_date = datetime.now().strftime("%Y-%m-%d")
start_date = (datetime.now() - timedelta(days=30)).strftime("%Y-%m-%d")
kline = BasicApi.getDayKline(
symbol="stock",
code="000001",
period="1d",
dividend="1",
startDate=start_date,
endDate=end_date,
token=token
)
WebSocket 实时推送使用
from tickplus.scripts.StockWebSocketClient import StockWebSocketClient
from tickplus.scripts.Config import Config
import time
token = Config.TOKEN
ws_url = f"ws://ws.tickplus.org/ws/{token}"
# 创建客户端实例
client = StockWebSocketClient(ws_url)
# 建立连接
if client.connect():
# 订阅数据(集合竞价 + 个股 tick + 分钟K线)
auth_codes = ["auction", "000001.SZ", "600000.SH", "minute.hsj"]
client.subscribe(token, auth_codes)
# 等待接收数据
print("Waiting for data...")
time.sleep(10)
# 取消订阅
client.unsubscribe(token, auth_codes)
# 断开连接
client.disconnect()
3. 运行完整测试
测试 REST API
python tickplus/scripts/StockApiClient.py
# 等价写法(在项目根目录执行)
python -m tickplus.scripts.StockApiClient
这将测试所有 16 个 REST API 接口,验证功能是否正常。
测试 WebSocket 实时推送
python tickplus/scripts/StockWebSocketClient.py
# 等价写法(在项目根目录执行)
python -m tickplus.scripts.StockWebSocketClient
这将测试 WebSocket 连接、订阅、数据接收、取消订阅等功能。
📚 API 接口分类
WebSocket 实时推送
| 功能 | 说明 | 权限 |
|---|---|---|
| StockWebSocketClient | WebSocket 客户端 | 按数据类型开通 |
| connect() | 建立 WebSocket 连接 | 按数据类型开通 |
| subscribe() | 订阅股票代码/数据类型 | 按数据类型开通 |
| unsubscribe() | 取消订阅 | 按数据类型开通 |
| disconnect() | 断开连接 | 按数据类型开通 |
特点:
- 长连接,服务器主动推送数据
- 秒级数据更新
- 支持文本和二进制(gzip/zip)数据格式
- 适用于实时性要求高的场景
推送权限与数据类型对应:
| authCode | 数据 | 对应接口(权限) |
|---|---|---|
000001.SZ / 600000.SH |
个股 tick | /plus/basic/fullquotes(1、2、3)、/plus/expert/fivelevel(3) |
auction |
集合竞价 | /plus/expert/fullbid(3) |
minute.hsj / minute.index / minute.etf |
1 分钟 K 线 | /plus/pro/fullminute(2、3) |
Basic Api(基础接口)- 基础版、高级版、专业版可用
| 接口 | 说明 | 权限 |
|---|---|---|
| getStockList | 获取股票列表 | 基础版+ |
| getFullQuotes | 实时行情全推 | 基础版+ |
| getDayKline | 实时日K线数据 | 基础版+ |
| getFullMetric | 行情指标全推 | 基础版+ |
| getFinanceCore | 核心财务指标 | 基础版+ |
| getCapital | 股本数据 | 基础版+ |
| getUpdateDayKline | 盘后增量数据 | 基础版+ |
Pro Api(专业接口)- 高级版、专业版可用
| 接口 | 说明 | 权限 |
|---|---|---|
| getTimeKline | 日内分时数据 | 高级版+ |
| getGncgf | 题材概念成分股 | 高级版+ |
| getMinuteKline | 实时分钟K线数据 | 高级版+ |
| getFullMinute | 盘中分钟K线全推 | 高级版+ |
| getFullMinuteSnapshot | 盘中分钟快照全推 | 高级版+ |
Expert Api(专家接口)- 专业版可用
| 接口 | 说明 | 权限 |
|---|---|---|
| getTransaction | 逐笔交易数据 | 专业版 |
| getFiveLevel | 买卖五档全推 | 专业版 |
| getFullBid | 集合竞价全推 | 专业版 |
| getFluctuation | 异动数据(涨停板股池) | 专业版 |
权限说明:
- 基础版 (1): 免费注册用户,可访问 Basic Api
- 高级版 (2): 付费升级用户,可访问 Basic Api + Pro Api
- 专业版 (3): 专业级用户,可访问所有接口
- 权限向下兼容,高级版权限包含基础版,专业版权限包含高级版
📖 详细文档
- API 接口文档: tickplus/references/apidoc.md
- WebSocket 详细文档: tickplus/references/websocket.md
- 使用技能文档: tickplus/SKILL.md
- 在线文档: http://www.tickplus.org/doc
- GitHub 项目: https://github.com/tickplusx/TickPlusSkill
💡 使用示例
示例1:批量获取股票行情
# 获取多只股票的实时行情
codes = "000001,000002,600000,600519" # 平安银行、万科A、浦发银行、贵州茅台
quotes = BasicApi.getFullQuotes(symbol="stock", code=codes, token=token)
for quote in quotes:
print(f"{quote['code']}: 最新价={quote['c']}, 昨收={quote['pc']}")
示例2:获取行情指标
# 行情指标接口没有 symbol 参数
indicators = BasicApi.getFullMetric(code="000001", token=token)
if indicators:
data = indicators[0]
print(f"最新价: {data['zxj']}")
print(f"涨跌幅: {data['zdf']}%")
print(f"换手率: {data['hsl']}%")
print(f"市盈率(TTM): {data['ttmsyl']}")
print(f"总市值: {data['zsz']}")
示例3:获取板块成分股
# 获取行业板块列表(需要高级版或专业版权限)
industries = ProApi.getGncgf(symbol="hy", token=token)
for industry in industries:
print(f"板块: {industry['bkname']}")
print(f"成分股数量: {len(industry['stocks'])}")
print(f"成分股: {', '.join(industry['stocks'][:5])}...") # 显示前5只
示例4:获取买卖五档
# 获取买卖五档数据(需要专业版权限,symbol 必填)
five_level = ExpertApi.getFiveLevel(symbol="stock", code="000001", token=token)
if five_level:
data = five_level[0]
print("买盘:")
for i in range(1, 6):
print(f" 买{i}: {data[f'bp{i}']} x {data[f'bv{i}']}")
print("卖盘:")
for i in range(1, 6):
print(f" 卖{i}: {data[f'sp{i}']} x {data[f'sv{i}']}")
示例5:获取异动数据(涨停板股池)
# 需要专业版权限
fluctuation = ExpertApi.getFluctuation(tradeDate="2026-11-14", token=token)
for item in fluctuation:
print(f"{item['code']} 连续涨停 {item['days']} 天,封板资金 {item['fba']}")
示例6:WebSocket 实时推送
基础用法:
from tickplus.scripts.StockWebSocketClient import StockWebSocketClient
from tickplus.scripts.Config import Config
import time
token = Config.TOKEN
ws_url = f"ws://ws.tickplus.org/ws/{token}"
# 创建客户端实例
client = StockWebSocketClient(ws_url)
# 建立连接
if client.connect():
# 订阅集合竞价、个股 tick 和分钟K线
auth_codes = ["auction", "000001.SZ", "600000.SH", "minute.hsj"]
client.subscribe(token, auth_codes)
# 等待接收数据(服务器会主动推送)
print("Waiting for real-time data...")
time.sleep(10)
# 取消订阅
client.unsubscribe(token, auth_codes)
# 断开连接
client.disconnect()
高级用法:
关于 WebSocket 的更多高级功能,包括:
- 自定义消息处理
- 错误处理和自动重连
- 数据批处理和过滤
- 性能优化建议
- 常见问题解答
请参考完整文档:tickplus/references/websocket.md
获取官方示例代码:
# 从 GitHub 获取最新示例
git clone https://github.com/tickplusx/TickPlusSkill.git
cd TickPlusSkill
# 运行 WebSocket 测试
python tickplus/scripts/StockWebSocketClient.py
🔧 项目结构
DemoTickPlusPythonSkill/
├── tickplus/
│ ├── __init__.py
│ ├── SKILL.md # 使用技能文档
│ ├── references/
│ │ ├── apidoc.md # API接口文档(由 apidoc.json 生成)
│ │ └── websocket.md # WebSocket详细文档
│ └── scripts/
│ ├── api/
│ │ ├── BasicApi.py # 基础API接口(7个)
│ │ ├── ProApi.py # 专业API接口(5个)
│ │ └── ExpertApi.py # 专家API接口(4个)
│ ├── util/
│ │ └── DataUtil.py # 请求与压缩数据解析工具
│ ├── Config.py # 配置文件
│ ├── StockApiClient.py # REST API客户端测试类
│ ├── StockWebSocketClient.py # WebSocket客户端
│ ├── CompleteExampleClient.py # WebSocket完整示例
│ ├── generate_apidoc.py # apidoc.md 生成器
│ └── __init__.py
├── requirements.txt # 依赖包
└── README.md # 项目说明
⚠️ 注意事项
- Token 认证: 所有接口都需要有效的 token,请在官网注册获取
- 权限等级:
- Basic Api: 基础版、高级版、专业版可用
- Pro Api: 高级版、专业版可用
- Expert Api: 仅专业版可用
- WebSocket 推送: 分钟K线推送为高级版+,五档/竞价推送为专业版
- WebSocket 连接:
- WebSocket地址:
ws://ws.tickplus.org/ws/{token} - 支持实时数据推送,数据更新频率为秒级
- 订阅后服务器会主动推送数据,无需轮询
- 支持文本和二进制(gzip/zip)两种数据格式
- 官方示例:https://github.com/tickplusx/TickPlusSkill
- WebSocket地址:
- 批量限制: 批量查询最多支持 100 个股票代码
- 单只限制:
daykline、financecore、capital、timekline、minutekline、transaction仅支持单个股票代码 - 无 symbol 参数:
fullmetric(行情指标)与fullbid(集合竞价)只接受code与token - 日期格式: 统一使用
YYYY-MM-DD格式 - 交易时间:
- A股: 09:30-11:30, 13:00-15:00
- 集合竞价: 09:15-09:25
- 性能建议:
- 避免频繁全市场数据请求
- 批量查询优于多次单次查询
- 缓存常用数据减少 API 调用
- 对于实时性要求高的场景,优先使用 WebSocket
🤝 贡献指南
欢迎提交 Issue 和 Pull Request!
📄 许可证
本项目仅供学习和研究使用。
🔗 相关链接
- TickPlus 官网: http://www.tickplus.org
- 在线文档: http://www.tickplus.org/doc
- API 接口文档: tickplus/references/apidoc.md
- WebSocket 详细文档: tickplus/references/websocket.md
- GitHub 项目: https://github.com/tickplusx/TickPlusSkill
📮 联系方式
如有问题或建议,请通过以下方式联系:
- Email: tickplus@126.com
最后更新: 2026-11-14
Metadata
Release files for tickplus 0.1.3
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 |
|---|---|---|---|---|
| tickplus-0.1.3.tar.gz | 34.5 kB | Without provenance | Details for tickplus-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tickplus-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for tickplus-0.1.3-py3-none-any.whl |
Total release size: 73.1 kB
Release files / tickplus-0.1.3.tar.gz
| Download URL | tickplus-0.1.3.tar.gz |
|---|---|
| Size | 34.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f11d33e6061f8bc1958a3a907e6aa297fce41ba11a2c6eeab0c0a90dcebe6e31
|
|
BLAKE2b-256 checksum How to use checksums |
d4505b869482f303e83928b216d0cbddd32b77521bfc3a6be92b14fbd025db5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.4
|
Release files / tickplus-0.1.3-py3-none-any.whl
| Download URL | tickplus-0.1.3-py3-none-any.whl |
|---|---|
| Size | 38.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cc30fb61608761a0820f2fbc4fb53a8ec51924927a1de8edf28620807590057f
|
|
BLAKE2b-256 checksum How to use checksums |
8bbb65b892cb7ed3bfe82166b0fd9706d449c965125c49fb522011477bf0e647
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.4
|
Security for tickplus 0.1.3
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.