cryptodatapy.extract.adapters.vendors.defillama_adapter
Attributes
Classes
Adapter class for retrieving data from DefiLlama API. |
Module Contents
- cryptodatapy.extract.adapters.vendors.defillama_adapter.logger
- cryptodatapy.extract.adapters.vendors.defillama_adapter.data_cred
- class cryptodatapy.extract.adapters.vendors.defillama_adapter.DefiLlamaAdapter(config: Dict[str, Any] | None = None)
Bases:
cryptodatapy.extract.adapters.base_adapter.BaseAPIAdapterAdapter class for retrieving data from DefiLlama API. Implements the BaseAdapter contract via BaseAPIAdapter.
- assets = None
- fields = None
- stablecoins = None
- yields = None
- _fetch_raw_meta(info_type: str) Dict[str, Any]
Helper method to fetch raw metadata (chains, protocols, fees, etc.)
- Parameters:
info_type (str) – The type of metadata to fetch (‘chains’, ‘protocols’, ‘fees’, ‘stablecoins’, ‘yields’).
- Returns:
The raw metadata response from DefiLlama.
- Return type:
Dict[str, Any]
- get_chains_info(as_list: bool = False, remove_missing: list | None = None) pandas.DataFrame | list
Get DefiLlama chains information.
- Parameters:
as_list (bool, default False) – If True, returns the chains information as a list.
remove_missing (Optional[list], optional) – List of fields (column names) to check for missing values to filter out. Default is None.
- Returns:
The requested chains information.
- Return type:
Union[pd.DataFrame, list]
- get_protocols_info(as_list: bool = False, remove_missing: list | None = None) pandas.DataFrame | list
Get DefiLlama protocols information.
- Parameters:
as_list (bool, default False) – If True, returns the chains information as a list.
remove_missing (Optional[list], optional) – List of fields (column names) to check for missing values to filter out. Default is None.
- Returns:
The requested protocols information.
- Return type:
Union[pd.DataFrame, list]
- get_fees_info(as_list: bool = False, remove_missing: list | None = None) pandas.DataFrame | list
Get DefiLlama fees information.
- Parameters:
as_list (bool, default False) – If True, returns the fees information as a list.
remove_missing (Optional[list], optional) – List of fields (column names) to check for missing values to filter out. Default is None.
- Returns:
The requested fees information.
- Return type:
Union[pd.DataFrame, list]
- get_stablecoins_info(as_list: bool = False, remove_missing: list | None = None) pandas.DataFrame | list
Get DefiLlama stablecoins information.
- Parameters:
as_list (bool, default False) – If True, returns the stablecoins information as a list.
remove_missing (Optional[list], optional) – List of fields (column names) to check for missing values to filter out. Default is None.
- Returns:
The requested stablecoins information.
- Return type:
Union[pd.DataFrame, list]
- get_yields_info() pandas.DataFrame | list
Get DefiLlama yields information.
- Returns:
The requested yields information.
- Return type:
Union[pd.DataFrame, list]
- static _normalize_protocols(protocols_df: pandas.DataFrame) pandas.DataFrame
Processes raw protocols endpoint data, selecting only high-value (Rating 4+) fields for identification, classification, and cross-referencing.
- Parameters:
protocols_df (pd.DataFrame) – Raw protocols DataFrame from DefiLlama.
- Returns:
Normalized protocols DataFrame.
- Return type:
pd.DataFrame
- static _normalize_chains(chains_df: pandas.DataFrame) pandas.DataFrame
Normalizes the raw chain data, adds the ‘dataEndpoint’ tag, and applies manual ticker corrections (e.g., TRON -> TRX).
- Parameters:
chains_df (pd.DataFrame) – Raw chains DataFrame from DefiLlama.
- Returns:
Normalized chains DataFrame.
- Return type:
pd.DataFrame
- static _normalize_stablecoins(stablecoins_df: pandas.DataFrame) pandas.DataFrame
Normalizes the raw stablecoins data.
- Parameters:
stablecoins_df (pd.DataFrame) – Raw stablecoins DataFrame from DefiLlama.
- Returns:
Normalized stablecoins DataFrame.
- Return type:
pd.DataFrame
- static _unify_assets(df_protocols: pandas.DataFrame, df_chains: pandas.DataFrame) pandas.DataFrame
Merges and concatenates protocols and chains data, applying the slug hierarchy, resolving collisions, and establishing a canonical ticker precedence based on Type, Category, and TVL.
- Parameters:
df_protocols (pd.DataFrame) – Normalized protocols DataFrame.
df_chains (pd.DataFrame) – Normalized chains DataFrame.
- Returns:
Unified assets DataFrame with canonical tickers.
- Return type:
pd.DataFrame
- get_assets_info(as_list: bool = False) pandas.DataFrame | list
Get DefiLlama assets information.
Note that DefiLlama does not have a direct “assets” endpoint. This method synthesizes the assets list by combining and normalizing data from the protocols and chains endpoints. It applies a hierarchy to resolve slugs and ticker collisions, establishing a canonical ticker based on asset type, category, and TVL.
- Parameters:
as_list (bool, default False) – If True, returns the assets information as a list.
- Returns:
The requested assets information.
- Return type:
pd.DataFrame
- get_fields_info(as_list: bool = False) pandas.DataFrame | list
Gets DefiLlama fields information.
- Parameters:
as_list (bool, default False) – If True, returns the fields information as a list.
- Returns:
The requested fields information.
- Return type:
pd.DataFrame
- get_rate_limit_info() Any | None
DefiLlama credits left in the api key, these reset on the 1st of each month.
- _build_single_request_params(single_request_dict: Dict[str, Any]) tuple[str, Dict[str, Any]]
Builds the URL and parameters for a single request object generated by the converter. This resolves the full path and query parameters for one API call.
- Parameters:
single_request_dict (Dict[str, Any]) – A dictionary representing a single request with keys: - ‘endpoint’: The API endpoint path. - ‘slug’: The slug to append to the endpoint. - ‘query_params’: A dictionary of query parameters specific to this request.
- Returns:
A tuple containing the full URL and the parameters dictionary for the request.
- Return type:
tuple[str, Dict[str, Any]]
- _fetch_all_raw_data(requests_list: List[Dict[str, Any]]) List[Dict[str, Any]]
Fetches raw data for all requests in the list, implementing rate limiting.
- Parameters:
requests_list (List[Dict[str, Any]]) – A list of request dictionaries generated by the converter.
- Returns:
A list of raw data responses corresponding to each request.
- Return type:
List[Dict[str, Any]]
- _convert_params_to_vendor(data_req: cryptodatapy.core.data_request.DataRequest) Dict[str, Any]
Converts the DataRequest object into the vendor’s specific API parameters. DefiLlama URLs rely heavily on protocol or chain name being part of the path.
- Parameters:
data_req (DataRequest) – The standardized DataRequest object containing user-specified parameters.
- Returns:
A dictionary of vendor-specific parameters including the full request list.
- Return type:
Dict[str, Any]
- _fetch_raw_data(params: Dict[str, Any]) Dict[str, Any] | List[Dict[str, Any]]
Submits the vendor-specific parameters to the API and returns the raw responses.
- Parameters:
params (Dict[str, Any]) – The vendor-specific parameters including the full request list.
- Returns:
The raw data responses from DefiLlama.
- Return type:
Union[Dict[str, Any], List[Dict[str, Any]]]
- _transform_raw_response(data_req: cryptodatapy.core.data_request.DataRequest, raw_data: Any) pandas.DataFrame
Processes the raw data responses into the package’s standardized tidy DataFrame format using the dedicated DefiLlamaWrangler.
- Parameters:
data_req (DataRequest) – The original DataRequest object.
raw_data (Any) – The raw data response from DefiLlama.
- Returns:
The transformed tidy DataFrame.
- Return type:
pd.DataFrame