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.2.tar.gz (6.4 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.2-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

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

Hashes for tendquant-0.1.2.tar.gz
Algorithm Hash digest
SHA256 08387ca9a60810027458c28718c498ce7c73b46e6973dd1a78ed191b1b1ac1d7
MD5 859b5d3a117dc530802cc054664d6dfb
BLAKE2b-256 13d54d09f1ea9c988bc57d78e898b3c3bcda5a9cf2b7341058d98f682958b906

See more details on using hashes here.

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

Hashes for tendquant-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8ba576a2a3887d3dd6f121a3782c22e2fcf933fa9f8453f588ae6816276c1595
MD5 2e6e72d032d52c2bd32e362346b8f7c7
BLAKE2b-256 795cc1967094e16f8362e41ae1fa24376d76ffbdd378598c96dc090727f2d75f

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