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.4.tar.gz
(6.5 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.4.tar.gz.
File metadata
- Download URL: tendquant-0.1.4.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80d494083a7aee715f6b99feb7f74bf529f8a57330ffb94c4ab7ce981a35ad26
|
|
| MD5 |
eca7343615916ecb0d152d2b0e099c12
|
|
| BLAKE2b-256 |
7722fac0ba9e89df7d02336b1cbe47eb5c8a4af3b8b756cb460c4ca980095694
|
File details
Details for the file tendquant-0.1.4-py3-none-any.whl.
File metadata
- Download URL: tendquant-0.1.4-py3-none-any.whl
- Upload date:
- Size: 6.7 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 |
a77d02bb62733546c54eeb1d2438c5fe35b6a4440caae1071d4222b26b887ef6
|
|
| MD5 |
a12dfce71ba676577c26e86e055623b6
|
|
| BLAKE2b-256 |
aad93d6814ba78848ad74854b2b65e4f47102635a47e4f66a987d6bef18c4577
|