Skip to main content

A MQTT client library for tendQuant

Project description

tendQuant

A MQTT client library for tendQuant, supporting MQTTv5 and WebSocket.

Features

  • MQTTv5 Support: Default use MQTTv5 protocol
  • WebSocket Support: Support WebSocket connection
  • Auto Reconnect: Automatic reconnection when disconnected
  • Easy API: Simple subscribe/unsubscribe interface
  • Error Handling: Detailed error messages and handling

Installation

pip install tendQuant

Usage

Basic Usage

from tendquant import MQTTClient

# Create client instance
client = MQTTClient(
    broker="quant.top2189.cn",
    port=80,
    username="test",
    password="test",
    use_ws=True,
    ws_path="/ws"
)

# Connect to broker
client.connect()

# Subscribe to topics
client.subscribe("lv1/tradeList/600089")
client.subscribe("lv1/tradeList/600111")

# Publish message
client.publish("test/topic", "Hello, MQTT!")

# Unsubscribe
client.unsubscribe("lv1/tradeList/600089")

# Disconnect
client.disconnect()

Custom Message Handler

from tendquant import MQTTClient
import json

def custom_on_message(client, userdata, msg):
    topic = msg.topic
    payload = msg.payload.decode('utf-8')
    data = json.loads(payload)
    print(f"Received message on {topic}: {data}")

# Create client
client = MQTTClient("quant.top2189.cn", 80, use_ws=True, ws_path="/ws")

# Set custom message handler
client.client.on_message = custom_on_message

# Connect
client.connect()

API Reference

MQTTClient

init(broker, port, username=None, password=None, keepalive=60, use_ws=False, ws_path="/mqtt")

Create a new MQTT client instance.

  • broker: MQTT broker address
  • port: MQTT broker port
  • username: Username for authentication
  • password: Password for authentication
  • keepalive: Keepalive interval in seconds
  • use_ws: Use WebSocket protocol
  • ws_path: WebSocket path

connect()

Connect to MQTT broker.

subscribe(topic, qos=1)

Subscribe to a topic.

  • topic: Topic to subscribe
  • qos: Quality of Service level (0, 1, 2)

unsubscribe(topic)

Unsubscribe from a topic.

  • topic: Topic to unsubscribe

publish(topic, payload, qos=0, retain=False)

Publish a message to a topic.

  • topic: Topic to publish
  • payload: Message payload
  • qos: Quality of Service level
  • retain: Retain message

disconnect()

Disconnect from MQTT broker.

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a 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.0.tar.gz (6.7 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.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file tendquant-0.1.0.tar.gz.

File metadata

  • Download URL: tendquant-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 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.0.tar.gz
Algorithm Hash digest
SHA256 f99f00070145d4ce36e12f99d4a3248abcffafcd5d3dc64e9b0bdda0f813880b
MD5 c40c9a73f0f025aaca94292cfcf723bb
BLAKE2b-256 abb6b703196b6d035070098bb8dd2d72a5232d5d223c4bc92ced3477e32c2f32

See more details on using hashes here.

File details

Details for the file tendquant-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tendquant-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9fc0b308cb2becb3c6c73c5174fddab714d3d80c51be10bd1ac5ac48ced46fe7
MD5 ade707010bd07ad52a5d728bfc51c3a7
BLAKE2b-256 214fde2eb09aef8d785bdb0991d456de83c6a889cbcb2bd5828d568a63f9f55a

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