DEX API: A Comprehensive Guide to Blockchain Data API (V2)

ยท

Introduction to DEX APIs

Decentralized Exchange (DEX) APIs provide critical access to trading data on blockchain networks. Our platform offers two primary APIs for retrieving DEX trading data:

  1. DEXTrades: Retrieves individual trade data.
  2. DEXTradeByTokens: Organizes trades by token pairs.

๐Ÿ‘‰ Learn more about API differences

Fetching DEX Information on Ethereum Networks

This query retrieves comprehensive data about all DEXs operating on a specified Ethereum network:

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}}}})
    }
  }
}

Parameters:

Retrieving Specific DEX Statistics

To analyze performance metrics for particular DEX protocols:

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)
    }
  }
}

Example Use Case:
Tracking Uniswap activity with parameters:

๐Ÿ‘‰ Explore advanced DEX analytics

Analyzing Trading Pairs

This query identifies all active trading pairs on a specified DEX:

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
    }
  }
}

Top Traders Analysis

Identify the most active traders on any DEX:

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)
    }
  }
}

Real-Time Trade Monitoring

Track the most recent transactions on any DEX:

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
        }
      }
    }
  }
}

FAQ Section

Q: What's the difference between DEXTrades and DEXTradeByTokens APIs?
A: DEXTrades returns individual transactions, while DEXTradeByTokens aggregates data by trading pairs.

Q: How frequently is the DEX data updated?
A: Our API provides real-time data with sub-minute latency for most networks.

Q: Can I filter DEX data by time range?
A: Yes, all queries support time-based filtering through the Block_Time parameter.

Q: What metrics are available for DEX analysis?
A: You can access trading volume, liquidity, active traders, price movements, and more.

Q: Is historical DEX data available?
A: Yes, we maintain complete historical records for all supported networks.

Q: How do I access less popular DEXs?
A: Simply specify the ProtocolFamily parameter with the DEX's exact name.