Skip to main content

dcex - DEX & CEX trading library

English | 繁體中文

dcex is a Rust-backed exchange library with synchronous and asynchronous Python clients and a standalone Rust crate. It covers market data, account queries, order APIs, and public and private WebSocket streams.

Broker codes: dcex does not set or attach a broker code or broker tag by default. You can specify one explicitly when the exchange API supports it.

Forked from krex, a simplified version of the ccxt Python library.

Python Rust License PyPI Crates.io

Installation

Python:

pip install dcex
# or, in a uv-managed project:
uv add dcex

Rust:

cargo add dcex

Key features

  • Synchronous and asynchronous Python HTTP clients, plus public and private WebSocket clients.
  • HTTP, WebSocket, and signing APIs for direct use from Rust.
  • A Product Table Manager (PTM) that normalizes exchange symbols and trading specifications.
  • Support for multiple CEX and DEX platforms; available endpoints vary by exchange.

External withdrawal creation endpoints are not wrapped. PTM includes listed options from Binance, Bybit, and OKX; option trading remains exchange-specific.

Supported exchanges

Exchange HTTP Sync HTTP Async WS Public WS Private
Binance Yes Yes Yes Yes
Bybit Yes Yes Yes Yes
OKX Yes Yes Yes Yes
Bitget Yes Yes Yes Yes
Kraken Yes Yes Yes Yes
MEXC Yes Yes Yes Yes
BingX Yes Yes Yes Yes
KuCoin Yes Yes Yes Yes
Hyperliquid Yes Yes Yes Yes
Lighter (Mainnet + Robinhood) Yes Yes Yes Yes
Backpack Yes Yes Yes Yes
Aster Yes Yes Yes Yes
Extended Yes Yes Yes Yes
Ondo Yes Yes Yes Yes
Arcus Yes Yes Yes Yes

Private WebSocket support includes authenticated or address-scoped user-data streams. Bybit also provides an authenticated trade WebSocket for order operations. Lighter Mainnet and Robinhood use separate credential profiles; select the network per client (Mainnet is the default); see .env.example and the Lighter examples. Ondo support covers perpetual futures only.

Python quick start

Synchronous HTTP:

import dcex

client = dcex.binance()
print(client.get_klines(product_symbol="BTC-USDT-SWAP", interval="1m"))

Asynchronous HTTP:

import asyncio
import dcex.async_support as dcex

async def main():
    client = await dcex.binance()
    try:
        print(await client.get_klines(product_symbol="BTC-USDT-SWAP", interval="1m"))
    finally:
        await client.close()

asyncio.run(main())

Public WebSocket:

import asyncio
from dcex.ws import binance

async def main():
    async with binance.public() as ws:
        await ws.subscribe_agg_trades("BTC-USDT-SPOT")
        print(await ws.recv())

asyncio.run(main())

Product Table Manager

PTM maps normalized product_symbol values, such as BTC-USDT-SWAP, to exchange-native exchange_symbol values and exposes trading metadata. Clients use this mapping where applicable.

Fields Meaning
exchange, product_symbol, exchange_symbol Exchange and normalized/native symbols
product_type, exchange_type Normalized and exchange-specific market types
base_currency, quote_currency Product currencies
price_precision, size_precision Price and size increments
min_size, min_notional Minimum size and notional
size_per_contract Contract multiplier
from dcex.product_table.manager import ProductTableManager

table = ProductTableManager.get_instance("binance")
print(table.get_exchange_symbol("binance", "BTC-USDT-SWAP"))
print(table.get_product_symbol("binance", "BTCUSDT", product_type="swap"))
print(table.rows()[0])

More examples and development

Runnable examples are in Python sync, Python async and WebSocket, and Rust. They focus on public data or read-only account queries. Private HTTP examples require credentials; private stream examples require credentials or a user address.

uv run python examples/sync/binance_public.py
uv run python examples/async/binance_ws_public.py
cargo run -p dcex --example binance_ws_public

For direct Rust usage, see the crate README. The default test suite runs offline with uv run pytest; live suites are opt-in. See the contributing guide for development and testing details.

This project uses the MIT License; see the third-party notices for additional licenses.

Release files for dcex 0.33.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dcex 0.33.0
File Size Uploaded
dcex-0.33.0.tar.gz 716.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for dcex 0.33.0
File Interpreter ABI Platform
dcex-0.33.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
dcex-0.33.0-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details
dcex-0.33.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details

Total release size: 35.7 MB

Release files / dcex-0.33.0.tar.gz

Download URL dcex-0.33.0.tar.gz
Size 716.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a775d322ada8ad8a4c7a2e5476c3b264dcc87622a8ad04886bdb07402c311ef5
BLAKE2b-256 checksum
How to use checksums
ff231d6534a7e06b0fc178249d9d2d1733cf307db1aa69c1c6cf002800b18078
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / dcex-0.33.0-cp312-cp312-win_amd64.whl

Download URL dcex-0.33.0-cp312-cp312-win_amd64.whl
Size 12.3 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
d274b97c22586929f5edda403e977509539b999c4e9a67189eb5bc613829f151
BLAKE2b-256 checksum
How to use checksums
2d8213e6791a8f743d23a042292711c2809fe85836a71fb813e1572985e7f22e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / dcex-0.33.0-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL dcex-0.33.0-cp312-cp312-manylinux_2_34_x86_64.whl
Size 11.7 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
154841c6ba151df0ffa0ad8503e49f757f07a140b0b7bfed64e75f1164bc25f6
BLAKE2b-256 checksum
How to use checksums
79018931b5d9bd21a896abf3cec064f6c1f099cc3ba4ca0c614dc637caef9f31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / dcex-0.33.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL dcex-0.33.0-cp312-cp312-macosx_11_0_arm64.whl
Size 10.9 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c5a145c8b4a8480d1b7d1efccb4f7f12c2d323292545cabb7862f42c3d177fdd
BLAKE2b-256 checksum
How to use checksums
4d30cfa1858eb0b281c387b5623f1fa8d47d22bd4aabb173a1ab2fdd649359a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.33.0 This release

4 release files

0.32.0

4 release files

0.31.0

4 release files

0.30.0

4 release files

0.29.1

4 release files

0.29.0

4 release files

0.28.5

4 release files

0.28.4

4 release files

0.28.3

4 release files

0.28.2

4 release files

0.28.1

4 release files

0.28.0

4 release files

0.27.0

4 release files

0.26.2

4 release files

0.26.1

4 release files

0.26.0

4 release files

0.25.0

4 release files

0.24.2

4 release files

0.24.1

4 release files

0.24.0

4 release files

0.23.0

4 release files

0.22.0

4 release files

0.21.2

2 release files

0.21.1

2 release files

0.21.0

2 release files

0.20.3

2 release files

0.20.2

2 release files

0.20.1

2 release files

0.20.0

2 release files

0.10.0

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page