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.12.tar.gz (113.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.12-cp313-cp313-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

dextrades-0.1.12-cp313-cp313-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

dextrades-0.1.12-cp312-cp312-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.12Windows x86-64

dextrades-0.1.12-cp312-cp312-manylinux_2_34_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

dextrades-0.1.12-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.12-cp312-cp312-macosx_11_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

dextrades-0.1.12-cp312-cp312-macosx_10_12_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for dextrades-0.1.12.tar.gz
Algorithm Hash digest
SHA256 e62396e6491734f71859318c1444b4945177396183adbe9c36add8a378c448f1
MD5 772c0bbb57010c227c5bd2e2b1d9bd5c
BLAKE2b-256 5c7c0802faad671db7de4796463ab11478e0b764efaee7d48c8863e08d6c426b

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.12.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.12-cp313-cp313-win_amd64.whl.

File metadata

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

File hashes

Hashes for dextrades-0.1.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e279cf3a7c26a130298a498d5ef8e5c50fcb4ed136b5b8f7aa27cb504a6da4a8
MD5 0e004f572fd13a1a6b0c0c8caf6f6982
BLAKE2b-256 c7e5d7fa6b360f7df83f1e25e07a50eb35e83062bfaa255c295b2520ddcb9c7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.12-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.12-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.12-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d0097c84952cd5917a3f4caa2accc13e39074c5d3ac8d73debd5ddcb402373dd
MD5 004843c558f11f27beb9f01bf358f5f7
BLAKE2b-256 7e24c9ad740e44e1d75e7c9031bd86e7e5397b3a18eee8c916261068c6d403b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.12-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.12-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.12-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 af6e69a86f865e96437de7a2e89498ac752d7d8e82103d533110de5517723b15
MD5 24dc12d200f371601af38c9bca91b3ec
BLAKE2b-256 3e712fa891a2df23d449693bd0d3b812da78e1407aece54b79a5584699cf5bd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.12-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.12-cp312-cp312-win_amd64.whl.

File metadata

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

File hashes

Hashes for dextrades-0.1.12-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ac8b5712e895fdbe2fe1838647a4ace505b05795b065511557a7712fa42defb4
MD5 41a4ef17f12e8bc44c13f495807a93dd
BLAKE2b-256 587d7bc164642f0b96a6b29d1ef52b5e0d69af74cb1aa5a13a84daf914e9bda1

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.12-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.12-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.12-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0b07b4d6f56964a40ecb00701473052cb37a30bd43460d44856cd2191c41ab8a
MD5 0cebd521dcb447db4afed219073dc3dc
BLAKE2b-256 23154edc5d389cc60a9ba0e5b4a6fde7ca6cc47c14c6d157577a935bd76b72c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.12-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.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c739cb01b83f1fb674746416a5942bff4d9ba98386bc805a10c55efcf16c3da7
MD5 0cceda807e6fbded05c6beb513153928
BLAKE2b-256 fd2f5355e56324cfce41f90f04517556bdd1ee24fc0dd037efb3524e0b4f847e

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.12-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.12-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.12-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3a14f3c86bafe30fb032ce79e7b46472faa70b69dac6de28f6f0e31a9aec30e1
MD5 efa3972d4d536f78805bccafe58b95ea
BLAKE2b-256 a6ea344d34b9ffa073a1feadb87b1b7666d664bed53c92fc6254ec3543153232

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.12-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.12-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for dextrades-0.1.12-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cf83e181a9f76aaedf89c2e12d0bc40a3b87fa5bd1f045aedfd55ae2d1a54b05
MD5 7ac0313eb9fe0441d39732f7bb9a272d
BLAKE2b-256 650d09880076289b2c9f1bb790843dd60f8e19e5bc38212f4e8a488234c4cbc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for dextrades-0.1.12-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