Skip to main content

A Lightweight Python Package for Low-Latency and Cross-Exchange Trading.

Project description

dcex - DEX & CEX trading library

Important: No default broker tags are set. You may manually specify a broker tag within function arguments if needed.

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

Originally created and maintained by the same contributor, this fork continues active development, building upon the original foundation with enhanced design, unified DEX + CEX support, and fixes for previously unresolved issues.

A high-performance and lightweight Python library for interacting with cryptocurrency exchanges. dcex offers synchronous and asynchronous clients across multiple major exchanges, designed for speed, modularity, and ease of use.

Scope note: dcex focuses on market data, account queries, and trading/order APIs. External withdrawal creation endpoints are not currently wrapped, and options support is limited to exchange-specific APIs rather than the unified Product Table Manager.

Python License PyPI

Installation

pip install dcex

or use uv to manage the project:

uv add dcex

Quick Start

Synchronous Usage

import dcex

client = dcex.binance()

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

Asynchronous Usage

import os
import asyncio
import dcex.async_support as dcex
from dotenv import load_dotenv

load_dotenv()

BINANCE_API_KEY = os.getenv("BINANCE_API_KEY")
BINANCE_API_SECRET = os.getenv("BINANCE_API_SECRET")

async def main():
    client = await dcex.binance(
        api_key=BINANCE_API_KEY,
        api_secret=BINANCE_API_SECRET
    )

    try:
        result = await client.get_income_history()
        print(result)

    finally:
        await client.close()

if __name__ == "__main__":
    asyncio.run(main())

Supported Exchanges

Exchange Sync Support Async Support
Binance Yes Yes
Bybit Yes Yes
OKX Yes Yes
Bitget Yes Yes
Kraken Yes Yes
MEXC Yes Yes
BitMart Yes Yes
BitMEX Yes Yes
Gate.io Yes Yes
BingX Yes Yes
KuCoin Yes Yes
Hyperliquid Yes Yes
Lighter Yes Yes
Backpack Yes Yes
Aster Yes Yes

Key Features

  • Product Table Manager for unifying trading instruments across exchanges
  • Sync and async API clients with consistent interfaces where available
  • Low-overhead HTTP clients for market data, account queries, and trading workflows
  • Opt-in live test suites for public, private, stateful, and generated-report endpoints

What is Product Table Manager (PTM)?

PTM is a utility that standardizes and unifies trading instrument metadata across different exchanges, making cross-exchange strategy development easier.

It is a table that contains the following columns:

Column Description
exchange The exchange name
product_symbol The symbol we use to identify the product, it will be the same in different exchanges. For example, BTC-USDT-SWAP is the same product in Binance and Bybit, which named BTCUSDT in Binance and BTC-USDT-SWAP in OKX.
exchange_symbol The symbol that the exchange actually uses
product_type The normalized product type used by dcex, e.g. spot, swap, futures
exchange_type The exchange-specific product type, e.g. spot, linear, inverse, perpetual, delivery
base_currency The base currency, e.g. BTC
quote_currency The quote currency, e.g. USDT
price_precision The price precision, e.g. 0.000001
size_precision The size precision, e.g. 0.000001
min_size The minimum size, e.g. 0.000001
min_notional The minimum notional, e.g. 0.000001
size_per_contract The size per contract. Sometimes 1 contract is not the same as 1 unit in exchanges like OKX.

Options are not currently included in the unified PTM output. Some exchange-specific clients expose option-related parameters or market endpoints, but options are not normalized across exchanges.

How to use Product Table Manager?

In most cases, dcex handles product-symbol mapping internally. If you have a specific use case, you can use ptm to get the information you need.

from dcex.utils.common import Common
from dcex.product_table.manager import ProductTableManager

ptm = ProductTableManager.get_instance(Common.BINANCE)

product_symbol = ptm.get_product_symbol(
    exchange=Common.BINANCE,
    exchange_symbol="BTCUSDT",
    product_type="swap",
)

print(product_symbol)

Contributing

We welcome contributions. Please see our Contributing Guide for details.

Testing

The default test suite is offline and does not require exchange API keys or network access:

uv run pytest

For live, private, stateful, and generated-report test commands, see the Contributing Guide.

Examples

Examples are under examples/sync and examples/async. See examples/README.md for the example conventions.

License

This project is licensed under the MIT License.

Support

Disclaimer

Cryptocurrency trading involves significant risk. This library is provided as-is without any warranty. Users are responsible for their own trading decisions and risk management.

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

dcex-0.20.1.tar.gz (297.8 kB view details)

Uploaded Source

Built Distribution

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

dcex-0.20.1-py3-none-any.whl (414.0 kB view details)

Uploaded Python 3

File details

Details for the file dcex-0.20.1.tar.gz.

File metadata

  • Download URL: dcex-0.20.1.tar.gz
  • Upload date:
  • Size: 297.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","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}

File hashes

Hashes for dcex-0.20.1.tar.gz
Algorithm Hash digest
SHA256 b391bc791bbc034d22634fe919cd8b1721cc04076d2f66649d21e3d52aeec525
MD5 e8ed9c968a1965a561a4c8378b7575e4
BLAKE2b-256 ee5eba9decfe693a4970f063fb316b8ab062c8453a3aa5021c1a3d970d583cda

See more details on using hashes here.

File details

Details for the file dcex-0.20.1-py3-none-any.whl.

File metadata

  • Download URL: dcex-0.20.1-py3-none-any.whl
  • Upload date:
  • Size: 414.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","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}

File hashes

Hashes for dcex-0.20.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73f7ebc20d73eeb2b891518d05de90ea5601746c5a598c126a8c8cbe51d8d8c2
MD5 606c9c6c590a4b67fd80d95e2826597c
BLAKE2b-256 630493191a5eeab46dea58beab73d557fec82b538ab6dd15c8166c5d66eaa143

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