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.3.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.3.tar.gz.
File metadata
- Download URL: tendquant-0.1.3.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 |
fa55e96c40e6cf9929ccf29b1553e5b655d6b2070d3355a7eed6419019b8db00
|
|
| MD5 |
cfa37dbafda6a5c58e3c16f5e90a035b
|
|
| BLAKE2b-256 |
2b797f5803f2366e39ae2172decaeee612b042ff58dc77ed5f1bc956dc68616e
|
File details
Details for the file tendquant-0.1.3-py3-none-any.whl.
File metadata
- Download URL: tendquant-0.1.3-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 |
11b6c9fbe24b9e2ba9a4bf5bc4f4f1be907df9428e3c56bf549f0f3b21aad321
|
|
| MD5 |
c73c2ca807512c4f5e07984c7145e7bb
|
|
| BLAKE2b-256 |
56d8e0416a90243ed53520c6baaab1a8d3c332d7d5df274c8b6983e5b3c6e3c2
|