API documentation for tradingstrategy.pair Python module in Trading Strategy.

Module description#

Trading pair information and pair datasets.

The core classes to understand the data are

  • DEXPair: describe one trading pair on different DEXes on different blockchains

  • PandasPairUniverse: all available trading pairs across all blockchains and functions to look them up.

  • HumanReadableTradingPairDescription: define the format for symbolic look iup for trading pairs

Trading pairs are not fungible across DEXes and blockchains.

  • The same token might have different address on a different blockchains

  • The same trading pair may be on multiple DEXes, or even on the same DEX with different fee tiers e.g. Uniswap v3 gives WETH-USDC at 0.05%, 0.30% and 1% fee tiers, most real trading happening on 0.05% tier

Here is an example how to look up a particular trading pair:

.. code-block:: python

from pyarrow import Table from tradingstrategy.chain import ChainId from import ExchangeUniverse from tradingstrategy.pair import PandasPairUniverse from tradingstrategy.pair import HumanReadableTradingPairDescription

# Exchange map data is so small it does not need any decompression exchange_universe: ExchangeUniverse = client.fetch_exchange_universe()

# Decompress the pair dataset to Python map # This is raw PyArrow data columnar_pair_table: Table = client.fetch_pair_universe() print(f”Total pairs {len(columnar_pair_table)}, total exchanges {len(exchange_universe.exchanges)}”)

# Wrap the data in a helper class with indexes for easier access pair_universe = PandasPairUniverse(columnar_pair_table.to_pandas(), exchange_universe=exchange_universe)

# Get BNB-BUSD pair on PancakeSwap v2 # # There are no fee tiers, so we # desc: HumanReadableTradingPairDescription = (ChainId.bsc, “pancakeswap-v2”, “WBNB”, “BUSD”) bnb_busd = pair_universe.get_pair_by_human_description(desc) print(f”We have pair {bnb_busd} with 30d volume of USD {bnb_busd.volume_30d}”)

See Code examples section for Pairs tutorial for more information.

For exploring the trading pairs through web you can use



Trading pair information for a single pair.


The queries universe, as returned by the server.


A pair universe implementation that is created from Pandas dataset.


How to filter pairs in stablecoin filtering.


filter_for_base_tokens(pairs, ...)

Filter dataset so that it only contains data for the trading pairs that have a certain base token.

filter_for_chain(pairs, chain_id)

Extract trading pairs for specific blockchain.

filter_for_exchange(pairs, exchange_slug)

Extract trading pairs for specific exchange(s).

filter_for_exchanges(pairs, exchanges)

Filter dataset so that it only contains data for the trading pairs from a certain exchange.

filter_for_quote_tokens(pairs, ...)

Filter dataset so that it only contains data for the trading pairs that have a certain quote tokens.

filter_for_stablecoins(pairs, mode)

Filter dataset so that it only contains data for the trading pairs that are either stablecoin pairs or not.

filter_for_trading_fee(pairs, fee)

Select only pairs with a specific trading fee.


Add base_token_address, quote_token_address columns.

resolve_pairs_based_on_ticker(df[, ...])

Resolve symbolic trading pairs to their internal integer primary key ids.