Metadata-Version: 2.1
Name: tendQuant
Version: 0.1.0
Summary: A MQTT client library for tendQuant
Home-page: https://github.com/top2189/tendQuant
Author: tendQuant
Author-email: tendQuant <fengyuan2189@gmail.com>
Project-URL: Homepage, https://github.com/top2189/tendQuant
Project-URL: Bug Tracker, https://github.com/top2189/tendQuant/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: paho-mqtt>=2.0.0

# 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

```bash
pip install tendQuant
```

## Usage

### Basic Usage

```python
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

```python
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.
