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(
    username="test",
    password="test",
)

# Connect to broker
client.connect()

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

# 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(username=None, password=None, keepalive=60, use_ws=False, ws_path="/mqtt")

Create a new MQTT client instance.

  • 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.1.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.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tendquant-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 6d77a308cd138576a53abca5730466bf26a1c4a71c989afd5805fbc4fe82a597
MD5 98acebcc852515a1219cbadb2aee875c
BLAKE2b-256 f05ed0e701f29db595306f17316c80599ad17d37433140fe8f357ebf4e804131

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tendquant-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bac7d21ab803437a365b918a1e7b4d21bc3c9727c51191270fbd4efa53c1a91c
MD5 1fbc4a7b8742f3a1efe5fa1bebe38195
BLAKE2b-256 f8ba65891a031e8e8738b02f030ea6b8f19293cb686afc8e2051f9696470a505

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