Metadata-Version: 2.4
Name: toobit-connector-python
Version: 0.1.0
Summary: Python3 Toobit HTTP/WebSocket API Connector
Home-page: https://github.com/nicetip/tbpy
Author: Toobit
Author-email: dev@toobit.com
License: MIT License
Keywords: toobit api connector
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28.0
Requires-Dist: websocket-client>=1.6.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# tbpy

Official Python3 API connector for Toobit's HTTP and WebSocket APIs.

## Installation

`tbpy` requires Python 3.10 or higher. Install via [PyPI](https://pypi.org/project/tbpy/):

```bash
pip install tbpy
```

## Quick Start

### REST API

```python
from tbpy import HTTP

# Public endpoints (no authentication)
client = HTTP(base_url="https://api.toobit.com")
print(client.get_exchange_info())
print(client.get_depth(symbol="BTCUSDT"))

# Authenticated endpoints
client = HTTP(
    base_url="https://api.toobit.com",
    api_key="YOUR_API_KEY",
    api_secret="YOUR_API_SECRET",
)
print(client.get_account())
```

### WebSocket Market Data

```python
import time
from tbpy import WebSocket

def handle_message(msg):
    print(msg)

ws = WebSocket(
    url="wss://stream.toobit.com/quote/ws/v1",
    on_message=handle_message,
)
ws.connect()
ws.subscribe(symbol="BTCUSDT", topic="realtimes")

try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    ws.disconnect()
```

### WebSocket Account Data (Spot)

```python
import time
from tbpy import HTTP, WebSocketAccount

http = HTTP(
    base_url="https://api.toobit.com",
    api_key="YOUR_API_KEY",
    api_secret="YOUR_API_SECRET",
)

ws = WebSocketAccount(
    http_client=http,
    on_message=lambda msg: print(msg),
)
ws.connect()

try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    ws.disconnect()
```

### WebSocket Account Data (Futures)

```python
import time
from tbpy import HTTP, WebSocketFuturesAccount

http = HTTP(
    base_url="https://api.toobit.com",
    api_key="YOUR_API_KEY",
    api_secret="YOUR_API_SECRET",
)

ws = WebSocketFuturesAccount(
    http_client=http,
    on_message=lambda msg: print(msg),
)
ws.connect()

try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    ws.disconnect()
```

## Available APIs

### Spot

| Category | Class | Description |
|----------|-------|-------------|
| Market Data | `HTTP` | Exchange info, depth, trades, klines, tickers |
| Wallet | `HTTP` | Withdraw, deposit address, deposit/withdraw history |
| Account & Trading | `HTTP` | Orders, balances, trades, transfers |
| WS Market Data | `WebSocket` | Real-time quotes, trades, klines, depth |
| WS Account Data | `WebSocketAccount` | Balance, order, trade push events |

### USDT-M Futures

| Category | Class | Description |
|----------|-------|-------------|
| Market Data | `HTTP` | Futures exchange info, depth, trades, klines, funding rate |
| Account & Trading | `HTTP` | Futures orders, positions, leverage, margin |
| WS Market Data | `WebSocket` | Real-time futures quotes, mark price, index, depth |
| WS Account Data | `WebSocketFuturesAccount` | Position, order, trade, TP/SL push events |

## Examples

Check out the [examples](examples/) directory for complete usage examples.

## Documentation

Full API documentation is available at [https://api-docs.toobit.com](https://api-docs.toobit.com).

## License

MIT License. See [LICENSE](LICENSE) for details.
