filter_for_blacklisted_tokens#

API documentation for tradingstrategy.utils.token_filter.filter_for_blacklisted_tokens Python function.

filter_for_blacklisted_tokens(pairs, blacklisted_tokens)[source]#

Remove blacklisted tokens from the trading pair set.

Useful as a preprocess step for creating trading pairs that cause issues in open-ended strategies. Example:

avoid_backtesting_tokens = {

    # MKR market is created and pulled out,
    # leaving us no good price source in the dataset
    # https://tradingstrategy.ai/trading-view/ethereum/uniswap-v3/mkr-usdc-fee-5#7d
    "MKR",

    # Not sure what's going on with this token,
    # price action and TVL not normal though 100k liquidity
    # https://tradingstrategy.ai/trading-view/ethereum/uniswap-v3/sbio-usdc-fee-30#1d
    "SBIO",

    # Same problems as MKR,
    # it has historical TVL that then gets pulled down to zero
    # https://tradingstrategy.ai/trading-view/ethereum/uniswap-v3/ldo-usdc-fee-30
    "LDO",

    # Trading jsut stops (though there is liq left)
    # https://tradingstrategy.ai/trading-view/ethereum/uniswap-v3/id-usdc-fee-30
    "ID",

    # Disappearing market, as above
    "DMT",
    "XCHF",
    "FLC",
    "GF",
    "CVX",
    "MERC",
    "ICHI",
    "DOVU",
    "DOVU[eth]",
    "DHT",
    "EWIT",

    # Abnormal price during the rebalance
    # adjust_position() does not have good price checks /
    # how to recover in the case price goes hayware after opening the position
    "MAP",
    "TRX",
    "LAI",
}
tradeable_pairs_df = client.fetch_pair_universe().to_pandas()
tradeable_pairs_df = filter_for_blacklisted_tokens(tradeable_pairs_df, avoid_backtesting_tokens)
print("Pairs without blacklisted base token", len(tradeable_pairs_df))
Parameters:
  • blacklisted_tokens (Union[List[str], Set[str]]) – Blacklisted token symbols or addresses.

  • pairs (DataFrame) –

Returns:

DataFrame with trading pairs filtered to match quote token condition

Return type:

DataFrame