A MQTT client library for tendQuant
Project description
tendQuant
个人量化开发必备,快速获取A股全市场5000+股票和场内ETF的实时行情数据,基于 MQTT 协议提供实时、稳定、高效的行情数据推送服务,免费获取常见 A股 指数的实时行情数据。
官网链接:https://tendquant.cn
项目地址:https://github.com/top2189/tendQuant
功能特性
- MQTTv5支持:默认使用MQTTv5协议
- WebSocket支持:支持通过WebSocket协议连接
- 自动重连:断开连接后自动尝试重连
- 简单API:简洁的订阅/取消订阅接口
- 错误处理:详细的错误信息和处理机制
安装方法
pip install -U tendquant
使用示例
基本用法
from tendquant import Client
# 创建客户端实例
client = Client(
username="a2dZMmrflhY4MwRN",
password="6WUc6unvD4G3VVPx4K6t2Nl5mVq4fjtu",
)
# 连接到broker
client.connect()
# 订阅主题
client.subscribe("lv1/tradeList/000001")
client.subscribe("lv1/tradeList/600000")
# 取消订阅
client.unsubscribe("lv1/tradeList/000001")
# 断开连接
client.disconnect()
自定义消息处理器
from tendquant import Client
import json
def custom_on_message(client, userdata, msg):
topic = msg.topic
payload = msg.payload.decode('utf-8')
data = json.loads(payload)
print(f"收到消息: {topic} -> {data}")
# 创建客户端
client = Client(
username="a2dZMmrflhY4MwRN",
password="6WUc6unvD4G3VVPx4K6t2Nl5mVq4fjtu",
)
# 设置自定义消息处理器
client.client.on_message = custom_on_message
# 连接
client.connect()
CLI工具
Cli工具使用
# 订阅所有股票的五档盘口数据,“#” 表示订阅所有股票代码
tendquant -u a2dZMmrflhY4MwRN -p 6WUc6unvD4G3VVPx4K6t2Nl5mVq4fjtu -s lv1/orderBook/#
许可证
MIT License
贡献
欢迎贡献代码!请提交Pull Request。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tendquant-1.1.2.tar.gz
(10.8 kB
view details)
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
tendquant-1.1.2-py3-none-any.whl
(11.5 kB
view details)
File details
Details for the file tendquant-1.1.2.tar.gz.
File metadata
- Download URL: tendquant-1.1.2.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d092c8bcd66ad842ddef08f73a1bbad6be5224d82f88d9086bf619ecef5ccd4f
|
|
| MD5 |
cfd63b28e00e142bc434c5d21d9a4fee
|
|
| BLAKE2b-256 |
230fb09a76dd5d75ec1881d0835b5c12c03683c5124e16e6b200a731a2e438bd
|
File details
Details for the file tendquant-1.1.2-py3-none-any.whl.
File metadata
- Download URL: tendquant-1.1.2-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ad2f61f7ed1e50d54c961925ba2bef264c852bdb8e58eedc6f8ad5c7d068cb7
|
|
| MD5 |
1ea94a0a62f5d98d7dd179f957064e9a
|
|
| BLAKE2b-256 |
d401bde28ba3a6c767f282066b879586522eee2822d6f86a01dcebd96f6e4827
|