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 full synchronous and asynchronous support across major exchanges, designed for speed, modularity, and ease of use.

Python Version License: MIT PyPI version

📦 Installation

pip install dcex

or use uv to manage the project:

uv add dcex

🚀 Quick Start

Synchronous Usage

import dcex
import os

# Initialize client for any supported exchange
client = dcex.binance(
    api_key="your_api_key",
    api_secret="your_api_secret"
)

# Get market data
klines = client.get_klines(product_symbol="BTC-USDT-SWAP", interval="1h")
print(klines)

Asynchronous Usage

import asyncio
import dcex.async_support as dcex
import os

async def main():
    # Initialize async client
    client = await dcex.binance(
        api_key="your_api_key",
        api_secret="your_api_secret"
    )

    try:
        # Get market data
        klines = await client.get_klines(product_symbol="BTC-USDT-SWAP", interval="1h")
        print(klines)

    finally:
        await client.close()

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

📚 Supported Exchanges

Exchange Sync Support Async Support
Binance Testing Testing
Bybit Testing Testing
OKX
BitMart Testing Testing
Gate.io Testing Testing
Hyperliquid Testing Testing
BitMEX Testing Testing
BingX Developing Developing
AscendEX Developing Developing
KuCoin Developing Developing

🔍 Key Features

  • 📘 Product Table Manager for unifying trading instruments in different exchanges
  • 🔁 Sync & Async API clients with identical interfaces
  • ⚡ Optimized for low-latency, high-frequency trading

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 will actually used
product_type The type we will use, e.g. spot, inverse, swap, futures
exchange_type The type the exchange will actually used, e.g. linear, INVERSE, perp... different exchanges have different types, pretty annoying...
base_symbol The base symbol, e.g. BTC
quote_symbol The quote symbol, 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
multiplier The multiplier of the product, such symbol like 1000BONKUSDT in Bybit will need to be multiplied by 1000 to get the actual size, if you are trading across spot and swap, you will need this
size_per_contract The size per contract. Sometimes 1 contract is not the same as 1 unit in exchanges like OKX.

How to use Product Table Manager?

In most cases, we have handled the case, but if you have any specific use cases, you can use the ptm to get the information you want.

import dcex

bn = dcex.binance()

product_symbol = bn.ptm.get_product_symbol(
    exchange="binance",
    exchange_symbol="BTCUSDT",
    product_type="swap",
)

print(product_symbol)

🤝 Contributing

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

Contributors

📄 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.3.2.tar.gz (49.9 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.3.2-py3-none-any.whl (59.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dcex-0.3.2.tar.gz
  • Upload date:
  • Size: 49.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for dcex-0.3.2.tar.gz
Algorithm Hash digest
SHA256 c667d3cde902ca61649108473d38132f136062906b7bdcb397c967189dd024ee
MD5 4dcf1569a7d5f4faa10dd7e4f6bab5dd
BLAKE2b-256 bf974766d6d6fc26e02a5fc38e289534b46f553d2ac0996bf7a5a1b02ec81165

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dcex-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 59.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for dcex-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b74ec9765911238bf8ff4f8d5ba8038d379aa848e7ad52731bf476c5a1390aa5
MD5 d73be174dc2f4adf9ed0ef67560f2048
BLAKE2b-256 e31fd9b5d26aaa86fef597b30aa088fd1124cbf7e766fa8846ed0fbeb10b6450

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