load_extra_metadata#
API documentation for tradingstrategy.utils.token_extra_data.load_extra_metadata Python function.
- load_extra_metadata(pairs_df, client=None, top_pair_reply=None, ignored_tokens={'ALUSD', 'BAC', 'BDO', 'BEAN', 'BOB', 'BUSD', 'CADC', 'CEUR', 'CJPY', 'CNHT', 'CRVUSD', 'CUSD', 'DAI', 'DJED', 'DOLA', 'DUSD', 'EOSDT', 'EURA', 'EUROC', 'EUROe', 'EURS', 'EURT', 'EURe', 'EUSD', 'FDUSD', 'FEI', 'FLEXUSD', 'FRAX', 'FXD', 'FXUSD', 'GBPT', 'GHO', 'GHST', 'GUSD', 'GYD', 'GYEN', 'HUSD', 'IRON', 'JCHF', 'JPYC', 'KDAI', 'LISUSD', 'LUSD', 'MIM', 'MIMATIC', 'MKUSD', 'MUSD', 'ONC', 'OUSD', 'PAR', 'PAXG', 'PYUSD', 'RAI', 'RUSD', 'SEUR', 'SFRAX', 'SILK', 'STUSD', 'SUSD', 'TCNH', 'TOR', 'TRYB', 'TUSD', 'USC', 'USD+', 'USDB', 'USDC', 'USDC.e', 'USDD', 'USDE', 'USDN', 'USDP', 'USDR', 'USDS', 'USDT', 'USDT.e', 'USDV', 'USDX', 'USDe', 'USDs', 'USK', 'UST', 'USTC', 'USX', 'UUSD', 'VAI', 'VEUR', 'VST', 'VUSD', 'WAVAX', 'WBNB', 'WBTC', 'WETH', 'WMATIC', 'XAUT', 'XDAI', 'XIDR', 'XSGD', 'XSTUSD', 'XUSD', 'YUSD', 'ZSD', 'ZUSD', 'crvUSD', 'gmUSD', 'iUSD', 'jEUR', 'kUSD', 'sosUSDT'})[source]#
Load token tax data for given pairs dataframe.
Supplements loaded trading pair data with additional metadata from /top API endpoint
Mainly used to get the token tax for trading pairs
Data is added by the base token, because TokenSniffer does not provide per-pair data
Can only handle token amounts /top endpoint can handle
Note
In the future, this data will be with supplied the core data, but due to heterogenous systems, you need to retrofit the data for pairs you need.
Warning
This is heavily under development.
Warning
Because we use third party services like TokenSniffer for token tax data, and often these services key this data by tokens, not by trading pairs, this data might be invalid per trading pair.
Warning
The /top endpoint may not return data for dead trading pairs or assets. The trading pair must have seen at least $1 volume during the last 24h to be alive, or other similar condition.
Example how to perform scam filter on pair universe data:
# Scam filter using TokenSniffer pairs_df = load_extra_metadata( pairs_df, client, ) all_pairs_df = pairs_df pairs_df = pairs_df.loc[pairs_df["risk_score"] >= Parameters.min_token_sniffer_score] print(f"After scam filter we have {len(pairs_df)} pairs") clean_tokens = pairs_df["base_token_symbol"] only_scams = all_pairs_df.loc[~all_pairs_df["base_token_symbol"].isin(clean_tokens)] for idx, row in only_scams.iterrows(): print(f"Scammy pair {row.base_token_symbol} - {row.quote_token_symbol}, risk score {row.risk_score}, pool {row.address}, token {row.base_token_address}") pairs_df = pairs_df.sort_values("volume", ascending=False) print("Top pair matches (including benchmark pairs):") for _, pair in pairs_df.head(10).iterrows(): print(f" Pair: {pair.base_token_symbol} - {pair.quote_token_symbol} ({pair.exchange_slug})")
Another example:
from tradingstrategy.utils.token_extra_data import load_extra_metadata exchange_universe = client.fetch_exchange_universe() addresses = [ "0x71fc7cf3e26ce5933fa1952590ca6014a5938138", # FRIEND.TECH 0x71fc7cf3e26ce5933fa1952590ca6014a5938138 SCAM "0x14feE680690900BA0ccCfC76AD70Fd1b95D10e16", # $PAAL 0x14feE680690900BA0ccCfC76AD70Fd1b95D10e16 "0x576e2BeD8F7b46D34016198911Cdf9886f78bea7" # TRUMP 0x576e2BeD8F7b46D34016198911Cdf9886f78bea7 ] addresses = list(map(str.lower, addresses)) # Get all pairs data and filter to our subset pairs_df = client.fetch_pair_universe().to_pandas() pairs_df = add_base_quote_address_columns(pairs_df) pairs_df = pairs_df.loc[ (pairs_df["base_token_address"].isin(addresses)) & (pairs_df["chain_id"] == 1) ] # Retrofit TokenSniffer data pairs_df = load_extra_metadata( pairs_df, client=client, ) assert isinstance(pairs_df, pd.DataFrame) assert "buy_tax" in pairs_df.columns assert "sell_tax" in pairs_df.columns assert "other_data" in pairs_df.columns # pair_universe = PandasPairUniverse( pairs_df, exchange_universe=exchange_universe, ) trump_weth = pair_universe.get_pair_by_human_description( (ChainId.ethereum, "uniswap-v2", "TRUMP", "WETH"), ) # Read buy/sell/tokensniffer metadta through DEXPair instance assert trump_weth.buy_tax == pytest.approx(1.0, rel=0.02) assert trump_weth.sell_tax == pytest.approx(1.0, rel=0.02) assert trump_weth.token_sniffer_data.get("balances") is not None # Read random column from TokenSniffer reply
- Parameters:
pairs_df (DataFrame) –
Pandas DataFrame with pairs data.
Must be retrofitted with add_base_quote_address_columns().
client (tradingstrategy.client.Client | None) – Give client to load /top metadata
top_pair_reply (tradingstrategy.top.TopPairsReply | None) – Pass preloaded /top metadata
ignored_tokens –
Ignore popular quote tokens.
Asking data for these tokens causes too many hits and pollutes the query. The column risk_score column is set to 100 for these tokens.
- Returns:
DataFrame with new columns added:
buy_tax
sell_tax
other_data dict, contains top_pair_data which is TopPairData instance for the base asset
risk_score - risk score 0 to 100, we recommend to cull everything beloe 65
whitelisted - token is on ignored_tokens whitelist
- Return type:
DataFrame