Skip to main content

dcex - DEX & CEX trading library

English | 繁體中文

dcex is a Rust-backed crypto exchange API 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 for centralized exchanges (Binance, Bybit, OKX, Bitget, Kraken, MEXC, BingX) and decentralized perpetual exchanges (Hyperliquid, Lighter, Backpack, Aster, Extended, Ondo, Arcus).

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 Ask DeepWiki

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.

Compared with ccxt

ccxt offers one unified API across 100+ exchanges. dcex covers fewer exchanges and keeps each exchange's own endpoints instead:

  • Exchange-native methods and parameters, with coverage tracked endpoint by endpoint against the official docs.
  • Signing, serialization and response validation run in Rust, including DEX signing for Hyperliquid, Lighter and Extended.
  • The same core is available from Python (sync and async) and Rust.
  • Normalized symbols (BTC-USDT-SWAP) and trading specifications through the Product Table Manager.

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

Product product_symbol Example
Spot BASE-QUOTE-SPOT BTC-USDT-SPOT
Perpetual BASE-QUOTE-SWAP BTC-USDT-SWAP
Dated futures BASE-QUOTE-YYMMDD-FUTURES (UTC delivery date) BTC-USD-261225-FUTURES
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

Binance and BingX coin-margined contracts sit in their own exchange namespaces, binance_coinm and bingx_coinm (for example BTC-USD-SWAP), so they never collide with USDT-margined products; their coin-margined methods resolve symbols there.

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])

Hyperliquid loads its first perp DEX, spot and every builder-deployed (HIP-3) perp DEX by default. Pass perp_dexs to load only the builder DEXs you trade; names come from get_perp_dexs, unknown names are rejected, and asset ids stay the same as with the full table:

from dcex.hyperliquid import Client

client = Client(perp_dexs=["xyz"])
table = ProductTableManager.get_instance("hyperliquid", perp_dexs=["xyz"])

Lighter nonces

Every Lighter transaction method accepts nonce. Without it, dcex asks the exchange for the next nonce, which costs one request per transaction. Trading systems usually keep the nonce themselves:

  • Read the starting value once per API key with get_next_nonce(api_key_index=...).
  • Increment it locally and pass nonce= with each transaction, holding a lock if several tasks share the key.
  • After a failed transaction or a nonce error, read get_next_nonce again; a rejected transaction may not consume its nonce.
  • Give each process its own api_key_index so their nonces never collide.

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.43.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.43.0
File Size Uploaded Provenance Actions
dcex-0.43.0.tar.gz 1.7 MB Without provenance Details for dcex-0.43.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for dcex 0.43.0
File Actions
dcex-0.43.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for dcex-0.43.0-cp312-abi3-win_amd64.whl
dcex-0.43.0-cp312-abi3-manylinux_2_34_x86_64.whl CPython 3.12 abi3 Linux glibc 2.34+ x86-64 Details for dcex-0.43.0-cp312-abi3-manylinux_2_34_x86_64.whl
dcex-0.43.0-cp312-abi3-manylinux_2_34_aarch64.whl CPython 3.12 abi3 Linux glibc 2.34+ ARM64 Details for dcex-0.43.0-cp312-abi3-manylinux_2_34_aarch64.whl
dcex-0.43.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for dcex-0.43.0-cp312-abi3-macosx_11_0_arm64.whl
dcex-0.43.0-cp312-abi3-macosx_10_12_x86_64.whl CPython 3.12 abi3 macOS 10.12+ x86-64 Details for dcex-0.43.0-cp312-abi3-macosx_10_12_x86_64.whl

Total release size: 68.5 MB

Release files / dcex-0.43.0.tar.gz

Download URL dcex-0.43.0.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
d0da4b44d90d8ea0f78270b59aa9ca270b66e2e2625f08f2faa76841d9d9ba0f
BLAKE2b-256 checksum
How to use checksums
3ba7ff92bfd720c9696c4e470379fdee1c889cfba622da46597572956f36ffc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","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.43.0-cp312-abi3-win_amd64.whl

Download URL dcex-0.43.0-cp312-abi3-win_amd64.whl
Size 15.4 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
865ba4087c2d491c0d53dc7ca4e8021c5378e50e779d4e58711e7995abef459b
BLAKE2b-256 checksum
How to use checksums
d59d9ec069d72160f6688513cb20cd58398f59d9b30cc52ae845ebdf93e85327
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","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.43.0-cp312-abi3-manylinux_2_34_x86_64.whl

Download URL dcex-0.43.0-cp312-abi3-manylinux_2_34_x86_64.whl
Size 13.3 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
9c434ae6b999836f6c4b8ba342b9d504d6a500dfb269aee04e850021fc3e241f
BLAKE2b-256 checksum
How to use checksums
0f2b6eca10fd8be0ce0a7a322a6859d6baf229e59ba7c51de2888f96436c3178
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","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.43.0-cp312-abi3-manylinux_2_34_aarch64.whl

Download URL dcex-0.43.0-cp312-abi3-manylinux_2_34_aarch64.whl
Size 12.8 MB
Tags CPython 3.12 Linux glibc 2.34+ ARM64 abi3
SHA-256 checksum
How to use checksums
6c42830e228813cecdd779c25addfadd04a08634f25f789116968601db349c28
BLAKE2b-256 checksum
How to use checksums
58c70bb20d39619b7bbb0e45a3aa943ec923229a2aebde4b4ef93f45362d96ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","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.43.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL dcex-0.43.0-cp312-abi3-macosx_11_0_arm64.whl
Size 12.4 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f7cb985f130e520ea653f8ae86537926182213279565db3271a68d3b83bc6c7b
BLAKE2b-256 checksum
How to use checksums
241d20ea3bf9b7be9db971bec2575284bebf8478c35d526a55d81e8661c5a7f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","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.43.0-cp312-abi3-macosx_10_12_x86_64.whl

Download URL dcex-0.43.0-cp312-abi3-macosx_10_12_x86_64.whl
Size 12.9 MB
Tags CPython 3.12 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
82210009253f2aacdc34272a3f9871864135f207415ddc1b5fda0d1b3da2019c
BLAKE2b-256 checksum
How to use checksums
6362c78735ad3e6c3185d54b7fd19921dc405ad04a6f1026c1107c96f2177b6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","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}

Security for dcex 0.43.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.43.0 This release

6 release files No provenance

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