Skip to main content
Decentralized exchanges are playing an increasingly important role in supporting cryptoasset trading, particularly when it comes to tokens using the ERC-20 standard. Coin Metrics has been actively working on collecting data from major DeFi protocols. For our first release, we have added support for all major liquidity pools on Uniswap v2, Uniswap v3, and Sushiswap v1.

Resources

This notebook demonstrates basic functionality offered by the Coin Metrics Python API Client and DEX Market Data. Coin Metrics offers a vast assortment of data for hundreds of cryptoassets. The Python API Client allows for easy access to this data using Python without needing to create your own wrappers using requests and other such libraries. To understand the data that Coin Metrics offers, feel free to peruse the resources below.

File Download

Download the entire notebook as either a jupyter notebook to run yourself or as a pdf from the two links below DEFI - Dex Data.ipynb DEFI_dex_data (1).pdf

Setup

DEX Market Catalog

The catalog/markets endpoint returns a list of available markets along with time ranges of available data. Users can pass in a list of markets, exchanges, or market types (spot, futures, options). We can retrieve our DEX markets by fetching a list of all ‘spot’ markets, then filtering for the markets where the ‘experimental’ parameter equals true.
2544 rows × 39 columns

DEX markets include metadata for 3 different smart contracts

  • contract_address: The address of the liquidity pool contract. Each liquidity pool is a unique instance of a smart contract, deployed at a dedicated address. The pool contract holds both the base and the quote asset.
  • base_address: The address of the ERC-20 token contract associated with the base asset.
  • quote_address: The address of the ERC-20 token contract associated with the quote asset.
2544 rows × 5 columns Each liquidity pool is also associated with a corresponding fee percentage. With each trade, fees are distributed pro-rata to the pool’s liquidity providers.
Due to the permissionless nature of provisioning a liquidity pool, users can easily add arbitrary ERC-20 tokens to the decentralized exchange. There are over 50,000 trading pairs available on Uniswap today. To prioritize only the most relevant and liquid markets, we cover the subset of markets where both tokens are part of Coin Metrics reference rate coverage.
The majority of DEX assets trade against Wrapped Ether (WETH). Note that Ethereum’s native asset ETH is not supported in Uniswap V2/V3, as the asset was created prior to the ERC-20 standard. From the Uniswap documentation:
“Unlike Uniswap V1 pools, V2 pairs do not support ETH directly, so ETH⇄ERC-20 pairs must be emulated with WETH. The motivation behind this choice was to remove ETH-specific code in the core, resulting in a leaner codebase. End users can be kept fully ignorant of this implementation detail, however, by simply wrapping/unwrapping ETH in the periphery.”
docs.uniswap.org

Using the min_time parameter, we can filter for the newest DEX liquidity pool deployed in our coverage

DEX Swaps Data

Swaps data is served through our existing /timeseries/market-trades endpoint because swaps are conceptually identical to a trade. Users can see all the standard trade fields for a swap such as time, price, and volume but can also see defi-specific fields such as the block height, block hash, transaction id, addresses involved in the swap, and more.

Unlike centralized exchanges, where there is an unknown buyer and a seller, each swap is associated with 3 different Ethereum addresses

  • Initiator is the ethereum address which submitted the transaction as a result of which the swap/liquidity action occurred
  • Sender is the ethereum address that invoked the uniswap pool smart contract’s function for swapping or adding/removing liquidity
  • Beneficiary is the ethereum address that got credited with the output tokens (in case of a swap or liquidity removal) or with liquidity (in case of liquidity addition)
ATLAS by Coin Metrics
Blockchain Search Engine\
BUYER ADDRESS: https://atlas.coinmetrics.io/address-details?asset=weth\&address=ddc25c965443834179438c2eb30e70f34b854a04\ TRANSACTION INFO: https://atlas.coinmetrics.io/transaction-details?asset=weth\&tx\_hash=cb93842f093812b85469b576914d02907345d2624e1eee463999bade940a8851\ BlOCK INFO: https://atlas.coinmetrics.io/block-details?asset=weth\&block\_hash=73155bd5ea974746d59ed3b05d93f24d2011f391b527b9d7d5c42e59752c6d41\ For more info on ATLAS visit: https://coinmetrics.io/atlas/
72 rows × 1 columns

Retrieving volume for a centralized exchange via the market-candles endpoint

70 rows × 2 columns