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.
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.
Documented withdrawal, market-maker and partner endpoints are in scope; current coverage and specification gaps are recorded in the endpoint ledger. API withdrawals have no second confirmation; they execute on submit. Trading API keys should not have withdrawal permission. 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 |
Bitget began migrating accounts to UTA on 2026-09-15. Classic-account private endpoints that Bitget rejects for UTA accounts (error 40085) have been removed; public market-data, tax and institutional-loan endpoints that still work remain. Use a UTA account for trading. See the official UTA upgrade guide and account settings.
Private WebSocket support includes authenticated or address-scoped user-data streams. Trading WebSocket APIs are available for Binance, Bybit, Bitget, OKX, KuCoin and Kraken Spot; Hyperliquid and Lighter accept signed actions, and Arcus provides signed request construction. 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 spot currently supports only public market data (depth, trades, symbol_info, history and WS spot channels); Ondo has not published its spot trading API, so private operations such as placing or cancelling orders with a -SPOT symbol fail locally without sending a request.
Endpoint coverage, limitations and verification.
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())
Additional profiles cover Binance Alpha, Aster Prediction, KuCoin Classic/Pro and Kraken Spot V1. Bitget SBE returns raw binary frames for caller-side decoding.
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.
Metadata
Release files for dcex 0.37.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dcex-0.37.0.tar.gz | 1.7 MB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dcex-0.37.0-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details |
| dcex-0.37.0-cp312-cp312-manylinux_2_34_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.34+ x86-64 | Details |
| dcex-0.37.0-cp312-cp312-macosx_11_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64 | Details |
Total release size: 47.0 MB
Release files / dcex-0.37.0.tar.gz
| Download URL | dcex-0.37.0.tar.gz |
|---|---|
| Size | 1.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6fb5ee1fe6f859103f4a6dba57f8a24efe8b78ea6afda2c0f5156343fc1cee1
|
|
BLAKE2b-256 checksum How to use checksums |
6bdab16f305dff42dc45f4131f910eb8d1d519bf13ebe1376655e545a64982ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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.37.0-cp312-cp312-win_amd64.whl
| Download URL | dcex-0.37.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 16.1 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
b7bff25ffdfc97950b935253f602d4e13c8682a7e06de80f03811b1c062f7222
|
|
BLAKE2b-256 checksum How to use checksums |
c9f2715589054aa82921bbdedb942d4f6261315ec81ee017bf5868d9af236a0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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.37.0-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | dcex-0.37.0-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 15.0 MB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
4a3d6b7e0c636565e4de10845e136890537a222f0ca933d8168f8f6c81638e6c
|
|
BLAKE2b-256 checksum How to use checksums |
55a94f480a53ac3e3dffa11a17c6b4ff29c3f75c52db7111951cc61126cedaae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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.37.0-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | dcex-0.37.0-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 14.1 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
77cd4827b74266a647893d638a05041163d0ce6c189091ae0a5c846c7bc72bce
|
|
BLAKE2b-256 checksum How to use checksums |
d3315b6d5182bbbe3cc4a868f32f742c5d26cc865c578d66209ff5bb08039531
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","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}
|