DEX API | Blockchain Data API (V2)

·

The decentralized exchange (DEX) ecosystem is growing at an unprecedented pace, driven by innovations in DeFi and blockchain interoperability. Accessing real-time, accurate trading data has become essential for developers, analysts, and traders. This guide explores how to leverage the powerful DEX API to retrieve granular blockchain data across Ethereum and other EVM-compatible networks.

Built on robust blockchain indexing infrastructure, this API suite enables seamless access to decentralized trading activity through two core endpoints: DEXTrades and DEXTradeByTokens. These tools empower users to extract everything from high-level market overviews to granular trade-level insights.

Whether you're building analytics dashboards, monitoring liquidity movements, or conducting competitive research, understanding how to use these APIs effectively can unlock deep visibility into DEX operations.

👉 Discover how to access real-time decentralized trading data with powerful API tools.

Understanding the Core DEX APIs

At the foundation of this system are two primary query types:

While DEXTrades is ideal for event-level analysis, DEXTradeByTokens excels in performance when querying large datasets due to its pre-aggregated structure. For most analytical use cases—such as tracking top trading pairs or monitoring DEX performance—DEXTradeByTokens offers faster response times and reduced data processing overhead.

For more technical differences, refer to the official schema documentation.

Retrieve All DEXs on the Ethereum Network

To get a comprehensive list of all decentralized exchanges operating on Ethereum, use the following query:

query DexMarkets($network: evm_network) {
  EVM(network: $network) {
    DEXTradeByTokens {
      Trade {
        Dex {
          ProtocolFamily
        }
      }
      buyers: uniq(of: Trade_Buyer)
      sellers: uniq(of: Trade_Sender)
      count(if: {Trade: {Side: {Type: {is: buy}}}})
    }
  }
}
{
  "network": "eth"
}

This returns aggregated data per DEX (identified by ProtocolFamily), including:

You can test this query directly in the Bitquery IDE and visualize results in real time.

Fetch Statistics for a Specific DEX

Need performance metrics for a single decentralized exchange like Uniswap or SushiSwap? Use this targeted query:

query DexMarkets($network: evm_network, $market: String) {
  EVM(network: $network) {
    DEXTradeByTokens(
      orderBy: {ascendingByField: "Block_Time"}
      where: {Trade: {Dex: {ProtocolFamily: {is: $market}}}}
    ) {
      Block {
        Time(interval: {count: 1, in: hours})
      }
      trades: count
      buyers: uniq(of: Trade_Buyer)
      sellers: uniq(of: Trade_Sender)
      tokens: uniq(of: Trade_Currency_SmartContract)
    }
  }
}
{
  "market": "Uniswap",
  "network": "eth"
}

This query returns hourly-aggregated data showing:

Such insights are invaluable for identifying user engagement trends and measuring protocol adoption over time.

👉 Learn how to analyze DEX performance using advanced blockchain queries.

Get All Trading Pairs on a Specific DEX

To discover the most active token pairs on a given DEX (e.g., ETH/USDC on Uniswap), run:

query DexMarkets(
  $network: evm_network
  $market: String
  $time_10min_ago: DateTime
  $time_1h_ago: DateTime
  $time_3h_ago: DateTime
) {
  EVM(network: $network) {
    DEXTradeByTokens(
      orderBy: {descendingByField: "usd"}
      where: {
        Trade: {Dex: {ProtocolFamily: {is: $market}}}
        Block: {Time: {after: $time_3h_ago}}
      }
      limit: {count: 200}
    ) {
      Trade {
        Currency {
          Symbol
          Name
          SmartContract
          Fungible
        }
        Side {
          Currency {
            Symbol
            Name
            SmartContract
          }
        }
        price_usd: PriceInUSD(maximum: Block_Number)
        price_last: Price(maximum: Block_Number)
        price_10min_ago: Price(
          maximum: Block_Number
          if: {Block: {Time: {before: $time_10min_ago}}}
        )
        price_1h_ago: Price(
          maximum: Block_Number
          if: {Block: {Time: {before: $time_1h_ago}}}
        )
        price_3h_ago: PriceInUSD(minimum: Block_Number)
      }
      usd: sum(of: Trade_AmountInUSD)
      count
    }
  }
}

This returns the top 200 trading pairs ranked by USD volume over the last three hours, complete with:

This data supports arbitrage detection, liquidity analysis, and market-making strategy development.

Identify Top Traders on a DEX

Understanding who’s moving markets can provide strategic advantages. The following query reveals the top 100 traders by trading volume:

query DexMarkets($network: evm_network, $market: String) {
  EVM(network: $network) {
    DEXTradeByTokens(
      orderBy: {descendingByField: "volumeUsd"}
      limit: {count: 100}
      where: {Trade: {Dex: {ProtocolFamily: {is: $market}}}}
    ) {
      Trade {
        Buyer
        Dex {
          OwnerAddress
          ProtocolFamily
          ProtocolName
        }
        Currency {
          SmartContract
          Symbol
          Name
        }
        Side {
          Currency {
            SmartContract
            Symbol
            Name
          }
        }
      }
      volumeUsd: sum(of: Trade_Side_AmountInUSD)
    }
  }
}

Each result includes:

This enables behavioral analysis, whale tracking, and influencer identification within DeFi ecosystems.

Monitor Latest Trades in Real Time

For real-time monitoring or alert systems, retrieve the most recent trades:

query LatestTrades($network: evm_network, $market: String) {
  EVM(network: $network) {
    DEXTradeByTokens(
      orderBy: {descending: Block_Time}
      limit: {count: 50}
      where: {Trade: {Dex: {ProtocolFamily: {is: $market}}}}
    ) {
      Block {
        Time
      }
      Transaction {
        Hash
      }
      Trade {
        Dex {
          OwnerAddress
          ProtocolFamily
          ProtocolName
        }
        AmountInUSD
        Price
        Amount
        Side {
          Type
          Currency {
            Symbol
            SmartContract
            Name
          }
          AmountInUSD
          Amount
        }
        Currency {
          Symbol
          SmartContract
          Name
        }
      }
    }
  }
}

Returns include:

Ideal for surveillance bots, front-running detection, or live market feeds.

👉 Access real-time blockchain trading data with powerful API integrations.

Frequently Asked Questions

What is a DEX API?
A DEX API allows developers to programmatically access decentralized exchange trading data, including trades, volumes, prices, and participant addresses across blockchains.

How does DEXTradeByTokens differ from DEXTrades?
DEXTradeByTokens provides aggregated trade data optimized for analytics, while DEXTrades delivers raw, per-trade records suitable for forensic or compliance use cases.

Which blockchains are supported?
The API supports Ethereum and other EVM-compatible networks such as BSC, Polygon, Arbitrum, Optimism, and Avalanche.

Can I track specific wallets using this API?
Yes. By filtering on Trade_Buyer or Trade_Sender, you can monitor activities of specific addresses across DEXs.

Is historical data available?
Yes. The API indexes years of blockchain data, allowing queries over custom time ranges from minutes to months.

How often is data updated?
Data is indexed in near real-time—typically within seconds of block confirmation—ensuring low-latency access to the latest trades.


Core Keywords: DEX API, blockchain data API, decentralized exchange data, EVM blockchain queries, crypto trading analytics, on-chain trading data, Uniswap analytics, real-time DEX data