cryptodatapy.extract.params.base_param_converter
Attributes
Classes
Abstract Base Class for all parameter conversion logic. |
Module Contents
- cryptodatapy.extract.params.base_param_converter.logger
- class cryptodatapy.extract.params.base_param_converter.BaseParamConverter(data_req: cryptodatapy.core.data_request.DataRequest)
Bases:
abc.ABCAbstract Base Class for all parameter conversion logic.
This class defines the interface (the ‘convert’ method) and provides common utility methods needed by all data source-specific parameter converters to translate a DataRequest object into source-specific parameter dictionary.
- data_req
- _convert_case_tickers(case: str = 'upper') List[str]
Helper function to handle simple ticker conversion logic. This method is placed in the base class to avoid repetition in subclasses that only require simple case changes.
If source_tickers are already provided in the DataRequest, they are used directly. Otherwise, standard DataRequest tickers are converted to the specified case (‘upper’ or ‘lower’).
- Parameters:
case (str) – The desired case for tickers: ‘upper’ or ‘lower’.
- Returns:
The list of converted tickers.
- Return type:
List[str]
- _convert_quote_ccy(default_ccy: str = 'USD', case: str = 'upper') str
Converts the quote currency to the format required by the vendor.
This method serves as a default implementation for the most common conversion, but allows subclasses to customize the default currency and the case requirement.
- Parameters:
default_ccy (str, optional) – The currency to return if self.data_req.quote_ccy is None. Defaults to ‘USD’.
case (str, optional) – The desired case for the currency: ‘upper’, ‘lower’, or ‘none’. Defaults to ‘upper’.
- Returns:
The converted quote currency string.
- Return type:
str
- _convert_markets() List[str]
Implementation of the most common market conversion pattern.
The most common market type conversion is for ‘spot’ markets, which usually involves creating a simple BASE/QUOTE market identifier.
- _convert_freq() str
Converts frequency from CryptoDataPy format (e.g., ‘30min’, ‘m’) to the common canonical API format (e.g., ‘30m’, ‘1M’).
This serves as a robust default for many exchange APIs.
- Returns:
The converted canonical frequency string.
- Return type:
str
- _load_field_map(source: str) pandas.DataFrame
Loads the field mapping file (fields.csv) and returns the relevant data source’s mapping for use in converting fields.
- Parameters:
source (str) – The name of the data source (e.g., ‘cryptocompare’, ‘fred’).
- Returns:
A DataFrame containing the mapping from CryptoDataPy fields to source fields.
- Return type:
pd.DataFrame
- convert_fields(data_source: str) List[str]
Converts the standard CryptoDataPy fields (e.g., ‘close’, ‘volume’) in data_req.fields to the vendor-specific field names.
- Parameters:
data_source (str) – The name of the data source/vendor.
- Returns:
A list of source-specific field names.
- Return type:
List[str]
- _get_standardized_timestamp(date_input: str | datetime.datetime | None, is_end_date: bool) pandas.Timestamp | None
Converts any date input (str, datetime, or None) into a standardized, timezone-naive Pandas Timestamp in UTC, applying sensible defaults.
- Parameters:
date_input (Optional[Union[str, datetime]]) – The input date from data_req.start_date or data_req.end_date.
is_end_date (bool) – True if processing end_date (defaults to now), False if start_date.
- Returns:
The normalized Timestamp, or None if no date is provided and no default applies.
- Return type:
Optional[pd.Timestamp]
- _convert_dates(format_type: str, default_start_str: str | None = None) Tuple[str | int | datetime.datetime | None, str | int | datetime.datetime | None]
Converts data request start and end dates to a specified source format.
This utility performs the standard conversion from the DataRequest’s start/end dates to the output format required by the vendor (e.g., timestamp or YYYY-MM-DD string).
- Parameters:
format_type (str) – The desired output format for the source: - ‘str_ymd’: YYYY-MM-DD string format - ‘str_dmy’: DD/MM/YYYY string format - ‘ts_sec’: Unix timestamp in seconds - ‘ts_ms’: Unix timestamp in milliseconds - ‘int_year’: Integer year - ‘direct’: Direct assignment (no conversion)
default_start_str (Optional[str]) – A specific string to use if self.data_req.start_date is None. If None, the start date remains None.
- Returns:
A tuple containing the converted start_date and end_date.
- Return type:
Tuple[Optional[Union[str, int, datetime]], Optional[Union[str, int, datetime]]]
- abstractmethod convert(**kwargs: Any) Dict[str, Any]
Abstract method that must be implemented by all subclasses.
This method is responsible for translating all relevant fields (tickers, freq, dates, etc.) from the standard DataRequest format into a dictionary of parameters expected by the specific data vendor’s API.
The adapter is responsible for passing any necessary metadata (like lists of known assets/metrics/indexes) via **kwargs.
- Parameters:
**kwargs (Any) – Additional keyword arguments for flexibility, typically vendor metadata.
- Returns:
A dictionary containing the vendor-specific parameters, which may include a list of requests under a key like ‘requests’.
- Return type:
Dict[str, Any]