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

Using uv (recommended):

uv add dextrades

Or with pip:

pip install dextrades

💻 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

📊 Available Fields

Enricher Fields Added Description
Core block_number, tx_hash, log_index, dex_protocol, pool_address Always present
transaction tx_from, tx_to, gas_used Transaction context
timestamp block_timestamp Block mining time
token_metadata token0_address, token1_address, token0_symbol, token1_symbol, token0_decimals, token1_decimals Token information
swap token_bought_address, token_sold_address, token_bought_symbol, token_sold_symbol, token_bought_amount, token_sold_amount, token_bought_amount_raw, token_sold_amount_raw Trade direction & amounts
price_usd value_usd, value_usd_method, chainlink_updated_at USD valuation (stablecoins + Chainlink ETH/USD)

Network overrides (generic per-chain pricing)

Provide network-specific overrides at client initialization to make USD pricing and warmup work on non-mainnet chains.

overrides = {
    # Wrapped native token address (e.g., WETH, wCAMP)
    "native_wrapped": "0x4200000000000000000000000000000000000006",
    # Chainlink-style native/USD aggregator (optional)
    # "native_usd_aggregator": "0x...",
    # Stablecoin addresses to treat as USD stables on this network
    "stable_addresses": [
        # "0x...", "0x..."
    ],
    # Optional warmup tokens that exist on the current network (avoid noisy warmup logs)
    "warmup_tokens": []
}

with dextrades.Client(["<rpc-url>"], network_overrides=overrides) as client:
    async for swap in client.stream_swaps(["uniswap_v2", "uniswap_v3"], 100, 100, enrich_usd=True):
        ...

If no per-network aggregator is provided, USD pricing falls back to:

  • Stablecoin passthrough (by address or common stable symbols)
  • Native/USD via Chainlink only on Ethereum mainnet (default mainnet aggregator)

Router filter (optional)

Filter to SmartRouter transactions only:

async for swap in client.stream_swaps(["uniswap_v2","uniswap_v3"], 100, 100, routers=["0xRouter..."]):
    ...

# Also available for individual streaming:
client.stream_individual_swaps(["uniswap_v2","uniswap_v3"], 100, 100, routers=["0xRouter..."])

🗺️ 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.11.tar.gz (110.4 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.11-cp313-cp313-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.13Windows x86-64

dextrades-0.1.11-cp313-cp313-win32.whl (2.9 MB view details)

Uploaded CPython 3.13Windows x86

dextrades-0.1.11-cp313-cp313-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

dextrades-0.1.11-cp313-cp313-macosx_10_12_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

dextrades-0.1.11-cp312-cp312-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.12Windows x86-64

dextrades-0.1.11-cp312-cp312-win32.whl (2.9 MB view details)

Uploaded CPython 3.12Windows x86

dextrades-0.1.11-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.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

dextrades-0.1.11-cp312-cp312-macosx_11_0_arm64.whl (3.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

dextrades-0.1.11-cp312-cp312-macosx_10_12_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: dextrades-0.1.11.tar.gz
  • Upload date:
  • Size: 110.4 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.11.tar.gz
Algorithm Hash digest
SHA256 0fd9b593438531444f8663c451bf35536e128c67daa9b8e56e389a2ae82ac0b5
MD5 a12a029fbd5b79d24fb3016131c09b62
BLAKE2b-256 1acc76bcf8e3cd0b61a942ebbf4ec932eca7d1b1fdad8e2342002991c5f0f248

See more details on using hashes here.

Provenance

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

Publisher: build.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.11-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: dextrades-0.1.11-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dextrades-0.1.11-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 833a2236827b085fcf453bf03bcaf05518d21cb89fe4263fff52a8e3b1a44445
MD5 aa2624bef891b4853ecc810b66740cc0
BLAKE2b-256 a29cf45575bd29e40c72d33c9c88348f392568fc1ead2387af55362b8c30b95c

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.11-cp313-cp313-win_amd64.whl:

Publisher: build.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.11-cp313-cp313-win32.whl.

File metadata

  • Download URL: dextrades-0.1.11-cp313-cp313-win32.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.13, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dextrades-0.1.11-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 0c7dcbb764c985472b9829ebb4f2588ff75ed10bb0ab4c5b908a4adfb535ec8b
MD5 2612284c6c5421e796ee2436f5424a69
BLAKE2b-256 21cffbb731e6a4d395039b15aebeb56feccc44944464048a1615e2cfaee15ed4

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.11-cp313-cp313-win32.whl:

Publisher: build.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.11-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.11-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 da0498457004a339f5c5a42f63203bbe143bc228dc58e950ce8e894df0ee44cb
MD5 ad362fa9f1b3f7c2fa7ad1541bacb7b4
BLAKE2b-256 54f90fe172e48f9a4787bba4880d9ea7722ff42aafec2e1ec1c0181a7517eec1

See more details on using hashes here.

Provenance

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

Publisher: build.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.11-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.11-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 11a950026c6434361535a638704b459d5d719a69b94df9ff42f5e5b4d9be9d2e
MD5 6e1bc51fc90c61bfe5ea22f1737d8a02
BLAKE2b-256 82bb71be8e34051748624d0466758d485f326771567806086d8caa4f4ea1c262

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.11-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: build.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.11-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: dextrades-0.1.11-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dextrades-0.1.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a2ed356822367ee4f94f385c04f045f8b9f49fa6104f60372df17fb850d66308
MD5 d67a34e9349a1fbf6f8432a6c6ba7ecb
BLAKE2b-256 f1c9e82383d525c427ab06204e155fe17ebff51d38dd69951046eacea221a0ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.11-cp312-cp312-win_amd64.whl:

Publisher: build.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.11-cp312-cp312-win32.whl.

File metadata

  • Download URL: dextrades-0.1.11-cp312-cp312-win32.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for dextrades-0.1.11-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 d1ed8ff1fcca75ff94184e565f0f34e92b22a43f2c6e310fc30cfd662c6ba552
MD5 2a6d207887fb6183832f31e49393d766
BLAKE2b-256 470886dbb684e45ac5ae88572757aa7ebb4bba68b7ddf76d14aca0e39878c2ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.11-cp312-cp312-win32.whl:

Publisher: build.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.11-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.11-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f49d0a7add8c8ad8dbdd24c6380d6c37886624565611ddb07d659554bf18aa3e
MD5 6f875176f1f29360f131cd7799797c3b
BLAKE2b-256 9c9dcfa0d7641dd25103b0439ef5723df7ad1bad844156ba26645efae78ba748

See more details on using hashes here.

Provenance

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

Publisher: build.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.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b53d934d6366afb999de124fb9dc7fbaf178bc1d8d86ca84c9e52385a77617d7
MD5 3c3ea9e8f0b4c6d3e5ce9c49bf78b89c
BLAKE2b-256 aaebbb2cdc575c6266b5d1740925851a88e1e9c3dc0511b1ae3958af259e534c

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.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.11-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.11-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 727561da9cb2c3e5ec583710aeb580cbb6d2c6366a95dc3905eecfd1c8925faa
MD5 dde8d9ef7697f90105e8c8642d27e31e
BLAKE2b-256 c99082ed5b94f7bb65a52c6bc9f5f66af43dd813ce1a8c2ebdb0d8d7a82762df

See more details on using hashes here.

Provenance

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

Publisher: build.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.11-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.11-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 db9614c62a107baa2f5534afbcfe43bce4316a497366a20ffa23846295076325
MD5 8086f46f06248c84b76973fda43e3272
BLAKE2b-256 0da72c980b07217b1341fa861e5a3efe207c54e93ef10a67625af0fd189ec9a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.11-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: build.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