Skip to main content

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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tendquant-0.1.4-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

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

Hashes for tendquant-0.1.4.tar.gz
Algorithm Hash digest
SHA256 80d494083a7aee715f6b99feb7f74bf529f8a57330ffb94c4ab7ce981a35ad26
MD5 eca7343615916ecb0d152d2b0e099c12
BLAKE2b-256 7722fac0ba9e89df7d02336b1cbe47eb5c8a4af3b8b756cb460c4ca980095694

See more details on using hashes here.

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

Hashes for tendquant-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a77d02bb62733546c54eeb1d2438c5fe35b6a4440caae1071d4222b26b887ef6
MD5 a12dfce71ba676577c26e86e055623b6
BLAKE2b-256 aad93d6814ba78848ad74854b2b65e4f47102635a47e4f66a987d6bef18c4577

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page