cryptodatapy.extract.params.base_param_converter ================================================ .. py:module:: cryptodatapy.extract.params.base_param_converter Attributes ---------- .. autoapisummary:: cryptodatapy.extract.params.base_param_converter.logger Classes ------- .. autoapisummary:: cryptodatapy.extract.params.base_param_converter.BaseParamConverter Module Contents --------------- .. py:data:: logger .. py:class:: BaseParamConverter(data_req: cryptodatapy.core.data_request.DataRequest) Bases: :py:obj:`abc.ABC` Abstract 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. .. py:attribute:: data_req .. py:method:: _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'). :param case: The desired case for tickers: 'upper' or 'lower'. :type case: str :returns: The list of converted tickers. :rtype: List[str] .. py:method:: _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. :param default_ccy: The currency to return if self.data_req.quote_ccy is None. Defaults to 'USD'. :type default_ccy: str, optional :param case: The desired case for the currency: 'upper', 'lower', or 'none'. Defaults to 'upper'. :type case: str, optional :returns: The converted quote currency string. :rtype: str .. py:method:: _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. .. py:method:: _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. :rtype: str .. py:method:: _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. :param source: The name of the data source (e.g., 'cryptocompare', 'fred'). :type source: str :returns: A DataFrame containing the mapping from CryptoDataPy fields to source fields. :rtype: pd.DataFrame .. py:method:: 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. :param data_source: The name of the data source/vendor. :type data_source: str :returns: A list of source-specific field names. :rtype: List[str] .. py:method:: _get_standardized_timestamp(date_input: Optional[Union[str, datetime.datetime]], is_end_date: bool) -> Optional[pandas.Timestamp] Converts any date input (str, datetime, or None) into a standardized, timezone-naive Pandas Timestamp in UTC, applying sensible defaults. :param date_input: The input date from data_req.start_date or data_req.end_date. :type date_input: Optional[Union[str, datetime]] :param is_end_date: True if processing end_date (defaults to now), False if start_date. :type is_end_date: bool :returns: The normalized Timestamp, or None if no date is provided and no default applies. :rtype: Optional[pd.Timestamp] .. py:method:: _convert_dates(format_type: str, default_start_str: Optional[str] = None) -> Tuple[Optional[Union[str, int, datetime.datetime]], Optional[Union[str, int, datetime.datetime]]] 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). :param format_type: 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) :type format_type: str :param default_start_str: A specific string to use if self.data_req.start_date is None. If None, the start date remains None. :type default_start_str: Optional[str] :returns: A tuple containing the converted start_date and end_date. :rtype: Tuple[Optional[Union[str, int, datetime]], Optional[Union[str, int, datetime]]] .. py:method:: convert(**kwargs: Any) -> Dict[str, Any] :abstractmethod: 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. :param \*\*kwargs: Additional keyword arguments for flexibility, typically vendor metadata. :type \*\*kwargs: Any :returns: A dictionary containing the vendor-specific parameters, which may include a list of requests under a key like 'requests'. :rtype: Dict[str, Any]