filter_for_quote_tokens#

API documentation for tradingstrategy.pair.filter_for_quote_tokens Python function.

filter_for_quote_tokens(pairs, quote_token_addresses)[source]#

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

Useful as a preprocess step for creating tradingstrategy.candle.GroupedCandleUniverse or tradingstrategy.liquidity.GroupedLiquidityUniverse.

You might, for example, want to construct a trading universe where you have only BUSD pairs.

Example:

exchange_universe = client.fetch_exchange_universe()

quote_tokens = {
    "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",  # USDC polygon
    "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",  # USDT polygon
}

pairs_df = client.fetch_pair_universe().to_pandas()

# Find out all volatile pairs traded against USDC and USDT on Polygon
pairs_df = filter_for_chain(pairs_df, ChainId.polygon)
pairs_df = filter_for_stablecoins(pairs_df, StablecoinFilteringMode.only_volatile_pairs)
pairs_df = filter_for_quote_tokens(pairs_df, quote_tokens)

pairs_df = filter_for_quote_tokens(pairs_df, lending_reserves.get_asset_addresses())
pair_universe = PandasPairUniverse(pairs_df, exchange_universe=exchange_universe)
Parameters:
  • quote_token_addresses (Union[List[str], Set[str]]) –

    List of Ethereum addresses of the tokens.

    Lowercased, non-checksummed.

  • pairs (DataFrame) –

Returns:

DataFrame with trading pairs filtered to match quote token condition

Return type:

DataFrame