CachedTokenRisk
Documentation for eth_defi.token_analysis.tokenrisk.CachedTokenRisk Python class.
- class CachedTokenRisk
Bases:
eth_defi.token_analysis.tokenrisk.TokenRiskAdd file-system based cache for Token Risk API.
Example:
TOKEN_RISK_API_KEY = os.environ.get("TOKEN_RISK_API_KEY") token_risk = CachedTokenRisk( TOKEN_RISK_API_KEY, ) # COW on BNB Chain data = token_risk.fetch_token_info(56, "0x7aaaa5b10f97321345acd76945083141be1c5631") assert data["score"] == 0 assert not is_tradeable_token(data)
You can also pass your custom SQLite file for caching:
path = Path("./cache/token_risk.sqlite") token_risk = CachedTokenRisk( api_key=os.environ["TOKEN_RISK_API_KEY"], cache_file=path, )
- Parameters
api_key – Token Risk API key.
session – requests.Session for persistent HTTP connections
cache_file –
Path to a local file system SQLite file used as a cached.
For simple local use cases.
cache –
Direct custom cache interface as a Python dict interface.
For your own database caching.
Cache keys are format: cache_key = f”{chain_id}-{address}”. Cache values are JSON blobs as string.
Methods summary
__init__(api_key[, cache_file, session, ...])- param api_key
fetch_token_info(chain_id, address)Get Token Risk info.
Get a diagnostics message.
- __init__(api_key, cache_file=PosixPath('/home/runner/.cache/tradingstrategy/glide-token-risk.sqlite'), session=None, cache=None, retries=15)
- Parameters
api_key (str) – Token Risk API key.
session (requests.sessions.Session) – requests.Session for persistent HTTP connections
cache_file (pathlib.Path | None) –
Path to a local file system SQLite file used as a cached.
For simple local use cases.
cache (dict | None) –
Direct custom cache interface as a Python dict interface.
For your own database caching.
Cache keys are format: cache_key = f”{chain_id}-{address}”. Cache values are JSON blobs as string.
retries (int | None) –
- fetch_token_info(chain_id, address)
Get Token Risk info.
Use local file cache if available.
- Returns
Data passed through Token Risk.
A special member cached is set depending on whether the reply was cached or not.
- Parameters
chain_id (int) –
address (Union[str, eth_typing.evm.HexAddress]) –
- Return type
- get_diagnostics()
Get a diagnostics message.
Use for logging what kind of data we have collected
Example output:
Token sniffer info is: Token Risk cache database /Users/moo/.cache/tradingstrategy/Token Risk.sqlite summary: Entries: 195 Max score: 100 Min score: 0 Avg score: 56.6- Returns
Multi-line human readable string
- Return type