A MQTT client library for tendQuant
Project description
tendQuant
一个用于tendQuant的MQTT客户端库,支持MQTTv5和WebSocket协议。
功能特性
- MQTTv5支持:默认使用MQTTv5协议
- WebSocket支持:支持通过WebSocket协议连接
- 自动重连:断开连接后自动尝试重连
- 简单API:简洁的订阅/取消订阅接口
- 错误处理:详细的错误信息和处理机制
安装方法
pip install tendquant
使用示例
基本用法
from tendquant import Client
# 创建客户端实例
client = Client(
username="test",
password="test",
)
# 连接到broker
client.connect()
# 订阅主题
client.subscribe("lv1/tradeList/600089")
client.subscribe("lv1/tradeList/600111")
# 取消订阅
client.unsubscribe("lv1/tradeList/600089")
# 断开连接
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="test",
password="test",
)
# 设置自定义消息处理器
client.client.on_message = custom_on_message
# 连接
client.connect()
API参考
Client
init(username=None, password=None, keepalive=60, use_ws=False, ws_path="/mqtt")
创建一个新的MQTT客户端实例。
username: 认证用户名password: 认证密码keepalive: 心跳间隔(秒)use_ws: 是否使用WebSocket协议ws_path: WebSocket路径
connect()
连接到MQTT broker。
subscribe(topic, qos=1)
订阅主题。
topic: 要订阅的主题qos: 服务质量等级(0, 1, 2)
unsubscribe(topic)
取消订阅主题。
topic: 要取消订阅的主题
disconnect()
断开与MQTT broker的连接。
许可证
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-0.1.2.tar.gz
(6.4 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
File details
Details for the file tendquant-0.1.2.tar.gz.
File metadata
- Download URL: tendquant-0.1.2.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08387ca9a60810027458c28718c498ce7c73b46e6973dd1a78ed191b1b1ac1d7
|
|
| MD5 |
859b5d3a117dc530802cc054664d6dfb
|
|
| BLAKE2b-256 |
13d54d09f1ea9c988bc57d78e898b3c3bcda5a9cf2b7341058d98f682958b906
|
File details
Details for the file tendquant-0.1.2-py3-none-any.whl.
File metadata
- Download URL: tendquant-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.6 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 |
8ba576a2a3887d3dd6f121a3782c22e2fcf933fa9f8453f588ae6816276c1595
|
|
| MD5 |
2e6e72d032d52c2bd32e362346b8f7c7
|
|
| BLAKE2b-256 |
795cc1967094e16f8362e41ae1fa24376d76ffbdd378598c96dc090727f2d75f
|