filter_for_base_tokens#
API documentation for tradingstrategy.utils.token_filter.filter_for_base_tokens Python function.
- filter_for_base_tokens(pairs, base_token_addresses)[source]#
Filter dataset so that it only contains data for the trading pairs that have a certain base token.
Useful as a preprocess step for creating
tradingstrategy.lending.LendingUniverse
Example:
client = persistent_test_client 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) # Create lending universe and trading universe with the cross section of # - Available assets in the lending protocols # - Asset we can trade lending_reserves = client.fetch_lending_reserve_universe() pairs_df = filter_for_base_tokens(pairs_df, lending_reserves.get_asset_addresses()) pair_universe = PandasPairUniverse(pairs_df, exchange_universe=exchange_universe) # Lending reserves have around ~320 individual trading pairs on Polygon across different DEXes assert 1 < pair_universe.get_count() < 1_000 eth_usdc = pair_universe.get_pair_by_human_description((ChainId.polygon, "uniswap-v3", "WETH", "USDC"))