Skip to main content

High-performance DEX swap streaming and analysis (Rust/PyO3)

Project description


DexTrades 🦄

A Python library for streaming DEX trades from RPC nodes.

PyPI License: MIT

✨ Features

  • Direct On-Chain Data: Pulls event logs directly from a given RPC URL, requiring no indexers or third-party APIs. It currently decodes swaps from Uniswap V2 and V3.

  • Data Enrichment Pipeline: The library can enrich raw log data with:

    • Token metadata (symbols, decimals) for readable amounts.
    • Block timestamps for each swap.
    • USD values calculated using Chainlink ETH/USD price feeds at the swap's block height.
  • Rust Core: Built with a Rust backend (PyO3, alloy) for processing. It implements RPC provider racing, a circuit breaker, and automatic retries for connection resilience.

  • Friendly Python API: Provides an async generator to stream trades. Enrichments are controlled via boolean flags. Supports streaming individual swaps or Apache Arrow batches.

📦 Installation

Quick Install

Using uv (recommended):

uv add dextrades

Or with pip:

pip install dextrades

Platform Support

Pre-built wheels available for:

  • 🍎 macOS: Intel (x86_64) + Apple Silicon (arm64)
  • 🪟 Windows: x64 + x86 (32-bit)
  • 🐍 Python: 3.12 and 3.13

Linux Installation: Due to cryptographic library compilation requirements, Linux users should install from source:

# Install Rust first (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Install from source
pip install dextrades --no-binary=dextrades

Alternatively, use the development Docker setup for a containerized environment.

💻 Usage

The Client manages connections to one or more RPC endpoints. The stream_swaps method returns an async iterator of swap events.

import asyncio
import dextrades

urls = [
    "https://eth-pokt.nodies.app",
    "https://ethereum.publicnode.com",
]
with dextrades.Client(urls) as client:
    # Stream a small block range; normalized token amounts included
    async for swap in client.stream_swaps(
        ["uniswap_v2", "uniswap_v3"],
        17000003, 17000003,
        batch_size=1,
        enrich_timestamps=True,
        enrich_usd=True,
    ):
        print(
            swap.get("dex_protocol"),
            swap.get("token_sold_symbol"), swap.get("token_sold_amount"),
            "→",
            swap.get("token_bought_symbol"), swap.get("token_bought_amount"),
            "USD:", swap.get("value_usd"),
        )

Example Output

time                 dex           bought           sold              value_usd  trader  hash  
-----------------------------------------------------------------------------------------------------------------------------
2023-04-08 01:58:47  Uniswap V2    0.0529  WETH     98.9990  USDC        $99.00  0x5eA7  0x37f7
2023-04-08 01:58:47  Uniswap V2    0.0398  XMON      0.0529  WETH        $98.63  0x5eA7  0x37f7
2023-04-08 01:58:47  Uniswap V2    0.0452  WETH      0.7000  QNT         $84.38  0x4a30  0x5428
2023-04-08 01:58:47  Uniswap V2    3.2402  WETH      2.9994  PAXG     $6,045.62  0xdBC2  0x8f46

🗺️ Roadmap

  • Uniswap V2
  • Uniswap V3
  • and deduplication
  • Enrichments:
    • token metadata
    • trade direction
    • timestamps
    • USD values via Chainlink
    • USD values via stablecoin passthrough
  • RPC provider
    • racing
    • retries
    • circuit breakers
    • sharded getLogs
  • Python API
  • CLI
  • example and demo
  • benchmarks
  • additional enrichments:
    • trader balance
    • Uniswap V3 Quoter fallback for non-WETH/stable tokens
  • Chainlink Feed Registry (USD feeds) and multi-chain aggregator addresses
  • CLI UX polish (enrichment flags, simple table mode)
  • Light metrics: stage counters and provider health snapshot
  • Additional DEX protocols
  • Optional persistent caches and Parquet/Polars export helpers

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

dextrades-0.1.2.tar.gz (105.7 kB view details)

Uploaded Source

Built Distributions

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

dextrades-0.1.2-cp313-cp313-macosx_11_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

dextrades-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl (6.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

dextrades-0.1.2-cp312-cp312-macosx_11_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file dextrades-0.1.2.tar.gz.

File metadata

  • Download URL: dextrades-0.1.2.tar.gz
  • Upload date:
  • Size: 105.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dextrades-0.1.2.tar.gz
Algorithm Hash digest
SHA256 fca5ea173a67bc67c81e0ed4aeaf7db686eb50a76b43ffccba703ebec8cf0428
MD5 3cdb48c296bcf46bd907b8d5f7702591
BLAKE2b-256 8b0a6055d1e64ff1a960b7b559075a2ba5890f089b616bb7ee215d742fc3d8b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.2.tar.gz:

Publisher: release.yml on elyase/dextrades

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dextrades-0.1.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 09049fbe496fae2192b7c90d67b9449b113417c4b176dc9a6e4caeb40fd8347e
MD5 fa2bc24b445328e3b5a0df66011b324d
BLAKE2b-256 7df6e7bd67bc3e216900955fe58640811988d659adff55a7dffc0a6e346ffe81

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on elyase/dextrades

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dextrades-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 135705cf57804c365d056290843e1e5a14e0cedb5b02525d12c6c71a06dca0d2
MD5 da7d374304bd0f0aa676c6660dcf61d4
BLAKE2b-256 85073a77475ea7e54f215f8e759120b09f3cc335fe9a57587ea05d639d455cfa

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.2-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: release.yml on elyase/dextrades

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dextrades-0.1.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 150fed7d3ccc327c743f731e25ad15e939045f0eccf17be81d0e246d3acd39ae
MD5 440b38600a612a9a7fcb4761a7ae3f4b
BLAKE2b-256 907f038860b9c04b56f82dd8be930b2a1c8e5392ff45358442539990256c85d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on elyase/dextrades

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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