Skip to main content

Python client for Zex exchange.

Project description

🔁 zex-sdk

A Python SDK for the Zex Exchange – a decentralized exchange (DEX) designed to deliver the speed, usability, and reliability of centralized exchanges (CEXs) while preserving the security and control of a DEX.

zex-sdk provides a seamless interface to interact with Zex Exchange's API, including essential trading, balance management, and live socket streaming capabilities.


🚀 Features

  • 📥 Place and cancel orders (single or batch)
  • 🧾 Register user accounts
  • 💰 Query account balances and user information
  • 📈 Retrieve live market prices
  • 🔄 Deposit and withdraw assets
  • 🔔 Live execution reports via WebSocket stream

📦 Installation

Install directly from PyPI:

pip install zex-sdk

⚡ Quick Start

Here's how to get started with the async Zex client in just a few lines of code.

import asyncio
from zex.sdk import AsyncClient

async def main():
    # Create a Zex client instance (testnet is True by default)
    client = await AsyncClient.create(api_key="your-api-key")

    # Example: get the price of ETH/USDT
    price = await client.get_price("ETH-USDT")
    print("Current price:", price)

asyncio.run(main())

Note: Use AsyncClient.create(...) instead of the constructor. It handles registration and setup for you.


📘 Usage Examples

Here are some common usage examples using the AsyncClient and ZexSocketManager.


✅ Place a Batch of Orders

from zex_sdk.models import PlaceOrderRequest, OrderSide

orders = [
    PlaceOrderRequest(
        base_token="ETH",
        quote_token="USDT",
        side=OrderSide.BUY,
        volume=0.5,
        price=1900.0
    ),
    PlaceOrderRequest(
        base_token="BTC",
        quote_token="USDT",
        side=OrderSide.SELL,
        volume=0.1,
        price=30000.0
    ),
]

await client.place_batch_order(orders)

❌ Cancel a Batch of Orders

# Suppose you have stored signed orders
signed_orders = [...] # List[bytes]

await client.cancel_batch_order(signed_orders)

📈 Get Current Market Price

price = await client.get_price("ETH-USDT")
print("ETH price:", price)

🔔 Listen to Execution Reports in Real-Time

from zex_sdk.socket import ZexSocketManager

async def on_execution_report(message):
    print("Execution report received:", message)

socket_manager = ZexSocketManager(client)

# Use async context manager to open and manage the socket
async with await socket_manager.execution_report_socket(on_execution_report):
await asyncio.sleep(60) # keep listening for 60 seconds

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

zex_sdk-0.4.0.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zex_sdk-0.4.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file zex_sdk-0.4.0.tar.gz.

File metadata

  • Download URL: zex_sdk-0.4.0.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.9 CPython/3.11.13 Linux/6.11.0-1018-azure

File hashes

Hashes for zex_sdk-0.4.0.tar.gz
Algorithm Hash digest
SHA256 28cf4ca07c4d966cc12feb955bba109473c14d1bce9a2f01d043a336ae1c88ab
MD5 8ddc9c0b1f6d67ee89a09abd8bfb7e07
BLAKE2b-256 adfd79d8d09710530f478786f755996c6b8303dbf5c4a5ab9a3b699a75b311a8

See more details on using hashes here.

File details

Details for the file zex_sdk-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: zex_sdk-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.9 CPython/3.11.13 Linux/6.11.0-1018-azure

File hashes

Hashes for zex_sdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4331cceaaf9ab693b18a9e3c02b2b424508bbefdf70636d7a3f8b5aa04aa48c
MD5 9b288061d7065c26b0bc1f9caec6b7db
BLAKE2b-256 95c3faf3e6f35277fde4072871ec7f2518f1814e8bc04a46eae723f39a0f5197

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